achievement.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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.closeModal();
  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. message.success(`${info.file.name} 文件上传成功!`);
  166. this.state.enclosureUrl = info.file.response.data;
  167. } else if (info.file.status === 'error') {
  168. message.error(`${info.file.name} 文件上传失败。`);
  169. }
  170. }}
  171. >
  172. <Button><Icon type="upload" /> 上传文件 </Button>
  173. </Upload>
  174. </div>
  175. <FormItem style={{ marginTop: '20px' }}>
  176. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  177. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  178. </FormItem>
  179. </Form >
  180. );
  181. },
  182. }));
  183. const AchievementDesc = React.createClass({
  184. getInitialState() {
  185. return {
  186. visible: false,
  187. loading: false
  188. };
  189. },
  190. componentWillReceiveProps(nextProps) {
  191. this.state.visible = nextProps.showDesc
  192. },
  193. showModal() {
  194. this.setState({
  195. visible: true,
  196. });
  197. },
  198. handleOk() {
  199. this.setState({
  200. visible: false,
  201. });
  202. this.props.closeDesc(false);
  203. },
  204. handleCancel(e) {
  205. this.setState({
  206. visible: false,
  207. });
  208. this.props.closeDesc(false);
  209. },
  210. spinChange(e) {
  211. this.setState({
  212. loading: e
  213. });
  214. },
  215. render() {
  216. return (
  217. <div className="patent-addNew">
  218. <Spin spinning={this.state.loading} className='spin-box'>
  219. <Modal title="科技成果转化" visible={this.state.visible}
  220. onOk={this.handleOk} onCancel={this.handleCancel}
  221. width='800px'
  222. footer=''
  223. >
  224. <AchievementDescFrom
  225. data={this.props.data}
  226. activityNumberList={this.props.activityNumberList}
  227. spinState={this.spinChange} closeModal={this.handleCancel} />
  228. </Modal>
  229. </Spin>
  230. </div>
  231. );
  232. },
  233. });
  234. const Achievement = React.createClass({
  235. loadData(pageNo) {
  236. this.state.data = [];
  237. this.setState({
  238. loading: true
  239. });
  240. $.when($.ajax({
  241. method: "get",
  242. dataType: "json",
  243. crossDomain: false,
  244. url: globalConfig.context + "/techservice/cognizance/achievementList",
  245. data: {
  246. pageNo: pageNo || 1,
  247. pageSize: this.state.pagination.pageSize,
  248. }
  249. }), $.ajax({
  250. method: "get",
  251. dataType: "json",
  252. crossDomain: false,
  253. url: globalConfig.context + "/techservice/cognizance/activityNumber",
  254. })).done((data1, data2) => {
  255. let data = data1[0];
  256. let activityNumber = data2[0];
  257. if (data.error.length || !data.data || !data.data.list) {
  258. message.warning(data.error[0].message);
  259. return;
  260. };
  261. if (activityNumber.error.length || !activityNumber.data) {
  262. message.warning(activityNumber.error[0].message);
  263. return;
  264. };
  265. for (let i = 0; i < data.data.list.length; i++) {
  266. let thisdata = data.data.list[i];
  267. this.state.data.push({
  268. key: i,
  269. id:thisdata.id,
  270. uid: thisdata.uid,
  271. achievementName: thisdata.achievementName,
  272. source: thisdata.source,
  273. conversionForm: thisdata.conversionForm,
  274. conversionResult: thisdata.conversionResult,
  275. year: thisdata.year,
  276. enclosureUrl: thisdata.enclosureUrl,
  277. });
  278. };
  279. this.state.activityNumberList = activityNumber.data;
  280. this.state.pagination.current = data.data.pageNo;
  281. this.state.pagination.total = data.data.totalCount;
  282. this.setState({
  283. dataSource: this.state.data,
  284. pagination: this.state.pagination
  285. });
  286. }).always(function () {
  287. this.setState({
  288. loading: false
  289. });
  290. }.bind(this));
  291. },
  292. getInitialState() {
  293. return {
  294. selectedRowKeys: [],
  295. selectedRows: [],
  296. loading: false,
  297. pagination: {
  298. defaultCurrent: 1,
  299. defaultPageSize: 10,
  300. showQuickJumper: true,
  301. pageSize: 10,
  302. onChange: function (page) {
  303. this.loadData(page);
  304. }.bind(this),
  305. showTotal: function (total) {
  306. return '共' + total + '条数据';
  307. }
  308. },
  309. columns: [
  310. {
  311. title: '年份',
  312. dataIndex: 'year',
  313. key: 'year'
  314. }, {
  315. title: '成果名称',
  316. dataIndex: 'achievementName',
  317. key: 'achievementName'
  318. }, {
  319. title: '成果来源',
  320. dataIndex: 'source',
  321. key: 'source',
  322. }, {
  323. title: '转化形式',
  324. dataIndex: 'conversionForm',
  325. key: 'conversionForm',
  326. render: (text) => { return getConversionForm(text) }
  327. }, {
  328. title: '转化结果',
  329. dataIndex: 'conversionResult',
  330. key: 'conversionResult',
  331. }, {
  332. title: '相关附件',
  333. dataIndex: 'enclosureUrl',
  334. key: 'enclosureUrl',
  335. render: (text) => {
  336. <a href="" onClick={() => {
  337. window.open(globalConfig.context + "/techservice/patent/downloadFile?path=" + text + "&sign=" + "type")
  338. }}></a>
  339. }
  340. }
  341. ],
  342. dataSource: []
  343. };
  344. },
  345. componentWillMount() {
  346. this.loadData();
  347. },
  348. tableRowClick(record, index) {
  349. this.state.RowData = record;
  350. this.setState({
  351. showDesc: true
  352. });
  353. },
  354. delectRow() {
  355. let deletedIds = [];
  356. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  357. let rowItem = this.state.selectedRows[idx];
  358. if (rowItem.id) {
  359. deletedIds.push(rowItem.id)
  360. }
  361. }
  362. this.setState({
  363. selectedRowKeys: [],
  364. loading: deletedIds.length > 0
  365. });
  366. $.ajax({
  367. method: "POST",
  368. dataType: "json",
  369. crossDomain: false,
  370. url: globalConfig.context + "/techservice/cognizance/deleteAchievement",
  371. data: {
  372. ids: deletedIds
  373. }
  374. }).done(function (data) {
  375. if (!data.error.length) {
  376. message.success('保存成功!');
  377. this.setState({
  378. loading: false,
  379. });
  380. } else {
  381. message.warning(data.error[0].message);
  382. };
  383. this.loadData();
  384. }.bind(this));
  385. },
  386. closeDesc(e) {
  387. this.state.showDesc = e;
  388. this.loadData();
  389. },
  390. search() {
  391. this.loadData();
  392. },
  393. reset() {
  394. this.loadData();
  395. },
  396. render() {
  397. const rowSelection = {
  398. selectedRowKeys: this.state.selectedRowKeys,
  399. onChange: (selectedRowKeys, selectedRows) => {
  400. this.setState({
  401. selectedRows: selectedRows,
  402. selectedRowKeys: selectedRowKeys
  403. });
  404. }
  405. };
  406. const hasSelected = this.state.selectedRowKeys.length > 0;
  407. return (
  408. <div className="user-content" >
  409. <div className="content-title">
  410. <span>科技成果转化</span>
  411. </div>
  412. <div className="user-search">
  413. <p>
  414. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  415. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  416. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  417. disabled={!hasSelected}
  418. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  419. </p>
  420. </div>
  421. <div className="patent-table">
  422. <Spin spinning={this.state.loading}>
  423. <Table columns={this.state.columns}
  424. dataSource={this.state.dataSource}
  425. pagination={this.state.pagination}
  426. rowSelection={rowSelection}
  427. onRowClick={this.tableRowClick} />
  428. </Spin>
  429. </div>
  430. <AchievementDesc
  431. data={this.state.RowData}
  432. activityNumberList={this.state.activityNumberList}
  433. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  434. </div >
  435. );
  436. }
  437. });
  438. export default Achievement;