orgTechCenter.jsx 22 KB

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