index.js 6.6 KB

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