index.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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 > 14) {
  353. this.setState({ nicknameError: '用户名长度不足2个自负或超过14个字符' });
  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-14个字符。"
  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({
  748. empty: {
  749. 'position[0]': !data.position[0],
  750. 'position[1]': !data.position[1],
  751. 'position[2]': !data.position[2],
  752. content: !data.content,
  753. originContent: !data.originContent,
  754. },
  755. });
  756. return Promise.reject();
  757. }
  758. return My.addFeedbackErrorData(
  759. data.dataId,
  760. data.title,
  761. data.position.join(','),
  762. data.originContent,
  763. data.content,
  764. ).then(() => {
  765. this.setState({ data: { position: ['', '', ''], content: '', originContent: '' } });
  766. if (onConfirm) onConfirm();
  767. });
  768. }
  769. onCancel() {
  770. const { onCancel } = this.props;
  771. this.setState({ data: { position: ['', '', ''], content: '', originContent: '' } });
  772. if (onCancel) onCancel();
  773. }
  774. render() {
  775. const { show } = this.props;
  776. const { data, empty = {} } = this.state;
  777. return (
  778. <Modal
  779. show={show}
  780. title="纠错"
  781. btnType="link"
  782. width={630}
  783. onConfirm={() => this.onConfirm()}
  784. onCancel={() => this.onCancel()}
  785. >
  786. <div className="t-2 m-b-1 t-s-16">
  787. 定位:
  788. <input
  789. value={data.position[0]}
  790. className="t-c b-c-1 m-r-5"
  791. style={{ width: 56 }}
  792. empty={empty['position[0]']}
  793. onChange={e => {
  794. this.changeDataIndex('position', 0, e.target.value);
  795. }}
  796. />
  797. <span className="require">页</span>
  798. <input
  799. value={data.position[1]}
  800. className="t-c b-c-1 m-r-5"
  801. style={{ width: 56 }}
  802. empty={empty['position[1]']}
  803. onChange={e => {
  804. this.changeDataIndex('position', 1, e.target.value);
  805. }}
  806. />
  807. <span className="require">行</span> , 题号
  808. <input
  809. value={data.position[2]}
  810. className="t-c b-c-1"
  811. style={{ width: 56 }}
  812. empty={empty['position[2]']}
  813. onChange={e => {
  814. this.changeDataIndex('position', 2, e.target.value);
  815. }}
  816. />
  817. </div>
  818. <div className="t-2 t-s-16">错误内容是:</div>
  819. <textarea
  820. value={data.originContent}
  821. className="b-c-1 w-10 p-10"
  822. rows={10}
  823. placeholder={'可简单描述您发现的问题'}
  824. empty={empty.originContent}
  825. onChange={e => {
  826. this.changeData('originContent', e.target.value);
  827. }}
  828. />
  829. <div className="t-2 t-s-16">应该更改为:</div>
  830. <textarea
  831. value={data.content}
  832. className="b-c-1 w-10 p-10"
  833. rows={10}
  834. placeholder={'提供您认为正确的内容即可'}
  835. empty={empty.content}
  836. onChange={e => {
  837. this.changeData('content', e.target.value);
  838. }}
  839. />
  840. <div className="b-b m-t-2" />
  841. </Modal>
  842. );
  843. }
  844. }
  845. export class AskCourseModal extends Component {
  846. constructor(props) {
  847. super(props);
  848. this.state = { data: { position: [], content: '', originContent: '' } };
  849. }
  850. componentWillReceiveProps(nextProps) {
  851. if (nextProps.show && nextProps.defaultData) {
  852. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  853. }
  854. }
  855. changeData(field, value) {
  856. let { data, empty } = this.state;
  857. data = data || {};
  858. empty = empty || {};
  859. data[field] = value;
  860. if (value) empty[field] = !value;
  861. this.setState({ data, empty });
  862. }
  863. onConfirm() {
  864. const { course, courseNo, onConfirm } = this.props;
  865. const { data } = this.state;
  866. if (!data.content || !data.originContent) {
  867. this.setState({ empty: { content: !data.content, originContent: !data.originContent } });
  868. return Promise.reject();
  869. }
  870. return My.addCourseAsk(course.id, courseNo.id, data.position.join(','), data.originContent, data.content).then(
  871. () => {
  872. this.setState({ data: { position: [], content: '', originContent: '' } });
  873. if (onConfirm) onConfirm();
  874. },
  875. );
  876. }
  877. onCancel() {
  878. const { onCancel } = this.props;
  879. this.setState({ data: { position: [], content: '', originContent: '' } });
  880. if (onCancel) onCancel();
  881. }
  882. render() {
  883. const { show, selectList, courseNo, getContainer } = this.props;
  884. const { data, empty = {} } = this.state;
  885. return (
  886. <Modal
  887. show={show}
  888. title="提问"
  889. btnType="link"
  890. width={630}
  891. getContainer={getContainer}
  892. confirmText="提交"
  893. onConfirm={() => this.onConfirm()}
  894. onCancel={() => this.onCancel()}
  895. >
  896. <div className="t-2 m-b-1 t-s-16">
  897. 针对<span className="t-4">课时{courseNo.no}</span>的{' '}
  898. <Select
  899. value={data.position}
  900. theme="white"
  901. list={selectList}
  902. onChange={item => {
  903. this.changeData('position', item.key);
  904. }}
  905. />
  906. 进行提问.
  907. </div>
  908. <div className="t-2 t-s-16">老师讲解的内容是:</div>
  909. <textarea
  910. value={data.originContent}
  911. className="b-c-1 w-10 p-10"
  912. rows={4}
  913. placeholder={'请简单描述,以便老师准确定位。'}
  914. empty={empty.originContent}
  915. onChange={e => {
  916. this.changeData('originContent', e.target.value);
  917. }}
  918. />
  919. <div className="t-2 t-s-16">您的问题是:</div>
  920. <textarea
  921. value={data.content}
  922. className="b-c-1 w-10 p-10"
  923. rows={4}
  924. placeholder={'老师会在n小时内回答你的问题。'}
  925. onChange={e => {
  926. this.changeData('content', e.target.value);
  927. }}
  928. />
  929. <div className="b-b m-t-2" />
  930. </Modal>
  931. );
  932. }
  933. }
  934. export class CourseNoteModal extends Component {
  935. constructor(props) {
  936. super(props);
  937. this.state = { data: { content: '' } };
  938. }
  939. componentWillReceiveProps(nextProps) {
  940. if (nextProps.show && nextProps.defaultData) {
  941. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  942. }
  943. }
  944. changeData(field, value) {
  945. let { data, empty } = this.state;
  946. data = data || {};
  947. empty = empty || {};
  948. data[field] = value;
  949. if (value) empty[field] = !value;
  950. this.setState({ data, empty });
  951. }
  952. onConfirm() {
  953. const { course, onConfirm } = this.props;
  954. const { data } = this.state;
  955. if (!data.content || !data.originContent) {
  956. this.setState({ empty: { content: !data.content } });
  957. return Promise.reject();
  958. }
  959. return My.updateCourseNote(course.id, data.courseNoId, data.content).then(() => {
  960. this.setState({ data: { content: '' } });
  961. if (onConfirm) onConfirm();
  962. });
  963. }
  964. onCancel() {
  965. const { onCancel } = this.props;
  966. this.setState({ data: { content: '' } });
  967. if (onCancel) onCancel();
  968. }
  969. render() {
  970. const { show, course = {}, courseNos = [], noteMap = {}, getContainer } = this.props;
  971. const { data, empty = {} } = this.state;
  972. return (
  973. <Modal
  974. show={show}
  975. title="笔记"
  976. width={630}
  977. getContainer={getContainer}
  978. confirmText="提交"
  979. onConfirm={() => this.onConfirm()}
  980. onCancel={() => this.onCancel()}
  981. >
  982. <div className="t-2 m-b-1 t-s-16">
  983. {course.title}
  984. <Select
  985. theme="white"
  986. value={data.courseNoId}
  987. list={courseNos.map(row => {
  988. return {
  989. title: `课时${row.no}`,
  990. key: row.id,
  991. };
  992. })}
  993. onChange={item => {
  994. if (data.courseNoId !== item.key) {
  995. data.courseNoId = item.key;
  996. data.content = noteMap[item.key] ? noteMap[item.key].content : '';
  997. }
  998. this.setState({ data });
  999. }}
  1000. />
  1001. </div>
  1002. <textarea
  1003. value={data.content}
  1004. className="b-c-1 w-10 p-10"
  1005. rows={10}
  1006. placeholder={'写下笔记,方便以后复习。'}
  1007. empty={empty.content}
  1008. onChange={e => {
  1009. this.changeData('content', e.target.value);
  1010. }}
  1011. />
  1012. <div className="b-b m-t-2" />
  1013. </Modal>
  1014. );
  1015. }
  1016. }
  1017. export class TextbookFeedbackModal extends Component {
  1018. constructor(props) {
  1019. super(props);
  1020. this.state = {
  1021. data: { content: '' },
  1022. targetList: TextbookFeedbackTarget.map(row => {
  1023. return {
  1024. title: row.label,
  1025. key: row.value,
  1026. };
  1027. }),
  1028. textbookSubject: TextbookSubject.map(row => {
  1029. return {
  1030. title: row.label,
  1031. key: row.value,
  1032. };
  1033. }),
  1034. };
  1035. }
  1036. componentWillReceiveProps(nextProps) {
  1037. if (nextProps.show && nextProps.defaultData) {
  1038. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  1039. }
  1040. }
  1041. changeData(field, value) {
  1042. let { data, empty } = this.state;
  1043. data = data || {};
  1044. empty = empty || {};
  1045. data[field] = value;
  1046. if (value) empty[field] = !value;
  1047. this.setState({ data, empty });
  1048. }
  1049. onConfirm() {
  1050. const { onConfirm } = this.props;
  1051. const { data } = this.state;
  1052. if (data.target !== 'new' && (!data.no || !data.content)) {
  1053. this.setState({ empty: { content: !data.content, no: !data.no } });
  1054. return Promise.reject();
  1055. }
  1056. if (!data.content) {
  1057. this.setState({ empty: { content: !data.content } });
  1058. return Promise.reject();
  1059. }
  1060. return My.addTextbookFeedback(data.textbookSubject, data.target, data.no, data.content)
  1061. .then(() => {
  1062. this.setState({ data: { content: '' } });
  1063. if (onConfirm) onConfirm();
  1064. })
  1065. .catch(e => {
  1066. asyncSMessage(e.message, 'error');
  1067. });
  1068. }
  1069. onCancel() {
  1070. const { onCancel } = this.props;
  1071. this.setState({ data: { content: '' } });
  1072. if (onCancel) onCancel();
  1073. }
  1074. render() {
  1075. const { show } = this.props;
  1076. const { data, targetList, textbookSubject, empty = {} } = this.state;
  1077. return (
  1078. <Modal show={show} title="反馈" width={630} onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
  1079. <div className="t-2 t-s-16 m-b-1">
  1080. 机经类别:{' '}
  1081. <Select
  1082. value={data.textbookSubject}
  1083. theme="white"
  1084. list={textbookSubject}
  1085. onChange={value => {
  1086. data.textbookSubject = value;
  1087. this.setState({ data });
  1088. }}
  1089. />
  1090. 反馈类型:{' '}
  1091. <Select
  1092. value={data.target}
  1093. theme="white"
  1094. list={targetList}
  1095. onChange={({ key }) => {
  1096. data.target = key;
  1097. this.setState({ data });
  1098. }}
  1099. />
  1100. <span hidden={data.target === 'new'}>
  1101. {' '}
  1102. 题号是{' '}
  1103. <input
  1104. value={data.no}
  1105. style={{ width: 80 }}
  1106. className="m-l-1 b-c-1 t-c"
  1107. empty={empty.no}
  1108. onChange={e => {
  1109. this.changeData('no', e.target.value);
  1110. }}
  1111. />
  1112. </span>
  1113. </div>
  1114. <div className="t-2 t-s-16">{TextbookFeedbackTargetMap[data.target]}:</div>
  1115. <textarea
  1116. value={data.content}
  1117. className="b-c-1 w-10 p-10"
  1118. rows={10}
  1119. placeholder={TextbookFeedbackTargetMap[data.target]}
  1120. empty={empty.content}
  1121. onChange={e => {
  1122. this.changeData('content', e.target.value);
  1123. }}
  1124. />
  1125. <div className="b-b m-t-2" />
  1126. </Modal>
  1127. );
  1128. }
  1129. }
  1130. export class FaqModal extends Component {
  1131. constructor(props) {
  1132. super(props);
  1133. this.state = { data: { content: '' } };
  1134. }
  1135. componentWillReceiveProps(nextProps) {
  1136. if (nextProps.defaultData && nextProps.show) {
  1137. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  1138. }
  1139. }
  1140. changeData(field, value) {
  1141. let { data, empty } = this.state;
  1142. data = data || {};
  1143. empty = empty || {};
  1144. data[field] = value;
  1145. if (value) empty[field] = !value;
  1146. this.setState({ data, empty });
  1147. }
  1148. onConfirm() {
  1149. const { onConfirm } = this.props;
  1150. const { data } = this.state;
  1151. if (!data.content) {
  1152. this.setState({ empty: { content: !data.content } });
  1153. return Promise.reject();
  1154. }
  1155. return My.addFaq(data.channel, data.position, data.content).then(() => {
  1156. this.setState({ data: { content: '' } });
  1157. if (onConfirm) onConfirm();
  1158. });
  1159. }
  1160. onCancel() {
  1161. const { onCancel } = this.props;
  1162. this.setState({ data: { content: '' } });
  1163. if (onCancel) onCancel();
  1164. }
  1165. render() {
  1166. const { show } = this.props;
  1167. const { data, empty = {} } = this.state;
  1168. return (
  1169. <Modal show={show} title="咨询" onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
  1170. <textarea
  1171. className="b-c-1 w-10 p-10"
  1172. value={data.content}
  1173. rows={6}
  1174. placeholder="请输入您的问题!"
  1175. empty={empty.content}
  1176. onChange={e => {
  1177. this.changeData('content', e.target.value);
  1178. }}
  1179. />
  1180. <div className="b-b m-t-2" />
  1181. </Modal>
  1182. );
  1183. }
  1184. }
  1185. export class CommentModal extends Component {
  1186. constructor(props) {
  1187. super(props);
  1188. this.state = { data: { content: '' } };
  1189. }
  1190. componentWillReceiveProps(nextProps) {
  1191. if (nextProps.show && nextProps.defaultData) {
  1192. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  1193. }
  1194. }
  1195. changeData(field, value) {
  1196. let { data, empty } = this.state;
  1197. data = data || {};
  1198. empty = empty || {};
  1199. data[field] = value;
  1200. if (value) empty[field] = !value;
  1201. this.setState({ data, empty });
  1202. }
  1203. onConfirm() {
  1204. const { onConfirm } = this.props;
  1205. const { data } = this.state;
  1206. if (!data.content) {
  1207. this.setState({ empty: { content: !data.content } });
  1208. return Promise.reject();
  1209. }
  1210. return My.addComment(data.channel, data.position, data.content).then(() => {
  1211. this.setState({ data: { content: '' } });
  1212. if (onConfirm) onConfirm();
  1213. });
  1214. }
  1215. onCancel() {
  1216. const { onCancel } = this.props;
  1217. this.setState({ data: { content: '' } });
  1218. if (onCancel) onCancel();
  1219. }
  1220. render() {
  1221. const { show } = this.props;
  1222. const { data, empty = {} } = this.state;
  1223. return (
  1224. <Modal show={show} title="评价" onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
  1225. <textarea
  1226. value={data.content}
  1227. className="b-c-1 w-10 p-10"
  1228. rows={6}
  1229. placeholder="您的看法对我们来说很重要!"
  1230. empty={empty.content}
  1231. onChange={e => {
  1232. this.changeData('content', e.target.value);
  1233. }}
  1234. />
  1235. <div className="b-b m-t-2" />
  1236. </Modal>
  1237. );
  1238. }
  1239. }
  1240. export class FinishModal extends Component {
  1241. render() {
  1242. const { show, onConfirm } = this.props;
  1243. return (
  1244. <Modal show={show} title="提交成功" confirmText="好的,知道了" btnAlign="center" onConfirm={() => onConfirm()}>
  1245. <div className="t-2 t-s-18">
  1246. <Icon type="check" className="t-5 m-r-5" />
  1247. 您的每一次反馈都是千行进步的动力。
  1248. </div>
  1249. </Modal>
  1250. );
  1251. }
  1252. }
  1253. export class SuppleModal extends Component {
  1254. constructor(props) {
  1255. super(props);
  1256. this.state = { data: { content: '' } };
  1257. }
  1258. componentWillReceiveProps(nextProps) {
  1259. if (nextProps.show && nextProps.defaultData) {
  1260. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  1261. }
  1262. }
  1263. changeData(field, value) {
  1264. let { data, empty } = this.state;
  1265. data = data || {};
  1266. empty = empty || {};
  1267. data[field] = value;
  1268. if (value) empty[field] = !value;
  1269. this.setState({ data, empty });
  1270. }
  1271. onConfirm() {
  1272. const { onConfirm } = this.props;
  1273. const { data } = this.state;
  1274. if (!data.content) {
  1275. this.setState({ empty: { content: !data.content } });
  1276. return Promise.reject();
  1277. }
  1278. return My.addRoomFeedback(data.roomId, data.content).then(() => {
  1279. this.setState({ data: { content: '' } });
  1280. if (onConfirm) onConfirm();
  1281. });
  1282. }
  1283. onCancel() {
  1284. const { onCancel } = this.props;
  1285. this.setState({ data: { content: '' } });
  1286. if (onCancel) onCancel();
  1287. }
  1288. render() {
  1289. const { show, info = {} } = this.props;
  1290. const { data, empty = {} } = this.state;
  1291. return (
  1292. <Modal show={show} title="考场信息" onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
  1293. <div className="t-2 t-s-16">
  1294. 考场位置: {info.isOverseas ? '海外' : '中国'}
  1295. {info.area ? ` ${info.area}` : ''} {info.title}
  1296. </div>
  1297. <div className="t-2 t-s-16">补充内容:</div>
  1298. <textarea
  1299. value={data.content}
  1300. className="b-c-1 w-10 p-10"
  1301. empty={empty.content}
  1302. rows={6}
  1303. onChange={e => {
  1304. this.changeData('content', e.target.value);
  1305. }}
  1306. />
  1307. <div className="b-b m-t-2" />
  1308. </Modal>
  1309. );
  1310. }
  1311. }
  1312. export class SuppleFinishModal extends Component {
  1313. render() {
  1314. const { show, onConfirm } = this.props;
  1315. return (
  1316. <Modal show={show} title="提交成功" confirmText="好的,知道了" btnAlign="center" onConfirm={() => onConfirm()}>
  1317. <div className="t-2 t-s-18">
  1318. <Icon type="check" className="t-5 m-r-5" />
  1319. 内容将在审核通过后发布,感谢您的参与。
  1320. </div>
  1321. </Modal>
  1322. );
  1323. }
  1324. }
  1325. export class QuestionNoteModal extends Component {
  1326. constructor(props) {
  1327. super(props);
  1328. this.state = { data: {}, noteField: AskTarget[0].value };
  1329. }
  1330. componentWillReceiveProps(nextProps) {
  1331. if (nextProps.show && nextProps.defaultData) {
  1332. this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
  1333. }
  1334. }
  1335. changeData(field, value) {
  1336. let { data, empty } = this.state;
  1337. data = data || {};
  1338. empty = empty || {};
  1339. data[field] = value;
  1340. if (value) empty[field] = !value;
  1341. this.setState({ data, empty });
  1342. }
  1343. onConfirm(close) {
  1344. const { questionNo, onConfirm } = this.props;
  1345. const { data } = this.state;
  1346. return My.updateQuestionNote(questionNo.id, data).then(() => {
  1347. if (close) {
  1348. this.setState({ data: {}, noteField: AskTarget[0].value });
  1349. if (onConfirm) onConfirm();
  1350. }
  1351. });
  1352. }
  1353. onCancel() {
  1354. const { onCancel } = this.props;
  1355. this.setState({ data: { content: '' } });
  1356. if (onCancel) onCancel();
  1357. }
  1358. render() {
  1359. const { show } = this.props;
  1360. const { data, noteField } = this.state;
  1361. return (
  1362. <div hidden={!show} className="question-modal note">
  1363. <div className="mask" />
  1364. <div className="body">
  1365. <div className="title">提问</div>
  1366. <div className="content">
  1367. <div className="tabs">
  1368. {AskTarget.map(item => {
  1369. return (
  1370. <div
  1371. className={`tab ${noteField === item.key ? 'active' : ''}`}
  1372. onClick={() => {
  1373. this.setState({ noteField: item.key });
  1374. }}
  1375. >
  1376. <div className="text">{item.label}</div>
  1377. <div className="date">{data[`${item.key}Time`] ? formatDate(data[`${item.key}Time`]) : ''}</div>
  1378. </div>
  1379. );
  1380. })}
  1381. </div>
  1382. <div className="input">
  1383. <textarea
  1384. className="textarea"
  1385. value={data[`${noteField}Content`] || ''}
  1386. placeholder="记下笔记,方便以后复习"
  1387. onChange={e => {
  1388. data[`${noteField}Time`] = new Date();
  1389. data[`${noteField}Content`] = e.target.value;
  1390. this.setState({ data });
  1391. }}
  1392. />
  1393. <div className="bottom">
  1394. <AnswerButton
  1395. theme="cancel"
  1396. size="lager"
  1397. onClick={() => {
  1398. this.onCancel();
  1399. }}
  1400. >
  1401. 取消
  1402. </AnswerButton>
  1403. <AnswerButton
  1404. size="lager"
  1405. onClick={() => {
  1406. this.onConfirm();
  1407. }}
  1408. >
  1409. 编辑
  1410. </AnswerButton>
  1411. <AnswerButton
  1412. size="lager"
  1413. onClick={() => {
  1414. this.onConfirm(true);
  1415. }}
  1416. >
  1417. 保存
  1418. </AnswerButton>
  1419. </div>
  1420. </div>
  1421. </div>
  1422. </div>
  1423. </div>
  1424. );
  1425. }
  1426. }