1
0

index.js 37 KB

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