import React, { Component } from 'react'; import './index.less'; import { Icon } from 'antd'; import { Main } from '../../stores/main'; export default class extends Component { constructor(props) { super(props); this.state = { quant: 50 }; this.time = 0; this.compute(props.value, 50); } componentWillReceiveProps(nextProps) { if (this.props.value !== nextProps.value) { this.compute(nextProps.value, this.state.quant || 50); } } compute(value, quant) { if (value === this.props.value && quant === this.state.quant) return; console.log(quant); this.time += 1; const number = this.time; this.setState({ quant }); Main.getScore(value, quant) .then(result => { if (number !== this.time) return; this.setState({ data: result }); }) .catch(() => { }); } render() { const { value, onChange } = this.props; const { data = {} } = this.state; return (
{ onChange(Math.max(value - 10, 200)); }} /> { onChange(Math.min(value + 10, 800)); }} />
预计全球排名{data.totalRank || 0}th
Quant :
{ this.compute(value, Math.min(this.state.quant + 1, 51)); }} /> { this.compute(value, Math.max(this.state.quant - 1, 6)); }} />
排名{data.quantRank || 0}th
Verbal :
{/* */}
排名{data.verbalRank || 0}th
); } }