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/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. termStartTimeFormattedDate: thisdata.termStartTimeFormattedDate,
  266. termEndTimeFormattedDate: thisdata.termEndTimeFormattedDate
  267. });
  268. };
  269. this.state.pagination.current = data.data.pageNo;
  270. this.state.pagination.total = data.data.totalCount;
  271. this.setState({
  272. dataSource: this.state.data,
  273. pagination: this.state.pagination
  274. });
  275. }).always(function () {
  276. this.setState({
  277. loading: false
  278. });
  279. }.bind(this));
  280. },
  281. getInitialState() {
  282. return {
  283. selectedRowKeys: [],
  284. selectedRows: [],
  285. loading: false,
  286. pagination: {
  287. defaultCurrent: 1,
  288. defaultPageSize: 10,
  289. showQuickJumper: true,
  290. pageSize: 10,
  291. onChange: function (page) {
  292. this.loadData(page);
  293. }.bind(this),
  294. showTotal: function (total) {
  295. return '共' + total + '条数据';
  296. }
  297. },
  298. columns: [
  299. {
  300. title: '时间',
  301. dataIndex: 'projectTimeFormattedDate',
  302. key: 'projectTimeFormattedDate'
  303. }, {
  304. title: '项目名称',
  305. dataIndex: 'projectName',
  306. key: 'projectName'
  307. }, {
  308. title: '期限',
  309. dataIndex: 'termTimeFormattedDate',
  310. key: 'termTimeFormattedDate',
  311. render: (text) => {
  312. return text[0] + ' - ' + text[1];
  313. }
  314. }, {
  315. title: '科研院所',
  316. dataIndex: 'institution',
  317. key: 'institution'
  318. }, {
  319. title: '协议附件',
  320. dataIndex: 'protocol',
  321. key: 'protocol',
  322. render: (text) => {
  323. return <a onClick={newDownloadFile.bind(null, text[0], 'protocol', '/api/admin/downloadProtocol')}>{text[1]}</a>
  324. }
  325. }
  326. ],
  327. dataSource: []
  328. };
  329. },
  330. componentWillMount() {
  331. this.loadOrgTechCenterDetail();
  332. },
  333. componentWillReceiveProps(nextProps) {
  334. if (this.props.data.uid !== nextProps.data.uid) {
  335. this.loadOrgTechCenterDetail(nextProps.data.uid);
  336. };
  337. },
  338. tableRowClick(record, index) {
  339. this.state.RowData = record;
  340. this.setState({
  341. showDesc: true
  342. });
  343. },
  344. delectRow() {
  345. let deletedIds = [];
  346. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  347. let rowItem = this.state.selectedRows[idx];
  348. if (rowItem.id) {
  349. deletedIds.push(rowItem.id)
  350. }
  351. }
  352. this.setState({
  353. selectedRowKeys: [],
  354. loading: deletedIds.length > 0
  355. });
  356. $.ajax({
  357. method: "POST",
  358. dataType: "json",
  359. crossDomain: false,
  360. url: globalConfig.context + "/api/admin/deleteOrgTechCenterDetail",
  361. data: {
  362. ids: deletedIds
  363. }
  364. }).done(function (data) {
  365. if (!data.error.length) {
  366. message.success('保存成功!');
  367. this.setState({
  368. loading: false,
  369. });
  370. } else {
  371. message.warning(data.error[0].message);
  372. };
  373. this.loadData();
  374. }.bind(this));
  375. },
  376. closeDesc(e, s) {
  377. this.state.showDesc = e;
  378. if (s) {
  379. this.loadData();
  380. };
  381. },
  382. saveCenterDetail() {
  383. this.setState({
  384. loading: true
  385. });
  386. $.ajax({
  387. method: "post",
  388. dataType: "json",
  389. crossDomain: false,
  390. url: globalConfig.context + "/api/admin/disposeCenter",
  391. data: {
  392. uid: this.props.data.uid,
  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. } else {
  406. message.warning(data.error[0].message);
  407. };
  408. this.setState({
  409. loading: false,
  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. allowClear={false}
  439. value={this.state.foundingTime ? moment(this.state.foundingTime) : undefined}
  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/admin/uploadInstitution"}
  469. data={{ 'sign': 'institution', 'uid': this.props.data.uid }}
  470. beforeUpload={beforeUploadFile}
  471. showUploadList={false}
  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. }}
  488. >
  489. <Button><Icon type="upload" /> 上传研发部门制度 </Button>
  490. </Upload>
  491. <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>
  492. </div>
  493. </div>
  494. <Button type='primary' onClick={this.saveCenterDetail} style={{ marginBottom: '10px' }}>保存</Button>
  495. <div className="content-title">
  496. <span>产学研情况</span>
  497. </div>
  498. <div className="user-search">
  499. <p>
  500. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  501. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  502. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  503. disabled={!hasSelected}
  504. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  505. </p>
  506. </div>
  507. <div className="patent-table">
  508. <Spin spinning={this.state.loading}>
  509. <Table columns={this.state.columns}
  510. dataSource={this.state.dataSource}
  511. pagination={this.state.pagination}
  512. rowSelection={rowSelection}
  513. onRowClick={this.tableRowClick} />
  514. </Spin>
  515. </div>
  516. <CenterListDesc
  517. cid={this.state.cid}
  518. uid={this.props.data.uid}
  519. data={this.state.RowData}
  520. showDesc={this.state.showDesc}
  521. closeDesc={this.closeDesc} />
  522. </div >
  523. );
  524. }
  525. });
  526. export default CenterList;