index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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, info: result.info });
  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).then(result => {
  101. this.setState({ result });
  102. this.onNext();
  103. });
  104. }
  105. onClose() {
  106. const { onClose } = this.props;
  107. if (onClose) onClose();
  108. this.setState({ step: 0 });
  109. }
  110. render() {
  111. const { step } = this.state;
  112. const { show } = this.props;
  113. return (
  114. <Modal
  115. className="examination-modal"
  116. show={show}
  117. width={460}
  118. {...this.stepProp[step]}
  119. onClose={() => this.onClose()}
  120. >
  121. <div className="examination-modal-wrapper">{this[`renderStep${step}`]()}</div>
  122. </Modal>
  123. );
  124. }
  125. renderStep0() {
  126. const { data } = this.state;
  127. const { prepareStatus } = data;
  128. return (
  129. <div className="step-0-layout">
  130. <SpecialRadioGroup
  131. list={PrepareStatus}
  132. value={prepareStatus}
  133. width={190}
  134. space={10}
  135. onChange={key => this.onChange('prepareStatus', key)}
  136. />
  137. <div className="action-layout">
  138. <div className="next" onClick={() => prepareStatus && this.onNext()}>
  139. 下一题
  140. <Icon type="right-circle" theme="filled" />
  141. </div>
  142. </div>
  143. </div>
  144. );
  145. }
  146. renderStep1() {
  147. const { data } = this.state;
  148. const { prepareExaminationTime } = data;
  149. return (
  150. <div className="step-1-layout">
  151. <SpecialRadioGroup
  152. list={PrepareExaminationTime}
  153. value={prepareExaminationTime}
  154. width={195}
  155. space={10}
  156. onChange={key => this.onChange('prepareExaminationTime', key)}
  157. />
  158. <div className="action-layout">
  159. <div className="prev" onClick={() => this.onPrev()}>
  160. <Icon type="left-circle" theme="filled" />
  161. 上一题
  162. </div>
  163. <div className="next" onClick={() => prepareExaminationTime && this.onNext()}>
  164. 下一题
  165. <Icon type="right-circle" theme="filled" />
  166. </div>
  167. </div>
  168. </div>
  169. );
  170. }
  171. renderStep2() {
  172. const { data } = this.state;
  173. const { prepareGoal } = data;
  174. return (
  175. <div className="step-2-layout">
  176. <TotalSort
  177. value={prepareGoal}
  178. onChange={goal => {
  179. this.onChange('prepareGoal', goal);
  180. }}
  181. />
  182. <div className="action-layout">
  183. <div className="prev" onClick={() => this.onPrev()}>
  184. <Icon type="left-circle" theme="filled" />
  185. 上一题
  186. </div>
  187. <div className="next" onClick={() => prepareGoal && this.onNext()}>
  188. 下一题
  189. <Icon type="right-circle" theme="filled" />
  190. </div>
  191. </div>
  192. </div>
  193. );
  194. }
  195. renderStep3() {
  196. const { data, info, step } = this.state;
  197. const { prepareScoreTime } = data;
  198. return (
  199. <div className="step-3-layout">
  200. {info && <a href={info.link} className="a-l" target='_blank'>{info.title}</a>}
  201. <Date
  202. show={step === 3}
  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. }