index.js 7.9 KB

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