step1.jsx 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. componentWillReceiveProps(nextProps) {
  31. if(!this.props.visible&&nextProps.visible){
  32. this.setState({
  33. initialData:nextProps.data
  34. })
  35. this.loadData()
  36. }
  37. },
  38. loadData() {
  39. $.when($.ajax({
  40. url: globalConfig.context + '/open/findIndustryCategory'
  41. }), $.ajax({
  42. url: globalConfig.context + '/open/findDistrict'
  43. })).done(function (industryRes, districtRes) {
  44. let i = [], d = [{
  45. id: 0, level: 0, pid: 0, name: '全国'
  46. }];
  47. if (industryRes[0] && industryRes[0].data) {
  48. i = industryRes[0].data;
  49. }
  50. if (districtRes[0] && districtRes[0].data) {
  51. d = d.concat(districtRes[0].data);
  52. }
  53. this.setState({
  54. loading: false,
  55. industry: i,
  56. district: d
  57. });
  58. if (this.state.initialData) {
  59. this.changeFormField({
  60. 'industry': this.stringify(this.state.initialData.industry),
  61. 'transferArea': this.state.initialData.transferArea && this.state.initialData.transferArea.split(',')
  62. });
  63. this.loadSubIndustry(this.state.initialData.industry, this.state.initialData.subIndustry)
  64. }
  65. }.bind(this)).fail(function () {
  66. this.setState({
  67. loading: false
  68. })
  69. }.bind(this));
  70. },
  71. loadIndustry(pid, initValue) {
  72. if (this.industryLoader) {
  73. this.industryLoader.abort();
  74. }
  75. this.setState({
  76. loading: true
  77. })
  78. this.industryLoader = $.ajax({
  79. url: globalConfig.context + '/open/findIndustryCategory',
  80. method: 'get',
  81. data: {
  82. id: pid || 0
  83. }
  84. }).done(function (res) {
  85. if (res.data && res.data.length) {
  86. this.state.subIndustries[pid] = res.data;
  87. this.setState({
  88. loading: false,
  89. subIndustry: res.data
  90. })
  91. if (initValue) {
  92. this.changeFormField({
  93. 'subIndustry': initValue.split(',')
  94. });
  95. }
  96. }
  97. }.bind(this)).always(function () {
  98. this.setState({
  99. loading: false
  100. })
  101. }.bind(this));
  102. },
  103. loadSubIndustry(pid, initValue) {
  104. let { subIndustries } = this.state;
  105. pid = Number(pid);
  106. this.changeFormField({
  107. 'subIndustry': []
  108. });
  109. if (subIndustries[pid]) {
  110. this.setState({
  111. subIndustry: subIndustries[pid]
  112. })
  113. } else {
  114. this.loadIndustry(pid, initValue)
  115. }
  116. },
  117. subIndustryChanged(values) {
  118. let warn = false
  119. while (values.length > 3) {
  120. values.pop();
  121. warn = true;
  122. }
  123. if (warn) {
  124. message.warn("子行业最多选择三个!")
  125. this.changeFormField({
  126. 'subIndustry': values
  127. });
  128. }
  129. },
  130. districtChanged(values) {
  131. let warn = false
  132. values.forEach((val) => {
  133. if (val === '0') {
  134. warn = true;
  135. }
  136. });
  137. if (warn) {
  138. this.changeFormField({
  139. 'transferArea': ['0']
  140. });
  141. }
  142. },
  143. changeFormField(data) {
  144. setTimeout(function () {
  145. this.props.form.setFieldsValue(data);
  146. }.bind(this), 10);
  147. },
  148. next() {
  149. if (this.state.loading) {
  150. return;
  151. }
  152. this.props.form.validateFields((err, values) => {
  153. if (!err) {
  154. this.setState({
  155. loading: true
  156. })
  157. values.id = this.props.id;
  158. values.subIndustry = values.subIndustry.join(',');
  159. values.transferArea = values.transferArea.join(',');
  160. values.benchmarkDate = values.benchmarkDate.format('YYYY-MM-DD')
  161. $.ajax({
  162. url: globalConfig.context + '/api/user/evaluate/step1',
  163. method: 'post',
  164. data: values
  165. }).done(function (res) {
  166. if (res.error && res.error.length) {
  167. message.error(res.error[0].message)
  168. } else {
  169. if (this.props.next) {
  170. this.props.next(values);
  171. }
  172. }
  173. }.bind(this)).fail(function () {
  174. this.setState({
  175. loading: false
  176. })
  177. }.bind(this));
  178. }
  179. });
  180. },
  181. onDateChange(date) {
  182. date && date.date(1)
  183. this.changeFormField({
  184. 'benchmarkDate': date
  185. });
  186. },
  187. stringify(val) {
  188. return val && String(val)
  189. },
  190. render() {
  191. const { getFieldDecorator } = this.props.form;
  192. let { subIndustry, industry, district, loading} = this.state;
  193. let initialData=this.state.initialData||{};
  194. return (
  195. <Spin spinning={loading}>
  196. <Form className="steps-form">
  197. <FormItem label="技术名称" {...formItemLayout}>
  198. {getFieldDecorator('name', {
  199. rules: [{ required: true, message: '请输入技术名称!' }],
  200. initialValue: initialData.name
  201. })(
  202. <Input placeholder="请输入技术名称" />
  203. )}
  204. </FormItem>
  205. <FormItem label="所属主行业" {...formItemLayout}>
  206. {getFieldDecorator('industry', {
  207. rules: [{ required: true, message: '请选择技术所属主行业!' }],
  208. initialValue:initialData.industry
  209. })(
  210. <Select placeholder="请选择技术所属主行业" onChange={this.loadSubIndustry}>
  211. {industry.map((it) => {
  212. return <Option key={it.id} value={String(it.id)}>{it.name}</Option>
  213. })}
  214. </Select>
  215. )}
  216. </FormItem>
  217. <FormItem label="所属子行业" {...formItemLayout}>
  218. {getFieldDecorator('subIndustry', {
  219. rules: [{ required: true, message: '请选择技术所属子行业!' }],
  220. initialValue:initialData.subIndustry
  221. })(
  222. <Select placeholder="请选择技术所属子行业" allowClear={true} multiple={true} onChange={this.subIndustryChanged}>
  223. {
  224. subIndustry.length ? subIndustry.map((it) => {
  225. return <Option key={it.id} value={String(it.id)}>{it.name}</Option>
  226. }) : []
  227. }
  228. </Select>
  229. )}
  230. </FormItem>
  231. <FormItem label="转让方式" {...formItemLayout}>
  232. {getFieldDecorator('transferType', {
  233. rules: [{ required: true, message: '请选择技术转让方式!' }],
  234. initialValue: this.stringify(initialData.transferType)
  235. })(
  236. <Select placeholder="请选择技术转让方式">
  237. {transferTypes.map((it) => {
  238. return <Option key={it.id} value={it.id}>{it.text}</Option>
  239. })}
  240. </Select>
  241. )}
  242. </FormItem>
  243. <FormItem label="预估技术剩余寿命" {...formItemLayout}>
  244. {getFieldDecorator('timeLeft', {
  245. rules: [{ required: true, message: '请选择技术剩余寿命!' }],
  246. initialValue: this.stringify(initialData.timeLeft)
  247. })(
  248. <Select placeholder="请选择技术剩余寿命">
  249. {leftTimes.map((it) => {
  250. return <Option key={it.id} value={it.id}>{it.text}</Option>
  251. })}
  252. </Select>
  253. )}
  254. </FormItem>
  255. <FormItem label="转让区域" {...formItemLayout}>
  256. {getFieldDecorator('transferArea', {
  257. rules: [{ required: true, message: '请选择技术转让区域!' }],
  258. initialValue:initialData.transferArea
  259. })(
  260. <Select placeholder="请选择技术转让区域" allowClear={true} multiple={true} onChange={this.districtChanged}>
  261. {district.map((it) => {
  262. return <Option key={it.id} value={String(it.id)}>{it.name}</Option>
  263. })}
  264. </Select>
  265. )}
  266. </FormItem>
  267. <FormItem label="评估基准日" {...formItemLayout}>
  268. {getFieldDecorator('benchmarkDate', {
  269. rules: [{ required: true, message: '请输入评估基准日!' }],
  270. initialValue: initialData.benchmarkDate ? moment(initialData.benchmarkDate, 'YYYY-MM-DD') : null
  271. })(
  272. <MonthPicker allowClear={false} onChange={this.onDateChange} placeholder="请输入评估基准日" format="YYYY-MM-DD" />
  273. )}
  274. </FormItem>
  275. <FormItem label="评估币种" {...formItemLayout}>
  276. {getFieldDecorator('currencyType', {
  277. rules: [{ required: true, message: '请选择评估币种!' }],
  278. initialValue: initialData.currencyType || '人民币 (RMB)'
  279. })(
  280. <Select placeholder="请选择评估币种">
  281. {currency.map((it, idx) => {
  282. return <Option key={idx} value={it}>{it}</Option>
  283. })}
  284. </Select>
  285. )}
  286. </FormItem>
  287. </Form>
  288. <div className="steps-action">
  289. <Button type="primary" onClick={this.next}>保存,下一步</Button>
  290. </div>
  291. </Spin>
  292. )
  293. },
  294. }));
  295. export default EvaluateStep1;