index.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  1. import React, { Component } from 'react';
  2. import Cropper from 'react-cropper';
  3. import 'cropperjs/dist/cropper.css';
  4. import './index.less';
  5. import { Checkbox, Icon } from 'antd';
  6. import FileUpload from '@src/components/FileUpload';
  7. import Assets from '@src/components/Assets';
  8. import scale from '@src/services/Scale';
  9. import { asyncSMessage } from '@src/services/AsyncTools';
  10. import AnswerButton from '../AnswerButton';
  11. import { SelectInput, VerificationInput, DefaultInput, Input, Textarea } from '../Input';
  12. import { MobileArea, TextbookFeedbackTarget, TextbookSubject, AskTarget, QrCodeAssets } from '../../../Constant';
  13. import Invite from '../Invite';
  14. import Modal from '../Modal';
  15. import { Common } from '../../stores/common';
  16. import { User } from '../../stores/user';
  17. import { My } from '../../stores/my';
  18. import Select from '../Select';
  19. import { formatDate, getMap, checkMobile, checkEmail } from '../../../../src/services/Tools';
  20. const TextbookFeedbackTargetMap = getMap(TextbookFeedbackTarget, 'value', 'tip');
  21. export class BindPhone extends Component {
  22. constructor(props) {
  23. super(props);
  24. this.validNumber = 0;
  25. this.props.data = this.props.data || {};
  26. this.state = Object.assign({ step: 0, data: {}, empty: {} }, this.initState(this.props));
  27. this.stepProp = {
  28. 0: {
  29. title: '绑定手机',
  30. onConfirm: props.onConfirm,
  31. },
  32. 1: {
  33. title: '绑定手机',
  34. onConfirm: () => {
  35. this.submit();
  36. },
  37. onCancel: props.onCancel,
  38. confirmText: '提交',
  39. },
  40. };
  41. }
  42. initState(props) {
  43. if (!props.show || this.props.show) return {};
  44. const data = Object.assign({}, props.data);
  45. if (!data.area) data.area = MobileArea[0].value;
  46. return { step: props.data.mobile ? 0 : 1, data, validError: '', empty: {} };
  47. }
  48. componentWillReceiveProps(nextProps) {
  49. this.setState(this.initState(nextProps));
  50. }
  51. onNext() {
  52. this.setState({ step: 1, validError: '', mobileError: '', empty: {} });
  53. }
  54. changeData(field, value) {
  55. let { data, empty } = this.state;
  56. data = data || {};
  57. empty = empty || {};
  58. data[field] = value;
  59. if (value) empty[field] = !value;
  60. this.setState({ data, empty, mobileError: null });
  61. }
  62. validMobile() {
  63. const { data } = this.state;
  64. const { area, mobile } = data;
  65. if (!area || !mobile) return;
  66. if (!checkMobile(mobile)) {
  67. this.setState({ mobileError: '请输入正确手机号' });
  68. return;
  69. }
  70. this.validNumber += 1;
  71. const number = this.validNumber;
  72. if (mobile === this.props.data.mobile) {
  73. this.setState({ mobileError: '' });
  74. return;
  75. }
  76. this.setState({ mobileError: '' });
  77. User.validMobile(area, mobile)
  78. .then(result => {
  79. if (number !== this.validNumber) return Promise.resolve();
  80. if (result) {
  81. this.setState({ mobileError: '' });
  82. return Promise.resolve();
  83. }
  84. return Promise.reject(new Error('该手机已绑定其他账号,请更换手机号码'));
  85. })
  86. .catch(err => {
  87. this.setState({ mobileError: err.message });
  88. });
  89. }
  90. sendValid() {
  91. const { data, mobileError } = this.state;
  92. const { area, mobile } = data;
  93. if (mobileError) return Promise.reject();
  94. if (!area || !mobile) {
  95. this.setState({ empty: { area: !data.area, mobile: !data.mobile } });
  96. return Promise.reject();
  97. }
  98. return Common.sendSms(area, mobile)
  99. .then(result => {
  100. if (result) {
  101. asyncSMessage('发送成功');
  102. this.setState({ mobileError: '', validError: '' });
  103. } else {
  104. throw new Error('发送失败');
  105. }
  106. })
  107. .catch(err => {
  108. this.setState({ mobileError: err.message });
  109. throw err;
  110. });
  111. }
  112. submit() {
  113. const { data, validError, mobileError } = this.state;
  114. if (validError || mobileError) return;
  115. const { area, mobile, mobileVerifyCode } = data;
  116. if (!area || !mobile || !mobileVerifyCode) {
  117. this.setState({ empty: { area: !data.area, mobile: !data.mobile, mobileVerifyCode: !mobileVerifyCode } });
  118. return;
  119. }
  120. My.bindMobile(area, mobile, mobileVerifyCode)
  121. .then(() => {
  122. asyncSMessage('操作成功');
  123. this.setState({ step: 0, validError: '', mobileError: '' });
  124. User.infoHandle(Object.assign(this.props.data, { area, mobile }));
  125. this.props.onConfirm();
  126. })
  127. .catch(err => {
  128. if (err.message.indexOf('验证码') >= 0) {
  129. this.setState({ validError: err.message });
  130. } else {
  131. this.setState({ mobileError: err.message });
  132. }
  133. });
  134. }
  135. render() {
  136. const { show } = this.props;
  137. const { step = 0 } = this.state;
  138. return (
  139. <Modal className="bind-phone-modal" show={show} width={630} {...this.stepProp[step]}>
  140. <div className="bind-phone-modal-wrapper">{this[`renderStep${step}`]()}</div>
  141. </Modal>
  142. );
  143. }
  144. renderStep0() {
  145. const { data } = this.state;
  146. return (
  147. <div className="step-0-layout t-2">
  148. 已绑定手机 {data.mobile}
  149. <a onClick={() => this.onNext()}>修改</a>
  150. </div>
  151. );
  152. }
  153. renderStep1() {
  154. return (
  155. <div className="step-1-layout">
  156. <div className="label">手机号</div>
  157. <div className="input-layout">
  158. <SelectInput
  159. className="w-10"
  160. placeholder="请输入手机号"
  161. selectValue={this.state.data.area}
  162. select={MobileArea}
  163. value={this.state.data.mobile}
  164. error={this.state.mobileError}
  165. empty={this.state.empty.mobile}
  166. onSelect={value => {
  167. this.changeData('area', value);
  168. this.validMobile();
  169. }}
  170. onChange={e => {
  171. this.changeData('mobile', e.target.value);
  172. this.validMobile();
  173. }}
  174. />
  175. <VerificationInput
  176. className="w-10"
  177. placeholder="请输入验证码"
  178. value={this.state.data.mobileVerifyCode}
  179. error={this.state.validError}
  180. empty={this.state.empty.mobileVerifyCode}
  181. onSend={() => {
  182. return this.sendValid();
  183. }}
  184. onChange={e => {
  185. this.changeData('mobileVerifyCode', e.target.value);
  186. this.setState({ validError: '' });
  187. }}
  188. />
  189. </div>
  190. </div>
  191. );
  192. }
  193. }
  194. export class BindEmail extends Component {
  195. constructor(props) {
  196. super(props);
  197. this.validNumber = 0;
  198. this.props.data = this.props.data || {};
  199. this.state = Object.assign({ step: 0, data: {}, empty: {} }, this.initState(this.props));
  200. this.stepProp = {
  201. 0: {
  202. title: '绑定邮箱',
  203. onConfirm: props.onConfirm,
  204. },
  205. 1: {
  206. title: '绑定邮箱',
  207. onConfirm: () => {
  208. this.submit();
  209. },
  210. onCancel: props.onCancel,
  211. confirmText: '提交',
  212. },
  213. };
  214. }
  215. initState(props) {
  216. if (!props.show || this.props.show) return {};
  217. return { step: props.data.email ? 0 : 1, data: Object.assign({}, props.data) };
  218. }
  219. componentWillReceiveProps(nextProps) {
  220. this.setState(this.initState(nextProps));
  221. }
  222. onNext() {
  223. this.setState({ step: 1, error: '', empty: {} });
  224. }
  225. changeData(field, value) {
  226. let { data, empty } = this.state;
  227. data = data || {};
  228. empty = empty || {};
  229. data[field] = value;
  230. if (value) empty[field] = !value;
  231. this.setState({ data, empty, error: null });
  232. }
  233. validEmail() {
  234. const { data } = this.state;
  235. const { email } = data;
  236. if (!email) return;
  237. if (!checkEmail(email)) {
  238. this.setState({ error: '请输入正确邮箱' });
  239. return;
  240. }
  241. this.validNumber += 1;
  242. const number = this.validNumber;
  243. if (email === this.props.data.email) {
  244. this.setState({ error: '' });
  245. return;
  246. }
  247. this.setState({ error: '' });
  248. User.validEmail(email)
  249. .then(result => {
  250. if (number !== this.validNumber) return Promise.resolve();
  251. if (result) {
  252. this.setState({ error: '' });
  253. return Promise.resolve();
  254. }
  255. return Promise.reject(new Error('该邮箱已绑定其他账号,请更换邮箱地址'));
  256. })
  257. .catch(err => {
  258. this.setState({ error: err.message });
  259. });
  260. }
  261. submit() {
  262. const { data, error } = this.state;
  263. if (error) return;
  264. if (!data.email) {
  265. this.setState({ empty: { email: !data.email } });
  266. return;
  267. }
  268. const { email } = data;
  269. My.bindEmail(email)
  270. .then(() => {
  271. asyncSMessage('操作成功');
  272. this.setState({ step: 0, error: '' });
  273. User.infoHandle(Object.assign(this.props.data, { email }));
  274. this.props.onConfirm();
  275. })
  276. .catch(e => {
  277. this.setState({ error: e.message });
  278. });
  279. }
  280. render() {
  281. const { show } = this.props;
  282. const { step = 0 } = this.state;
  283. return (
  284. <Modal className="bind-email-modal" show={show} width={630} {...this.stepProp[step]}>
  285. <div className="bind-email-modal-wrapper">{this[`renderStep${step}`]()}</div>
  286. </Modal>
  287. );
  288. }
  289. renderStep0() {
  290. const { data } = this.state;
  291. return (
  292. <div className="step-0-layout t-2">
  293. 已绑定邮箱 {data.email}
  294. <a onClick={() => this.onNext()}>修改</a>
  295. </div>
  296. );
  297. }
  298. renderStep1() {
  299. return (
  300. <div className="step-1-layout">
  301. <div className="label">邮箱地址</div>
  302. <div className="input-layout">
  303. <DefaultInput
  304. className="w-10"
  305. placeholder="请输入邮箱"
  306. value={this.state.data.email}
  307. error={this.state.error}
  308. empty={this.state.empty.email}
  309. onChange={e => {
  310. this.changeData('email', e.target.value);
  311. this.validEmail();
  312. }}
  313. />
  314. </div>
  315. </div>
  316. );
  317. }
  318. }
  319. export class EditInfo extends Component {
  320. constructor(props) {
  321. super(props);
  322. this.props.data = this.props.data || {};
  323. this.state = Object.assign({ data: {}, empty: {} }, this.initState(this.props));
  324. }
  325. initState(props) {
  326. if (props.image && this.waitImage) {
  327. const { state } = this;
  328. Common.upload(props.image)
  329. .then(result => {
  330. const { data } = this.state;
  331. data.avatar = result.url;
  332. this.setState({ data, uploading: false });
  333. })
  334. .catch(e => {
  335. this.setState({ imageError: e.message });
  336. });
  337. state.uploading = true;
  338. this.waitImage = false;
  339. return state;
  340. }
  341. if (!props.show || this.props.show) return {};
  342. return { data: Object.assign({}, props.data) };
  343. }
  344. componentWillReceiveProps(nextProps) {
  345. this.setState(this.initState(nextProps));
  346. }
  347. changeData(field, value) {
  348. let { data, empty } = this.state;
  349. data = data || {};
  350. empty = empty || {};
  351. data[field] = value;
  352. if (value) empty[field] = !value;
  353. this.setState({ data, empty, nicknameError: null });
  354. }
  355. strLen(str) {
  356. let len = 0;
  357. for (let i = 0; i < str.length; i += 1) {
  358. if (str.charCodeAt(i) > 255 || str.charCodeAt(i) < 0) len += 2; else len += 1;
  359. }
  360. return len;
  361. }
  362. // 将字符串拆成字符,并存到数组中
  363. strToChars(str) {
  364. const chars = [];
  365. for (let i = 0; i < str.length; i += 1) {
  366. chars[i] = [str.substr(i, 1), this.isCHS(str, i)];
  367. }
  368. return chars;
  369. }
  370. // 判断某个字符是否是汉字
  371. isCHS(str, i) {
  372. if (str.charCodeAt(i) > 255 || str.charCodeAt(i) < 0) {
  373. return true;
  374. }
  375. return false;
  376. }
  377. // 截取字符串(从start字节到end字节)
  378. subCHString(str, start, end) {
  379. let len = 0;
  380. let s = '';
  381. const chars = this.strToChars(str);
  382. for (let i = 0; i < str.length; i += 1) {
  383. if (chars[i][1]) {
  384. len += 2;
  385. } else {
  386. len += 1;
  387. }
  388. if (end < len) {
  389. return s;
  390. }
  391. if (start < len) {
  392. s += chars[i][0];
  393. }
  394. }
  395. return s;
  396. }
  397. // 截取字符串(从start字节截取length个字节)
  398. subCHStr(str, start, length) {
  399. return this.subCHString(str, start, start + length);
  400. }
  401. submit() {
  402. const { data, nicknameError } = this.state;
  403. if (nicknameError) return;
  404. if (!data.nickname) {
  405. this.setState({ empty: { nickname: !data.nickname } });
  406. return;
  407. }
  408. const len = this.strLen(data.nickname);
  409. if (len < 2 || len > 14) {
  410. this.setState({ nicknameError: '用户名长度不足2个字符或超过14个字符' });
  411. return;
  412. }
  413. const { nickname, avatar } = data;
  414. My.editInfo({ nickname, avatar })
  415. .then(() => {
  416. asyncSMessage('操作成功');
  417. User.infoHandle(Object.assign(this.props.data, { nickname, avatar }));
  418. this.props.onConfirm();
  419. this.setState({ nicknameError: '' });
  420. })
  421. .catch(e => {
  422. this.setState({ nicknameError: e.message });
  423. });
  424. }
  425. render() {
  426. const { show, onCancel, onSelectImage } = this.props;
  427. return (
  428. <Modal
  429. className="edit-info-modal"
  430. show={show}
  431. width={630}
  432. title="修改资料"
  433. confirmText="保存"
  434. onCancel={onCancel}
  435. onConfirm={() => {
  436. this.submit();
  437. }}
  438. >
  439. <div className="edit-info-modal-wrapper">
  440. <div className="edit-info-modal-block">
  441. <div className="label">用户名</div>
  442. <div className="input-layout">
  443. <DefaultInput
  444. className="w-10"
  445. placeholder="2-14个字符。"
  446. value={this.state.data.nickname || ''}
  447. error={this.state.nicknameError}
  448. empty={this.state.empty.nickname}
  449. onChange={e => {
  450. this.changeData('nickname', e.target.value);
  451. }}
  452. />
  453. </div>
  454. </div>
  455. <div className="edit-info-modal-block">
  456. <div className="label">头像</div>
  457. <div className="input-layout">
  458. <FileUpload
  459. uploading={this.state.uploading}
  460. value={this.state.data.avatar}
  461. onUpload={({ file }) => {
  462. this.waitImage = true;
  463. onSelectImage(file);
  464. return Promise.reject();
  465. }}
  466. />
  467. {this.state.imageError || ''}
  468. </div>
  469. </div>
  470. </div>
  471. </Modal>
  472. );
  473. }
  474. }
  475. export class RealAuth extends Component {
  476. constructor(props) {
  477. super(props);
  478. this.state = { data: {} };
  479. }
  480. render() {
  481. const { show, onConfirm } = this.props;
  482. return (
  483. <Modal
  484. className="real-auth-modal"
  485. show={show}
  486. width={630}
  487. title="实名认证"
  488. confirmText="好的,知道了"
  489. btnAlign="center"
  490. onConfirm={onConfirm}
  491. >
  492. <div className="real-auth-modal-wrapper">
  493. <div className="real-auth-text">
  494. <div className="t1">完成实名认证即可领取:</div>
  495. <div className="t2">30天VIP权限。</div>
  496. <div className="t3">扫码关注公众号,点击“我的-实名认证”</div>
  497. </div>
  498. <div className="real-auth-qrcode">
  499. <Assets name={QrCodeAssets} width={150} height={150} />
  500. </div>
  501. </div>
  502. </Modal>
  503. );
  504. }
  505. }
  506. export class EditAvatar extends Component {
  507. constructor(props) {
  508. super(props);
  509. this.state = Object.assign({ data: {} }, this.initState(this.props));
  510. }
  511. initState(props) {
  512. if (props.image) this.loadImage(props.image);
  513. if (!props.show || this.props.show) return {};
  514. return { data: {} };
  515. }
  516. componentWillReceiveProps(nextProps) {
  517. this.setState(this.initState(nextProps));
  518. }
  519. loadImage(file) {
  520. this.defaultZoomValue = 1;
  521. if (window.FileReader) {
  522. const reader = new FileReader();
  523. reader.readAsDataURL(file);
  524. // 渲染文件
  525. reader.onload = arg => {
  526. this.setState({ image: arg.target.result, fileName: file.name, zoomValue: 1 });
  527. };
  528. } else {
  529. const img = new Image();
  530. img.onload = function () {
  531. const canvas = document.createElement('canvas');
  532. canvas.height = img.height;
  533. canvas.width = img.width;
  534. const ctx = canvas.getContext('2d');
  535. ctx.drawImage(img, 0, 0);
  536. this.setState({ image: canvas.toDataURL() });
  537. };
  538. img.src = '1.gif';
  539. }
  540. }
  541. computerZoom() {
  542. const data = this.cropRef.getImageData();
  543. this.defaultZoomValue = 200 / parseFloat(Math.max(data.naturalWidth, data.naturalHeight));
  544. }
  545. crop() {
  546. // image in dataUrl
  547. // console.log(this.cropRef.getCroppedCanvas().toDataURL())
  548. // const canvas = this.cropRef.getCroppedCanvas();
  549. // const avatar = scale(this.props.crop, canvas, 'png-src');
  550. // let scaleCanvas = this.cropRef.getCroppedCanvas(this.props.crop)
  551. // this.setState({ avatar });
  552. }
  553. select() {
  554. const { fileName } = this.state;
  555. const { onConfirm } = this.props;
  556. const canvas = this.cropRef.getCroppedCanvas();
  557. const scaleCanvas = scale(this.props.crop, canvas);
  558. // let scaleCanvas = this.cropRef.getCroppedCanvas(this.props.crop)
  559. scaleCanvas.toBlob(blob => {
  560. const file = new File([blob], fileName);
  561. onConfirm(file);
  562. });
  563. }
  564. render() {
  565. const { show, onCancel } = this.props;
  566. const { image } = this.state;
  567. return (
  568. <Modal
  569. className="edit-avatar-modal"
  570. show={show}
  571. width={630}
  572. title="调整头像"
  573. confirmText="保存头像"
  574. onConfirm={() => {
  575. this.select();
  576. }}
  577. onCancel={onCancel}
  578. >
  579. <div className="edit-avatar-modal-wrapper">
  580. <div className="edit-avatar-o">
  581. <Cropper
  582. ref={ref => {
  583. this.cropRef = ref;
  584. }}
  585. src={image}
  586. ready={() => {
  587. this.computerZoom();
  588. }}
  589. style={{ height: 360, width: 360 }}
  590. // Cropper.js options
  591. aspectRatio={1}
  592. viewMode={0}
  593. // autoCropArea={0.8}
  594. preview=".img-preview"
  595. // dragMode='move'
  596. guides={false}
  597. movable={false}
  598. rotatable={false}
  599. scalable={false}
  600. // zoom={(value) => {
  601. // console.log('zoom', value);
  602. // const zoomValue = value * this.defaultZoomValue / 50;
  603. // this.cropRef.zoomTo(zoomValue);
  604. // }}
  605. cropmove={() => {
  606. this.crop();
  607. }}
  608. toggleDragModeOnDblclick={false}
  609. cropBoxResizable
  610. />
  611. </div>
  612. <div className="edit-avatar-r">
  613. <div className="text">头像预览</div>
  614. <div className="img-preview" style={{ width: 100, height: 100, overflow: 'hidden' }} />
  615. </div>
  616. </div>
  617. </Modal>
  618. );
  619. }
  620. }
  621. export class InviteModal extends Component {
  622. constructor(props) {
  623. super(props);
  624. this.state = { data: {} };
  625. }
  626. render() {
  627. const { show, onClose, data } = this.props;
  628. return (
  629. <Modal className="invite-modal" show={show} width={630} title="邀请好友" onClose={onClose}>
  630. <div className="invite-modal-wrapper">
  631. <div className="tip">每邀请一位小伙伴加入“千行GMAT”, 您的VIP权限会延长7天,可累加 无上限!赶紧行动吧~</div>
  632. <Invite data={data} />
  633. </div>
  634. </Modal>
  635. );
  636. }
  637. }
  638. // 模考选择下载
  639. export class DownloadModal extends Component {
  640. constructor(props) {
  641. super(props);
  642. this.state = { checkMap: {} };
  643. }
  644. onConfirm() {
  645. const { onConfirm, data } = this.props;
  646. if (onConfirm) onConfirm();
  647. const { checkMap } = this.state;
  648. Object.keys(checkMap).forEach(key => {
  649. if (!checkMap[key]) return;
  650. const link = data[`${key}`];
  651. if (link) {
  652. openLink(`${link}&download=true`);
  653. }
  654. });
  655. this.setState({ checkList: [] });
  656. }
  657. render() {
  658. const { show, data = {}, onCancel } = this.props;
  659. const { checkMap = {} } = this.state;
  660. const quantVersion = data.quantVersion || 0;
  661. const irVersion = data.irVersion || 0;
  662. const rcVersion = data.rcVersion || 0;
  663. return (
  664. <Modal
  665. className="download-modal"
  666. show={show}
  667. width={570}
  668. title="下载"
  669. confirmText="下载"
  670. onConfirm={() => this.onConfirm()}
  671. onCancel={onCancel}
  672. >
  673. <div className="download-modal-wrapper">
  674. <div className="t-2 t-s-18 m-b-1">请选择下载科目</div>
  675. <div className="m-b-1">
  676. {quantVersion > 0 && (
  677. <div className="t-2 t-s-16">
  678. <Checkbox
  679. checked={checkMap.quant}
  680. onChange={() => {
  681. checkMap.quant = !checkMap.quant;
  682. this.setState({ checkMap });
  683. }}
  684. />
  685. <span className="m-l-5">数学</span>
  686. <span className="t-8">
  687. (版本{quantVersion} 最后更新:{formatDate(data.quantTime, 'YYYY-MM-DD HH:mm:ss')})
  688. </span>
  689. </div>
  690. )}
  691. {irVersion > 0 && (
  692. <div className="t-2 t-s-16">
  693. <Checkbox
  694. checked={checkMap.ir}
  695. onChange={() => {
  696. checkMap.ir = !checkMap.ir;
  697. this.setState({ checkMap });
  698. }}
  699. />
  700. <span className="m-l-5">逻辑</span>
  701. <span className="t-8">
  702. (版本{irVersion} 最后更新:{formatDate(data.irTime, 'YYYY-MM-DD HH:mm:ss')})
  703. </span>
  704. </div>
  705. )}
  706. {rcVersion > 0 && (
  707. <div className="t-2 t-s-16">
  708. <Checkbox
  709. checked={checkMap.rc}
  710. onChange={() => {
  711. checkMap.rc = !checkMap.rc;
  712. this.setState({ checkMap });
  713. }}
  714. />
  715. <span className="m-l-5">阅读</span>
  716. <span className="t-8">
  717. (版本{rcVersion} 最后更新:{formatDate(data.rcTime, 'YYYY-MM-DD HH:mm:ss')})
  718. </span>
  719. </div>
  720. )}
  721. </div>
  722. </div>
  723. </Modal>
  724. );
  725. }
  726. }
  727. // 模考开通确认
  728. export class OpenConfirmModal extends Component {
  729. render() {
  730. const { show, onConfirm, onCancel, data = {} } = this.props;
  731. return (
  732. <Modal
  733. className="open-confirm-modal"
  734. show={show}
  735. width={570}
  736. title="开通确认"
  737. confirmText="开通"
  738. cancelText="暂不开通"
  739. onConfirm={onConfirm}
  740. onCancel={onCancel}
  741. >
  742. <div className="open-confirm-modal-wrapper m-b-2">
  743. <div className="t-2 t-s-18">您正在开通「{data.title}」。</div>
  744. <div className="t-2 t-s-18">模考有效期至:{data.endTime && formatDate(data.endTime, 'YYYY-MM-DD')}</div>
  745. </div>
  746. </Modal>
  747. );
  748. }
  749. }
  750. // 模考重置确认
  751. export class RestartConfirmModal extends Component {
  752. render() {
  753. const { show, onConfirm, onCancel } = this.props;
  754. return (
  755. <Modal
  756. className="restart-confirm-modal"
  757. show={show}
  758. width={570}
  759. title="重置确认"
  760. confirmText="立即重置"
  761. cancelText="暂不重置"
  762. onConfirm={onConfirm}
  763. onCancel={onCancel}
  764. >
  765. <div className="restart-confirm-modal-wrapper m-b-2">
  766. <div className="t-2 t-s-18">重置后,可进行新一轮的模考。 </div>
  767. <div className="t-2 t-s-18 m-b-2">本轮模考的成绩和报告可在本页面或「我的报告」查看。 </div>
  768. <div className="t-2 t-s-18 m-b-1">只有 1 次重置机会。</div>
  769. </div>
  770. </Modal>
  771. );
  772. }
  773. }
  774. export class FeedbackErrorDataModal extends Component {
  775. constructor(props) {
  776. super(props);
  777. this.state = { data: { position: ['', '', ''], content: '', originContent: '' } };
  778. }
  779. componentWillReceiveProps(nextProps) {
  780. if (nextProps.show && nextProps.defaultData) {
  781. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  782. }
  783. }
  784. changeData(field, value) {
  785. let { data, empty } = this.state;
  786. data = data || {};
  787. empty = empty || {};
  788. data[field] = value;
  789. if (value) empty[field] = !value;
  790. this.setState({ data, empty });
  791. }
  792. changeDataIndex(field, index, value) {
  793. let { data, empty } = this.state;
  794. data = data || {};
  795. empty = empty || {};
  796. data[field][index] = value;
  797. if (value) empty[`${field}[${index}]`] = !value;
  798. this.setState({ data, empty });
  799. }
  800. onConfirm() {
  801. const { onConfirm } = this.props;
  802. const { data } = this.state;
  803. if (!data.position[0] || !data.position[1] || !data.position[2] || !data.content || !data.originContent) {
  804. this.setState({
  805. empty: {
  806. 'position[0]': !data.position[0],
  807. 'position[1]': !data.position[1],
  808. 'position[2]': !data.position[2],
  809. content: !data.content,
  810. originContent: !data.originContent,
  811. },
  812. });
  813. return Promise.reject();
  814. }
  815. return My.addFeedbackErrorData(
  816. data.dataId,
  817. data.title,
  818. data.position.join(','),
  819. data.originContent,
  820. data.content,
  821. ).then(() => {
  822. this.setState({ data: { position: ['', '', ''], content: '', originContent: '' } });
  823. if (onConfirm) onConfirm();
  824. });
  825. }
  826. onCancel() {
  827. const { onCancel } = this.props;
  828. this.setState({ data: { position: ['', '', ''], content: '', originContent: '' } });
  829. if (onCancel) onCancel();
  830. }
  831. render() {
  832. const { show } = this.props;
  833. const { data, empty = {} } = this.state;
  834. return (
  835. <Modal
  836. show={show}
  837. title="纠错"
  838. btnType="link"
  839. width={630}
  840. onConfirm={() => this.onConfirm()}
  841. onCancel={() => this.onCancel()}
  842. >
  843. <div className="t-2 m-b-1 t-s-16">
  844. 定位:
  845. <Input
  846. value={data.position[0]}
  847. className="t-c b-c-1 m-r-5"
  848. style={{ width: 56 }}
  849. empty={empty['position[0]']}
  850. onChange={e => {
  851. this.changeDataIndex('position', 0, e.target.value);
  852. }}
  853. />
  854. <span className="require">页</span>
  855. <Input
  856. value={data.position[1]}
  857. className="t-c b-c-1 m-r-5"
  858. style={{ width: 56 }}
  859. empty={empty['position[1]']}
  860. onChange={e => {
  861. this.changeDataIndex('position', 1, e.target.value);
  862. }}
  863. />
  864. <span className="require">行</span> , 题号
  865. <Input
  866. value={data.position[2]}
  867. className="t-c b-c-1"
  868. style={{ width: 56 }}
  869. empty={empty['position[2]']}
  870. onChange={e => {
  871. this.changeDataIndex('position', 2, e.target.value);
  872. }}
  873. />
  874. </div>
  875. <div className="t-2 t-s-16">错误内容是:</div>
  876. <Textarea
  877. value={data.originContent}
  878. className="b-c-1 w-10 p-10"
  879. rows={10}
  880. placeholder={'可简单描述您发现的问题'}
  881. empty={empty.originContent}
  882. onChange={e => {
  883. this.changeData('originContent', e.target.value);
  884. }}
  885. />
  886. <div className="t-2 t-s-16">应该更改为:</div>
  887. <Textarea
  888. value={data.content}
  889. className="b-c-1 w-10 p-10"
  890. rows={10}
  891. placeholder={'提供您认为正确的内容即可'}
  892. empty={empty.content}
  893. onChange={e => {
  894. this.changeData('content', e.target.value);
  895. }}
  896. />
  897. <div className="b-b m-t-2" />
  898. </Modal>
  899. );
  900. }
  901. }
  902. export class AskCourseModal extends Component {
  903. constructor(props) {
  904. super(props);
  905. this.state = { data: { position: [], content: '', originContent: '' } };
  906. }
  907. componentWillReceiveProps(nextProps) {
  908. if (nextProps.show && nextProps.defaultData) {
  909. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  910. }
  911. }
  912. changeData(field, value) {
  913. let { data, empty } = this.state;
  914. data = data || {};
  915. empty = empty || {};
  916. data[field] = value;
  917. if (value) empty[field] = !value;
  918. this.setState({ data, empty });
  919. }
  920. onConfirm() {
  921. const { course, courseNo, onConfirm } = this.props;
  922. const { data } = this.state;
  923. if (!data.content || !data.originContent) {
  924. this.setState({ empty: { content: !data.content, originContent: !data.originContent } });
  925. return Promise.reject();
  926. }
  927. return My.addCourseAsk(course.id, courseNo.id, data.position.join(','), data.originContent, data.content).then(
  928. () => {
  929. this.setState({ data: { position: [], content: '', originContent: '' } });
  930. if (onConfirm) onConfirm();
  931. },
  932. );
  933. }
  934. onCancel() {
  935. const { onCancel } = this.props;
  936. this.setState({ data: { position: [], content: '', originContent: '' } });
  937. if (onCancel) onCancel();
  938. }
  939. render() {
  940. const { show, selectList, courseNo, getContainer } = this.props;
  941. const { data, empty = {} } = this.state;
  942. return (
  943. <Modal
  944. show={show}
  945. title="提问"
  946. btnType="link"
  947. width={630}
  948. getContainer={getContainer}
  949. confirmText="提交"
  950. onConfirm={() => this.onConfirm()}
  951. onCancel={() => this.onCancel()}
  952. >
  953. <div className="t-2 m-b-1 t-s-16">
  954. 针对<span className="t-4">课时{courseNo.no}</span>的{' '}
  955. <Select
  956. value={data.position}
  957. theme="white"
  958. list={selectList}
  959. onChange={item => {
  960. this.changeData('position', item.key);
  961. }}
  962. />
  963. 进行提问.
  964. </div>
  965. <div className="t-2 t-s-16">老师讲解的内容是:</div>
  966. <Textarea
  967. value={data.originContent}
  968. className="b-c-1 w-10 p-10"
  969. rows={4}
  970. placeholder={'请简单描述,以便老师准确定位。'}
  971. empty={empty.originContent}
  972. onChange={e => {
  973. this.changeData('originContent', e.target.value);
  974. }}
  975. />
  976. <div className="t-2 t-s-16">您的问题是:</div>
  977. <Textarea
  978. value={data.content}
  979. className="b-c-1 w-10 p-10"
  980. rows={4}
  981. placeholder={'老师会在n小时内回答你的问题。'}
  982. onChange={e => {
  983. this.changeData('content', e.target.value);
  984. }}
  985. />
  986. <div className="b-b m-t-2" />
  987. </Modal>
  988. );
  989. }
  990. }
  991. export class CourseNoteModal extends Component {
  992. constructor(props) {
  993. super(props);
  994. this.state = { data: { content: '' } };
  995. }
  996. componentWillReceiveProps(nextProps) {
  997. if (nextProps.show && nextProps.defaultData) {
  998. this.setState({ data: Object.assign({}, nextProps.defaultData) });
  999. }
  1000. }
  1001. changeData(field, value) {
  1002. let { data, empty } = this.state;
  1003. data = data || {};
  1004. empty = empty || {};
  1005. data[field] = value;
  1006. if (value) empty[field] = !value;
  1007. this.setState({ data, empty });
  1008. }
  1009. onConfirm() {
  1010. const { course, onConfirm } = this.props;
  1011. const { data } = this.state;
  1012. if (!data.content) {
  1013. this.setState({ empty: { content: !data.content } });
  1014. return Promise.reject();
  1015. }
  1016. if (!data.courseNoId) {
  1017. data.courseNoId = this.state.courseNos[0].id;
  1018. }
  1019. return My.updateCourseNote(course.id, data.courseNoId, data.content).then(() => {
  1020. this.setState({ data: { content: '' } });
  1021. if (onConfirm) onConfirm();
  1022. });
  1023. }
  1024. onCancel() {
  1025. const { onCancel } = this.props;
  1026. this.setState({ data: { content: '' } });
  1027. if (onCancel) onCancel();
  1028. }
  1029. render() {
  1030. const { show, course = {}, courseNos = [], noteMap = {}, getContainer } = this.props;
  1031. const { data, empty = {} } = this.state;
  1032. return (
  1033. <Modal
  1034. show={show}
  1035. title="笔记"
  1036. width={630}
  1037. getContainer={getContainer}
  1038. confirmText="提交"
  1039. onConfirm={() => this.onConfirm()}
  1040. onCancel={() => this.onCancel()}
  1041. >
  1042. <div className="t-2 m-b-1 t-s-16">
  1043. {course.title}
  1044. <Select
  1045. theme="white"
  1046. value={data.courseNoId}
  1047. list={courseNos.map(row => {
  1048. return {
  1049. title: `课时${row.no}`,
  1050. key: row.id,
  1051. };
  1052. })}
  1053. onChange={item => {
  1054. if (data.courseNoId !== item.key) {
  1055. data.courseNoId = item.key;
  1056. data.content = noteMap[item.key] ? noteMap[item.key].content : '';
  1057. }
  1058. this.setState({ data });
  1059. }}
  1060. />
  1061. </div>
  1062. <Textarea
  1063. value={data.content}
  1064. className="b-c-1 w-10 p-10"
  1065. rows={10}
  1066. placeholder={'写下笔记,方便以后复习。'}
  1067. empty={empty.content}
  1068. onChange={e => {
  1069. this.changeData('content', e.target.value);
  1070. }}
  1071. />
  1072. <div className="b-b m-t-2" />
  1073. </Modal>
  1074. );
  1075. }
  1076. }
  1077. export class TextbookFeedbackModal extends Component {
  1078. constructor(props) {
  1079. super(props);
  1080. this.state = {
  1081. data: { content: '' },
  1082. targetList: TextbookFeedbackTarget.map(row => {
  1083. return {
  1084. title: row.label,
  1085. key: row.value,
  1086. };
  1087. }),
  1088. textbookSubject: TextbookSubject.map(row => {
  1089. return {
  1090. title: row.label,
  1091. key: row.value,
  1092. };
  1093. }),
  1094. };
  1095. }
  1096. componentWillReceiveProps(nextProps) {
  1097. if (nextProps.show && nextProps.defaultData) {
  1098. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  1099. }
  1100. }
  1101. changeData(field, value) {
  1102. let { data, empty } = this.state;
  1103. data = data || {};
  1104. empty = empty || {};
  1105. data[field] = value;
  1106. if (value) empty[field] = !value;
  1107. this.setState({ data, empty });
  1108. }
  1109. onConfirm() {
  1110. const { onConfirm } = this.props;
  1111. const { data } = this.state;
  1112. if (data.target !== 'new' && (!data.no || !data.content)) {
  1113. this.setState({ empty: { content: !data.content, no: !data.no } });
  1114. return Promise.reject();
  1115. }
  1116. if (!data.content) {
  1117. this.setState({ empty: { content: !data.content } });
  1118. return Promise.reject();
  1119. }
  1120. return My.addTextbookFeedback(data.textbookSubject, data.target, data.no, data.content)
  1121. .then(() => {
  1122. this.setState({ data: { content: '' } });
  1123. if (onConfirm) onConfirm();
  1124. })
  1125. .catch(e => {
  1126. asyncSMessage(e.message, 'error');
  1127. });
  1128. }
  1129. onCancel() {
  1130. const { onCancel } = this.props;
  1131. this.setState({ data: { content: '' } });
  1132. if (onCancel) onCancel();
  1133. }
  1134. render() {
  1135. const { show } = this.props;
  1136. const { data, targetList, textbookSubject, empty = {} } = this.state;
  1137. return (
  1138. <Modal show={show} title="反馈" width={630} onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
  1139. <div className="t-2 t-s-16 m-b-1">
  1140. 机经类别:{' '}
  1141. <Select
  1142. value={data.textbookSubject}
  1143. theme="white"
  1144. list={textbookSubject}
  1145. onChange={value => {
  1146. data.textbookSubject = value;
  1147. this.setState({ data });
  1148. }}
  1149. />
  1150. 反馈类型:{' '}
  1151. <Select
  1152. value={data.target}
  1153. theme="white"
  1154. list={targetList}
  1155. onChange={({ key }) => {
  1156. data.target = key;
  1157. this.setState({ data });
  1158. }}
  1159. />
  1160. <span hidden={data.target === 'new'}>
  1161. {' '}
  1162. 题号是{' '}
  1163. <Input
  1164. value={data.no}
  1165. style={{ width: 80 }}
  1166. className="m-l-1 b-c-1 t-c"
  1167. empty={empty.no}
  1168. onChange={e => {
  1169. this.changeData('no', e.target.value);
  1170. }}
  1171. />
  1172. </span>
  1173. </div>
  1174. <div className="t-2 t-s-16">{TextbookFeedbackTargetMap[data.target]}:</div>
  1175. <Textarea
  1176. value={data.content}
  1177. className="b-c-1 w-10 p-10"
  1178. rows={10}
  1179. placeholder={TextbookFeedbackTargetMap[data.target]}
  1180. empty={empty.content}
  1181. onChange={e => {
  1182. this.changeData('content', e.target.value);
  1183. }}
  1184. />
  1185. <div className="b-b m-t-2" />
  1186. </Modal>
  1187. );
  1188. }
  1189. }
  1190. export class FaqModal extends Component {
  1191. constructor(props) {
  1192. super(props);
  1193. this.state = { data: { content: '' } };
  1194. }
  1195. componentWillReceiveProps(nextProps) {
  1196. if (nextProps.defaultData && nextProps.show) {
  1197. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  1198. }
  1199. }
  1200. changeData(field, value) {
  1201. let { data, empty } = this.state;
  1202. data = data || {};
  1203. empty = empty || {};
  1204. data[field] = value;
  1205. if (value) empty[field] = !value;
  1206. this.setState({ data, empty });
  1207. }
  1208. onConfirm() {
  1209. const { onConfirm } = this.props;
  1210. const { data } = this.state;
  1211. if (!data.content) {
  1212. this.setState({ empty: { content: !data.content } });
  1213. return Promise.reject();
  1214. }
  1215. return My.addFaq(data.channel, data.position, data.content).then(() => {
  1216. this.setState({ data: { content: '' } });
  1217. if (onConfirm) onConfirm();
  1218. });
  1219. }
  1220. onCancel() {
  1221. const { onCancel } = this.props;
  1222. this.setState({ data: { content: '' } });
  1223. if (onCancel) onCancel();
  1224. }
  1225. render() {
  1226. const { show } = this.props;
  1227. const { data, empty = {} } = this.state;
  1228. return (
  1229. <Modal show={show} title="咨询" onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
  1230. <Textarea
  1231. className="b-c-1 w-10 p-10"
  1232. value={data.content}
  1233. rows={6}
  1234. placeholder="请输入您的问题!"
  1235. empty={empty.content}
  1236. onChange={e => {
  1237. this.changeData('content', e.target.value);
  1238. }}
  1239. />
  1240. <div className="b-b m-t-2" />
  1241. </Modal>
  1242. );
  1243. }
  1244. }
  1245. export class CommentModal extends Component {
  1246. constructor(props) {
  1247. super(props);
  1248. this.state = { data: { content: '' } };
  1249. }
  1250. componentWillReceiveProps(nextProps) {
  1251. if (nextProps.show && nextProps.defaultData) {
  1252. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  1253. }
  1254. }
  1255. changeData(field, value) {
  1256. let { data, empty } = this.state;
  1257. data = data || {};
  1258. empty = empty || {};
  1259. data[field] = value;
  1260. if (value) empty[field] = !value;
  1261. this.setState({ data, empty });
  1262. }
  1263. onConfirm() {
  1264. const { onConfirm } = this.props;
  1265. const { data } = this.state;
  1266. if (!data.content) {
  1267. this.setState({ empty: { content: !data.content } });
  1268. return Promise.reject();
  1269. }
  1270. return My.addComment(data.channel, data.position, data.content).then(() => {
  1271. this.setState({ data: { content: '' } });
  1272. if (onConfirm) onConfirm();
  1273. });
  1274. }
  1275. onCancel() {
  1276. const { onCancel } = this.props;
  1277. this.setState({ data: { content: '' } });
  1278. if (onCancel) onCancel();
  1279. }
  1280. render() {
  1281. const { show } = this.props;
  1282. const { data, empty = {} } = this.state;
  1283. return (
  1284. <Modal show={show} title="评价" onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
  1285. <Textarea
  1286. value={data.content}
  1287. className="b-c-1 w-10 p-10"
  1288. rows={6}
  1289. placeholder="您的看法对我们来说很重要!"
  1290. empty={empty.content}
  1291. onChange={e => {
  1292. this.changeData('content', e.target.value);
  1293. }}
  1294. />
  1295. <div className="b-b m-t-2" />
  1296. </Modal>
  1297. );
  1298. }
  1299. }
  1300. export class FinishModal extends Component {
  1301. render() {
  1302. const { show, onConfirm } = this.props;
  1303. return (
  1304. <Modal show={show} title="提交成功" confirmText="好的,知道了" btnAlign="center" onConfirm={() => onConfirm()}>
  1305. <div className="t-2 t-s-18">
  1306. <Icon type="check" className="t-5 m-r-5" />
  1307. 您的每一次反馈都是千行进步的动力。
  1308. </div>
  1309. </Modal>
  1310. );
  1311. }
  1312. }
  1313. export class SuppleModal extends Component {
  1314. constructor(props) {
  1315. super(props);
  1316. this.state = { data: { content: '' } };
  1317. }
  1318. componentWillReceiveProps(nextProps) {
  1319. if (nextProps.show && nextProps.defaultData) {
  1320. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  1321. }
  1322. }
  1323. changeData(field, value) {
  1324. let { data, empty } = this.state;
  1325. data = data || {};
  1326. empty = empty || {};
  1327. data[field] = value;
  1328. if (value) empty[field] = !value;
  1329. this.setState({ data, empty });
  1330. }
  1331. onConfirm() {
  1332. const { onConfirm } = this.props;
  1333. const { data } = this.state;
  1334. if (!data.content) {
  1335. this.setState({ empty: { content: !data.content } });
  1336. return Promise.reject();
  1337. }
  1338. return My.addRoomFeedback(data.roomId, data.content).then(() => {
  1339. this.setState({ data: { content: '' } });
  1340. if (onConfirm) onConfirm();
  1341. });
  1342. }
  1343. onCancel() {
  1344. const { onCancel } = this.props;
  1345. this.setState({ data: { content: '' } });
  1346. if (onCancel) onCancel();
  1347. }
  1348. render() {
  1349. const { show, info = {} } = this.props;
  1350. const { data, empty = {} } = this.state;
  1351. return (
  1352. <Modal show={show} title="考场信息" onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
  1353. <div className="t-2 t-s-16">
  1354. 考场位置: {info.isOverseas ? '海外' : '中国'}
  1355. {info.area ? ` ${info.area}` : ''} {info.title}
  1356. </div>
  1357. <div className="t-2 t-s-16">补充内容:</div>
  1358. <Textarea
  1359. value={data.content}
  1360. className="b-c-1 w-10 p-10"
  1361. empty={empty.content}
  1362. rows={6}
  1363. onChange={e => {
  1364. this.changeData('content', e.target.value);
  1365. }}
  1366. />
  1367. <div className="b-b m-t-2" />
  1368. </Modal>
  1369. );
  1370. }
  1371. }
  1372. export class SuppleFinishModal extends Component {
  1373. render() {
  1374. const { show, onConfirm } = this.props;
  1375. return (
  1376. <Modal show={show} title="提交成功" confirmText="好的,知道了" btnAlign="center" onConfirm={() => onConfirm()}>
  1377. <div className="t-2 t-s-18">
  1378. <Icon type="check" className="t-5 m-r-5" />
  1379. 内容将在审核通过后发布,感谢您的参与。
  1380. </div>
  1381. </Modal>
  1382. );
  1383. }
  1384. }
  1385. export class QuestionNoteModal extends Component {
  1386. constructor(props) {
  1387. super(props);
  1388. this.state = { data: {}, noteField: AskTarget[0].value };
  1389. this.target = [{ label: '题目', value: 'question', title: '题目', key: 'question' }];
  1390. }
  1391. componentWillReceiveProps(nextProps) {
  1392. if (nextProps.show && nextProps.defaultData) {
  1393. this.setState({ data: Object.assign({}, nextProps.defaultData) });
  1394. }
  1395. }
  1396. changeData(field, value) {
  1397. let { data, empty } = this.state;
  1398. data = data || {};
  1399. empty = empty || {};
  1400. data[field] = value;
  1401. if (value) empty[field] = !value;
  1402. this.setState({ data, empty });
  1403. }
  1404. onConfirm(close) {
  1405. const { questionNo, onConfirm } = this.props;
  1406. const { data } = this.state;
  1407. return My.updateQuestionNote(questionNo.id, data).then(() => {
  1408. if (close) {
  1409. this.setState({ noteField: AskTarget[0].value });
  1410. if (onConfirm) onConfirm(data);
  1411. }
  1412. });
  1413. }
  1414. onCancel() {
  1415. const { onCancel } = this.props;
  1416. this.setState({ data: { content: '' } });
  1417. if (onCancel) onCancel();
  1418. }
  1419. render() {
  1420. const { show } = this.props;
  1421. const { data, noteField } = this.state;
  1422. return (
  1423. <div hidden={!show} className="question-modal question-note-modal">
  1424. <div className="mask" />
  1425. <div className="modal-body">
  1426. <div className="modal-title">笔记</div>
  1427. <div className="modal-content">
  1428. <div className="tabs">
  1429. {this.target.map(item => {
  1430. return (
  1431. <div
  1432. className={`tab ${noteField === item.key ? 'active' : ''}`}
  1433. onClick={() => {
  1434. this.setState({ noteField: item.key });
  1435. }}
  1436. >
  1437. <div className="text">{item.label}</div>
  1438. <div className="date">{data[`${item.key}Time`] ? formatDate(data[`${item.key}Time`]) : ''}</div>
  1439. </div>
  1440. );
  1441. })}
  1442. </div>
  1443. <div className="input">
  1444. <Textarea
  1445. className="textarea"
  1446. value={data[`${noteField}Content`] || ''}
  1447. placeholder="记下笔记,方便以后复习"
  1448. onChange={e => {
  1449. data[`${noteField}Time`] = new Date();
  1450. data[`${noteField}Content`] = e.target.value;
  1451. this.setState({ data });
  1452. }}
  1453. />
  1454. <div className="bottom">
  1455. <AnswerButton
  1456. theme="cancel"
  1457. size="lager"
  1458. onClick={() => {
  1459. this.onCancel();
  1460. }}
  1461. >
  1462. 取消
  1463. </AnswerButton>
  1464. {/* <AnswerButton
  1465. size="lager"
  1466. onClick={() => {
  1467. this.onConfirm();
  1468. }}
  1469. >
  1470. 编辑
  1471. </AnswerButton> */}
  1472. <AnswerButton
  1473. size="lager"
  1474. onClick={() => {
  1475. this.onConfirm(true);
  1476. }}
  1477. >
  1478. 保存
  1479. </AnswerButton>
  1480. </div>
  1481. </div>
  1482. </div>
  1483. </div>
  1484. </div>
  1485. );
  1486. }
  1487. }