index.js 35 KB

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