technologyChange.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. import React from 'react';
  2. import { Icon, Form, Button, Input, Select, Spin, Table, message, Modal, Radio, Upload } from 'antd';
  3. import { cognizanceStateList } from '../../dataDic.js';
  4. import { getCognizanceState, beforeUpload, beforeUploadFile, downloadFile } 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/user/techproject/techProjectDetial",
  17. data: {
  18. pid: id || this.props.data.pid
  19. },
  20. success: function (data) {
  21. if (data.error.length || !data.data) {
  22. message.warning(data.error[0].message);
  23. return;
  24. };
  25. this.state.data = data.data;
  26. this.state.moneyType = undefined;
  27. if (data.data.projectMode == 1) {
  28. this.state.projectMode = data.data.projectMode;
  29. this.setState({ moneyType: 2 });
  30. };
  31. if (data.data.subsidy == 1) {
  32. this.state.subsidy = data.data.subsidy;
  33. this.setState({ moneyType: 1 });
  34. };
  35. }.bind(this),
  36. }).always(function () {
  37. this.setState({
  38. loading: false
  39. });
  40. }.bind(this));
  41. },
  42. getStateData(id) {
  43. this.setState({
  44. loading: true
  45. });
  46. $.ajax({
  47. method: "post",
  48. dataType: "json",
  49. crossDomain: false,
  50. url: globalConfig.context + "/api/user/techproject/techProjectLog",
  51. data: {
  52. pid: id || this.props.data.pid
  53. },
  54. success: function (data) {
  55. if (data.error.length || !data.data) {
  56. message.warning(data.error[0].message);
  57. return;
  58. };
  59. var myDate = new Date();
  60. this.state.stateTable = [];
  61. for (let i = 0; i < data.data.length; i++) {
  62. this.state.stateTable.push({
  63. key: i,
  64. state: data.data[i].state,
  65. recordTime: myDate.toLocaleDateString(data.data[i].recordTime),
  66. principal: data.data[i].principal,
  67. comment: data.data[i].comment
  68. });
  69. };
  70. }.bind(this),
  71. }).always(function () {
  72. this.setState({
  73. loading: false
  74. });
  75. }.bind(this));
  76. },
  77. getInitialState() {
  78. return {
  79. loading: false,
  80. departmentOption: [],
  81. projectDes: '',
  82. projectMode: 0,
  83. subsidy: 0,
  84. projectModeState: false,
  85. subsidyState: false,
  86. stateColumns: [{
  87. title: '科技项目状态',
  88. dataIndex: 'state',
  89. key: 'state',
  90. render: (text) => { return getCognizanceState(text) }
  91. }, {
  92. title: '处理时间',
  93. dataIndex: 'recordTime',
  94. key: 'recordTime'
  95. }, {
  96. title: '负责人',
  97. dataIndex: 'principal',
  98. key: 'principal',
  99. }, {
  100. title: '备注',
  101. dataIndex: 'comment',
  102. key: 'comment',
  103. }],
  104. stateTable: []
  105. };
  106. },
  107. componentWillMount() {
  108. this.loadData();
  109. this.getStateData();
  110. },
  111. handleSubmit(e) {
  112. e.preventDefault();
  113. this.props.form.validateFields((err, values) => {
  114. if (!err) {
  115. this.props.spinState(true);
  116. let contacts = !isNaN(values.contacts) ? values.contacts : this.state.data.contacts;
  117. $.ajax({
  118. method: "POST",
  119. dataType: "json",
  120. crossDomain: false,
  121. url: globalConfig.context + "/api/user/techproject/updateTechProject",
  122. data: {
  123. id: this.props.data.pid,
  124. contacts: contacts,
  125. department: values.department,
  126. projectName: values.projectName,
  127. projectCatagory: values.projectCatagory,
  128. techField: values.techField,
  129. projectDes: values.projectDes,
  130. projectMode: this.state.projectMode,
  131. projectApproval: values.projectApproval,
  132. subsidy: this.state.subsidy,
  133. approvalUrl: this.state.approvalUrl,
  134. }
  135. }).done(function (data) {
  136. if (!data.error.length) {
  137. message.success('保存成功!');
  138. this.props.closeModal();
  139. this.props.form.resetFields();
  140. this.props.spinState(false);
  141. } else {
  142. message.warning(data.error[0].message);
  143. this.props.spinState(false);
  144. }
  145. }.bind(this));
  146. }
  147. });
  148. },
  149. componentWillReceiveProps(nextProps) {
  150. if (!this.props.visible && nextProps.visible) {
  151. this.loadData(nextProps.data.pid);
  152. this.getStateData(nextProps.data.pid);
  153. this.state.fileList = [];
  154. };
  155. },
  156. subsidyCheck(e) {
  157. if (e.target.value == 1) {
  158. this.state.subsidy = 1;
  159. this.state.projectMode = 0;
  160. } else if (e.target.value == 2) {
  161. this.state.subsidy = 0;
  162. this.state.projectMode = 1;
  163. };
  164. this.setState({
  165. moneyType: e.target.value
  166. });
  167. },
  168. render() {
  169. const FormItem = Form.Item;
  170. const { getFieldDecorator } = this.props.form;
  171. const theData = this.state.data;
  172. const formItemLayout = {
  173. labelCol: { span: 6 },
  174. wrapperCol: { span: 12 },
  175. };
  176. const _me = this;
  177. if (this.state.data) {
  178. return (
  179. <Form onSubmit={this.handleSubmit} id="highTechApply-form">
  180. <div className="clearfix">
  181. <div className="half-item">
  182. <span className="item-title">公司名称: </span>
  183. <span>{theData.unitName}</span>
  184. </div>
  185. <div className="half-item">
  186. <span className="item-title">公司组织机构代码: </span>
  187. <span>{theData.orgCode}</span>
  188. </div>
  189. <div className="half-item">
  190. <span className="item-title">公司地址: </span>
  191. <span>{theData.province + ' ' + theData.city + ' ' + theData.area}</span>
  192. </div>
  193. <div className="half-item">
  194. <FormItem
  195. labelCol={{ span: 4 }}
  196. wrapperCol={{ span: 10 }}
  197. label="联系人:"
  198. >
  199. {getFieldDecorator('contacts', {
  200. initialValue: String(theData.contacts)
  201. })(
  202. <Select>{this.props.contactsOption}</Select>
  203. )}
  204. </FormItem>
  205. </div>
  206. </div>
  207. <div className="clearfix">
  208. <FormItem className="third-item"
  209. {...formItemLayout}
  210. label="科技部门"
  211. >
  212. {getFieldDecorator('department', {
  213. initialValue: this.state.department
  214. })(
  215. <Input />
  216. )}
  217. </FormItem>
  218. </div>
  219. <div className="clearfix">
  220. <div className="half-item">
  221. <FormItem
  222. labelCol={{ span: 4 }}
  223. wrapperCol={{ span: 12 }}
  224. label="项目名称"
  225. >
  226. {getFieldDecorator('projectName', {
  227. initialValue: theData.projectName
  228. })(
  229. <Input />
  230. )}
  231. </FormItem>
  232. </div>
  233. </div>
  234. <div className="clearfix">
  235. <div className="half-item">
  236. <FormItem
  237. labelCol={{ span: 4 }}
  238. wrapperCol={{ span: 12 }}
  239. label="项目类型"
  240. >
  241. {getFieldDecorator('projectCatagory', {
  242. initialValue: theData.projectCatagory
  243. })(
  244. <Input />
  245. )}
  246. </FormItem>
  247. </div>
  248. </div>
  249. <div className="clearfix">
  250. <div className="half-item">
  251. <FormItem
  252. labelCol={{ span: 4 }}
  253. wrapperCol={{ span: 12 }}
  254. label="技术领域"
  255. >
  256. {getFieldDecorator('techField', {
  257. initialValue: theData.techField
  258. })(
  259. <Input />
  260. )}
  261. </FormItem>
  262. </div>
  263. </div>
  264. <div className="clearfix">
  265. <span className="item-title">项目简介: </span>
  266. {getFieldDecorator('projectDes', {
  267. initialValue: theData.projectDes
  268. })(
  269. <Input type="textarea"
  270. placeholder="多行输入"
  271. rows={6} />
  272. )}
  273. </div>
  274. <div className="clearfix">
  275. <div className="half-item">
  276. <span className="item-title">立项/后补助: </span>
  277. <Radio.Group value={this.state.moneyType} onChange={this.subsidyCheck}>
  278. <Radio value={1}>立项</Radio>
  279. <Radio value={2}>后补助</Radio>
  280. </Radio.Group>
  281. </div>
  282. <div className="half-item">
  283. <FormItem
  284. {...formItemLayout}
  285. label='金额'
  286. >
  287. {getFieldDecorator('projectApproval', {
  288. initialValue: theData.projectApproval
  289. })(
  290. <Input style={{ width: 200 }} />
  291. )}
  292. <span>万元</span>
  293. </FormItem>
  294. </div>
  295. </div>
  296. <div className="hrSituation-roster">
  297. <Upload
  298. name="avatar"
  299. action={globalConfig.context + "/api/user/techproject/upload"}
  300. data={{ 'id': this.props.data.pid, 'sign': 'tech_project' }}
  301. beforeUpload={beforeUploadFile}
  302. fileList={this.state.fileList}
  303. onChange={(info) => {
  304. if (info.file.status !== 'uploading') {
  305. console.log(info.file, info.fileList);
  306. }
  307. if (info.file.status === 'done') {
  308. if (!info.file.response.error.length) {
  309. message.success(`${info.file.name} 文件上传成功!`);
  310. } else {
  311. message.warning(info.file.response.error[0].message);
  312. return;
  313. };
  314. this.state.approvalUrl = info.file.response.data;
  315. } else if (info.file.status === 'error') {
  316. message.error(`${info.file.name} 文件上传失败。`);
  317. };
  318. this.setState({ fileList: info.fileList.slice(-1) });
  319. }}
  320. >
  321. <Button><Icon type="upload" /> 项目材料上传 </Button>
  322. </Upload>
  323. <p style={{ marginTop: '10px' }}>{theData.approvalUrl ? <a onClick={downloadFile.bind(null, theData.approvalUrl, theData.approvalDownloadFileName)}>{theData.approvalDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  324. </div>
  325. <div className="form-title">状态流转记录: </div>
  326. <Table pagination={false} dataSource={this.state.stateTable} columns={this.state.stateColumns} />
  327. <FormItem style={{ marginTop: '20px' }}>
  328. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  329. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  330. </FormItem>
  331. </Form >
  332. );
  333. } else {
  334. return (<div></div>)
  335. };
  336. },
  337. }));
  338. const ApplyChange = React.createClass({
  339. getInitialState() {
  340. return {
  341. visible: false,
  342. loading: false
  343. };
  344. },
  345. componentWillReceiveProps(nextProps) {
  346. this.state.visible = nextProps.showDesc
  347. },
  348. showModal() {
  349. this.setState({
  350. visible: true,
  351. });
  352. },
  353. handleOk() {
  354. this.setState({
  355. visible: false,
  356. });
  357. this.props.closeDesc(false);
  358. },
  359. handleCancel(e) {
  360. this.setState({
  361. visible: false,
  362. });
  363. this.props.closeDesc(false);
  364. },
  365. spinChange(e) {
  366. this.setState({
  367. loading: e
  368. });
  369. },
  370. render() {
  371. return (
  372. <div className="patent-addNew">
  373. <Spin spinning={this.state.loading} className='spin-box'>
  374. <Modal title="编辑科技项目" visible={this.state.visible}
  375. onOk={this.handleOk} onCancel={this.handleCancel}
  376. width='1000px'
  377. footer=''
  378. >
  379. <ApplyChangeFrom
  380. visible={this.state.visible}
  381. data={this.props.data}
  382. contactsOption={this.props.contactsOption}
  383. spinState={this.spinChange}
  384. closeModal={this.handleCancel} />
  385. </Modal>
  386. </Spin>
  387. </div>
  388. );
  389. }
  390. });
  391. export default ApplyChange;