applyChange.jsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. import React from 'react';
  2. import { Icon, Form, Button, Input, Select, Spin, Table, DatePicker, message, Modal, Upload, Radio } from 'antd';
  3. import { technologyStateList } from '../../../dataDic.js';
  4. import { getTechnologyState, beforeUpload, beforeUploadFile, techDownloadFile } from '../../../tools.js';
  5. import ajax from 'jquery/src/ajax/xhr.js';
  6. import $ from 'jquery/src/ajax';
  7. const ApplyChangeFrom = Form.create()(React.createClass({
  8. loadData(id) {
  9. this.setState({
  10. loading: true
  11. });
  12. $.ajax({
  13. method: "post",
  14. dataType: "json",
  15. crossDomain: false,
  16. url: globalConfig.context + "/api/admin/techproject/techProjectDetial",
  17. data: {
  18. pid: id || this.props.data.pid
  19. },
  20. success: function (data) {
  21. if (!data.data) {
  22. if (data.error && data.error.length) {
  23. message.warning(data.error[0].message);
  24. };
  25. return;
  26. };
  27. this.state.data = data.data;
  28. this.state.moneyType = undefined;
  29. if (data.data.projectMode == 1) {
  30. this.state.projectMode = data.data.projectMode;
  31. this.setState({ moneyType: 2 });
  32. };
  33. if (data.data.subsidy == 1) {
  34. this.state.subsidy = data.data.subsidy;
  35. this.setState({ moneyType: 1 });
  36. };
  37. this.getContactsList();
  38. }.bind(this),
  39. }).always(function () {
  40. this.setState({
  41. loading: false
  42. });
  43. }.bind(this));
  44. },
  45. getStateData(id) {
  46. this.setState({
  47. loading: true
  48. });
  49. $.ajax({
  50. method: "post",
  51. dataType: "json",
  52. crossDomain: false,
  53. url: globalConfig.context + "/api/admin/techproject/techProjectLog",
  54. data: {
  55. pid: id || this.props.data.pid
  56. },
  57. success: function (data) {
  58. if (!data.data) {
  59. if (data.error && data.error.length) {
  60. message.warning(data.error[0].message);
  61. };
  62. return;
  63. };
  64. var myDate = new Date();
  65. this.state.stateTable = [];
  66. for (let i = 0; i < data.data.length; i++) {
  67. this.state.stateTable.push({
  68. key: i,
  69. state: data.data[i].state,
  70. recordTime: data.data[i].recordTime,
  71. recordTimeFormattedDate:data.data[i].recordTimeFormattedDate,
  72. principal: data.data[i].principal,
  73. comment: data.data[i].comment
  74. });
  75. };
  76. }.bind(this),
  77. }).always(function () {
  78. this.setState({
  79. loading: false
  80. });
  81. }.bind(this));
  82. },
  83. getContactsList(id) {
  84. $.ajax({
  85. method: "get",
  86. dataType: "json",
  87. crossDomain: false,
  88. url: globalConfig.context + "/api/admin/getContacts",
  89. data: { "uid": id || this.props.data.uid },
  90. success: function (data) {
  91. let theOption = [];
  92. if (!data.data) {
  93. if (data.error && data.error.length) {
  94. message.warning(data.error[0].message);
  95. };
  96. return;
  97. };
  98. for (let item in data.data) {
  99. let theData = data.data[item];
  100. theOption.push(
  101. <Select.Option value={item} key={item}>{theData}</Select.Option>
  102. );
  103. };
  104. this.setState({
  105. contactsOption: theOption
  106. });
  107. }.bind(this),
  108. });
  109. },
  110. getDepartmentList(id) {
  111. $.ajax({
  112. method: "get",
  113. dataType: "json",
  114. crossDomain: false,
  115. url: globalConfig.context + "/api/admin/techproject/getDepartment",
  116. data: { "uid": id || this.props.data.uid },
  117. success: function (data) {
  118. let theOption = [];
  119. if (!data.data) {
  120. if (data.error && data.error.length) {
  121. message.warning(data.error[0].message);
  122. };
  123. return;
  124. };
  125. for (let item in data.data) {
  126. let theData = data.data[item];
  127. theOption.push(
  128. <Select.Option value={item} key={item}>{theData}</Select.Option>
  129. );
  130. };
  131. this.setState({
  132. departmentOption: theOption,
  133. });
  134. }.bind(this),
  135. });
  136. },
  137. getOptionList() {
  138. this.setState({
  139. loading: true
  140. });
  141. $.ajax({
  142. method: "get",
  143. dataType: "json",
  144. crossDomain: false,
  145. url: globalConfig.context + "/api/admin/techproject/status",
  146. success: function (data) {
  147. let _me = this;
  148. if (!data.data) {
  149. if (data.error && data.error.length) {
  150. message.warning(data.error[0].message);
  151. return;
  152. };
  153. };
  154. _me.state.stateOption = [];
  155. for (var item in data.data) {
  156. _me.state.stateOption.push(
  157. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  158. )
  159. };
  160. }.bind(this),
  161. }).always(function () {
  162. this.setState({
  163. loading: false
  164. });
  165. }.bind(this));
  166. },
  167. getInitialState() {
  168. return {
  169. loading: false,
  170. stateOption: [],
  171. projectDes: '',
  172. projectMode: 0,
  173. subsidy: 0,
  174. projectModeState: false,
  175. subsidyState: false,
  176. stateColumns: [{
  177. title: '专利状态',
  178. dataIndex: 'state',
  179. key: 'state',
  180. render: (text) => { return getTechnologyState(text) }
  181. }, {
  182. title: '处理时间',
  183. dataIndex: 'recordTimeFormattedDate',
  184. key: 'recordTimeFormattedDate'
  185. }, {
  186. title: '负责人',
  187. dataIndex: 'principal',
  188. key: 'principal',
  189. }, {
  190. title: '备注',
  191. dataIndex: 'comment',
  192. key: 'comment',
  193. }],
  194. stateTable: []
  195. };
  196. },
  197. componentWillMount() {
  198. this.loadData();
  199. this.getOptionList();
  200. this.getStateData();
  201. this.getContactsList();
  202. this.getDepartmentList();
  203. },
  204. handleSubmit(e) {
  205. e.preventDefault();
  206. this.props.form.validateFields((err, values) => {
  207. if (values.state || values.principal || values.recordTime || values.comment) {
  208. if (!values.state || !values.principal || !values.recordTime) {
  209. message.warning("请填写完整的状态流转信息!");
  210. return;
  211. };
  212. };
  213. if (!err) {
  214. this.props.spinState(true);
  215. let contacts = !isNaN(values.contacts) ? values.contacts : this.state.data.contacts;
  216. $.ajax({
  217. method: "POST",
  218. dataType: "json",
  219. crossDomain: false,
  220. url: globalConfig.context + "/api/admin/techproject/updateTechProject",
  221. data: {
  222. id: this.props.data.pid,
  223. uid: this.props.data.uid,
  224. contacts: contacts,
  225. department: values.department,
  226. projectName: values.projectName,
  227. projectCatagory: values.projectCatagory,
  228. techField: values.techField,
  229. projectDes: values.projectDes,
  230. projectMode: this.state.projectMode,
  231. projectApproval: values.projectApproval,
  232. subsidy: this.state.subsidy,
  233. approvalUrl: this.state.approvalUrl,
  234. recordTimeFormattedDate: values.recordTime ? values.recordTime.format("YYYY-MM-DD HH:mm:ss") : undefined,
  235. state: values.state,
  236. principal: values.principal,
  237. comment: values.comment,
  238. }
  239. }).done(function (data) {
  240. if (!data.error.length) {
  241. message.success('保存成功!');
  242. this.props.closeModal();
  243. this.props.form.resetFields();
  244. this.props.spinState(false);
  245. } else {
  246. message.warning(data.error[0].message);
  247. this.props.spinState(false);
  248. }
  249. }.bind(this));
  250. }
  251. });
  252. },
  253. componentWillReceiveProps(nextProps) {
  254. if (!this.props.visible && nextProps.visible) {
  255. this.loadData(nextProps.data.pid);
  256. this.getStateData(nextProps.data.pid);
  257. this.getContactsList(nextProps.data.uid);
  258. this.getDepartmentList(nextProps.data.uid);
  259. };
  260. },
  261. subsidyCheck(e) {
  262. if (e.target.value == 1) {
  263. this.state.subsidy = 1;
  264. this.state.projectMode = 0;
  265. } else if (e.target.value == 2) {
  266. this.state.subsidy = 0;
  267. this.state.projectMode = 1;
  268. };
  269. this.setState({
  270. moneyType: e.target.value
  271. });
  272. },
  273. render() {
  274. const FormItem = Form.Item;
  275. const { getFieldDecorator } = this.props.form;
  276. const theData = this.state.data;
  277. const formItemLayout = {
  278. labelCol: { span: 6 },
  279. wrapperCol: { span: 12 },
  280. };
  281. const _me = this;
  282. if (this.state.data) {
  283. return (
  284. <Form onSubmit={this.handleSubmit} id="highTechApply-form">
  285. <div className="clearfix">
  286. <div className="half-item">
  287. <span className="item-title">公司名称: </span>
  288. <span>{theData.unitName}</span>
  289. </div>
  290. <div className="half-item">
  291. <span className="item-title">公司组织机构代码: </span>
  292. <span>{theData.orgCode}</span>
  293. </div>
  294. <div className="half-item">
  295. <span className="item-title">公司地址: </span>
  296. <span>{theData.province + ' ' + theData.city + ' ' + theData.area}</span>
  297. </div>
  298. <div className="half-item">
  299. <FormItem
  300. labelCol={{ span: 4 }}
  301. wrapperCol={{ span: 10 }}
  302. label="联系人:"
  303. >
  304. {getFieldDecorator('contacts', {
  305. initialValue: this.state.data.contacts
  306. })(
  307. <Select>{this.state.contactsOption}</Select>
  308. )}
  309. </FormItem>
  310. </div>
  311. </div>
  312. <div className="clearfix">
  313. <FormItem className="third-item"
  314. {...formItemLayout}
  315. label="科技部门"
  316. >
  317. {getFieldDecorator('department', {
  318. initialValue: theData.department
  319. })(
  320. <Select placeholder='请输入科技部门' >{this.state.departmentOption}</Select>
  321. )}
  322. </FormItem>
  323. </div>
  324. <div className="clearfix">
  325. <div className="half-item">
  326. <span className="item-title">派单信息: </span>
  327. <span>{theData.dispatchInfo}</span>
  328. </div>
  329. </div>
  330. <div className="clearfix">
  331. <div className="half-item">
  332. <FormItem
  333. labelCol={{ span: 4 }}
  334. wrapperCol={{ span: 12 }}
  335. label="项目名称"
  336. >
  337. {getFieldDecorator('projectName', {
  338. initialValue: theData.projectName
  339. })(
  340. <Input />
  341. )}
  342. </FormItem>
  343. </div>
  344. </div>
  345. <div className="clearfix">
  346. <div className="half-item">
  347. <FormItem
  348. labelCol={{ span: 4 }}
  349. wrapperCol={{ span: 12 }}
  350. label="项目类型"
  351. >
  352. {getFieldDecorator('projectCatagory', {
  353. initialValue: theData.projectCatagory
  354. })(
  355. <Input />
  356. )}
  357. </FormItem>
  358. </div>
  359. </div>
  360. <div className="clearfix">
  361. <div className="half-item">
  362. <FormItem
  363. labelCol={{ span: 4 }}
  364. wrapperCol={{ span: 12 }}
  365. label="技术领域"
  366. >
  367. {getFieldDecorator('techField', {
  368. initialValue: theData.techField
  369. })(
  370. <Input />
  371. )}
  372. </FormItem>
  373. </div>
  374. </div>
  375. <div className="clearfix">
  376. <span className="item-title">项目简介: </span>
  377. {getFieldDecorator('projectDes', {
  378. initialValue: theData.projectDes
  379. })(
  380. <Input type="textarea"
  381. placeholder="多行输入"
  382. rows={6} />
  383. )}
  384. </div>
  385. <div className="clearfix">
  386. <div className="half-item">
  387. <span className="item-title">立项/后补助: </span>
  388. <Radio.Group value={this.state.moneyType} onChange={this.subsidyCheck}>
  389. <Radio value={1}>立项</Radio>
  390. <Radio value={2}>后补助</Radio>
  391. </Radio.Group>
  392. </div>
  393. <div className="half-item">
  394. <FormItem
  395. {...formItemLayout}
  396. label={this.state.moneyType !== 2 ? '立项金额' : '后补助金额'}
  397. >
  398. {getFieldDecorator('projectApproval', {
  399. initialValue: theData.projectApproval
  400. })(
  401. <Input style={{ width: 200 }} />
  402. )}
  403. <span>万元</span>
  404. </FormItem>
  405. </div>
  406. </div>
  407. <div className="hrSituation-roster">
  408. <Upload
  409. name="avatar"
  410. action={globalConfig.context + "/api/admin/techproject/upload"}
  411. data={{ 'uid': this.props.data.uid, 'id': this.props.data.pid, 'sign': 'tech_project' }}
  412. beforeUpload={beforeUploadFile}
  413. showUploadList={false}
  414. onChange={(info) => {
  415. if (info.file.status !== 'uploading') {
  416. console.log(info.file, info.fileList);
  417. }
  418. if (info.file.status === 'done') {
  419. if (!info.file.response.error.length) {
  420. message.success(`${info.file.name} 文件上传成功!`);
  421. } else {
  422. message.warning(info.file.response.error[0].message);
  423. return;
  424. };
  425. this.state.approvalUrl = info.file.response.data;
  426. } else if (info.file.status === 'error') {
  427. message.error(`${info.file.name} 文件上传失败。`);
  428. }
  429. }}
  430. >
  431. <Button><Icon type="upload" /> 项目材料上传 </Button>
  432. </Upload>
  433. <p style={{ marginTop: '10px' }}>{theData.approvalUrl ? <a onClick={techDownloadFile.bind(null, "/api/admin/techproject/download", this.state.data.id)}>项目材料</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  434. </div>
  435. <div className="form-title">状态流转记录: </div>
  436. <Table pagination={false} dataSource={this.state.stateTable} columns={this.state.stateColumns} />
  437. <div className="clearfix">
  438. <FormItem className="third-item"
  439. {...formItemLayout}
  440. label="状态流转"
  441. >
  442. {getFieldDecorator('state')(
  443. <Select placeholder="选择一个状态">{this.state.stateOption}</Select>
  444. )}
  445. </FormItem>
  446. <FormItem className="third-item"
  447. labelCol={{ span: 6 }}
  448. wrapperCol={{ span: 12 }}
  449. label="处理时间"
  450. >
  451. {getFieldDecorator('recordTime')(
  452. <DatePicker />
  453. )}
  454. </FormItem>
  455. <FormItem className="third-item"
  456. {...formItemLayout}
  457. label="负责人"
  458. >
  459. {getFieldDecorator('principal')(
  460. <Select placeholder="选择负责人">{this.props.authorOption}</Select>
  461. )}
  462. </FormItem>
  463. </div>
  464. <FormItem
  465. labelCol={{ span: 2 }}
  466. wrapperCol={{ span: 12 }}
  467. label="备注"
  468. >
  469. {getFieldDecorator('comment')(
  470. <Input />
  471. )}
  472. </FormItem>
  473. <FormItem style={{ marginTop: '20px' }}>
  474. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  475. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  476. </FormItem>
  477. </Form >
  478. );
  479. } else {
  480. return (<div></div>)
  481. };
  482. },
  483. }));
  484. const ApplyChange = React.createClass({
  485. getInitialState() {
  486. return {
  487. visible: false,
  488. loading: false
  489. };
  490. },
  491. componentWillReceiveProps(nextProps) {
  492. this.state.visible = nextProps.showDesc
  493. },
  494. showModal() {
  495. this.setState({
  496. visible: true,
  497. });
  498. },
  499. handleOk() {
  500. this.setState({
  501. visible: false,
  502. });
  503. this.props.closeDesc(false);
  504. },
  505. handleCancel(e) {
  506. this.setState({
  507. visible: false,
  508. });
  509. this.props.closeDesc(false);
  510. },
  511. spinChange(e) {
  512. this.setState({
  513. loading: e
  514. });
  515. },
  516. render() {
  517. return (
  518. <div className="patent-addNew">
  519. <Spin spinning={this.state.loading} className='spin-box'>
  520. <Modal title="编辑科技项目" visible={this.state.visible}
  521. onOk={this.handleOk} onCancel={this.handleCancel}
  522. width='1000px'
  523. footer=''
  524. >
  525. <ApplyChangeFrom
  526. visible={this.state.visible}
  527. authorOption={this.props.authorOption}
  528. data={this.props.data}
  529. spinState={this.spinChange} closeModal={this.handleCancel} />
  530. </Modal>
  531. </Spin>
  532. </div>
  533. );
  534. }
  535. });
  536. export default ApplyChange;