achievement.jsx 17 KB

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