orgTechCenter.jsx 21 KB

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