step1.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. this.setState({
  167. loading: false
  168. })
  169. if (res.error && res.error.length) {
  170. message.error(res.error[0].message)
  171. } else {
  172. if (this.props.next) {
  173. this.props.next(values);
  174. }
  175. }
  176. }.bind(this)).fail(function () {
  177. this.setState({
  178. loading: false
  179. })
  180. }.bind(this));
  181. }
  182. });
  183. },
  184. onDateChange(date, dataString) {
  185. // date && date.date(1)
  186. this.changeFormField({
  187. 'benchmarkDate': date
  188. });
  189. },
  190. stringify(val) {
  191. return val && String(val)
  192. },
  193. render() {
  194. const { getFieldDecorator } = this.props.form;
  195. let { subIndustry, industry, district, loading } = this.state;
  196. let initialData = this.state.initialData || {};
  197. return (
  198. <Spin spinning={loading}>
  199. <Form className="steps-form">
  200. <FormItem label="技术名称" {...formItemLayout}>
  201. {getFieldDecorator('name', {
  202. rules: [{ required: true, message: '请输入技术名称!' }],
  203. initialValue: initialData.name
  204. })(
  205. <Input placeholder="请输入技术名称" />
  206. )}
  207. </FormItem>
  208. <FormItem label="所属主行业" {...formItemLayout}>
  209. {getFieldDecorator('industry', {
  210. rules: [{ required: true, message: '请选择技术所属主行业!' }],
  211. initialValue: initialData.industry
  212. })(
  213. <Select placeholder="请选择技术所属主行业" onChange={this.loadSubIndustry}>
  214. {industry.map((it) => {
  215. return <Option key={it.id} value={String(it.id)}>{it.name}</Option>
  216. })}
  217. </Select>
  218. )}
  219. </FormItem>
  220. <FormItem label="所属子行业" {...formItemLayout}>
  221. {getFieldDecorator('subIndustry', {
  222. rules: [{ required: true, message: '请选择技术所属子行业!' }],
  223. initialValue: initialData.subIndustry
  224. })(
  225. <Select placeholder="请选择技术所属子行业" allowClear={true} multiple={true} onChange={this.subIndustryChanged}>
  226. {
  227. subIndustry.length ? subIndustry.map((it) => {
  228. return <Option key={it.id} value={String(it.id)}>{it.name}</Option>
  229. }) : []
  230. }
  231. </Select>
  232. )}
  233. </FormItem>
  234. <FormItem label="转让方式" {...formItemLayout}>
  235. {getFieldDecorator('transferType', {
  236. rules: [{ required: true, message: '请选择技术转让方式!' }],
  237. initialValue: this.stringify(initialData.transferType)
  238. })(
  239. <Select placeholder="请选择技术转让方式">
  240. {transferTypes.map((it) => {
  241. return <Option key={it.id} value={it.id}>{it.text}</Option>
  242. })}
  243. </Select>
  244. )}
  245. </FormItem>
  246. <FormItem label="预估技术剩余寿命" {...formItemLayout}>
  247. {getFieldDecorator('timeLeft', {
  248. rules: [{ required: true, message: '请选择技术剩余寿命!' }],
  249. initialValue: this.stringify(initialData.timeLeft)
  250. })(
  251. <Select placeholder="请选择技术剩余寿命">
  252. {leftTimes.map((it) => {
  253. return <Option key={it.id} value={it.id}>{it.text}</Option>
  254. })}
  255. </Select>
  256. )}
  257. </FormItem>
  258. <FormItem label="转让区域" {...formItemLayout}>
  259. {getFieldDecorator('transferArea', {
  260. rules: [{ required: true, message: '请选择技术转让区域!' }],
  261. initialValue: initialData.transferArea
  262. })(
  263. <Select placeholder="请选择技术转让区域" allowClear={true} multiple={true} onChange={this.districtChanged}>
  264. {district.map((it) => {
  265. return <Option key={it.id} value={String(it.id)}>{it.name}</Option>
  266. })}
  267. </Select>
  268. )}
  269. </FormItem>
  270. <FormItem label="评估基准日" {...formItemLayout}>
  271. {getFieldDecorator('benchmarkDate', {
  272. rules: [{ required: true, message: '请输入评估基准日!' }],
  273. initialValue: initialData.benchmarkDate ? moment(initialData.benchmarkDate, 'YYYY-MM-DD') : null
  274. })(
  275. <DatePicker
  276. allowClear={false}
  277. onChange={this.onDateChange}
  278. placeholder="请输入评估基准日"
  279. format="YYYY-MM-DD"
  280. />
  281. // <MonthPicker allowClear={false} onChange={this.onDateChange} placeholder="请输入评估基准日" format="YYYY-MM-DD" />
  282. )}
  283. </FormItem>
  284. <FormItem label="评估币种" {...formItemLayout}>
  285. {getFieldDecorator('currencyType', {
  286. rules: [{ required: true, message: '请选择评估币种!' }],
  287. initialValue: initialData.currencyType || '人民币 (RMB)'
  288. })(
  289. <Select placeholder="请选择评估币种">
  290. {currency.map((it, idx) => {
  291. return <Option key={idx} value={it}>{it}</Option>
  292. })}
  293. </Select>
  294. )}
  295. </FormItem>
  296. </Form>
  297. <div className="steps-action">
  298. <Button type="primary" onClick={this.next}>保存,下一步</Button>
  299. </div>
  300. </Spin>
  301. )
  302. },
  303. }));
  304. export default EvaluateStep1;