techAchievement.jsx 14 KB

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