techAchievement.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import moment from 'moment';
  6. import '@/account/demand/techDemand.less';
  7. import TechDemandDesc from '@/account/achievement/achievementDesc';
  8. import { demandTypeList,achievementCategoryList,achievementType } from '@/dataDic.js';
  9. import { getDemandType,getReleaseStateList,getAchievementType } from '@/tools.js';
  10. const DemandList = React.createClass({
  11. loadData(pageNo) {
  12. this.state.data = [];
  13. this.setState({
  14. page:pageNo,
  15. loading: true
  16. });
  17. $.ajax({
  18. method: "get",
  19. dataType: "json",
  20. crossDomain: false,
  21. url: globalConfig.context + "/api/user/achievement/list",
  22. data: {
  23. pageNo: pageNo || 1,
  24. pageSize: this.state.pagination.pageSize,
  25. name: this.state.nameSearch, //需求名称
  26. startDate: this.state.releaseDate[0],
  27. endDate: this.state.releaseDate[1],
  28. dataCategory:this.state.dataCategorySearch,
  29. auditStatus:this.state.auditStatusSearch,
  30. },
  31. success: function (data) {
  32. let theArr = [];
  33. if (!data.data || !data.data.list) {
  34. if (data.error && data.error.length) {
  35. message.warning(data.error[0].message);
  36. };
  37. } else {
  38. for (let i = 0; i < data.data.list.length; i++) {
  39. let thisdata = data.data.list[i];
  40. theArr.push({
  41. key: i,
  42. id: thisdata.id,
  43. serialNumber: thisdata.serialNumber, //编号
  44. name: thisdata.name,
  45. dataCategory: thisdata.dataCategory,
  46. auditStatus: thisdata.auditStatus, //审核状态
  47. releaseDate:thisdata.releaseDate?(new Date(thisdata.releaseDate)).toLocaleString():''
  48. });
  49. };
  50. };
  51. this.state.pagination.current = data.data.pageNo;
  52. this.state.pagination.total = data.data.totalCount;
  53. if(data.data&&data.data.list&&!data.data.list.length){
  54. this.state.pagination.current=0
  55. this.state.pagination.total=0
  56. };
  57. this.setState({
  58. total:data.data.totalCount,
  59. dataSource: theArr,
  60. pagination: this.state.pagination
  61. });
  62. }.bind(this),
  63. }).always(function () {
  64. this.setState({
  65. loading: false
  66. });
  67. }.bind(this));
  68. },
  69. getInitialState() {
  70. return {
  71. searchMore: true,
  72. validityPeriodDate: [],
  73. releaseDate: [],
  74. selectedRowKeys: [],
  75. selectedRows: [],
  76. loading: false,
  77. pagination: {
  78. defaultCurrent: 1,
  79. defaultPageSize: 10,
  80. showQuickJumper: true,
  81. pageSize: 10,
  82. onChange: function (page) {
  83. this.loadData(page);
  84. }.bind(this),
  85. showTotal: function (total) {
  86. return '共' + total + '条数据';
  87. }
  88. },
  89. columns: [
  90. {
  91. title: '编号',
  92. dataIndex: 'serialNumber',
  93. key: 'serialNumber',
  94. }, {
  95. title: '成果名称',
  96. dataIndex: 'name',
  97. key: 'name',
  98. }, {
  99. title: '成果类型',
  100. dataIndex: 'dataCategory',
  101. key: 'dataCategory',
  102. render: text => { return getAchievementType(text); }
  103. },
  104. {
  105. title: '发布状态',
  106. dataIndex: 'auditStatus',
  107. key: 'auditStatus',
  108. render: text => { return getReleaseStateList(text) }
  109. },
  110. {
  111. title: '发布时间',
  112. dataIndex: 'releaseDate',
  113. key: 'releaseDate'
  114. },
  115. {
  116. title: '操作',
  117. dataIndex: 'caozuo',
  118. key: 'caozuo',
  119. render:(text,recard) => {
  120. return <div className="btnRight">
  121. {recard.auditStatus!='1'&&recard.auditStatus!='2'&&<Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation(),this.submission(recard)}}>提交审核</Button>}
  122. {recard.auditStatus!='1'&&recard.auditStatus=='2'&&<Button type="success" onClick={(e)=>{ e.stopPropagation(),this.updateFun(recard)}}>刷新发布</Button>}
  123. {recard.auditStatus!='1'&&recard.auditStatus=='2'&&<Button type="danger" onClick={(e)=>{e.stopPropagation(),this.revokeFun(recard)}}>撤销发布</Button>}
  124. </div>
  125. }
  126. }
  127. ],
  128. dataSource: [],
  129. searchTime: [,]
  130. };
  131. },
  132. //提交审核
  133. submission(record){
  134. this.setState({
  135. showDesc:false,
  136. loading:true
  137. });
  138. $.ajax({
  139. method: "POST",
  140. dataType: "json",
  141. crossDomain: false,
  142. url: globalConfig.context + "/api/user/achievement/commit",
  143. data: {
  144. id:record.id
  145. }
  146. }).done(function (data) {
  147. if (!data.error.length) {
  148. message.success('提交成功.');
  149. this.setState({
  150. loading: false,
  151. });
  152. this.loadData(this.state.page)
  153. } else {
  154. message.warning(data.error[0].message);
  155. };
  156. }.bind(this));
  157. },
  158. //刷新发布
  159. updateFun(recard){
  160. this.setState({
  161. loading:true
  162. })
  163. $.ajax({
  164. method: "POST",
  165. dataType: "json",
  166. crossDomain: false,
  167. url: globalConfig.context +'/api/user/achievement/refreshPublish',
  168. data: {
  169. id: recard.id,
  170. auditStatus:recard.auditStatus
  171. }
  172. }).done(function (data) {
  173. if (!data.error.length) {
  174. message.success('刷新成功!');
  175. this.setState({
  176. loading: false,
  177. });
  178. } else {
  179. message.warning(data.error[0].message);
  180. };
  181. this.loadData(this.state.page);
  182. }.bind(this));
  183. },
  184. //撤销发布
  185. revokeFun(recard){
  186. this.setState({
  187. loading:true
  188. })
  189. $.ajax({
  190. method: "POST",
  191. dataType: "json",
  192. crossDomain: false,
  193. url: globalConfig.context + '/api/user/achievement/offShelf',
  194. data: {
  195. id: recard.id,
  196. }
  197. }).done(function (data) {
  198. if (!data.error.length) {
  199. message.success('撤销成功!');
  200. this.setState({
  201. loading: false,
  202. });
  203. this.loadData(this.state.page);
  204. } else {
  205. message.warning(data.error[0].message);
  206. };
  207. }.bind(this));
  208. },
  209. componentWillMount() {
  210. let theArr = [];
  211. demandTypeList.map(function (item) {
  212. theArr.push(
  213. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  214. )
  215. });
  216. this.state.demandTypeOption = theArr;
  217. this.loadData();
  218. },
  219. tableRowClick(record, index) {
  220. this.state.RowData = record;
  221. this.setState({
  222. showDesc: true
  223. });
  224. },
  225. delectRow(recard) {
  226. let deletedIds =[];
  227. let rowItem = this.state.selectedRowKeys[0];
  228. let data = this.state.dataSource ||[];
  229. if (data.length) {
  230. deletedIds.push(data[rowItem].id);
  231. }
  232. this.setState({
  233. selectedRowKeys: [],
  234. loading: deletedIds.length > 0
  235. });
  236. $.ajax({
  237. method: "POST",
  238. dataType: "json",
  239. crossDomain: false,
  240. url: globalConfig.context + "/api/user/achievement/delete",
  241. data: {
  242. ids: deletedIds
  243. }
  244. }).done(function (data) {
  245. if (!data.error.length) {
  246. message.success('删除成功!');
  247. this.setState({
  248. loading: false
  249. });
  250. if((this.state.total)%10==1){
  251. this.loadData((this.state.page)-1);
  252. }else{
  253. this.loadData(this.state.page);
  254. }
  255. } else {
  256. message.warning(data.error[0].message);
  257. };
  258. }.bind(this));
  259. },
  260. addClick() {
  261. this.state.RowData = {};
  262. this.setState({
  263. showDesc: true
  264. });
  265. },
  266. closeDesc(e, s) {
  267. this.state.showDesc = e;
  268. if (s) {
  269. this.loadData(this.state.page);
  270. };
  271. },
  272. search() {
  273. this.loadData();
  274. },
  275. reset() {
  276. this.state.nameSearch = '';
  277. this.state.releaseDate = [];
  278. this.state.dataCategorySearch = undefined;
  279. this.state.auditStatusSearch = undefined;
  280. this.loadData();
  281. },
  282. searchSwitch() {
  283. this.setState({
  284. searchMore: !this.state.searchMore
  285. });
  286. },
  287. render() {
  288. const rowSelection = {
  289. selectedRowKeys: this.state.selectedRowKeys,
  290. onChange: (selectedRowKeys, selectedRows) => {
  291. this.setState({
  292. selectedRows: selectedRows.slice(-1),
  293. selectedRowKeys: selectedRowKeys.slice(-1)
  294. });
  295. }
  296. };
  297. const hasSelected = this.state.selectedRowKeys.length > 0;
  298. const { RangePicker } = DatePicker;
  299. return (
  300. <div className="user-content" >
  301. <div className="content-title">
  302. <span>科技成果列表</span>
  303. <div className="patent-addNew">
  304. <Button type="primary" onClick={this.addClick}>发布成果<Icon type="plus" /></Button>
  305. </div>
  306. </div>
  307. <div className="user-search">
  308. <Input placeholder="成果名称"
  309. value={this.state.nameSearch}
  310. onChange={(e) => { this.setState({ nameSearch: e.target.value }); }} />
  311. <Select placeholder="发布状态" style={{ width: 120 }}
  312. value={this.state.auditStatusSearch}
  313. onChange={(e) => { this.setState({ auditStatusSearch: e }) }}>
  314. <Select.Option value="0" >草稿</Select.Option>
  315. <Select.Option value="1" >发布审核</Select.Option>
  316. <Select.Option value="2" >已发布</Select.Option>
  317. <Select.Option value="3" >发布失败</Select.Option>
  318. <Select.Option value="4" >已撤销</Select.Option>
  319. </Select>
  320. <Select placeholder="成果类型" style={{ width: 120 }}
  321. value={this.state.dataCategorySearch}
  322. onChange={(e) => { this.setState({ dataCategorySearch: e }) }}>
  323. {
  324. achievementType.map(function (item) {
  325. return <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  326. })
  327. }
  328. </Select>
  329. <Button type="primary" onClick={this.search}>搜索</Button>
  330. <Button onClick={this.reset}>重置</Button>
  331. <Button
  332. type="danger"
  333. disabled={!hasSelected}
  334. onClick={this.delectRow}
  335. >
  336. 删除<Icon type="minus" />
  337. </Button>
  338. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  339. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  340. <span>发布时间 :</span>
  341. <RangePicker
  342. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  343. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  344. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  345. </div>
  346. </div>
  347. <div className="patent-table">
  348. <Spin spinning={this.state.loading}>
  349. <Table columns={this.state.columns}
  350. dataSource={this.state.dataSource}
  351. rowSelection={rowSelection}
  352. pagination={this.state.pagination}
  353. onRowClick={this.tableRowClick} />
  354. </Spin>
  355. </div>
  356. <TechDemandDesc
  357. data={this.state.RowData}
  358. demandTypeOption={this.state.demandTypeOption}
  359. showDesc={this.state.showDesc}
  360. closeDesc={this.closeDesc} />
  361. </div >
  362. );
  363. }
  364. });
  365. export default DemandList;