achievement.jsx 19 KB

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