orgTechCenter.jsx 22 KB

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