techAchievement.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. import React from 'react';
  2. import { Radio, Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal, Upload } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import moment from 'moment';
  6. import './techAchievement.less';
  7. import TechAchievementDesc from './techAchievementDesc.jsx';
  8. import { achievementCategoryList, techAuditStatusList } from '../../dataDic.js';
  9. import { beforeUploadFile, companySearch, getAchievementCategory, getSearchUrl, getTechAuditStatus } from '../../tools.js';
  10. import BatchImport from './batchImport';
  11. const AchievementList = React.createClass({
  12. loadData(pageNo, apiUrl) {
  13. this.state.data = [];
  14. this.setState({
  15. loading: true
  16. });
  17. $.ajax({
  18. method: "get",
  19. dataType: "json",
  20. crossDomain: false,
  21. url: globalConfig.context + (apiUrl || this.props['data-listApiUrl']),
  22. data: {
  23. pageNo: pageNo || 1,
  24. pageSize: this.state.pagination.pageSize,
  25. serialNumber: this.state.serialNumber, //编号
  26. name: this.state.name, //名称
  27. ownerName: this.state.searchType == 1 ? this.state.searchName : undefined,
  28. username: this.state.searchType == 0 && this.props['data-listApiUrl'].indexOf('org') == -1 ? this.state.searchName : undefined,
  29. unitName: this.state.searchType == 0 && this.props['data-listApiUrl'].indexOf('user') == -1 ? this.state.searchName : undefined,
  30. keyword: this.state.keyword, // 关键词
  31. category: this.state.category, //类型(0--专利, 2--软著, 3--项目, 4--版权, 5--工业设计, 6--配方, 7--非标)
  32. releaseDateStartDate: this.state.releaseDate[0],
  33. releaseDateEndDate: this.state.releaseDate[1],
  34. releaseStatus: this.state.releaseStatus ? Number(this.state.releaseStatus) : undefined, //是否发布(0--未发布,1--已发布)
  35. auditStatus: this.state.auditStatus
  36. },
  37. success: function (data) {
  38. let theArr = [];
  39. if (!data.data || !data.data.list) {
  40. if (data.error && data.error.length) {
  41. message.warning(data.error[0].message);
  42. };
  43. } else {
  44. for (let i = 0; i < data.data.list.length; i++) {
  45. let thisdata = data.data.list[i];
  46. theArr.push({
  47. key: i,
  48. id: thisdata.id,
  49. serialNumber: thisdata.serialNumber,
  50. dataCategory: thisdata.dataCategory,
  51. name: thisdata.name,
  52. keyword: thisdata.keyword,
  53. theName: thisdata.username || thisdata.ownerName,
  54. category: thisdata.category,
  55. ownerName: thisdata.username ? thisdata.username : thisdata.ownerName,
  56. ownerType: thisdata.ownerType,
  57. ownerMobile: thisdata.ownerMobile,
  58. status: thisdata.status,
  59. releaseDate: thisdata.releaseDate,
  60. releaseDateFormattedDate: thisdata.releaseDateFormattedDate,
  61. auditStatus: thisdata.auditStatus
  62. });
  63. };
  64. this.state.pagination.current = data.data.pageNo;
  65. this.state.pagination.total = data.data.totalCount;
  66. };
  67. this.setState({
  68. dataSource: theArr,
  69. pagination: this.state.pagination
  70. });
  71. }.bind(this),
  72. }).always(function () {
  73. this.setState({
  74. loading: false
  75. });
  76. }.bind(this));
  77. },
  78. getInitialState() {
  79. return {
  80. searchMore: true,
  81. searchType: 0,
  82. validityPeriodDate: [],
  83. releaseDate: [],
  84. selectedRowKeys: [],
  85. selectedRows: [],
  86. loading: false,
  87. pagination: {
  88. defaultCurrent: 1,
  89. defaultPageSize: 10,
  90. showQuickJumper: true,
  91. pageSize: 10,
  92. onChange: function (page) {
  93. this.loadData(page);
  94. }.bind(this),
  95. showTotal: function (total) {
  96. return '共' + total + '条数据';
  97. }
  98. },
  99. columns: [
  100. {
  101. title: '编号',
  102. dataIndex: 'serialNumber',
  103. key: 'serialNumber',
  104. }, {
  105. title: '名称',
  106. dataIndex: 'name',
  107. key: 'name',
  108. }, {
  109. title: '关键字',
  110. dataIndex: 'keyword',
  111. key: 'keyword',
  112. }, {
  113. title: '类型',
  114. dataIndex: 'category',
  115. key: 'category',
  116. render: text => { return getAchievementCategory(text); }
  117. }, {
  118. title: '所有人名称',
  119. dataIndex: 'theName',
  120. key: 'theName',
  121. }, {
  122. title: '审核状态',
  123. dataIndex: 'auditStatus',
  124. key: 'auditStatus',
  125. render: text => { return getTechAuditStatus(text) }
  126. }, {
  127. title: '发布时间',
  128. dataIndex: 'releaseDateFormattedDate',
  129. key: 'releaseDateFormattedDate',
  130. }
  131. ],
  132. dataSource: [],
  133. searchTime: [,]
  134. };
  135. },
  136. componentWillMount() {
  137. let theArr = [];
  138. achievementCategoryList.map(function (item) {
  139. theArr.push(
  140. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  141. )
  142. });
  143. let auditArr = [];
  144. techAuditStatusList.map(function (item) {
  145. auditArr.push(
  146. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  147. )
  148. });
  149. this.state.achievementCategoryOption = theArr;
  150. this.state.auditStatusOption = auditArr;
  151. if (window.location.search) {
  152. let theObj = getSearchUrl(window.location.search);
  153. if (theObj.rid) {
  154. theObj.id = theObj.rid;
  155. if (theObj.rid != 'null') {
  156. this.tableRowClick(theObj);
  157. };
  158. };
  159. };
  160. this.loadData();
  161. },
  162. componentWillReceiveProps(nextProps) {
  163. if (this.props['data-listApiUrl'] != nextProps['data-listApiUrl']) {
  164. this.state.selectedRowKeys = [];
  165. this.state.selectedRows = [];
  166. this.state.serialNumber = undefined;
  167. this.state.name = undefined;
  168. this.state.keyword = undefined;
  169. this.state.category = undefined;
  170. this.state.ownerType = undefined;
  171. this.state.releaseStatus = undefined;
  172. this.state.auditStatus = undefined;
  173. this.state.searchName = undefined;
  174. this.state.searchType = 0;
  175. this.state.releaseDate = [];
  176. this.loadData(null, nextProps['data-listApiUrl']);
  177. };
  178. },
  179. tableRowClick(record, index) {
  180. this.state.RowData = record;
  181. this.setState({
  182. showDesc: true
  183. });
  184. },
  185. delectRow() {
  186. let deletedIds = [];
  187. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  188. let rowItem = this.state.selectedRows[idx];
  189. if (rowItem.id) {
  190. deletedIds.push(rowItem.id)
  191. };
  192. };
  193. this.setState({
  194. selectedRowKeys: [],
  195. loading: deletedIds.length > 0
  196. });
  197. $.ajax({
  198. method: "POST",
  199. dataType: "json",
  200. crossDomain: false,
  201. url: globalConfig.context + "/api/admin/achievement/delete",
  202. data: {
  203. ids: deletedIds
  204. }
  205. }).done(function (data) {
  206. if (!data.error.length) {
  207. message.success('删除成功!');
  208. this.setState({
  209. loading: false,
  210. });
  211. } else {
  212. message.warning(data.error[0].message);
  213. };
  214. this.loadData();
  215. }.bind(this));
  216. },
  217. addClick() {
  218. this.state.RowData = {};
  219. this.setState({
  220. showDesc: true
  221. });
  222. },
  223. closeDesc(e, s) {
  224. this.state.showDesc = e;
  225. if (s) {
  226. this.loadData();
  227. };
  228. },
  229. search() {
  230. this.loadData();
  231. },
  232. reset() {
  233. this.state.serialNumber = undefined;
  234. this.state.name = undefined;
  235. this.state.keyword = undefined;
  236. this.state.category = undefined;
  237. this.state.ownerType = undefined;
  238. this.state.releaseStatus = undefined;
  239. this.state.auditStatus = undefined;
  240. this.state.searchName = undefined;
  241. this.state.releaseDate = [];
  242. this.loadData();
  243. },
  244. searchSwitch() {
  245. this.setState({
  246. searchMore: !this.state.searchMore
  247. });
  248. },
  249. render() {
  250. const rowSelection = {
  251. selectedRowKeys: this.state.selectedRowKeys,
  252. onChange: (selectedRowKeys, selectedRows) => {
  253. this.setState({
  254. selectedRows: selectedRows.slice(-1),
  255. selectedRowKeys: selectedRowKeys.slice(-1)
  256. });
  257. }
  258. };
  259. const hasSelected = this.state.selectedRowKeys.length > 0;
  260. const { RangePicker } = DatePicker;
  261. return (
  262. <div className="user-content" >
  263. <div className="content-title">
  264. {this.props['data-listApiUrl'].indexOf('org') == -1 ? <span>个人科技成果管理</span> : <span>组织科技成果管理</span>}
  265. <div className="patent-addNew clearfix">
  266. <Upload
  267. action={globalConfig.context + "/api/admin/achievement/uploadTemplate"}
  268. data={{ 'sign': 'achievement_template' }}
  269. beforeUpload={beforeUploadFile}
  270. showUploadList={false}
  271. onChange={(info) => {
  272. if (info.file.status !== 'uploading') {
  273. console.log(info.file, info.fileList);
  274. }
  275. if (info.file.status === 'done') {
  276. if (!info.file.response.error.length) {
  277. message.success(`${info.file.name} 文件上传成功!`);
  278. } else {
  279. message.warning(info.file.response.error[0].message);
  280. return;
  281. };
  282. } else if (info.file.status === 'error') {
  283. message.error(`${info.file.name} 文件上传失败。`);
  284. };
  285. }} >
  286. <Button>上传批量导入模板</Button>
  287. </Upload>
  288. <Button onClick={() => { window.open(globalConfig.context + '/api/admin/achievement/downloadTemplate?sign=achievement_template') }}>下载批量导入模板</Button>
  289. <Button type="primary" className="addButton" onClick={this.addClick}>发布成果<Icon type="plus" /></Button>
  290. <BatchImport closeDesc={this.closeDesc} />
  291. </div>
  292. </div>
  293. <div className="user-search">
  294. <Input placeholder="编号"
  295. value={this.state.serialNumber}
  296. onChange={(e) => { this.setState({ serialNumber: e.target.value }); }} />
  297. <Input placeholder="名称"
  298. value={this.state.name}
  299. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  300. <Input placeholder="关键字"
  301. value={this.state.keyword}
  302. onChange={(e) => { this.setState({ keyword: e.target.value }); }} />
  303. <Input placeholder="所有人名称"
  304. value={this.state.searchName}
  305. onChange={(e) => { this.setState({ searchName: e.target.value }); }} />
  306. <Radio.Group value={this.state.searchType} onChange={(e) => {
  307. this.setState({ searchType: e.target.value })
  308. }}>
  309. <Radio value={0}>认证用户</Radio>
  310. <Radio value={1}>非认证用户</Radio>
  311. </Radio.Group>
  312. <Button type="primary" onClick={this.search}>搜索</Button>
  313. <Button onClick={this.reset}>重置</Button>
  314. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  315. disabled={!hasSelected}
  316. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  317. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  318. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  319. <Select placeholder="选择类型" style={{ width: 160 }}
  320. value={this.state.category}
  321. onChange={(e) => { this.setState({ category: e }) }}>
  322. {this.state.achievementCategoryOption}
  323. </Select>
  324. <Select placeholder="选择审核状态"
  325. style={{ width: 160 }}
  326. value={this.state.auditStatus}
  327. onChange={(e) => { this.setState({ auditStatus: e }) }}>
  328. {this.state.auditStatusOption}
  329. </Select>
  330. <Select placeholder="选择是否发布" style={{ width: 120 }}
  331. value={this.state.releaseStatus}
  332. onChange={(e) => { this.setState({ releaseStatus: e }) }}>
  333. <Select.Option value="0" >未发布</Select.Option>
  334. <Select.Option value="1" >已发布</Select.Option>
  335. </Select>
  336. <span>发布时间 :</span>
  337. <RangePicker
  338. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  339. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  340. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  341. </div>
  342. </div>
  343. <div className="patent-table">
  344. <Spin spinning={this.state.loading}>
  345. <Table columns={this.state.columns}
  346. dataSource={this.state.dataSource}
  347. rowSelection={rowSelection}
  348. pagination={this.state.pagination}
  349. onRowClick={this.tableRowClick} />
  350. </Spin>
  351. </div>
  352. <TechAchievementDesc
  353. data={this.state.RowData}
  354. detailApiUrl={this.props['data-detailApiUrl']}
  355. achievementCategoryOption={this.state.achievementCategoryOption}
  356. showDesc={this.state.showDesc}
  357. closeDesc={this.closeDesc} />
  358. </div >
  359. );
  360. }
  361. });
  362. export default AchievementList;