achievement.jsx 17 KB

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