step1.jsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import React from 'react';
  2. import { Form, Select, Input, Cascader, Spin, message, Button, DatePicker } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js'
  4. import $ from 'jquery/src/ajax';
  5. import moment from 'moment';
  6. import { transferTypes, leftTimes } from './dict.js';
  7. const FormItem = Form.Item;
  8. const Option = Select.Option;
  9. const MonthPicker = DatePicker.MonthPicker;
  10. const formItemLayout = {
  11. labelCol: { span: 4 },
  12. wrapperCol: { span: 10 },
  13. };
  14. const currency = ['人民币 (RMB)', '美金 (USD)', '台币(TWD)', '港币 (HKD)', '澳门元(MOP)', '欧元 (EUR)', '英镑 (GBP)', '日元 (JPY)', '澳大利亚元 (AUD)', '巴西里亚尔(BRL)', '加拿大元 (CAD)', '瑞士法郎 (CHF)', '丹麦克朗(DKK)', '印尼卢比 (IDR)', '韩国元 (KRW)', '林吉特(MYR)', '新西兰元 (NZD)', '菲律宾比索 (PHP)', '瑞典克朗 (SEK)', '新加坡元 (SGD)', '泰国铢 (THB)', '越南盾 (VND)', '南非兰特 (ZAR)']
  15. const EvaluateStep1 = Form.create({})(React.createClass({
  16. getInitialState() {
  17. return {
  18. loading: true,
  19. industry: [],
  20. district: [],
  21. subIndustries: {},
  22. subIndustry: [],
  23. initialData: {}
  24. };
  25. },
  26. componentWillMount() {
  27. this.loadData();
  28. this.state.initialData = this.props.data || {};
  29. },
  30. loadData() {
  31. $.when($.ajax({
  32. url: globalConfig.context + '/open/findIndustryCategory'
  33. }), $.ajax({
  34. url: globalConfig.context + '/open/findDistrict'
  35. })).done(function (industryRes, districtRes) {
  36. let i = [], d = [{
  37. id: 0, level: 0, pid: 0, name: '全国'
  38. }];
  39. if (industryRes[0] && industryRes[0].data) {
  40. i = industryRes[0].data;
  41. }
  42. if (districtRes[0] && districtRes[0].data) {
  43. d = d.concat(districtRes[0].data);
  44. }
  45. this.setState({
  46. loading: false,
  47. industry: i,
  48. district: d
  49. });
  50. if (this.state.initialData) {
  51. this.changeFormField({
  52. 'industry': this.stringify(this.state.initialData.industry),
  53. 'transferArea': this.state.initialData.transferArea && this.state.initialData.transferArea.split(',')
  54. });
  55. this.loadSubIndustry(this.state.initialData.industry, this.state.initialData.subIndustry)
  56. }
  57. }.bind(this)).fail(function () {
  58. this.setState({
  59. loading: false
  60. })
  61. }.bind(this));
  62. },
  63. loadIndustry(pid, initValue) {
  64. if (this.industryLoader) {
  65. this.industryLoader.abort();
  66. }
  67. this.setState({
  68. loading: true
  69. })
  70. this.industryLoader = $.ajax({
  71. url: globalConfig.context + '/open/findIndustryCategory',
  72. method: 'get',
  73. data: {
  74. id: pid || 0
  75. }
  76. }).done(function (res) {
  77. if (res.data && res.data.length) {
  78. this.state.subIndustries[pid] = res.data;
  79. this.setState({
  80. loading: false,
  81. subIndustry: res.data
  82. })
  83. if (initValue) {
  84. this.changeFormField({
  85. 'subIndustry': initValue.split(',')
  86. });
  87. }
  88. }
  89. }.bind(this)).always(function () {
  90. this.setState({
  91. loading: false
  92. })
  93. }.bind(this));
  94. },
  95. loadSubIndustry(pid, initValue) {
  96. let { subIndustries } = this.state;
  97. pid = Number(pid);
  98. this.changeFormField({
  99. 'subIndustry': []
  100. });
  101. if (subIndustries[pid]) {
  102. this.setState({
  103. subIndustry: subIndustries[pid]
  104. })
  105. } else {
  106. this.loadIndustry(pid, initValue)
  107. }
  108. },
  109. subIndustryChanged(values) {
  110. let warn = false
  111. while (values.length > 3) {
  112. values.pop();
  113. warn = true;
  114. }
  115. if (warn) {
  116. message.warn("子行业最多选择三个!")
  117. this.changeFormField({
  118. 'subIndustry': values
  119. });
  120. }
  121. },
  122. districtChanged(values) {
  123. let warn = false
  124. values.forEach((val) => {
  125. if (val === '0') {
  126. warn = true;
  127. }
  128. });
  129. if (warn) {
  130. this.changeFormField({
  131. 'transferArea': ['0']
  132. });
  133. }
  134. },
  135. changeFormField(data) {
  136. setTimeout(function () {
  137. this.props.form.setFieldsValue(data);
  138. }.bind(this), 10);
  139. },
  140. next() {
  141. if (this.state.loading) {
  142. return;
  143. }
  144. this.props.form.validateFields((err, values) => {
  145. if (!err) {
  146. this.setState({
  147. loading: true
  148. })
  149. values.id = this.props.id;
  150. values.subIndustry = values.subIndustry.join(',');
  151. values.transferArea = values.transferArea.join(',');
  152. values.benchmarkDate = values.benchmarkDate.format('YYYY-MM-DD')
  153. $.ajax({
  154. url: globalConfig.context + '/api/user/evaluate/step1',
  155. method: 'post',
  156. data: values
  157. }).done(function (res) {
  158. if (res.error && res.error.length) {
  159. message.error(res.error[0].message)
  160. } else {
  161. if (this.props.next) {
  162. this.props.next(values);
  163. }
  164. }
  165. }.bind(this)).fail(function () {
  166. this.setState({
  167. loading: false
  168. })
  169. }.bind(this));
  170. }
  171. });
  172. },
  173. onDateChange(date) {
  174. date && date.date(1)
  175. this.changeFormField({
  176. 'benchmarkDate': date
  177. });
  178. },
  179. stringify(val) {
  180. return val && String(val)
  181. },
  182. render() {
  183. const { getFieldDecorator } = this.props.form;
  184. let { subIndustry, industry, district, loading, initialData } = this.state;
  185. return (
  186. <Spin spinning={loading}>
  187. <Form className="steps-form">
  188. <FormItem label="技术名称" {...formItemLayout}>
  189. {getFieldDecorator('name', {
  190. rules: [{ required: true, message: '请输入技术名称!' }],
  191. initialValue: initialData.name
  192. })(
  193. <Input placeholder="请输入技术名称" />
  194. )}
  195. </FormItem>
  196. <FormItem label="所属主行业" {...formItemLayout}>
  197. {getFieldDecorator('industry', {
  198. rules: [{ required: true, message: '请选择技术所属主行业!' }]
  199. })(
  200. <Select placeholder="请选择技术所属主行业" onChange={this.loadSubIndustry}>
  201. {industry.map((it) => {
  202. return <Option key={it.id} value={String(it.id)}>{it.name}</Option>
  203. })}
  204. </Select>
  205. )}
  206. </FormItem>
  207. <FormItem label="所属子行业" {...formItemLayout}>
  208. {getFieldDecorator('subIndustry', {
  209. rules: [{ required: true, message: '请选择技术所属子行业!' }]
  210. })(
  211. <Select placeholder="请选择技术所属子行业" allowClear={true} multiple={true} onChange={this.subIndustryChanged}>
  212. {
  213. subIndustry.length ? subIndustry.map((it) => {
  214. return <Option key={it.id} value={String(it.id)}>{it.name}</Option>
  215. }) : []
  216. }
  217. </Select>
  218. )}
  219. </FormItem>
  220. <FormItem label="转让方式" {...formItemLayout}>
  221. {getFieldDecorator('transferType', {
  222. rules: [{ required: true, message: '请选择技术转让方式!' }],
  223. initialValue: this.stringify(initialData.transferType)
  224. })(
  225. <Select placeholder="请选择技术转让方式">
  226. {transferTypes.map((it) => {
  227. return <Option key={it.id} value={it.id}>{it.text}</Option>
  228. })}
  229. </Select>
  230. )}
  231. </FormItem>
  232. <FormItem label="预估技术剩余寿命" {...formItemLayout}>
  233. {getFieldDecorator('timeLeft', {
  234. rules: [{ required: true, message: '请选择技术剩余寿命!' }],
  235. initialValue: this.stringify(initialData.timeLeft)
  236. })(
  237. <Select placeholder="请选择技术剩余寿命">
  238. {leftTimes.map((it) => {
  239. return <Option key={it.id} value={it.id}>{it.text}</Option>
  240. })}
  241. </Select>
  242. )}
  243. </FormItem>
  244. <FormItem label="转让区域" {...formItemLayout}>
  245. {getFieldDecorator('transferArea', {
  246. rules: [{ required: true, message: '请选择技术转让区域!' }]
  247. })(
  248. <Select placeholder="请选择技术转让区域" allowClear={true} multiple={true} onChange={this.districtChanged}>
  249. {district.map((it) => {
  250. return <Option key={it.id} value={String(it.id)}>{it.name}</Option>
  251. })}
  252. </Select>
  253. )}
  254. </FormItem>
  255. <FormItem label="评估基准日" {...formItemLayout}>
  256. {getFieldDecorator('benchmarkDate', {
  257. rules: [{ required: true, message: '请输入评估基准日!' }],
  258. initialValue: initialData.benchmarkDate ? moment(initialData.benchmarkDate, 'YYYY-MM-DD') : null
  259. })(
  260. <MonthPicker allowClear={false} onChange={this.onDateChange} placeholder="请输入评估基准日" format="YYYY-MM-DD" />
  261. )}
  262. </FormItem>
  263. <FormItem label="评估币种" {...formItemLayout}>
  264. {getFieldDecorator('currencyType', {
  265. rules: [{ required: true, message: '请选择评估币种!' }],
  266. initialValue: initialData.currencyType || '人民币 (RMB)'
  267. })(
  268. <Select placeholder="请选择评估币种">
  269. {currency.map((it, idx) => {
  270. return <Option key={idx} value={it}>{it}</Option>
  271. })}
  272. </Select>
  273. )}
  274. </FormItem>
  275. </Form>
  276. <div className="steps-action">
  277. <Button type="primary" onClick={this.next}>保存,下一步</Button>
  278. </div>
  279. </Spin>
  280. )
  281. },
  282. }));
  283. export default EvaluateStep1;