index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if (value === this.props.value && quant === this.state.quant) return;
  19. console.log(quant);
  20. this.time += 1;
  21. const number = this.time;
  22. this.setState({ quant });
  23. Main.getScore(value, quant)
  24. .then(result => {
  25. if (number !== this.time) return;
  26. this.setState({ data: result });
  27. })
  28. .catch(() => {
  29. });
  30. }
  31. render() {
  32. const { value, onChange } = this.props;
  33. const { data = {} } = this.state;
  34. return (
  35. <div className="total-sort">
  36. <div className="total-sort-num">
  37. <Icon className="minus" type="minus" onClick={() => {
  38. onChange(Math.max(value - 10, 200));
  39. }} />
  40. <input value={value} />
  41. <Icon className="plus" type="plus" onClick={() => {
  42. onChange(Math.min(value + 10, 800));
  43. }} />
  44. </div>
  45. <div className="total-sort-desc">
  46. 预计全球排名<b>{data.totalRank || 0}th</b>
  47. </div>
  48. <div className="total-sort-list">
  49. <div className="item">
  50. <div className="sort-num">
  51. <div className="sort-text">Quant :</div>
  52. <input value={this.state.quant} />
  53. <Icon className="up" type="caret-up" onClick={() => {
  54. this.compute(value, Math.min(this.state.quant + 1, 51));
  55. }} />
  56. <Icon className="down" type="caret-down" onClick={() => {
  57. this.compute(value, Math.max(this.state.quant - 1, 6));
  58. }} />
  59. </div>
  60. <div className="t2">
  61. 排名<b>{data.quantRank || 0}th</b>
  62. </div>
  63. </div>
  64. <div className="item">
  65. <div className="sort-num">
  66. <div className="sort-text">Verbal :</div>
  67. <input value={data.verbalScore} />
  68. {/* <Icon className="up" type="caret-up" />
  69. <Icon className="down" type="caret-down" /> */}
  70. </div>
  71. <div className="t2">
  72. 排名<b>{data.verbalRank || 0}th</b>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. );
  78. }
  79. }