index.js 44 KB

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