achievement.jsx 20 KB

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