index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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)
  105. .then(result => {
  106. this.setState({ result });
  107. this.onNext();
  108. });
  109. }
  110. onClose() {
  111. const { onClose } = this.props;
  112. if (onClose) onClose();
  113. this.setState({ step: 0 });
  114. }
  115. render() {
  116. const { step } = this.state;
  117. const { show } = this.props;
  118. return (
  119. <Modal
  120. className="examination-modal"
  121. show={show}
  122. width={460}
  123. {...this.stepProp[step]}
  124. onClose={() => this.onClose()}
  125. >
  126. <div className="examination-modal-wrapper">{this[`renderStep${step}`]()}</div>
  127. </Modal>
  128. );
  129. }
  130. renderStep0() {
  131. const { data } = this.state;
  132. const { prepareStatus } = data;
  133. return (
  134. <div className="step-0-layout">
  135. <SpecialRadioGroup
  136. list={PrepareStatus}
  137. value={prepareStatus}
  138. width={190}
  139. space={10}
  140. onChange={key => this.onChange('prepareStatus', key)}
  141. />
  142. <div className="action-layout">
  143. <div className="next" onClick={() => this.onNext()}>
  144. 下一题
  145. <Icon type="right-circle" theme="filled" />
  146. </div>
  147. </div>
  148. </div>
  149. );
  150. }
  151. renderStep1() {
  152. const { data } = this.state;
  153. const { prepareExaminationTime } = data;
  154. return (
  155. <div className="step-1-layout">
  156. <SpecialRadioGroup
  157. list={PrepareExaminationTime}
  158. value={prepareExaminationTime}
  159. width={195}
  160. space={10}
  161. onChange={key => this.onChange('prepareExaminationTime', key)}
  162. />
  163. <div className="action-layout">
  164. <div className="prev" onClick={() => this.onPrev()}>
  165. <Icon type="left-circle" theme="filled" />
  166. 上一题
  167. </div>
  168. <div className="next" onClick={() => this.onNext()}>
  169. 下一题
  170. <Icon type="right-circle" theme="filled" />
  171. </div>
  172. </div>
  173. </div>
  174. );
  175. }
  176. renderStep2() {
  177. const { data } = this.state;
  178. const { prepareGoal } = data;
  179. return (
  180. <div className="step-2-layout">
  181. <TotalSort
  182. value={prepareGoal}
  183. onChange={(goal) => {
  184. this.onChange('prepareGoal', goal);
  185. }}
  186. />
  187. <div className="action-layout">
  188. <div className="prev" onClick={() => this.onPrev()}>
  189. <Icon type="left-circle" theme="filled" />
  190. 上一题
  191. </div>
  192. <div className="next" onClick={() => this.onNext()}>
  193. 下一题
  194. <Icon type="right-circle" theme="filled" />
  195. </div>
  196. </div>
  197. </div>
  198. );
  199. }
  200. renderStep3() {
  201. const { data, link, step } = this.state;
  202. const { prepareScoreTime } = data;
  203. return (
  204. <div className="step-3-layout">
  205. {link && <a href={link.url} className="a-l" target='_blank'>{link.title}</a>}
  206. <Date
  207. show={step === 3}
  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 size="lager" radius onClick={() => {
  219. this.submitPrepare();
  220. }}>
  221. 提交
  222. </Button>
  223. </div>
  224. </div>
  225. );
  226. }
  227. renderStep4() {
  228. const { first, data, stat = {} } = this.state;
  229. return (
  230. <div className="step-4-layout">
  231. {first && <div className="tip">
  232. <Icon type="check" />
  233. 7天VIP权限已赠送至您的账户。
  234. </div>}
  235. <Ratio
  236. text="身份"
  237. subtext={PrepareStatusMap[data.prepareStatus]}
  238. values={stat.status || []}
  239. />
  240. <Ratio
  241. text="考试时间"
  242. subtext={PrepareExaminationTimeMap[data.prepareExaminationTime]}
  243. values={stat.examinationTime || []}
  244. />
  245. <Ratio
  246. text="目标成绩"
  247. subtext={`${data.prepareGoal}分`}
  248. values={stat.goal || []}
  249. />
  250. <Ratio
  251. text="出分日期"
  252. subtext={`${formatDate(data.prepareScoreTime, 'YYYY-MM')}`}
  253. values={stat.scoreTime || []}
  254. />
  255. </div>
  256. );
  257. }
  258. }