index.js 46 KB

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