index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import { Icon } from 'antd';
  4. import { getMap, formatDate, formatPercent } from '@src/services/Tools';
  5. import moment from 'moment';
  6. import { SpecialRadioGroup } from '../Radio';
  7. import Modal from '../Modal';
  8. import Button from '../Button';
  9. import TotalSort from '../TotalSort';
  10. import Date from '../Date';
  11. import Ratio from '../Ratio';
  12. import { My } from '../../stores/my';
  13. import { Main } from '../../stores/main';
  14. import { PrepareStatus, PrepareExaminationTime, PrepareScoreTime } from '../../../Constant';
  15. const PrepareStatusMap = getMap(PrepareStatus, 'value', 'short');
  16. const PrepareExaminationTimeMap = getMap(PrepareExaminationTime, 'value', 'label');
  17. const PrepareScoreTimeMap = getMap(PrepareScoreTime, 'value', 'label');
  18. export default class extends Component {
  19. constructor(props) {
  20. super(props);
  21. this.statusColors = ['#41A6F3', '#3F86EA', '#41A6F3', '#6DC0FF', '#9BD4FF'];
  22. this.examinationTimeColors = ['#6865FD', '#322EF2', '#8F65FF', '#8C8AFF'];
  23. this.goalColors = ['#2754E0', '#3F86EA', '#41A6F3', '#6DC0FF'];
  24. this.scoreTimeColors = ['#6865FD', '#322EF2', '#8F65FF', '#8C8AFF', '#8F65FF', '#C3C1D1'];
  25. this.stepProp = {
  26. 0: {
  27. title: '我的身份',
  28. },
  29. 1: {
  30. title: '下次考试时间',
  31. },
  32. 2: {
  33. title: '目标成绩',
  34. },
  35. 3: {
  36. title: '最晚出分时间(选填)',
  37. },
  38. 4: {
  39. title: '备考信息',
  40. onConfirm: props.onConfirm,
  41. onCancel: () => {
  42. this.setState({ step: 0 });
  43. },
  44. confirmText: '关闭',
  45. cancelText: '修改',
  46. },
  47. };
  48. this.state = { step: 0, data: { prepareGoal: 650 } };
  49. My.getPrepare()
  50. .then(result => {
  51. const statusTotal = result.stat.status.reduce((p, n) => { return p + n.value; }, 0);
  52. const goalTotal = result.stat.goal.reduce((p, n) => { return p + n.value; }, 0);
  53. const examinationTimeTotal = result.stat.examinationTime.reduce((p, n) => { return p + n.value; }, 0);
  54. const scoreTimeTotal = result.stat.scoreTime.reduce((p, n) => { return p + n.value; }, 0);
  55. const stat = {
  56. status: result.stat.status.map((row, index) => {
  57. row.value = formatPercent(row.value, statusTotal);
  58. row.label = `${PrepareStatusMap[row.key]}; ${row.value}%`;
  59. row.color = this.statusColors[index];
  60. return row;
  61. }),
  62. goal: result.stat.goal.map((row, index) => {
  63. row.value = formatPercent(row.value, goalTotal);
  64. row.label = `${row.key}+; ${row.value}%`;
  65. row.color = this.goalColors[index];
  66. return row;
  67. }),
  68. examinationTime: result.stat.status.map((row, index) => {
  69. row.value = formatPercent(row.value, examinationTimeTotal);
  70. row.label = `${PrepareExaminationTimeMap[row.key]}; ${row.value}%`;
  71. row.color = this.examinationTimeColors[index];
  72. return row;
  73. }),
  74. scoreTime: result.stat.scoreTime.map((row, index) => {
  75. row.value = formatPercent(row.value, scoreTimeTotal);
  76. row.label = `${PrepareScoreTimeMap[row.key]}; ${row.value}%`;
  77. row.color = this.scoreTimeColors[index];
  78. return row;
  79. }),
  80. };
  81. result.prepareGoal = result.prepareGoal || 650;
  82. result.prepareScoreTime = result.prepareScoreTime ? moment(result.prepareScoreTime) : null;
  83. this.setState({ data: result, stat, first: !result.prepareStatus, step: !result.prepareStatus ? 0 : 4 });
  84. });
  85. Main.getContract('register').then(() => {
  86. this.setState({ link: { url: 'www', title: '了解出分时间信息>' } });
  87. });
  88. }
  89. onChange(type, key) {
  90. const { data } = this.state;
  91. data[type] = key;
  92. this.setState({ data });
  93. }
  94. onPrev() {
  95. const { step } = this.state;
  96. this.setState({ step: step - 1 });
  97. }
  98. onNext() {
  99. const { step } = this.state;
  100. this.setState({ step: step + 1 });
  101. }
  102. submitPrepare() {
  103. const { data } = this.state;
  104. My.editPrepare(data).then(result => {
  105. this.setState({ result });
  106. this.onNext();
  107. });
  108. }
  109. onClose() {
  110. const { onClose } = this.props;
  111. if (onClose) onClose();
  112. this.setState({ step: 0 });
  113. }
  114. render() {
  115. const { step } = this.state;
  116. const { show } = this.props;
  117. return (
  118. <Modal
  119. className="examination-modal"
  120. show={show}
  121. width={460}
  122. {...this.stepProp[step]}
  123. onClose={() => this.onClose()}
  124. >
  125. <div className="examination-modal-wrapper">{this[`renderStep${step}`]()}</div>
  126. </Modal>
  127. );
  128. }
  129. renderStep0() {
  130. const { data } = this.state;
  131. const { prepareStatus } = data;
  132. return (
  133. <div className="step-0-layout">
  134. <SpecialRadioGroup
  135. list={PrepareStatus}
  136. value={prepareStatus}
  137. width={190}
  138. space={10}
  139. onChange={key => this.onChange('prepareStatus', key)}
  140. />
  141. <div className="action-layout">
  142. <div className="next" onClick={() => this.onNext()}>
  143. 下一题
  144. <Icon type="right-circle" theme="filled" />
  145. </div>
  146. </div>
  147. </div>
  148. );
  149. }
  150. renderStep1() {
  151. const { data } = this.state;
  152. const { prepareExaminationTime } = data;
  153. return (
  154. <div className="step-1-layout">
  155. <SpecialRadioGroup
  156. list={PrepareExaminationTime}
  157. value={prepareExaminationTime}
  158. width={195}
  159. space={10}
  160. onChange={key => this.onChange('prepareExaminationTime', key)}
  161. />
  162. <div className="action-layout">
  163. <div className="prev" onClick={() => this.onPrev()}>
  164. <Icon type="left-circle" theme="filled" />
  165. 上一题
  166. </div>
  167. <div className="next" onClick={() => this.onNext()}>
  168. 下一题
  169. <Icon type="right-circle" theme="filled" />
  170. </div>
  171. </div>
  172. </div>
  173. );
  174. }
  175. renderStep2() {
  176. const { data } = this.state;
  177. const { prepareGoal } = data;
  178. return (
  179. <div className="step-2-layout">
  180. <TotalSort
  181. value={prepareGoal}
  182. onChange={goal => {
  183. this.onChange('prepareGoal', goal);
  184. }}
  185. />
  186. <div className="action-layout">
  187. <div className="prev" onClick={() => this.onPrev()}>
  188. <Icon type="left-circle" theme="filled" />
  189. 上一题
  190. </div>
  191. <div className="next" onClick={() => this.onNext()}>
  192. 下一题
  193. <Icon type="right-circle" theme="filled" />
  194. </div>
  195. </div>
  196. </div>
  197. );
  198. }
  199. renderStep3() {
  200. const { data, link, step } = this.state;
  201. const { prepareScoreTime } = data;
  202. return (
  203. <div className="step-3-layout">
  204. {link && <a href={link.url} className="a-l" target='_blank'>{link.title}</a>}
  205. <Date
  206. show={step === 3}
  207. theme="filled"
  208. value={prepareScoreTime}
  209. onChange={date => {
  210. this.onChange('prepareScoreTime', date);
  211. }}
  212. />
  213. <div className="action-layout">
  214. <div className="prev" onClick={() => this.onPrev()}>
  215. <Icon type="left-circle" theme="filled" />
  216. 上一题
  217. </div>
  218. <Button
  219. size="lager"
  220. radius
  221. onClick={() => {
  222. this.submitPrepare();
  223. }}
  224. >
  225. 提交
  226. </Button>
  227. </div>
  228. </div>
  229. );
  230. }
  231. renderStep4() {
  232. const { first, data, stat = {} } = this.state;
  233. return (
  234. <div className="step-4-layout">
  235. {first && (
  236. <div className="tip">
  237. <Icon type="check" />
  238. 7天VIP权限已赠送至您的账户。
  239. </div>
  240. )}
  241. <Ratio text="身份" subtext={PrepareStatusMap[data.prepareStatus]} values={stat.status || []} />
  242. <Ratio
  243. text="考试时间"
  244. subtext={PrepareExaminationTimeMap[data.prepareExaminationTime]}
  245. values={stat.examinationTime || []}
  246. />
  247. <Ratio text="目标成绩" subtext={`${data.prepareGoal}分`} values={stat.goal || []} />
  248. <Ratio
  249. text="出分日期"
  250. subtext={`${formatDate(data.prepareScoreTime, 'YYYY-MM')}`}
  251. values={stat.scoreTime || []}
  252. />
  253. </div>
  254. );
  255. }
  256. }