orgTechCenter.jsx 23 KB

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