techAchievement.jsx 16 KB

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