achievement.jsx 20 KB

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