achievement.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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, downloadFile } 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 + "/techservice/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 + "/techservice/cognizance/upload"}
  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={downloadFile.bind(null, theData.enclosureUrl, theData.enclosureDownloadFileName)}>{theData.enclosureDownloadFileName}</a> : <span>未上传!</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 + "/techservice/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 + "/techservice/cognizance/activityNumber",
  267. })).done((data1, data2) => {
  268. let data = data1[0];
  269. let activityNumber = data2[0];
  270. if (data.error.length || !data.data || !data.data.list) {
  271. message.warning(data.error[0].message);
  272. return;
  273. };
  274. if (activityNumber.error.length || !activityNumber.data) {
  275. message.warning(activityNumber.error[0].message);
  276. return;
  277. };
  278. for (let i = 0; i < data.data.list.length; i++) {
  279. let thisdata = data.data.list[i];
  280. this.state.data.push({
  281. key: i,
  282. id: thisdata.id,
  283. uid: thisdata.uid,
  284. achievementName: thisdata.achievementName,
  285. source: thisdata.source,
  286. conversionForm: thisdata.conversionForm,
  287. conversionResult: thisdata.conversionResult,
  288. year: thisdata.year,
  289. enclosureUrl: thisdata.enclosureUrl,
  290. enclosureDownloadFileName: thisdata.enclosureDownloadFileName,
  291. enclosure: [thisdata.enclosureUrl, thisdata.enclosureDownloadFileName]
  292. });
  293. };
  294. this.state.activityNumberList = activityNumber.data;
  295. this.state.pagination.current = data.data.pageNo;
  296. this.state.pagination.total = data.data.totalCount;
  297. this.setState({
  298. dataSource: this.state.data,
  299. pagination: this.state.pagination
  300. });
  301. }).always(function () {
  302. this.setState({
  303. loading: false
  304. });
  305. }.bind(this));
  306. },
  307. getInitialState() {
  308. return {
  309. selectedRowKeys: [],
  310. selectedRows: [],
  311. loading: false,
  312. pagination: {
  313. defaultCurrent: 1,
  314. defaultPageSize: 10,
  315. showQuickJumper: true,
  316. pageSize: 10,
  317. onChange: function (page) {
  318. this.loadData(page);
  319. }.bind(this),
  320. showTotal: function (total) {
  321. return '共' + total + '条数据';
  322. }
  323. },
  324. columns: [
  325. {
  326. title: '年份',
  327. dataIndex: 'year',
  328. key: 'year'
  329. }, {
  330. title: '成果名称',
  331. dataIndex: 'achievementName',
  332. key: 'achievementName'
  333. }, {
  334. title: '成果来源',
  335. dataIndex: 'source',
  336. key: 'source',
  337. }, {
  338. title: '转化形式',
  339. dataIndex: 'conversionForm',
  340. key: 'conversionForm',
  341. render: (text) => { return getConversionForm(text) }
  342. }, {
  343. title: '转化结果',
  344. dataIndex: 'conversionResult',
  345. key: 'conversionResult',
  346. }, {
  347. title: '相关附件',
  348. dataIndex: 'enclosure',
  349. key: 'enclosure',
  350. render: (text) => {
  351. return <a onClick={downloadFile.bind(null, text[0], text[1])}>{text[1]}</a>
  352. }
  353. }
  354. ],
  355. dataSource: []
  356. };
  357. },
  358. componentWillMount() {
  359. this.loadData();
  360. },
  361. tableRowClick(record, index) {
  362. this.state.RowData = record;
  363. this.setState({
  364. showDesc: true
  365. });
  366. },
  367. delectRow() {
  368. let deletedIds = [];
  369. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  370. let rowItem = this.state.selectedRows[idx];
  371. if (rowItem.id) {
  372. deletedIds.push(rowItem.id)
  373. }
  374. }
  375. this.setState({
  376. selectedRowKeys: [],
  377. loading: deletedIds.length > 0
  378. });
  379. $.ajax({
  380. method: "POST",
  381. dataType: "json",
  382. crossDomain: false,
  383. url: globalConfig.context + "/techservice/cognizance/deleteAchievement",
  384. data: {
  385. ids: deletedIds
  386. }
  387. }).done(function (data) {
  388. if (!data.error.length) {
  389. message.success('保存成功!');
  390. this.setState({
  391. loading: false,
  392. });
  393. } else {
  394. message.warning(data.error[0].message);
  395. };
  396. this.loadData();
  397. }.bind(this));
  398. },
  399. closeDesc(e, s) {
  400. this.state.showDesc = e;
  401. if (s) {
  402. this.loadData();
  403. };
  404. },
  405. search() {
  406. this.loadData();
  407. },
  408. reset() {
  409. this.loadData();
  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="user-search">
  428. <p>
  429. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  430. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  431. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  432. disabled={!hasSelected}
  433. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  434. </p>
  435. </div>
  436. <div className="patent-table">
  437. <Spin spinning={this.state.loading}>
  438. <Table columns={this.state.columns}
  439. dataSource={this.state.dataSource}
  440. pagination={this.state.pagination}
  441. rowSelection={rowSelection}
  442. onRowClick={this.tableRowClick} />
  443. </Spin>
  444. </div>
  445. <AchievementDesc
  446. data={this.state.RowData}
  447. activityNumberList={this.state.activityNumberList}
  448. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  449. </div >
  450. );
  451. }
  452. });
  453. export default Achievement;