achievement.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. import React from 'react';
  2. import { Icon, Form, Button, Input, Spin, Table, message, Select, Modal, InputNumber, Upload } from 'antd';
  3. import './techProduct.less';
  4. import { getConversionForm, beforeUploadFile, newDownloadFile } from '../../tools.js';
  5. import { conversionFormList, technicalSourceList } from '../../dataDic.js';
  6. import ajax from 'jquery/src/ajax/xhr.js';
  7. import $ from 'jquery/src/ajax';
  8. const AchievementDescFrom = Form.create()(React.createClass({
  9. getInitialState() {
  10. return {
  11. loading: false,
  12. yearOption: [],
  13. conversionFormOption: [],
  14. technicalSourceOption: []
  15. };
  16. },
  17. componentWillMount() {
  18. let d = new Date();
  19. let _me = this;
  20. d = d.getFullYear();
  21. for (let i = d; i > d - 20; i--) {
  22. _me.state.yearOption.push(
  23. <Select.Option key={i.toString()} >{i}</Select.Option>
  24. )
  25. };
  26. conversionFormList.map(function (item) {
  27. _me.state.conversionFormOption.push(
  28. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  29. )
  30. });
  31. technicalSourceList.map(function (item) {
  32. _me.state.technicalSourceOption.push(
  33. <Select.Option value={item.key} key={item.key}>{item.key}</Select.Option>
  34. )
  35. });
  36. if (this.props.activityNumberList && this.props.activityNumberList.length) {
  37. for (let i = 0; i < this.props.activityNumberList.length; i++) {
  38. _me.state.technicalSourceOption.push(
  39. <Select.Option value={this.props.activityNumberList[i].activityNumber}
  40. key={this.props.activityNumberList[i].uid}>
  41. {this.props.activityNumberList[i].activityName}-{this.props.activityNumberList[i].activityNumber}
  42. </Select.Option>
  43. )
  44. };
  45. };
  46. },
  47. handleSubmit(e) {
  48. e.preventDefault();
  49. if (!this.state.year && !this.props.data.year) {
  50. message.warning("请选择一个年份!")
  51. return;
  52. };
  53. this.props.form.validateFields((err, values) => {
  54. if (!err) {
  55. this.props.spinState(true);
  56. $.ajax({
  57. method: "POST",
  58. dataType: "json",
  59. crossDomain: false,
  60. url: globalConfig.context + "/api/user/cognizance/disposeAchievement",
  61. data: {
  62. id: this.props.data.id,
  63. achievementName: values.achievementName,
  64. source: values.source,
  65. conversionForm: values.conversionForm,
  66. conversionResult: values.conversionResult,
  67. year: this.state.year || this.props.data.year,
  68. enclosureUrl: this.state.enclosureUrl
  69. }
  70. }).done(function (data) {
  71. if (!data.error.length) {
  72. message.success('保存成功!');
  73. this.props.clickOk();
  74. this.props.spinState(false);
  75. this.props.form.resetFields();
  76. } else {
  77. message.warning(data.error[0].message);
  78. this.props.spinState(false);
  79. }
  80. }.bind(this));
  81. }
  82. });
  83. },
  84. componentWillReceiveProps(nextProps) {
  85. if (!this.props.visible && nextProps.visible) {
  86. this.props.form.resetFields();
  87. this.state.fileList = [];
  88. this.state.enclosureUrl = undefined;
  89. };
  90. },
  91. render() {
  92. const FormItem = Form.Item;
  93. const { getFieldDecorator } = this.props.form;
  94. const theData = this.props.data;
  95. const formItemLayout = {
  96. labelCol: { span: 4 },
  97. wrapperCol: { span: 16 },
  98. };
  99. const _me = this;
  100. return (
  101. <Form onSubmit={this.handleSubmit} className="activityCost-form">
  102. <div className="activityCost-title"><span>年份: </span>
  103. {
  104. theData.year ? <span>{theData.year}</span> :
  105. <Select placeholder="请选择年份" style={{ width: 200 }}
  106. onSelect={(e, n) => { this.state.year = e }}>
  107. {this.state.yearOption}
  108. </Select>
  109. }
  110. </div>
  111. <div className="clearfix">
  112. <FormItem
  113. {...formItemLayout}
  114. label="成果名称"
  115. >
  116. {getFieldDecorator('achievementName', {
  117. rules: [{ type: 'string', required: true, message: '此项为必填项!' }],
  118. initialValue: theData.achievementName
  119. })(
  120. <Input />
  121. )}
  122. </FormItem>
  123. <FormItem
  124. {...formItemLayout}
  125. label="成果来源"
  126. >
  127. {getFieldDecorator('source', {
  128. rules: [{ type: 'string', required: true, message: '此项为必填项!' }],
  129. initialValue: theData.source
  130. })(
  131. <Select placeholder="请选择成果来源" style={{ width: 200 }}>
  132. {this.state.technicalSourceOption}
  133. </Select>
  134. )}
  135. </FormItem>
  136. <FormItem
  137. {...formItemLayout}
  138. label="转化形式"
  139. >
  140. {getFieldDecorator('conversionForm', {
  141. rules: [{ type: 'string', required: true, message: '此项为必填项!' }],
  142. initialValue: theData.conversionForm
  143. })(
  144. <Select placeholder="请选择转化形式" style={{ width: 200 }}>
  145. {this.state.conversionFormOption}
  146. </Select>
  147. )}
  148. </FormItem>
  149. <FormItem
  150. {...formItemLayout}
  151. label="转化结果"
  152. >
  153. {getFieldDecorator('conversionResult', {
  154. rules: [{ type: 'string', required: true, message: '此项为必填项!' }],
  155. initialValue: theData.conversionResult
  156. })(
  157. <Input type="textarea" rows={6} />
  158. )}
  159. </FormItem>
  160. </div>
  161. <div className="hrSituation-roster">
  162. <Upload
  163. name="ratepay"
  164. action={globalConfig.context + "/api/user/cognizance/uploadAchievement"}
  165. data={{ 'sign': 'achievement' }}
  166. beforeUpload={beforeUploadFile}
  167. fileList={this.state.fileList}
  168. onChange={(info) => {
  169. if (info.file.status !== 'uploading') {
  170. console.log(info.file, info.fileList);
  171. }
  172. if (info.file.status === 'done') {
  173. if (!info.file.response.error.length) {
  174. message.success(`${info.file.name} 文件上传成功!`);
  175. } else {
  176. message.warning(info.file.response.error[0].message);
  177. return;
  178. };
  179. this.state.enclosureUrl = info.file.response.data;
  180. } else if (info.file.status === 'error') {
  181. message.error(`${info.file.name} 文件上传失败。`);
  182. };
  183. this.setState({ fileList: info.fileList.slice(-1) });
  184. }}
  185. >
  186. <Button><Icon type="upload" /> 上传科技成果附件 </Button>
  187. </Upload>
  188. <p style={{ marginTop: '10px' }}>{theData.enclosureUrl ? <a onClick={newDownloadFile.bind(null, theData.id, 'achievement', '/api/user/cognizance/downloadAchievement')}>{theData.enclosureDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  189. </div>
  190. <FormItem style={{ marginTop: '20px' }}>
  191. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  192. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  193. </FormItem>
  194. </Form >
  195. );
  196. },
  197. }));
  198. const AchievementDesc = React.createClass({
  199. getInitialState() {
  200. return {
  201. visible: false,
  202. loading: false
  203. };
  204. },
  205. componentWillReceiveProps(nextProps) {
  206. this.state.visible = nextProps.showDesc
  207. },
  208. showModal() {
  209. this.setState({
  210. visible: true,
  211. });
  212. },
  213. handleOk() {
  214. this.setState({
  215. visible: false,
  216. });
  217. this.props.closeDesc(false, true);
  218. },
  219. handleCancel(e) {
  220. this.setState({
  221. visible: false,
  222. });
  223. this.props.closeDesc(false);
  224. },
  225. spinChange(e) {
  226. this.setState({
  227. loading: e
  228. });
  229. },
  230. render() {
  231. return (
  232. <div className="patent-addNew">
  233. <Modal maskClosable={false} title="科技成果转化" visible={this.state.visible}
  234. onOk={this.handleOk} onCancel={this.handleCancel}
  235. width='800px'
  236. footer='' >
  237. <Spin spinning={this.state.loading} className='spin-box'>
  238. <AchievementDescFrom
  239. data={this.props.data}
  240. visible={this.state.visible}
  241. activityNumberList={this.props.activityNumberList}
  242. spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  243. </Spin>
  244. </Modal>
  245. </div>
  246. );
  247. },
  248. });
  249. const Achievement = React.createClass({
  250. loadData(pageNo) {
  251. this.state.data = [];
  252. this.setState({
  253. loading: true
  254. });
  255. $.when($.ajax({
  256. method: "get",
  257. dataType: "json",
  258. crossDomain: false,
  259. url: globalConfig.context + "/api/user/cognizance/achievementList",
  260. data: {
  261. pageNo: pageNo || 1,
  262. pageSize: this.state.pagination.pageSize,
  263. }
  264. }), $.ajax({
  265. method: "get",
  266. dataType: "json",
  267. crossDomain: false,
  268. url: globalConfig.context + "/api/user/cognizance/activityNumber",
  269. })).done((data1, data2) => {
  270. let data = data1[0];
  271. let activityNumber = data2[0];
  272. if (!data.data || !data.data.list) {
  273. if (data.error && data.error.length) {
  274. message.warning(data.error[0].message);
  275. this.state.ButtonDisabled = true;
  276. };
  277. return;
  278. };
  279. if (!activityNumber.data) {
  280. if (activityNumber.error && activityNumber.error.length) {
  281. message.warning(activityNumber.error[0].message);
  282. this.state.ButtonDisabled = true;
  283. };
  284. return;
  285. };
  286. for (let i = 0; i < data.data.list.length; i++) {
  287. let thisdata = data.data.list[i];
  288. this.state.data.push({
  289. key: i,
  290. id: thisdata.id,
  291. uid: thisdata.uid,
  292. achievementName: thisdata.achievementName,
  293. source: thisdata.source,
  294. conversionForm: thisdata.conversionForm,
  295. conversionResult: thisdata.conversionResult,
  296. year: thisdata.year,
  297. enclosureUrl: thisdata.enclosureUrl,
  298. enclosureDownloadFileName: thisdata.enclosureDownloadFileName,
  299. enclosure: [thisdata.id, thisdata.enclosureDownloadFileName]
  300. });
  301. };
  302. this.state.activityNumberList = activityNumber.data;
  303. this.state.pagination.current = data.data.pageNo;
  304. this.state.pagination.total = data.data.totalCount;
  305. this.setState({
  306. dataSource: this.state.data,
  307. pagination: this.state.pagination
  308. });
  309. }).always(function () {
  310. this.setState({
  311. loading: false
  312. });
  313. }.bind(this));
  314. },
  315. getInitialState() {
  316. return {
  317. selectedRowKeys: [],
  318. selectedRows: [],
  319. loading: false,
  320. pagination: {
  321. defaultCurrent: 1,
  322. defaultPageSize: 10,
  323. showQuickJumper: true,
  324. pageSize: 10,
  325. onChange: function (page) {
  326. this.loadData(page);
  327. }.bind(this),
  328. showTotal: function (total) {
  329. return '共' + total + '条数据';
  330. }
  331. },
  332. columns: [
  333. {
  334. title: '年份',
  335. dataIndex: 'year',
  336. key: 'year'
  337. }, {
  338. title: '成果名称',
  339. dataIndex: 'achievementName',
  340. key: 'achievementName'
  341. }, {
  342. title: '成果来源',
  343. dataIndex: 'source',
  344. key: 'source',
  345. }, {
  346. title: '转化形式',
  347. dataIndex: 'conversionForm',
  348. key: 'conversionForm',
  349. render: (text) => { return getConversionForm(text) }
  350. }, {
  351. title: '转化结果',
  352. dataIndex: 'conversionResult',
  353. key: 'conversionResult',
  354. }, {
  355. title: '相关附件',
  356. dataIndex: 'enclosure',
  357. key: 'enclosure',
  358. render: (text) => {
  359. return <a onClick={newDownloadFile.bind(null, text[0], 'achievement', '/api/user/cognizance/downloadAchievement')}>{text[1]}</a>
  360. }
  361. }
  362. ],
  363. dataSource: []
  364. };
  365. },
  366. componentWillMount() {
  367. this.loadData();
  368. },
  369. tableRowClick(record, index) {
  370. this.state.RowData = record;
  371. this.setState({
  372. showDesc: true
  373. });
  374. },
  375. delectRow() {
  376. let deletedIds = [];
  377. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  378. let rowItem = this.state.selectedRows[idx];
  379. if (rowItem.id) {
  380. deletedIds.push(rowItem.id)
  381. }
  382. }
  383. this.setState({
  384. selectedRowKeys: [],
  385. loading: deletedIds.length > 0
  386. });
  387. $.ajax({
  388. method: "POST",
  389. dataType: "json",
  390. crossDomain: false,
  391. url: globalConfig.context + "/api/user/cognizance/deleteAchievement",
  392. data: {
  393. ids: deletedIds
  394. }
  395. }).done(function (data) {
  396. if (!data.error.length) {
  397. message.success('删除成功!');
  398. this.setState({
  399. loading: false,
  400. });
  401. } else {
  402. message.warning(data.error[0].message);
  403. };
  404. this.loadData();
  405. }.bind(this));
  406. },
  407. closeDesc(e, s) {
  408. this.state.showDesc = e;
  409. if (s) {
  410. this.loadData();
  411. };
  412. },
  413. search() {
  414. this.loadData();
  415. },
  416. reset() {
  417. this.loadData();
  418. },
  419. render() {
  420. const rowSelection = {
  421. selectedRowKeys: this.state.selectedRowKeys,
  422. onChange: (selectedRowKeys, selectedRows) => {
  423. this.setState({
  424. selectedRows: selectedRows,
  425. selectedRowKeys: selectedRowKeys
  426. });
  427. }
  428. };
  429. const hasSelected = this.state.selectedRowKeys.length > 0;
  430. return (
  431. <div className="user-content" >
  432. <div className="content-title">
  433. <span>科技成果转化</span>
  434. </div>
  435. <div className="user-search">
  436. <p>
  437. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  438. disabled={this.state.ButtonDisabled}
  439. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  440. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  441. disabled={!hasSelected}
  442. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  443. </p>
  444. </div>
  445. <div className="patent-table">
  446. <Spin spinning={this.state.loading}>
  447. <Table columns={this.state.columns}
  448. dataSource={this.state.dataSource}
  449. pagination={this.state.pagination}
  450. rowSelection={rowSelection}
  451. onRowClick={this.tableRowClick} />
  452. </Spin>
  453. </div>
  454. <AchievementDesc
  455. data={this.state.RowData}
  456. activityNumberList={this.state.activityNumberList}
  457. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  458. </div >
  459. );
  460. }
  461. });
  462. export default Achievement;