steps.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. import SpinContainer from "../../SpinContainer";
  15. const Step = Steps.Step;
  16. const steps = [
  17. {
  18. title: '基本信息',
  19. content: Step1
  20. },
  21. {
  22. title: '法律状况评估',
  23. content: Step2
  24. },
  25. {
  26. title: '技术状况评估',
  27. content: Step3
  28. },
  29. {
  30. title: '历史收入',
  31. content: Step4
  32. },
  33. {
  34. title: '收入预估',
  35. content: Step5
  36. },
  37. {
  38. title: '所得税预估',
  39. content: Step6
  40. },
  41. {
  42. title: '风险预估',
  43. content: Step7
  44. },
  45. {
  46. title: '评估值',
  47. content: Step8
  48. }
  49. ];
  50. const EvaluateSteps = React.createClass({
  51. getInitialState() {
  52. return {
  53. current: 0,
  54. loading: true,
  55. steps: null,
  56. value: 0,
  57. step: 0,
  58. dottList:[]
  59. };
  60. },
  61. next(values) {
  62. console.log(values)
  63. if (this.state.current == 7) {
  64. this.state.value = values;
  65. return;
  66. } else {
  67. this.state.value = 0;
  68. }
  69. const current = this.state.current + 1;
  70. this.state.steps[this.state.current] = values;
  71. if (this.state.current === 0 && this.props.title) {
  72. this.props.title(values.name);
  73. }
  74. if(!this.state.current){
  75. this.loadData(this.props.id)
  76. }
  77. this.setState({
  78. current: current,
  79. steps: this.state.steps
  80. });
  81. },
  82. prev() {
  83. const current = this.state.current - 1;
  84. this.setState({ current });
  85. },
  86. loadData(id) {
  87. this.state.dottList=[];
  88. this.state.step=0;
  89. $.ajax({
  90. url: globalConfig.context + '/api/user/evaluate/info/' + id
  91. })
  92. .done(
  93. function(res) {
  94. if (res && res.data) {
  95. this.setState({
  96. steps: res.data.steps || {},
  97. current: res.data.step || 0,
  98. step: res.data.step || 0,
  99. value: res.data.value || 0,
  100. loading: false
  101. });
  102. if (this.props.title) {
  103. this.props.title(res.data.name || '');
  104. }
  105. }
  106. }.bind(this)
  107. )
  108. .fail(
  109. function() {
  110. this.setState({
  111. loading: false
  112. });
  113. }.bind(this)
  114. );
  115. this.setState({
  116. current: this.props.step || 0
  117. });
  118. },
  119. componentWillMount() {
  120. this.loadData(this.props.id);
  121. },
  122. componentWillReceiveProps(nextProps) {
  123. if (!this.props.visible && nextProps.visible) {
  124. if (nextProps.id) {
  125. this.loadData(nextProps.id);
  126. }
  127. }
  128. },
  129. progressDot(dot, { index }) {
  130. return (
  131. <span
  132. style={{ cursor: 'pointer' }}
  133. onClick={() => {
  134. let dottList=this.state.dottList;
  135. if(index>0){
  136. dottList.push(index)
  137. }
  138. if (index == this.state.step || !!this.state.steps[index]) {
  139. this.setState({
  140. current: index,
  141. dottList:dottList
  142. });
  143. }
  144. }}
  145. >
  146. {dot}
  147. </span>
  148. );
  149. },
  150. render() {
  151. this.state.StepContent = steps[this.state.current].content;
  152. let loadContent = !!this.state.steps;
  153. let dottList =this.state.dottList;
  154. return (
  155. <SpinContainer spinning={this.state.loading}>
  156. <div style={{ marginTop: 10 }}>
  157. <Steps current={this.state.current} progressDot={this.progressDot} value={this.state.value}>
  158. {steps.map((item) => <Step key={item.title} title={item.title} />)}
  159. </Steps>
  160. <div className="steps-content">
  161. {loadContent ? (
  162. <this.state.StepContent
  163. next={this.next}
  164. prev={this.prev}
  165. id={this.props.id}
  166. visible={this.props.visible}
  167. data={this.state.step||dottList.length?this.state.steps[this.state.current]:{}}
  168. record={this.state.steps}
  169. value={this.state.value}
  170. />
  171. ) : (
  172. <div />
  173. )}
  174. </div>
  175. </div>
  176. </SpinContainer>
  177. );
  178. }
  179. });
  180. export default EvaluateSteps;