achievement.jsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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 = undefined;
  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. <Modal maskClosable={false} title="科技成果转化" visible={this.state.visible}
  249. onOk={this.handleOk} onCancel={this.handleCancel}
  250. width='800px'
  251. footer='' >
  252. <Spin spinning={this.state.loading} className='spin-box'>
  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. </Spin>
  260. </Modal>
  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 size="middle" columns={this.state.columns}
  473. dataSource={this.state.dataSource}
  474. pagination={this.state.pagination}
  475. rowSelection={rowSelection}
  476. style={{
  477. cursor: 'pointer',
  478. }}
  479. onRowClick={this.tableRowClick} />
  480. </Spin>
  481. </div>
  482. <AchievementDesc
  483. data={this.state.RowData}
  484. uid={this.props.data.uid}
  485. activityNumberList={this.state.activityNumberList}
  486. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  487. </div >
  488. );
  489. }
  490. });
  491. export default Achievement;