steps.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import React from 'react';
  2. import { Steps, Spin } from 'antd';
  3. import './steps.less';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. import Step1 from './steps/step1';
  7. import Step2 from './steps/step2';
  8. import Step3 from './steps/step3';
  9. import Step4 from './steps/step4';
  10. import Step5 from './steps/step5';
  11. import Step6 from './steps/step6';
  12. import Step7 from './steps/step7';
  13. import Step8 from './steps/step8';
  14. const Step = Steps.Step;
  15. const steps = [{
  16. title: '基本信息',
  17. content: Step1
  18. }, {
  19. title: '法律状况评估',
  20. content: Step2
  21. }, {
  22. title: '技术状况评估',
  23. content: Step3
  24. }, {
  25. title: '历史收入',
  26. content: Step4
  27. }, {
  28. title: '收入预估',
  29. content: Step5
  30. }, {
  31. title: '所得税预估',
  32. content: Step6
  33. }, {
  34. title: '风险预估',
  35. content: Step7
  36. }, {
  37. title: '评估值',
  38. content: Step8
  39. }];
  40. const EvaluateSteps = React.createClass({
  41. getInitialState() {
  42. return {
  43. current: 0,
  44. loading: true,
  45. steps: null,
  46. value: 0,
  47. step: 0
  48. };
  49. },
  50. next(values) {
  51. if (this.state.current == 7) {
  52. this.state.value = values;
  53. return;
  54. } else {
  55. this.state.value = 0;
  56. }
  57. const current = this.state.current + 1;
  58. this.state.steps[this.state.current] = values;
  59. if (this.state.current === 0 && this.props.title) {
  60. this.props.title(values.name);
  61. }
  62. this.setState({
  63. current: current,
  64. steps: this.state.steps
  65. });
  66. },
  67. prev() {
  68. const current = this.state.current - 1;
  69. this.setState({ current });
  70. },
  71. componentWillMount() {
  72. $.ajax({
  73. url: globalConfig.context + '/api/user/evaluate/info/' + this.props.id
  74. }).done(function (res) {
  75. if (res && res.data) {
  76. this.setState({
  77. steps: res.data.steps || {},
  78. current: res.data.step || 0,
  79. step: res.data.step || 0,
  80. value: res.data.value || 0,
  81. loading: false
  82. })
  83. if (this.props.title) {
  84. this.props.title(res.data.name || '');
  85. }
  86. }
  87. }.bind(this)).fail(function () {
  88. this.setState({
  89. loading: false
  90. })
  91. }.bind(this));
  92. this.setState({
  93. current: this.props.step || 0
  94. })
  95. },
  96. progressDot(dot, { index }) {
  97. return <span style={{ cursor: 'pointer' }} onClick={() => {
  98. if (index == this.state.step || !!this.state.steps[index]) {
  99. this.setState({
  100. current: index
  101. })
  102. }
  103. }}>{dot}</span>
  104. },
  105. render() {
  106. this.state.StepContent = steps[this.state.current].content;
  107. let loadContent = !!this.state.steps
  108. return (
  109. <Spin spinning={this.state.loading} >
  110. <div style={{ marginTop: 10 }}>
  111. <Steps current={this.state.current} progressDot={this.progressDot} value={this.state.value}>
  112. {steps.map(item => <Step key={item.title} title={item.title} />)}
  113. </Steps>
  114. <div className="steps-content">{
  115. loadContent ? <this.state.StepContent next={this.next} prev={this.prev} id={this.props.id} data={this.state.steps[this.state.current]} record={this.state.steps} value={this.state.value} />
  116. : <div />
  117. }</div>
  118. </div>
  119. </Spin >
  120. )
  121. },
  122. });
  123. export default EvaluateSteps;