applyChange.jsx 23 KB

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