1
0

index.js 32 KB

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