index.js 37 KB

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