index.js 36 KB

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