import React, { Component } from 'react';
import './index.less';
import { Icon } from 'antd';
import { getMap, formatDate, formatPercent } from '@src/services/Tools';
import moment from 'moment';
import { SpecialRadioGroup } from '../Radio';
import Modal from '../Modal';
import Button from '../Button';
import TotalSort from '../TotalSort';
import Date from '../Date';
import Ratio from '../Ratio';
import { My } from '../../stores/my';
import { Main } from '../../stores/main';
import { PrepareStatus, PrepareExaminationTime, PrepareScoreTime } from '../../../Constant';
const PrepareStatusMap = getMap(PrepareStatus, 'value', 'short');
const PrepareExaminationTimeMap = getMap(PrepareExaminationTime, 'value', 'label');
const PrepareScoreTimeMap = getMap(PrepareScoreTime, 'value', 'label');
export default class extends Component {
constructor(props) {
super(props);
this.statusColors = ['#41A6F3', '#3F86EA', '#41A6F3', '#6DC0FF', '#9BD4FF'];
this.examinationTimeColors = ['#6865FD', '#322EF2', '#8F65FF', '#8C8AFF'];
this.goalColors = ['#2754E0', '#3F86EA', '#41A6F3', '#6DC0FF'];
this.scoreTimeColors = ['#6865FD', '#322EF2', '#8F65FF', '#8C8AFF', '#8F65FF', '#C3C1D1'];
this.stepProp = {
0: {
title: '我的身份',
},
1: {
title: '下次考试时间',
},
2: {
title: '目标成绩',
},
3: {
title: '最晚出分时间(选填)',
},
4: {
title: '备考信息',
onConfirm: props.onConfirm,
onCancel: () => {
this.setState({ step: 0 });
},
confirmText: '关闭',
cancelText: '修改',
},
};
this.state = { step: 0, data: { prepareGoal: 650 } };
My.getPrepare()
.then(result => {
const statusTotal = result.stat.status.reduce((p, n) => { return p + n.value; }, 0);
const goalTotal = result.stat.goal.reduce((p, n) => { return p + n.value; }, 0);
const examinationTimeTotal = result.stat.examinationTime.reduce((p, n) => { return p + n.value; }, 0);
const scoreTimeTotal = result.stat.scoreTime.reduce((p, n) => { return p + n.value; }, 0);
const stat = {
status: result.stat.status.map((row, index) => {
row.value = formatPercent(row.value, statusTotal);
row.label = `${PrepareStatusMap[row.key]}; ${row.value}%`;
row.color = this.statusColors[index];
return row;
}),
goal: result.stat.goal.map((row, index) => {
row.value = formatPercent(row.value, goalTotal);
row.label = `${row.key}+; ${row.value}%`;
row.color = this.goalColors[index];
return row;
}),
examinationTime: result.stat.status.map((row, index) => {
row.value = formatPercent(row.value, examinationTimeTotal);
row.label = `${PrepareExaminationTimeMap[row.key]}; ${row.value}%`;
row.color = this.examinationTimeColors[index];
return row;
}),
scoreTime: result.stat.scoreTime.map((row, index) => {
row.value = formatPercent(row.value, scoreTimeTotal);
row.label = `${PrepareScoreTimeMap[row.key]}; ${row.value}%`;
row.color = this.scoreTimeColors[index];
return row;
}),
};
result.prepareGoal = result.prepareGoal || 650;
result.prepareScoreTime = result.prepareScoreTime ? moment(result.prepareScoreTime) : null;
this.setState({ data: result, stat, first: !result.prepareStatus, step: !result.prepareStatus ? 0 : 4 });
});
Main.getContract('register').then(() => {
this.setState({ link: { url: 'www', title: '了解出分时间信息>' } });
});
}
onChange(type, key) {
const { data } = this.state;
data[type] = key;
this.setState({ data });
}
onPrev() {
const { step } = this.state;
this.setState({ step: step - 1 });
}
onNext() {
const { step } = this.state;
this.setState({ step: step + 1 });
}
submitPrepare() {
const { data } = this.state;
My.editPrepare(data).then(result => {
this.setState({ result });
this.onNext();
});
}
onClose() {
const { onClose } = this.props;
if (onClose) onClose();
this.setState({ step: 0 });
}
render() {
const { step } = this.state;
const { show } = this.props;
return (