steps.jsx 3.7 KB

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