index.js 45 KB

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