achievement.jsx 17 KB

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