orgTechCenter.jsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. import React from 'react';
  2. import { Icon, Form, Button, Input, Spin, Table, message, Modal, Upload, DatePicker } from 'antd';
  3. import './techProduct.less';
  4. import { beforeUploadFile, newDownloadFile } from '../../tools.js';
  5. import moment from 'moment';
  6. import ajax from 'jquery/src/ajax/xhr.js';
  7. import $ from 'jquery/src/ajax';
  8. const CenterListDescFrom = Form.create()(React.createClass({
  9. getInitialState() {
  10. return {
  11. loading: false,
  12. fileList_protocol: []
  13. };
  14. },
  15. handleSubmit(e) {
  16. e.preventDefault();
  17. this.props.form.validateFields((err, values) => {
  18. if (!err) {
  19. this.props.spinState(true);
  20. $.ajax({
  21. method: "POST",
  22. dataType: "json",
  23. crossDomain: false,
  24. url: globalConfig.context + "/api/user/cognizance/disposeCenterDetail",
  25. data: {
  26. cid: this.props.cid,
  27. projectName: values.projectName,
  28. projectTimeFormattedDate: values.projectTimeFormattedDate ? values.projectTimeFormattedDate.format("YYYY-MM-DD") : null,
  29. institution: values.institution,
  30. termStartTimeFormattedDate: values.termTimeFormattedDate ? values.termTimeFormattedDate[0].format("YYYY-MM-DD") : null,
  31. termEndTimeFormattedDate: values.termTimeFormattedDate ? values.termTimeFormattedDate[1].format("YYYY-MM-DD") : null,
  32. protocolUrl: this.state.protocolUrl
  33. }
  34. }).done(function (data) {
  35. if (!data.error.length) {
  36. message.success('保存成功!');
  37. this.props.clickOk();
  38. this.props.spinState(false);
  39. this.props.form.resetFields();
  40. } else {
  41. message.warning(data.error[0].message);
  42. this.props.spinState(false);
  43. }
  44. }.bind(this));
  45. }
  46. });
  47. },
  48. componentWillReceiveProps(nextProps) {
  49. if (!this.props.visible && nextProps.visible) {
  50. this.props.form.resetFields();
  51. this.state.fileList_protocol = [];
  52. this.state.protocolUrl = undefined;
  53. };
  54. },
  55. render() {
  56. const FormItem = Form.Item;
  57. const { getFieldDecorator } = this.props.form;
  58. const { RangePicker } = DatePicker;
  59. const theData = this.props.data;
  60. const formItemLayout = {
  61. labelCol: { span: 6 },
  62. wrapperCol: { span: 14 },
  63. };
  64. const _me = this;
  65. return (
  66. <Form onSubmit={this.handleSubmit} className="activityCost-form">
  67. <div className="clearfix">
  68. <FormItem className="half-item"
  69. {...formItemLayout}
  70. label="时间"
  71. >
  72. {getFieldDecorator('projectTimeFormattedDate', {
  73. rules: [{ type: 'object', required: true, message: '此项为必填项!' }],
  74. initialValue: theData.projectTimeFormattedDate ? moment(theData.projectTimeFormattedDate) : null
  75. })(
  76. <DatePicker />
  77. )}
  78. </FormItem>
  79. <FormItem className="half-item"
  80. {...formItemLayout}
  81. label="项目名称"
  82. >
  83. {getFieldDecorator('projectName', {
  84. rules: [{ required: true, message: '此项为必填项!' }],
  85. initialValue: theData.projectName
  86. })(
  87. <Input />
  88. )}
  89. </FormItem>
  90. <FormItem className="half-item"
  91. {...formItemLayout}
  92. label="期限"
  93. >
  94. {getFieldDecorator('termTimeFormattedDate', {
  95. rules: [{ type: 'array', required: true, message: '此项为必填项!' }],
  96. initialValue: theData.termStartTimeFormattedDate && theData.termEndTimeFormattedDate ? [moment(theData.termStartTimeFormattedDate), moment(theData.termEndTimeFormattedDate)] : [null, null]
  97. })(
  98. <RangePicker />
  99. )}
  100. </FormItem>
  101. <FormItem className="half-item"
  102. {...formItemLayout}
  103. label="科研院所"
  104. >
  105. {getFieldDecorator('institution', {
  106. rules: [{ required: true, message: '此项为必填项!' }],
  107. initialValue: theData.institution
  108. })(
  109. <Input />
  110. )}
  111. </FormItem>
  112. </div>
  113. <div className="hrSituation-roster">
  114. <Upload
  115. name="ratepay"
  116. action={globalConfig.context + "/api/user/cognizance/uploadProtocol"}
  117. data={{ 'sign': 'protocol' }}
  118. beforeUpload={beforeUploadFile}
  119. fileList={this.state.fileList_protocol}
  120. onChange={(info) => {
  121. if (info.file.status !== 'uploading') {
  122. console.log(info.file, info.fileList);
  123. }
  124. if (info.file.status === 'done') {
  125. if (!info.file.response.error.length) {
  126. message.success(`${info.file.name} 文件上传成功!`);
  127. } else {
  128. message.warning(info.file.response.error[0].message);
  129. return;
  130. };
  131. this.state.protocolUrl = info.file.response.data;
  132. } else if (info.file.status === 'error') {
  133. message.error(`${info.file.name} 文件上传失败。`);
  134. };
  135. this.setState({ fileList_protocol: info.fileList.slice(-1) });
  136. }}
  137. >
  138. <Button><Icon type="upload" /> 上传研发费用台账 </Button>
  139. </Upload>
  140. <p style={{ marginTop: '10px' }}>{theData.protocolUrl ? <a onClick={newDownloadFile.bind(null, theData.id, 'protocol', '/api/user/cognizance/downloadProtocol')}>{theData.protocolDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  141. </div>
  142. <FormItem style={{ marginTop: '20px' }}>
  143. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  144. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  145. </FormItem>
  146. </Form >
  147. );
  148. },
  149. }));
  150. const CenterListDesc = React.createClass({
  151. getInitialState() {
  152. return {
  153. visible: false,
  154. loading: false
  155. };
  156. },
  157. componentWillReceiveProps(nextProps) {
  158. this.state.visible = nextProps.showDesc
  159. },
  160. showModal() {
  161. this.setState({
  162. visible: true,
  163. });
  164. },
  165. handleOk() {
  166. this.setState({
  167. visible: false,
  168. });
  169. this.props.closeDesc(false, true);
  170. },
  171. handleCancel(e) {
  172. this.setState({
  173. visible: false,
  174. });
  175. this.props.closeDesc(false);
  176. },
  177. spinChange(e) {
  178. this.setState({
  179. loading: e
  180. });
  181. },
  182. render() {
  183. return (
  184. <div className="patent-addNew">
  185. <Modal maskClosable={false} title="产学研情况详情" visible={this.state.visible}
  186. onOk={this.handleOk} onCancel={this.handleCancel}
  187. width='840px'
  188. footer='' >
  189. <Spin spinning={this.state.loading} className='spin-box'>
  190. <CenterListDescFrom
  191. visible={this.state.visible}
  192. data={this.props.data}
  193. cid={this.props.cid}
  194. spinState={this.spinChange}
  195. closeModal={this.handleCancel}
  196. clickOk={this.handleOk} />
  197. </Spin>
  198. </Modal>
  199. </div>
  200. );
  201. }
  202. });
  203. const CenterList = React.createClass({
  204. loadOrgTechCenterDetail() {
  205. this.setState({
  206. loading: true
  207. });
  208. $.ajax({
  209. method: "get",
  210. dataType: "json",
  211. crossDomain: false,
  212. url: globalConfig.context + "/api/user/cognizance/center",
  213. data: {
  214. }
  215. }).done((data) => {
  216. if (!data.data) {
  217. if (data.error && data.error.length) {
  218. message.warning(data.error[0].message);
  219. this.state.ButtonDisabled = true;
  220. }
  221. return;
  222. };
  223. this.state.cid = data.data.id;
  224. this.state.foundingTime = data.data.foundingTimeFormattedDate;
  225. this.state.principal = data.data.principal;
  226. this.state.systemCatalog = data.data.systemCatalog;
  227. this.state.systemUrl = data.data.systemUrl;
  228. this.state.systemDownloadFileName = data.data.systemDownloadFileName;
  229. this.state.centerName = data.data.centerName;
  230. this.state.comment = data.data.comment;
  231. this.loadData();
  232. }).always(function () {
  233. this.setState({
  234. loading: false
  235. });
  236. }.bind(this));
  237. },
  238. loadData(pageNo) {
  239. this.state.data = [];
  240. this.setState({
  241. loading: true
  242. });
  243. $.ajax({
  244. method: "post",
  245. dataType: "json",
  246. crossDomain: false,
  247. url: globalConfig.context + "/api/user/cognizance/centerDetail",
  248. data: {
  249. pageNo: pageNo || 1,
  250. pageSize: this.state.pagination.pageSize,
  251. cid: this.state.cid
  252. }
  253. }).done((data) => {
  254. if (!data.data || !data.data.list) {
  255. if (data.error.length) {
  256. message.warning(data.error[0].message);
  257. }
  258. return;
  259. };
  260. for (let i = 0; i < data.data.list.length; i++) {
  261. let thisdata = data.data.list[i];
  262. this.state.data.push({
  263. key: i,
  264. id: thisdata.id,
  265. cid: thisdata.cid,
  266. projectTimeFormattedDate: thisdata.projectTimeFormattedDate,
  267. projectName: thisdata.projectName,
  268. protocolDownloadFileName: thisdata.protocolDownloadFileName,
  269. protocolUrl: thisdata.protocolUrl,
  270. protocol: [thisdata.id, thisdata.protocolDownloadFileName],
  271. institution: thisdata.institution,
  272. termTimeFormattedDate: [thisdata.termStartTimeFormattedDate, thisdata.termEndTimeFormattedDate],
  273. termStartTimeFormattedDate: thisdata.termStartTimeFormattedDate,
  274. termEndTimeFormattedDate: thisdata.termEndTimeFormattedDate
  275. });
  276. };
  277. this.state.pagination.current = data.data.pageNo;
  278. this.state.pagination.total = data.data.totalCount;
  279. this.setState({
  280. dataSource: this.state.data,
  281. pagination: this.state.pagination
  282. });
  283. }).always(function () {
  284. this.setState({
  285. loading: false
  286. });
  287. }.bind(this));
  288. },
  289. getInitialState() {
  290. return {
  291. selectedRowKeys: [],
  292. selectedRows: [],
  293. loading: false,
  294. pagination: {
  295. defaultCurrent: 1,
  296. defaultPageSize: 10,
  297. showQuickJumper: true,
  298. pageSize: 10,
  299. onChange: function (page) {
  300. this.loadData(page);
  301. }.bind(this),
  302. showTotal: function (total) {
  303. return '共' + total + '条数据';
  304. }
  305. },
  306. columns: [
  307. {
  308. title: '时间',
  309. dataIndex: 'projectTimeFormattedDate',
  310. key: 'projectTimeFormattedDate'
  311. }, {
  312. title: '项目名称',
  313. dataIndex: 'projectName',
  314. key: 'projectName'
  315. }, {
  316. title: '期限',
  317. dataIndex: 'termTimeFormattedDate',
  318. key: 'termTimeFormattedDate',
  319. render: (text) => {
  320. return text[0] + ' - ' + text[1];
  321. }
  322. }, {
  323. title: '科研院所',
  324. dataIndex: 'institution',
  325. key: 'institution'
  326. }, {
  327. title: '协议附件',
  328. dataIndex: 'protocol',
  329. key: 'protocol',
  330. render: (text) => {
  331. return <a onClick={newDownloadFile.bind(null, text[0], 'protocol', '/api/user/cognizance/downloadProtocol')}>{text[1]}</a>
  332. }
  333. }
  334. ],
  335. dataSource: []
  336. };
  337. },
  338. componentWillMount() {
  339. this.loadOrgTechCenterDetail();
  340. },
  341. tableRowClick(record, index) {
  342. this.state.RowData = record;
  343. this.setState({
  344. showDesc: true
  345. });
  346. },
  347. delectRow() {
  348. let deletedIds = [];
  349. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  350. let rowItem = this.state.selectedRows[idx];
  351. if (rowItem.id) {
  352. deletedIds.push(rowItem.id)
  353. }
  354. };
  355. this.setState({
  356. selectedRowKeys: [],
  357. loading: deletedIds.length > 0
  358. });
  359. $.ajax({
  360. method: "POST",
  361. dataType: "json",
  362. crossDomain: false,
  363. url: globalConfig.context + "/api/user/cognizance/deleteOrgTechCenterDetail",
  364. data: {
  365. ids: deletedIds
  366. }
  367. }).done(function (data) {
  368. if (!data.error.length) {
  369. message.success('删除成功!');
  370. this.setState({
  371. loading: false,
  372. });
  373. } else {
  374. message.warning(data.error[0].message);
  375. };
  376. this.loadData();
  377. }.bind(this));
  378. },
  379. closeDesc(e, s) {
  380. this.state.showDesc = e;
  381. if (s) {
  382. this.loadData();
  383. };
  384. },
  385. saveCenterDetail() {
  386. if (!this.state.centerName) {
  387. message.warning('研发部门名称不能为空!');
  388. return;
  389. };
  390. this.setState({
  391. loading: true
  392. });
  393. $.ajax({
  394. method: "post",
  395. dataType: "json",
  396. crossDomain: false,
  397. url: globalConfig.context + "/api/user/cognizance/disposeCenter",
  398. data: {
  399. id: this.state.cid,
  400. principal: this.state.principal,
  401. systemUrl: this.state.systemUrl,
  402. systemCatalog: this.state.systemCatalog,
  403. foundingTimeFormattedDate: this.state.foundingTime,
  404. comment: this.state.comment,
  405. centerName: this.state.centerName
  406. }
  407. }).done((data) => {
  408. if (!data.error.length) {
  409. message.success('保存成功!');
  410. this.loadOrgTechCenterDetail();
  411. this.setState({
  412. loading: false,
  413. });
  414. } else {
  415. message.warning(data.error[0].message);
  416. };
  417. });
  418. },
  419. render() {
  420. const rowSelection = {
  421. selectedRowKeys: this.state.selectedRowKeys,
  422. onChange: (selectedRowKeys, selectedRows) => {
  423. this.setState({
  424. selectedRows: selectedRows,
  425. selectedRowKeys: selectedRowKeys
  426. });
  427. }
  428. };
  429. const hasSelected = this.state.selectedRowKeys.length > 0;
  430. return (
  431. <div className="user-content" >
  432. <div className="content-title">
  433. <span>研发部门</span>
  434. </div>
  435. <div className="clearfix">
  436. <div className="orgTech-item">
  437. <span>研发部门名称: </span>
  438. <Input
  439. value={this.state.centerName}
  440. onChange={(e) => { this.setState({ centerName: e.target.value }); }}
  441. />
  442. <span>成立时间: </span>
  443. <DatePicker
  444. value={this.state.foundingTime ? moment(this.state.foundingTime) : null}
  445. allowClear={false}
  446. onChange={(date, dateString) => { this.setState({ foundingTime: dateString }); }}
  447. />
  448. <span>负责人: </span>
  449. <Input
  450. value={this.state.principal}
  451. onChange={(e) => { this.setState({ principal: e.target.value }); }}
  452. />
  453. </div>
  454. <div className="orgTech-item">
  455. <span>制度目录: </span>
  456. <Input type='textarea' rows={6}
  457. value={this.state.systemCatalog}
  458. onChange={(e) => { this.setState({ systemCatalog: e.target.value }); }}
  459. />
  460. </div>
  461. <div className="orgTech-item">
  462. <span>备注: </span>
  463. <Input type='textarea' rows={3}
  464. value={this.state.comment}
  465. onChange={(e) => { this.setState({ comment: e.target.value }); }}
  466. />
  467. </div>
  468. </div>
  469. <div className="half-item">
  470. <p>制度上传: (上传 zip 或者 rar 文件)</p>
  471. <div style={{ margin: '10px 0' }}>
  472. <Upload
  473. name="ratepay"
  474. action={globalConfig.context + "/api/user/cognizance/uploadInstitution"}
  475. data={{ 'sign': 'institution' }}
  476. beforeUpload={beforeUploadFile}
  477. fileList={this.state.fileList_institution}
  478. onChange={(info) => {
  479. if (info.file.status !== 'uploading') {
  480. console.log(info.file, info.fileList);
  481. }
  482. if (info.file.status === 'done') {
  483. if (!info.file.response.error.length) {
  484. message.success(`${info.file.name} 文件上传成功!`);
  485. } else {
  486. message.warning(info.file.response.error[0].message);
  487. return;
  488. };
  489. this.state.systemUrl = info.file.response.data;
  490. } else if (info.file.status === 'error') {
  491. message.error(`${info.file.name} 文件上传失败。`);
  492. };
  493. this.setState({ fileList_institution: info.fileList.slice(-1) });
  494. }} >
  495. <Button disabled={this.state.ButtonDisabled}><Icon type="upload" /> 上传研发部门制度 </Button>
  496. </Upload>
  497. <p style={{ marginTop: '10px' }}>{this.state.systemUrl ? <a onClick={newDownloadFile.bind(null, this.state.cid, 'institution', '/api/user/cognizance/downloadInstitution')}>{this.state.systemDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  498. </div>
  499. </div>
  500. <Button disabled={this.state.ButtonDisabled} type='primary' onClick={this.saveCenterDetail}>保存</Button>
  501. <div className="content-title" style={{ marginTop: '10px' }}>
  502. <span>产学研情况</span>
  503. </div>
  504. <div className="user-search">
  505. <p>
  506. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  507. disabled={this.state.ButtonDisabled}
  508. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  509. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  510. disabled={!hasSelected}
  511. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  512. </p>
  513. </div>
  514. <div className="patent-table">
  515. <Spin spinning={this.state.loading}>
  516. <Table columns={this.state.columns}
  517. dataSource={this.state.dataSource}
  518. pagination={this.state.pagination}
  519. rowSelection={rowSelection}
  520. onRowClick={this.tableRowClick} />
  521. </Spin>
  522. </div>
  523. <CenterListDesc
  524. cid={this.state.cid}
  525. data={this.state.RowData}
  526. showDesc={this.state.showDesc}
  527. closeDesc={this.closeDesc} />
  528. </div >
  529. );
  530. }
  531. });
  532. export default CenterList;