index.js 46 KB

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