1
0

index.js 40 KB

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