index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import { Icon } from 'antd';
  4. import { Main } from '../../stores/main';
  5. export default class extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = { quant: 50 };
  9. this.time = 0;
  10. this.compute(props.value, 50);
  11. }
  12. componentWillReceiveProps(nextProps) {
  13. if (this.props.value !== nextProps.value) {
  14. this.compute(nextProps.value, this.state.quant || 50);
  15. }
  16. }
  17. compute(value, quant) {
  18. this.time += 1;
  19. const number = this.time;
  20. this.setState({ quant });
  21. Main.getScore(value, quant)
  22. .then(result => {
  23. if (number !== this.time) return;
  24. this.setState({ data: result });
  25. })
  26. .catch(() => {
  27. });
  28. }
  29. render() {
  30. const { value, onChange } = this.props;
  31. const { data = {} } = this.state;
  32. return (
  33. <div className="total-sort">
  34. <div className="total-sort-num">
  35. <Icon className="minus" type="minus" onClick={() => {
  36. onChange(Math.max(value - 10, 200));
  37. }} />
  38. <input value={value} />
  39. <Icon className="plus" type="plus" onClick={() => {
  40. onChange(Math.min(value + 10, 800));
  41. }} />
  42. </div>
  43. <div className="total-sort-desc">
  44. 预计全球排名<b>{data.totalRank || 0}th</b>
  45. </div>
  46. <div className="total-sort-list">
  47. <div className="item">
  48. <div className="sort-num">
  49. <div className="sort-text">Quant :</div>
  50. <input value={this.state.quant} />
  51. <Icon className="up" type="caret-up" onClick={() => {
  52. this.compute(value, Math.min(this.state.quant + 1, 51));
  53. }} />
  54. <Icon className="down" type="caret-down" onClick={() => {
  55. this.compute(value, Math.max(this.state.quant - 1, 6));
  56. }} />
  57. </div>
  58. <div className="t2">
  59. 排名<b>{data.quantRank || 0}th</b>
  60. </div>
  61. </div>
  62. <div className="item">
  63. <div className="sort-num">
  64. <div className="sort-text">Verbal :</div>
  65. <input value={data.verbalScore} />
  66. {/* <Icon className="up" type="caret-up" />
  67. <Icon className="down" type="caret-down" /> */}
  68. </div>
  69. <div className="t2">
  70. 排名<b>{data.verbalRank || 0}th</b>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. );
  76. }
  77. }