1
0

index.js 6.7 KB

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