achievement.jsx 18 KB

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