orgTechCenter.jsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. import React from 'react';
  2. import { Icon, Form, Button, Input, Spin, Table, message, Modal, Upload, DatePicker, Switch } from 'antd';
  3. import './techProduct.less';
  4. import { beforeUploadFile, newDownloadFile, getProportion, saveProportion, getPreview } 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/admin/disposeCenterDetail",
  24. data: {
  25. id: this.props.data.id,
  26. cid: this.props.cid,
  27. projectName: values.projectName,
  28. projectTimeFormattedDate: values.projectTimeFormattedDate.format("YYYY-MM-DD"),
  29. institution: values.institution,
  30. termStartTimeFormattedDate: values.termTimeFormattedDate[0].format("YYYY-MM-DD"),
  31. termEndTimeFormattedDate: values.termTimeFormattedDate[1].format("YYYY-MM-DD"),
  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 = [];
  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: 12 },
  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/admin/uploadProtocol"}
  117. data={{ 'sign': 'protocol', 'uid': this.props.uid }}
  118. beforeUpload={beforeUploadFile}
  119. fileList={this.state.fileList}
  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: info.fileList.slice(-1) });
  136. }}
  137. >
  138. <Button><Icon type="upload" /> 上传协议附件 </Button>
  139. </Upload>
  140. <p style={{ marginTop: '10px' }}>{theData.protocolUrl ?
  141. <span className="download-file">
  142. <a onClick={newDownloadFile.bind(null, this.props.data.id, 'protocol', '/api/admin/downloadProtocol')}>{theData.protocolDownloadFileName}</a>
  143. <a onClick={() => {
  144. var newTab = window.open('about:blank'); getPreview(theData.id, 'techCenterDetail', 'protocol', function (data) { newTab.location.href = data; });
  145. }}><Icon style={{ fontSize: '16px' }} type="eye-o" /></a>
  146. </span>
  147. : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  148. </div>
  149. <FormItem style={{ marginTop: '20px' }}>
  150. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  151. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  152. </FormItem>
  153. </Form >
  154. );
  155. },
  156. }));
  157. const CenterListDesc = React.createClass({
  158. getInitialState() {
  159. return {
  160. visible: false,
  161. loading: false
  162. };
  163. },
  164. componentWillReceiveProps(nextProps) {
  165. this.state.visible = nextProps.showDesc
  166. },
  167. showModal() {
  168. this.setState({
  169. visible: true,
  170. });
  171. },
  172. handleOk() {
  173. this.setState({
  174. visible: false,
  175. });
  176. this.props.closeDesc(false, true);
  177. },
  178. handleCancel(e) {
  179. this.setState({
  180. visible: false,
  181. });
  182. this.props.closeDesc(false);
  183. },
  184. spinChange(e) {
  185. this.setState({
  186. loading: e
  187. });
  188. },
  189. render() {
  190. return (
  191. <div className="patent-addNew">
  192. <Modal maskClosable={false} title="产学研情况详情" visible={this.state.visible}
  193. onOk={this.handleOk} onCancel={this.handleCancel}
  194. width='800px'
  195. footer=''>
  196. <Spin spinning={this.state.loading} className='spin-box'>
  197. <CenterListDescFrom
  198. visible={this.state.visible}
  199. cid={this.props.cid}
  200. uid={this.props.uid}
  201. data={this.props.data}
  202. spinState={this.spinChange}
  203. closeModal={this.handleCancel}
  204. clickOk={this.handleOk} />
  205. </Spin>
  206. </Modal>
  207. </div>
  208. );
  209. },
  210. });
  211. const CenterList = React.createClass({
  212. loadOrgTechCenterDetail(uid) {
  213. this.setState({
  214. loading: true
  215. });
  216. $.ajax({
  217. method: "post",
  218. dataType: "json",
  219. crossDomain: false,
  220. url: globalConfig.context + "/api/admin/center",
  221. data: {
  222. uid: uid || this.props.data.uid
  223. }
  224. }).done((data) => {
  225. let theData = data.data;
  226. if (!theData) {
  227. if (data.error.length) {
  228. message.warning(data.error[0].message);
  229. };
  230. theData = {};
  231. };
  232. this.state.cid = theData.id;
  233. this.state.foundingTime = theData.foundingTimeFormattedDate;
  234. this.state.principal = theData.principal;
  235. this.state.systemCatalog = theData.systemCatalog;
  236. this.state.systemUrl = theData.systemUrl;
  237. this.state.systemDownloadFileName = theData.systemDownloadFileName;
  238. this.state.centerName = theData.centerName;
  239. this.state.comment = theData.comment;
  240. this.loadData();
  241. }).always(function () {
  242. this.setState({
  243. loading: false
  244. });
  245. }.bind(this));
  246. let _me = this;
  247. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  248. },
  249. loadData(pageNo) {
  250. this.state.data = [];
  251. this.setState({
  252. loading: true
  253. });
  254. $.ajax({
  255. method: "get",
  256. dataType: "json",
  257. crossDomain: false,
  258. url: globalConfig.context + "/api/admin/centerDetail",
  259. data: {
  260. pageNo: pageNo || 1,
  261. pageSize: this.state.pagination.pageSize,
  262. cid: this.state.cid
  263. }
  264. }).done((data) => {
  265. if (!data.data || !data.data.list) {
  266. if (data.error.length) {
  267. message.warning(data.error[0].message);
  268. }
  269. return;
  270. };
  271. for (let i = 0; i < data.data.list.length; i++) {
  272. let thisdata = data.data.list[i];
  273. this.state.data.push({
  274. key: i,
  275. id: thisdata.id,
  276. cid: thisdata.cid,
  277. projectTimeFormattedDate: thisdata.projectTimeFormattedDate,
  278. projectName: thisdata.projectName,
  279. protocolDownloadFileName: thisdata.protocolDownloadFileName,
  280. protocolUrl: thisdata.protocolUrl,
  281. protocol: [thisdata.id, thisdata.protocolDownloadFileName],
  282. institution: thisdata.institution,
  283. termTimeFormattedDate: [thisdata.termStartTimeFormattedDate, thisdata.termEndTimeFormattedDate],
  284. termStartTimeFormattedDate: thisdata.termStartTimeFormattedDate,
  285. termEndTimeFormattedDate: thisdata.termEndTimeFormattedDate
  286. });
  287. };
  288. this.state.pagination.current = data.data.pageNo;
  289. this.state.pagination.total = data.data.totalCount;
  290. this.setState({
  291. dataSource: this.state.data,
  292. pagination: this.state.pagination
  293. });
  294. }).always(function () {
  295. this.setState({
  296. loading: false
  297. });
  298. }.bind(this));
  299. },
  300. getInitialState() {
  301. return {
  302. selectedRowKeys: [],
  303. selectedRows: [],
  304. loading: false,
  305. pagination: {
  306. defaultCurrent: 1,
  307. defaultPageSize: 10,
  308. showQuickJumper: true,
  309. pageSize: 10,
  310. onChange: function (page) {
  311. this.loadData(page);
  312. }.bind(this),
  313. showTotal: function (total) {
  314. return '共' + total + '条数据';
  315. }
  316. },
  317. columns: [
  318. {
  319. title: '时间',
  320. dataIndex: 'projectTimeFormattedDate',
  321. key: 'projectTimeFormattedDate'
  322. }, {
  323. title: '项目名称',
  324. dataIndex: 'projectName',
  325. key: 'projectName'
  326. }, {
  327. title: '期限',
  328. dataIndex: 'termTimeFormattedDate',
  329. key: 'termTimeFormattedDate',
  330. render: (text) => {
  331. return text[0] + ' - ' + text[1];
  332. }
  333. }, {
  334. title: '科研院所',
  335. dataIndex: 'institution',
  336. key: 'institution'
  337. }, {
  338. title: '协议附件',
  339. dataIndex: 'protocol',
  340. key: 'protocol',
  341. render: (text) => {
  342. return <a onClick={newDownloadFile.bind(null, text[0], 'protocol', '/api/admin/downloadProtocol')}>{text[1]}</a>
  343. }
  344. }
  345. ],
  346. dataSource: []
  347. };
  348. },
  349. componentWillMount() {
  350. this.loadOrgTechCenterDetail();
  351. },
  352. tableRowClick(record, index) {
  353. this.state.RowData = record;
  354. this.setState({
  355. showDesc: true
  356. });
  357. },
  358. delectRow() {
  359. let deletedIds = [];
  360. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  361. let rowItem = this.state.selectedRows[idx];
  362. if (rowItem.id) {
  363. deletedIds.push(rowItem.id)
  364. }
  365. }
  366. this.setState({
  367. selectedRowKeys: [],
  368. loading: deletedIds.length > 0
  369. });
  370. $.ajax({
  371. method: "POST",
  372. dataType: "json",
  373. crossDomain: false,
  374. url: globalConfig.context + "/api/admin/deleteOrgTechCenterDetail",
  375. data: {
  376. ids: deletedIds
  377. }
  378. }).done(function (data) {
  379. if (!data.error.length) {
  380. message.success('删除成功!');
  381. this.setState({
  382. loading: false,
  383. });
  384. } else {
  385. message.warning(data.error[0].message);
  386. };
  387. this.loadData();
  388. }.bind(this));
  389. },
  390. closeDesc(e, s) {
  391. this.state.showDesc = e;
  392. if (s) {
  393. this.loadData();
  394. };
  395. },
  396. saveCenterDetail() {
  397. this.setState({
  398. loading: true
  399. });
  400. $.ajax({
  401. method: "post",
  402. dataType: "json",
  403. crossDomain: false,
  404. url: globalConfig.context + "/api/admin/disposeCenter",
  405. data: {
  406. uid: this.props.data.uid,
  407. id: this.state.cid,
  408. principal: this.state.principal,
  409. systemUrl: this.state.systemUrl,
  410. systemCatalog: this.state.systemCatalog,
  411. foundingTimeFormattedDate: this.state.foundingTime,
  412. comment: this.state.comment,
  413. centerName: this.state.centerName
  414. }
  415. }).done((data) => {
  416. if (!data.error.length) {
  417. message.success('保存成功!');
  418. this.loadOrgTechCenterDetail();
  419. } else {
  420. message.warning(data.error[0].message);
  421. };
  422. this.setState({
  423. loading: false,
  424. });
  425. });
  426. },
  427. render() {
  428. const rowSelection = {
  429. selectedRowKeys: this.state.selectedRowKeys,
  430. onChange: (selectedRowKeys, selectedRows) => {
  431. this.setState({
  432. selectedRows: selectedRows,
  433. selectedRowKeys: selectedRowKeys
  434. });
  435. }
  436. };
  437. const hasSelected = this.state.selectedRowKeys.length > 0;
  438. return (
  439. <div className="user-content" >
  440. <div className="content-title">
  441. <span>研发部门 </span>
  442. <span className="proportion"> 是否已完成:</span>
  443. <Switch
  444. checked={this.state.proportion && this.state.proportion.institution == 1 ? true : false}
  445. checkedChildren={'已完成'}
  446. unCheckedChildren={'未完成'}
  447. onChange={(e) => {
  448. e ? this.state.proportion.institution = 1 : this.state.proportion.institution = 0;
  449. saveProportion(this.state.proportion.id, this.props.data.uid, 'institution', this.state.proportion.institution);
  450. this.setState({ proportion: this.state.proportion });
  451. }} />
  452. </div>
  453. <div className="clearfix">
  454. <div className="orgTech-item">
  455. <span>研发部门名称: </span>
  456. <Input
  457. value={this.state.centerName}
  458. onChange={(e) => { this.setState({ centerName: e.target.value }); }}
  459. />
  460. <span>成立时间: </span>
  461. <DatePicker
  462. allowClear={false}
  463. value={this.state.foundingTime ? moment(this.state.foundingTime) : undefined}
  464. onChange={(date, dateString) => { this.setState({ foundingTime: dateString }); }}
  465. />
  466. <span>负责人: </span>
  467. <Input
  468. value={this.state.principal}
  469. onChange={(e) => { this.setState({ principal: e.target.value }); }}
  470. />
  471. </div>
  472. <div className="orgTech-item">
  473. <span>制度目录: </span>
  474. <Input type='textarea' rows={6}
  475. value={this.state.systemCatalog}
  476. onChange={(e) => { this.setState({ systemCatalog: e.target.value }); }}
  477. />
  478. </div>
  479. <div className="orgTech-item">
  480. <span>备注: </span>
  481. <Input type='textarea' rows={3}
  482. value={this.state.comment}
  483. onChange={(e) => { this.setState({ comment: e.target.value }); }}
  484. />
  485. </div>
  486. </div>
  487. <div className="half-item">
  488. <p>制度上传: (上传 zip 或者 rar 文件)</p>
  489. <div style={{ margin: '10px 0' }}>
  490. <Upload
  491. name="ratepay"
  492. action={globalConfig.context + "/api/admin/uploadInstitution"}
  493. data={{ 'sign': 'institution', 'uid': this.props.data.uid }}
  494. beforeUpload={beforeUploadFile}
  495. fileList={this.state.fileList}
  496. onChange={(info) => {
  497. if (info.file.status !== 'uploading') {
  498. console.log(info.file, info.fileList);
  499. }
  500. if (info.file.status === 'done') {
  501. if (!info.file.response.error.length) {
  502. message.success(`${info.file.name} 文件上传成功!`);
  503. } else {
  504. message.warning(info.file.response.error[0].message);
  505. return;
  506. };
  507. this.state.systemUrl = info.file.response.data;
  508. } else if (info.file.status === 'error') {
  509. message.error(`${info.file.name} 文件上传失败。`);
  510. };
  511. this.setState({ fileList: info.fileList.slice(-1) });
  512. }}
  513. >
  514. <Button><Icon type="upload" /> 上传研发部门制度 </Button>
  515. </Upload>
  516. <p style={{ marginTop: '10px' }}>{this.state.systemUrl ? <a onClick={newDownloadFile.bind(null, this.state.cid, 'institution', '/api/admin/downloadInstitution')}>{this.state.systemDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  517. </div>
  518. </div>
  519. <Button type='primary' onClick={this.saveCenterDetail} style={{ marginBottom: '10px' }}>保存</Button>
  520. <div className="content-title">
  521. <span>产学研情况</span>
  522. </div>
  523. <div className="user-search">
  524. <p>
  525. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  526. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  527. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  528. disabled={!hasSelected}
  529. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  530. </p>
  531. </div>
  532. <div className="patent-table">
  533. <Spin spinning={this.state.loading}>
  534. <Table size="middle" columns={this.state.columns}
  535. dataSource={this.state.dataSource}
  536. pagination={this.state.pagination}
  537. rowSelection={rowSelection}
  538. style={{
  539. cursor: 'pointer',
  540. }}
  541. onRowClick={this.tableRowClick} />
  542. </Spin>
  543. </div>
  544. <CenterListDesc
  545. cid={this.state.cid}
  546. uid={this.props.data.uid}
  547. data={this.state.RowData}
  548. showDesc={this.state.showDesc}
  549. closeDesc={this.closeDesc} />
  550. </div >
  551. );
  552. }
  553. });
  554. export default CenterList;