index.js 45 KB

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