index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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().then(result => {
  49. const statusTotal = result.stat.status.reduce((p, n) => {
  50. return p + n.value;
  51. }, 0);
  52. const goalTotal = result.stat.goal.reduce((p, n) => {
  53. return p + n.value;
  54. }, 0);
  55. const examinationTimeTotal = result.stat.examinationTime.reduce((p, n) => {
  56. return p + n.value;
  57. }, 0);
  58. const scoreTimeTotal = result.stat.scoreTime.reduce((p, n) => {
  59. return p + n.value;
  60. }, 0);
  61. const stat = {
  62. status: result.stat.status.map((row, index) => {
  63. row.value = formatPercent(row.value, statusTotal);
  64. row.label = `${PrepareStatusMap[row.key]}; ${row.value}%`;
  65. row.color = this.statusColors[index];
  66. return row;
  67. }),
  68. goal: result.stat.goal.map((row, index) => {
  69. row.value = formatPercent(row.value, goalTotal);
  70. row.label = `${row.key}+; ${row.value}%`;
  71. row.color = this.goalColors[index];
  72. return row;
  73. }),
  74. examinationTime: result.stat.status.map((row, index) => {
  75. row.value = formatPercent(row.value, examinationTimeTotal);
  76. row.label = `${PrepareExaminationTimeMap[row.key]}; ${row.value}%`;
  77. row.color = this.examinationTimeColors[index];
  78. return row;
  79. }),
  80. scoreTime: result.stat.scoreTime.map((row, index) => {
  81. row.value = formatPercent(row.value, scoreTimeTotal);
  82. row.label = `${PrepareScoreTimeMap[row.key]}; ${row.value}%`;
  83. row.color = this.scoreTimeColors[index];
  84. return row;
  85. }),
  86. };
  87. result.prepareGoal = result.prepareGoal || 650;
  88. result.prepareScoreTime = result.prepareScoreTime ? moment(result.prepareScoreTime) : null;
  89. this.setState({ data: result, stat, first: !result.prepareStatus, step: !result.prepareStatus ? 0 : 4 });
  90. });
  91. }
  92. onChange(type, key) {
  93. const { data } = this.state;
  94. data[type] = key;
  95. this.setState({ data });
  96. }
  97. onPrev() {
  98. const { step } = this.state;
  99. this.setState({ step: step - 1 });
  100. }
  101. onNext() {
  102. const { step } = this.state;
  103. this.setState({ step: step + 1 });
  104. }
  105. submitPrepare() {
  106. const { data } = this.state;
  107. My.editPrepare(data).then(result => {
  108. this.setState({ result });
  109. this.onNext();
  110. });
  111. }
  112. render() {
  113. const { step } = this.state;
  114. const { show, onClose } = this.props;
  115. return (
  116. <Modal
  117. className="examination-modal"
  118. show={show}
  119. width={460}
  120. {...this.stepProp[step]}
  121. onClose={() => onClose && onClose()}
  122. >
  123. <div className="examination-modal-wrapper">{this[`renderStep${step}`]()}</div>
  124. </Modal>
  125. );
  126. }
  127. renderStep0() {
  128. const { data } = this.state;
  129. const { prepareStatus } = data;
  130. return (
  131. <div className="step-0-layout">
  132. <SpecialRadioGroup
  133. list={PrepareStatus}
  134. value={prepareStatus}
  135. width={190}
  136. space={10}
  137. onChange={key => this.onChange('prepareStatus', key)}
  138. />
  139. <div className="action-layout">
  140. <div className="next" onClick={() => this.onNext()}>
  141. 下一题
  142. <Icon type="right-circle" theme="filled" />
  143. </div>
  144. </div>
  145. </div>
  146. );
  147. }
  148. renderStep1() {
  149. const { data } = this.state;
  150. const { prepareExaminationTime } = data;
  151. return (
  152. <div className="step-1-layout">
  153. <SpecialRadioGroup
  154. list={PrepareExaminationTime}
  155. value={prepareExaminationTime}
  156. width={195}
  157. space={10}
  158. onChange={key => this.onChange('prepareExaminationTime', key)}
  159. />
  160. <div className="action-layout">
  161. <div className="prev" onClick={() => this.onPrev()}>
  162. <Icon type="left-circle" theme="filled" />
  163. 上一题
  164. </div>
  165. <div className="next" onClick={() => this.onNext()}>
  166. 下一题
  167. <Icon type="right-circle" theme="filled" />
  168. </div>
  169. </div>
  170. </div>
  171. );
  172. }
  173. renderStep2() {
  174. const { data } = this.state;
  175. const { prepareGoal } = data;
  176. return (
  177. <div className="step-2-layout">
  178. <TotalSort
  179. value={prepareGoal}
  180. onChange={goal => {
  181. this.onChange('prepareGoal', goal);
  182. }}
  183. />
  184. <div className="action-layout">
  185. <div className="prev" onClick={() => this.onPrev()}>
  186. <Icon type="left-circle" theme="filled" />
  187. 上一题
  188. </div>
  189. <div className="next" onClick={() => this.onNext()}>
  190. 下一题
  191. <Icon type="right-circle" theme="filled" />
  192. </div>
  193. </div>
  194. </div>
  195. );
  196. }
  197. renderStep3() {
  198. const { data } = this.state;
  199. const { prepareScoreTime } = data;
  200. return (
  201. <div className="step-3-layout">
  202. <Date
  203. theme="filled"
  204. value={prepareScoreTime}
  205. onChange={date => {
  206. this.onChange('prepareScoreTime', date);
  207. }}
  208. />
  209. <div className="action-layout">
  210. <div className="prev" onClick={() => this.onPrev()}>
  211. <Icon type="left-circle" theme="filled" />
  212. 上一题
  213. </div>
  214. <Button
  215. size="lager"
  216. radius
  217. onClick={() => {
  218. this.submitPrepare();
  219. }}
  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 && (
  232. <div className="tip">
  233. <Icon type="check" />
  234. 7天VIP权限已赠送至您的账户。
  235. </div>
  236. )}
  237. <Ratio text="身份" subtext={PrepareStatusMap[data.prepareStatus]} values={stat.status || []} />
  238. <Ratio
  239. text="考试时间"
  240. subtext={PrepareExaminationTimeMap[data.prepareExaminationTime]}
  241. values={stat.examinationTime || []}
  242. />
  243. <Ratio text="目标成绩" subtext={`${data.prepareGoal}分`} values={stat.goal || []} />
  244. <Ratio
  245. text="出分日期"
  246. subtext={`${formatDate(data.prepareScoreTime, 'YYYY-MM')}`}
  247. values={stat.scoreTime || []}
  248. />
  249. </div>
  250. );
  251. }
  252. }