achievement.jsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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. getPreview(theData.id, 'achievement', 'achievement', function (data) { window.open('https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(location.origin + globalConfig.context + "/open/preview?" + data)) });
  193. }}><Icon style={{ fontSize: '16px' }} type="eye-o" /></a>
  194. </span>
  195. : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  196. </div>
  197. <FormItem style={{ marginTop: '20px' }}>
  198. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  199. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  200. </FormItem>
  201. </Form >
  202. );
  203. },
  204. }));
  205. const AchievementDesc = React.createClass({
  206. getInitialState() {
  207. return {
  208. visible: false,
  209. loading: false
  210. };
  211. },
  212. componentWillReceiveProps(nextProps) {
  213. this.state.visible = nextProps.showDesc
  214. },
  215. showModal() {
  216. this.setState({
  217. visible: true,
  218. });
  219. },
  220. handleOk() {
  221. this.setState({
  222. visible: false,
  223. });
  224. this.props.closeDesc(false, true);
  225. },
  226. handleCancel(e) {
  227. this.setState({
  228. visible: false,
  229. });
  230. this.props.closeDesc(false);
  231. },
  232. spinChange(e) {
  233. this.setState({
  234. loading: e
  235. });
  236. },
  237. render() {
  238. return (
  239. <div className="patent-addNew">
  240. <Spin spinning={this.state.loading} className='spin-box'>
  241. <Modal title="科技成果转化" visible={this.state.visible}
  242. onOk={this.handleOk} onCancel={this.handleCancel}
  243. width='800px'
  244. footer=''
  245. >
  246. <AchievementDescFrom
  247. uid={this.props.uid}
  248. data={this.props.data}
  249. visible={this.state.visible}
  250. activityNumberList={this.props.activityNumberList}
  251. spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  252. </Modal>
  253. </Spin>
  254. </div>
  255. );
  256. },
  257. });
  258. const Achievement = React.createClass({
  259. loadData(pageNo) {
  260. this.state.data = [];
  261. this.setState({
  262. loading: true
  263. });
  264. $.when($.ajax({
  265. method: "post",
  266. dataType: "json",
  267. crossDomain: false,
  268. url: globalConfig.context + "/api/admin/achievementList",
  269. data: {
  270. pageNo: pageNo || 1,
  271. pageSize: this.state.pagination.pageSize,
  272. uid: this.props.data.uid
  273. }
  274. }), $.ajax({
  275. method: "post",
  276. dataType: "json",
  277. crossDomain: false,
  278. url: globalConfig.context + "/api/admin/activityNumber",
  279. data: {
  280. uid: this.props.data.uid
  281. }
  282. })).done((data1, data2) => {
  283. let data = data1[0];
  284. let activityNumber = data2[0];
  285. if (data.error.length || !data.data || !data.data.list) {
  286. message.warning(data.error[0].message);
  287. return;
  288. };
  289. if (activityNumber.error.length || !activityNumber.data) {
  290. message.warning(activityNumber.error[0].message);
  291. return;
  292. };
  293. for (let i = 0; i < data.data.list.length; i++) {
  294. let thisdata = data.data.list[i];
  295. this.state.data.push({
  296. key: i,
  297. id: thisdata.id,
  298. uid: thisdata.uid,
  299. achievementName: thisdata.achievementName,
  300. source: thisdata.source,
  301. conversionForm: thisdata.conversionForm,
  302. conversionResult: thisdata.conversionResult,
  303. year: thisdata.year,
  304. enclosureUrl: thisdata.enclosureUrl,
  305. enclosureDownloadFileName: thisdata.enclosureDownloadFileName,
  306. enclosure: [thisdata.id, thisdata.enclosureDownloadFileName]
  307. });
  308. };
  309. this.state.activityNumberList = activityNumber.data;
  310. this.state.pagination.current = data.data.pageNo;
  311. this.state.pagination.total = data.data.totalCount;
  312. this.setState({
  313. dataSource: this.state.data,
  314. pagination: this.state.pagination
  315. });
  316. }).always(function () {
  317. this.setState({
  318. loading: false
  319. });
  320. }.bind(this));
  321. let _me = this;
  322. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  323. },
  324. getInitialState() {
  325. return {
  326. selectedRowKeys: [],
  327. selectedRows: [],
  328. loading: false,
  329. pagination: {
  330. defaultCurrent: 1,
  331. defaultPageSize: 10,
  332. showQuickJumper: true,
  333. pageSize: 10,
  334. onChange: function (page) {
  335. this.loadData(page);
  336. }.bind(this),
  337. showTotal: function (total) {
  338. return '共' + total + '条数据';
  339. }
  340. },
  341. columns: [
  342. {
  343. title: '年份',
  344. dataIndex: 'year',
  345. key: 'year'
  346. }, {
  347. title: '成果名称',
  348. dataIndex: 'achievementName',
  349. key: 'achievementName'
  350. }, {
  351. title: '成果来源',
  352. dataIndex: 'source',
  353. key: 'source',
  354. }, {
  355. title: '转化形式',
  356. dataIndex: 'conversionForm',
  357. key: 'conversionForm',
  358. render: (text) => { return getConversionForm(text) }
  359. }, {
  360. title: '转化结果',
  361. dataIndex: 'conversionResult',
  362. key: 'conversionResult',
  363. }, {
  364. title: '相关附件',
  365. dataIndex: 'enclosure',
  366. key: 'enclosure',
  367. render: (text) => {
  368. return <a onClick={newDownloadFile.bind(null, text[0], 'achievement', '/api/admin/downloadAchievement')}>{text[1]}</a>
  369. }
  370. }
  371. ],
  372. dataSource: []
  373. };
  374. },
  375. componentWillMount() {
  376. this.loadData();
  377. },
  378. tableRowClick(record, index) {
  379. this.state.RowData = record;
  380. this.setState({
  381. showDesc: true
  382. });
  383. },
  384. delectRow() {
  385. let deletedIds = [];
  386. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  387. let rowItem = this.state.selectedRows[idx];
  388. if (rowItem.id) {
  389. deletedIds.push(rowItem.id)
  390. }
  391. }
  392. this.setState({
  393. selectedRowKeys: [],
  394. loading: deletedIds.length > 0
  395. });
  396. $.ajax({
  397. method: "POST",
  398. dataType: "json",
  399. crossDomain: false,
  400. url: globalConfig.context + "/api/admin/deleteAchievement",
  401. data: {
  402. ids: deletedIds
  403. }
  404. }).done(function (data) {
  405. if (!data.error.length) {
  406. message.success('保存成功!');
  407. this.setState({
  408. loading: false,
  409. });
  410. } else {
  411. message.warning(data.error[0].message);
  412. };
  413. this.loadData();
  414. }.bind(this));
  415. },
  416. closeDesc(e, s) {
  417. this.state.showDesc = e;
  418. if (s) {
  419. this.loadData();
  420. };
  421. },
  422. search() {
  423. this.loadData();
  424. },
  425. reset() {
  426. this.loadData();
  427. },
  428. render() {
  429. const rowSelection = {
  430. selectedRowKeys: this.state.selectedRowKeys,
  431. onChange: (selectedRowKeys, selectedRows) => {
  432. this.setState({
  433. selectedRows: selectedRows,
  434. selectedRowKeys: selectedRowKeys
  435. });
  436. }
  437. };
  438. const hasSelected = this.state.selectedRowKeys.length > 0;
  439. return (
  440. <div className="user-content" >
  441. <div className="content-title">
  442. <span>科技成果转化</span>
  443. <span className="proportion"> 是否已完成:</span>
  444. <Switch
  445. checked={this.state.proportion && this.state.proportion.achievement == 1 ? true : false}
  446. checkedChildren={'已完成'}
  447. unCheckedChildren={'未完成'}
  448. onChange={(e) => {
  449. e ? this.state.proportion.achievement = 1 : this.state.proportion.achievement = 0;
  450. saveProportion(this.state.proportion.id, this.props.data.uid, 'achievement', this.state.proportion.achievement);
  451. this.setState({ proportion: this.state.proportion });
  452. }} />
  453. </div>
  454. <div className="user-search">
  455. <p>
  456. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  457. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  458. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  459. disabled={!hasSelected}
  460. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  461. </p>
  462. </div>
  463. <div className="patent-table">
  464. <Spin spinning={this.state.loading}>
  465. <Table columns={this.state.columns}
  466. dataSource={this.state.dataSource}
  467. pagination={this.state.pagination}
  468. rowSelection={rowSelection}
  469. onRowClick={this.tableRowClick} />
  470. </Spin>
  471. </div>
  472. <AchievementDesc
  473. data={this.state.RowData}
  474. uid={this.props.data.uid}
  475. activityNumberList={this.state.activityNumberList}
  476. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  477. </div >
  478. );
  479. }
  480. });
  481. export default Achievement;