achievement.jsx 17 KB

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