orgTechCenter.jsx 22 KB

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