step3.jsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import React from 'react';
  2. import { Spin, Form, Button, Select, message } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js'
  4. import $ from 'jquery/src/ajax';
  5. import { progressiveness, innovativeness, ripeness, alternatives, defensive, prospect, supplyAndDemand, rangeOfApplication, imitable, profitability } from './dict.js';
  6. const FormItem = Form.Item;
  7. const Option = Select.Option;
  8. const formItemLayout = {
  9. labelCol: { span: 4 },
  10. wrapperCol: { span: 10 },
  11. };
  12. const EvaluateStep3 = Form.create({})(React.createClass({
  13. getInitialState() {
  14. return {
  15. loading: false,
  16. initialData: {}
  17. };
  18. },
  19. componentWillMount() {
  20. this.state.initialData = this.props.data || {};
  21. },
  22. next() {
  23. if (this.state.loading) {
  24. return;
  25. }
  26. this.props.form.validateFields((err, values) => {
  27. if (!err) {
  28. this.setState({
  29. loading: true
  30. })
  31. values.id = this.props.id;
  32. $.ajax({
  33. url: globalConfig.context + '/api/user/evaluate/step3',
  34. method: 'post',
  35. data: values
  36. }).done(function (res) {
  37. if (res.error && res.error.length) {
  38. message.error(res.error[0].message)
  39. } else {
  40. if (this.props.next) {
  41. this.props.next(values);
  42. }
  43. }
  44. }.bind(this)).fail(function () {
  45. this.setState({
  46. loading: false
  47. })
  48. }.bind(this));
  49. }
  50. });
  51. },
  52. prev() {
  53. if (this.props.prev) {
  54. this.props.prev();
  55. }
  56. },
  57. stringify(val) {
  58. return val && String(val)
  59. },
  60. render() {
  61. let { loading, initialData } = this.state;
  62. const { getFieldDecorator } = this.props.form;
  63. return (
  64. <Spin spinning={loading}>
  65. <Form className="steps-form">
  66. <FormItem label="先进性" {...formItemLayout}>
  67. {getFieldDecorator('progressiveness', {
  68. rules: [{ required: true, message: '请选择技术的先进性!' }],
  69. initialValue: this.stringify(initialData.progressiveness)
  70. })(
  71. <Select placeholder="请选择技术的先进性">
  72. {progressiveness.map((it) => {
  73. return <Option key={it.id} value={it.id}>{it.text}</Option>
  74. })}
  75. </Select>
  76. )}
  77. </FormItem>
  78. <FormItem label="创新性" {...formItemLayout}>
  79. {getFieldDecorator('innovativeness', {
  80. rules: [{ required: true, message: '请选择技术的创新性!' }],
  81. initialValue: this.stringify(initialData.innovativeness)
  82. })(
  83. <Select placeholder="请选择技术的创新性">
  84. {innovativeness.map((it) => {
  85. return <Option key={it.id} value={it.id}>{it.text}</Option>
  86. })}
  87. </Select>
  88. )}
  89. </FormItem>
  90. <FormItem label="成熟度" {...formItemLayout}>
  91. {getFieldDecorator('ripeness', {
  92. rules: [{ required: true, message: '请选择技术的成熟度!' }],
  93. initialValue: this.stringify(initialData.ripeness)
  94. })(
  95. <Select placeholder="请选择技术的成熟度">
  96. {ripeness.map((it) => {
  97. return <Option key={it.id} value={it.id}>{it.text}</Option>
  98. })}
  99. </Select>
  100. )}
  101. </FormItem>
  102. <FormItem label="替代性" {...formItemLayout}>
  103. {getFieldDecorator('alternatives', {
  104. rules: [{ required: true, message: '请选择技术的替代性!' }],
  105. initialValue: this.stringify(initialData.alternatives)
  106. })(
  107. <Select placeholder="请选择技术的替代性">
  108. {alternatives.map((it) => {
  109. return <Option key={it.id} value={it.id}>{it.text}</Option>
  110. })}
  111. </Select>
  112. )}
  113. </FormItem>
  114. <FormItem label="技术防御力" {...formItemLayout}>
  115. {getFieldDecorator('defensive', {
  116. rules: [{ required: true, message: '请选择技术的防御力!' }],
  117. initialValue: this.stringify(initialData.defensive)
  118. })(
  119. <Select placeholder="请选择技术的防御力">
  120. {defensive.map((it) => {
  121. return <Option key={it.id} value={it.id}>{it.text}</Option>
  122. })}
  123. </Select>
  124. )}
  125. </FormItem>
  126. <FormItem label="技术领域发展前景" {...formItemLayout}>
  127. {getFieldDecorator('prospect', {
  128. rules: [{ required: true, message: '请选择技术领域发展前景!' }],
  129. initialValue: this.stringify(initialData.prospect)
  130. })(
  131. <Select placeholder="请选择技术领域发展前景">
  132. {prospect.map((it) => {
  133. return <Option key={it.id} value={it.id}>{it.text}</Option>
  134. })}
  135. </Select>
  136. )}
  137. </FormItem>
  138. <FormItem label="供求关系" {...formItemLayout}>
  139. {getFieldDecorator('supplyAndDemand', {
  140. rules: [{ required: true, message: '请选择技术的供求关系!' }],
  141. initialValue: this.stringify(initialData.supplyAndDemand)
  142. })(
  143. <Select placeholder="请选择技术的供求关系">
  144. {supplyAndDemand.map((it) => {
  145. return <Option key={it.id} value={it.id}>{it.text}</Option>
  146. })}
  147. </Select>
  148. )}
  149. </FormItem>
  150. <FormItem label="产品应用范围" {...formItemLayout}>
  151. {getFieldDecorator('rangeOfApplication', {
  152. rules: [{ required: true, message: '请选择技术的应用范围!' }],
  153. initialValue: this.stringify(initialData.rangeOfApplication)
  154. })(
  155. <Select placeholder="请选择技术的应用范围">
  156. {rangeOfApplication.map((it) => {
  157. return <Option key={it.id} value={it.id}>{it.text}</Option>
  158. })}
  159. </Select>
  160. )}
  161. </FormItem>
  162. <FormItem label="遭他人模仿可能性" {...formItemLayout}>
  163. {getFieldDecorator('imitable', {
  164. rules: [{ required: true, message: '请选择技术的模仿可能性!' }],
  165. initialValue: this.stringify(initialData.imitable)
  166. })(
  167. <Select placeholder="请选择技术的模仿可能性">
  168. {imitable.map((it) => {
  169. return <Option key={it.id} value={it.id}>{it.text}</Option>
  170. })}
  171. </Select>
  172. )}
  173. </FormItem>
  174. <FormItem label="独立获利能力" {...formItemLayout}>
  175. {getFieldDecorator('profitability', {
  176. rules: [{ required: true, message: '请选择技术的独立获利能力!' }],
  177. initialValue: this.stringify(initialData.profitability)
  178. })(
  179. <Select placeholder="请选择技术的独立获利能力">
  180. {profitability.map((it) => {
  181. return <Option key={it.id} value={it.id}>{it.text}</Option>
  182. })}
  183. </Select>
  184. )}
  185. </FormItem>
  186. </Form>
  187. <div className="steps-action">
  188. <Button type="primary" onClick={() => this.next()}>保存,下一步</Button>
  189. <Button style={{ marginLeft: 8 }} onClick={() => this.prev()}>上一步</Button>
  190. </div>
  191. </Spin>
  192. )
  193. },
  194. }));
  195. export default EvaluateStep3;