star.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. import React from 'react';
  2. import { Icon, Button, Spin, message, Table, Cascader, Input } from 'antd';
  3. import { techFieldList, getTechField } from '../../../DicTechFieldList';
  4. import ajax from 'jquery/src/ajax/xhr.js';
  5. import $ from 'jquery/src/ajax';
  6. const Star = React.createClass({
  7. loadData(pageNo) {
  8. this.setState({
  9. loading: true
  10. });
  11. $.ajax({
  12. method: "get",
  13. dataType: "json",
  14. crossDomain: false,
  15. url: globalConfig.context + '/api/admin/star/list',
  16. data: {
  17. pageNo: pageNo || 1,
  18. pageSize: this.state.pagination.pageSize,
  19. number: this.state.searchNumber, //编号
  20. username: this.state.searchName, //名称
  21. engagedField: this.state.searchField ? this.state.searchField.join(',') : undefined,
  22. professionalTitle: this.state.searchPfs,
  23. workUnit: this.state.searchUnit
  24. },
  25. success: function (data) {
  26. let theArr = [];
  27. if (!data.data || !data.data.list) {
  28. if (data.error && data.error.length) {
  29. message.warning(data.error[0].message);
  30. };
  31. } else {
  32. for (let i = 0; i < data.data.list.length; i++) {
  33. let thisdata = data.data.list[i];
  34. theArr.push({
  35. key: thisdata.uid,
  36. uid: thisdata.uid,
  37. engagedField: thisdata.engagedField ? thisdata.engagedField.split(',') : [],
  38. username: thisdata.username,
  39. professionalTitle: thisdata.professionalTitle,
  40. workUnit: thisdata.workUnit,
  41. number: thisdata.number,
  42. achievementNums: thisdata.achievementNums,
  43. });
  44. };
  45. this.state.pagination.current = data.data.pageNo;
  46. this.state.pagination.total = data.data.totalCount;
  47. };
  48. this.setState({
  49. dataSource: theArr,
  50. pagination: this.state.pagination
  51. });
  52. }.bind(this),
  53. }).always(function () {
  54. this.setState({
  55. loading: false
  56. });
  57. }.bind(this));
  58. },
  59. loadHotData() {
  60. this.setState({
  61. loading: true
  62. });
  63. $.ajax({
  64. method: "get",
  65. dataType: "json",
  66. crossDomain: false,
  67. url: globalConfig.context + '/api/admin/star/hotList',
  68. success: function (data) {
  69. let theArr = [];
  70. if (!data.data) {
  71. if (data.error && data.error.length) {
  72. message.warning(data.error[0].message);
  73. };
  74. } else {
  75. for (let i = 0; i < data.data.length; i++) {
  76. let thisdata = data.data[i];
  77. theArr.push({
  78. key: thisdata.uid,
  79. uid: thisdata.uid,
  80. engagedField: thisdata.engagedField ? thisdata.engagedField.split(',') : [],
  81. username: thisdata.username,
  82. professionalTitle: thisdata.professionalTitle,
  83. workUnit: thisdata.workUnit,
  84. number: thisdata.number,
  85. achievementNums: thisdata.achievementNums,
  86. });
  87. };
  88. };
  89. this.setState({
  90. hotTableData: theArr
  91. });
  92. }.bind(this),
  93. }).always(function () {
  94. this.setState({
  95. loading: false
  96. });
  97. }.bind(this));
  98. },
  99. loadStarData() {
  100. this.setState({
  101. loading: true
  102. });
  103. $.ajax({
  104. method: "get",
  105. dataType: "json",
  106. crossDomain: false,
  107. url: globalConfig.context + '/api/admin/star/starList',
  108. success: function (data) {
  109. let theArr = [];
  110. if (!data.data) {
  111. if (data.error && data.error.length) {
  112. message.warning(data.error[0].message);
  113. };
  114. } else {
  115. for (let i = 0; i < data.data.length; i++) {
  116. let thisdata = data.data[i];
  117. theArr.push({
  118. key: thisdata.uid,
  119. uid: thisdata.uid,
  120. engagedField: thisdata.engagedField ? thisdata.engagedField.split(',') : [],
  121. username: thisdata.username,
  122. professionalTitle: thisdata.professionalTitle,
  123. workUnit: thisdata.workUnit,
  124. number: thisdata.number,
  125. achievementNums: thisdata.achievementNums,
  126. });
  127. };
  128. };
  129. this.setState({
  130. starTableData: theArr
  131. });
  132. }.bind(this),
  133. }).always(function () {
  134. this.setState({
  135. loading: false
  136. });
  137. }.bind(this));
  138. },
  139. getInitialState() {
  140. return {
  141. loading: false,
  142. hotSelectedRowKeys: [],
  143. hotSelectedRows: [],
  144. starSelectedRowKeys: [],
  145. starSelectedRows: [],
  146. pagination: {
  147. defaultCurrent: 1,
  148. defaultPageSize: 10,
  149. showQuickJumper: true,
  150. pageSize: 10,
  151. onChange: function (page) {
  152. this.loadData(page);
  153. }.bind(this),
  154. showTotal: function (total) {
  155. return '共' + total + '条数据';
  156. }
  157. },
  158. columns: [
  159. {
  160. title: '编号',
  161. dataIndex: 'number',
  162. key: 'number',
  163. }, {
  164. title: '姓名',
  165. dataIndex: 'username',
  166. key: 'username',
  167. }, {
  168. title: '从事领域',
  169. dataIndex: 'engagedField',
  170. key: 'engagedField',
  171. render: text => { return getTechField(text[0], text[1], text[2]); }
  172. }, {
  173. title: '职称名字',
  174. dataIndex: 'professionalTitle',
  175. key: 'professionalTitle',
  176. }, {
  177. title: '工作单位',
  178. dataIndex: 'workUnit',
  179. key: 'workUnit',
  180. }, {
  181. title: '成果数量',
  182. dataIndex: 'achievementNums',
  183. key: 'achievementNums',
  184. }, {
  185. title: '操作',
  186. dataIndex: 'action',
  187. key: 'action',
  188. render: (text, record, index) => {
  189. return <div>
  190. <Button onClick={() => { this.addIndex(record) }} type="primary" style={{ marginRight: '10px' }}>添加到大咖说</Button>
  191. <Button onClick={() => { this.addStar(record) }} type="primary">添加到明星页</Button>
  192. </div>
  193. }
  194. }
  195. ],
  196. otherColumns: [
  197. {
  198. title: '编号',
  199. dataIndex: 'number',
  200. key: 'number',
  201. }, {
  202. title: '姓名',
  203. dataIndex: 'username',
  204. key: 'username',
  205. }, {
  206. title: '从事领域',
  207. dataIndex: 'engagedField',
  208. key: 'engagedField',
  209. render: text => { return getTechField(text[0], text[1], text[2]); }
  210. }, {
  211. title: '职称名字',
  212. dataIndex: 'professionalTitle',
  213. key: 'professionalTitle',
  214. }, {
  215. title: '工作单位',
  216. dataIndex: 'workUnit',
  217. key: 'workUnit',
  218. }, {
  219. title: '成果数量',
  220. dataIndex: 'achievementNums',
  221. key: 'achievementNums',
  222. }
  223. ],
  224. dataSource: [],
  225. hotTableData: [],
  226. starTableData: []
  227. };
  228. },
  229. addIndex(record) {
  230. let theBool = true;
  231. if (this.state.hotTableData.length == 4) {
  232. message.warning('大咖列表最多只能显示4条记录!');
  233. theBool = false;
  234. };
  235. this.state.hotTableData.map((item, i) => {
  236. if (item.uid == record.uid) {
  237. message.warning('该条记录已经存在于大咖列表中!');
  238. theBool = false;
  239. return;
  240. };
  241. });
  242. if (theBool) {
  243. this.state.hotTableData.push(record);
  244. this.setState({ hotTableData: this.state.hotTableData });
  245. };
  246. },
  247. addStar(record) {
  248. let theBool = true;
  249. if (this.state.starTableData.length == 6) {
  250. message.warning('明星列表最多只能显示6条记录!');
  251. theBool = false;
  252. };
  253. this.state.starTableData.map((item, i) => {
  254. if (item.uid == record.uid) {
  255. message.warning('该条记录已经存在于明星列表中!');
  256. theBool = false;
  257. return;
  258. };
  259. });
  260. if (theBool) {
  261. this.state.starTableData.push(record);
  262. this.setState({ starTableData: this.state.starTableData });
  263. };
  264. },
  265. hotDelectRow() {
  266. let deletedArr = this.state.hotTableData.concat();
  267. for (let idx = 0; idx < this.state.hotSelectedRows.length; idx++) {
  268. let deleteIndex = this.state.hotSelectedRows[idx];
  269. if (deleteIndex.uid) {
  270. for (let n = 0; n < deletedArr.length; n++) {
  271. if (deleteIndex.uid == deletedArr[n].uid) {
  272. deletedArr.splice(n, 1);
  273. };
  274. };
  275. };
  276. };
  277. this.setState({
  278. hotTableData: deletedArr,
  279. hotSelectedRowKeys: []
  280. });
  281. },
  282. starDelectRow() {
  283. let deletedArr = this.state.starTableData.concat();
  284. for (let idx = 0; idx < this.state.starSelectedRows.length; idx++) {
  285. let deleteIndex = this.state.starSelectedRows[idx];
  286. if (deleteIndex.uid) {
  287. for (let n = 0; n < deletedArr.length; n++) {
  288. if (deleteIndex.uid == deletedArr[n].uid) {
  289. deletedArr.splice(n, 1);
  290. };
  291. };
  292. };
  293. };
  294. this.setState({
  295. starTableData: deletedArr,
  296. starSelectedRowKeys: []
  297. });
  298. },
  299. componentWillMount() {
  300. this.loadData();
  301. this.loadHotData();
  302. this.loadStarData();
  303. },
  304. submit() {
  305. let hotArr = [], starArr = [];
  306. for (let i = 0; i < this.state.hotTableData.length; i++) {
  307. let hotUid = this.state.hotTableData[i].uid;
  308. if (hotUid) {
  309. hotArr.push(hotUid);
  310. };
  311. };
  312. for (let n = 0; n < this.state.starTableData.length; n++) {
  313. let starUid = this.state.starTableData[n].uid;
  314. if (starUid) {
  315. starArr.push({
  316. uid: starUid,
  317. star: 1
  318. });
  319. };
  320. };
  321. this.setState({
  322. loading: true
  323. });
  324. $.ajax({
  325. method: "post",
  326. dataType: "json",
  327. crossDomain: false,
  328. url: globalConfig.context + '/api/admin/star/save',
  329. data: {
  330. data: JSON.stringify(starArr),
  331. hot: hotArr
  332. },
  333. success: function (data) {
  334. if (data.error && data.error.length) {
  335. message.warning(data.error[0].message);
  336. } else {
  337. message.success('保存成功!')
  338. };
  339. }.bind(this),
  340. }).always(function () {
  341. this.setState({
  342. loading: false
  343. });
  344. }.bind(this));
  345. },
  346. cleanCache() {
  347. this.setState({
  348. loading: true
  349. });
  350. $.ajax({
  351. method: "post",
  352. dataType: "json",
  353. crossDomain: false,
  354. url: globalConfig.context + '/api/admin/star/cleanCache',
  355. data: {
  356. 'cacheKey': 'big_shot_star_cache_key'
  357. },
  358. success: function (data) {
  359. if (data.error && data.error.length) {
  360. message.warning(data.error[0].message);
  361. } else {
  362. message.success('清除缓存成功!');
  363. };
  364. }.bind(this),
  365. }).always(function () {
  366. this.setState({
  367. loading: false
  368. });
  369. }.bind(this));
  370. },
  371. search() {
  372. this.loadData();
  373. },
  374. reset() {
  375. this.state.searchPfs = undefined;
  376. this.state.searchUnit = undefined;
  377. this.state.searchNumber = undefined;
  378. this.state.searchName = undefined;
  379. this.state.searchField = [];
  380. this.loadData();
  381. },
  382. render() {
  383. const hotRowSelection = {
  384. selectedRowKeys: this.state.hotSelectedRowKeys,
  385. onChange: (selectedRowKeys, selectedRows) => {
  386. this.setState({
  387. hotSelectedRows: selectedRows,
  388. hotSelectedRowKeys: selectedRowKeys
  389. });
  390. }
  391. };
  392. const starRowSelection = {
  393. selectedRowKeys: this.state.starSelectedRowKeys,
  394. onChange: (selectedRowKeys, selectedRows) => {
  395. this.setState({
  396. starSelectedRows: selectedRows,
  397. starSelectedRowKeys: selectedRowKeys
  398. });
  399. }
  400. };
  401. const hotHasSelected = this.state.hotSelectedRowKeys.length > 0;
  402. const starHasSelected = this.state.starSelectedRowKeys.length > 0;
  403. return (
  404. <div className="admin-content" >
  405. <div className="admin-content-title">科技明星管理</div>
  406. <div className="admin-content-warp">
  407. <div className="admin-content-header">
  408. <span>明星列表</span>
  409. </div>
  410. <div className="admin-content-search">
  411. <Input placeholder="编号" style={{ width: 100 }}
  412. value={this.state.searchNumber}
  413. onChange={(e) => { this.setState({ searchNumber: e.target.value }); }} />
  414. <Input placeholder="用户名" style={{ width: 160 }}
  415. value={this.state.searchName}
  416. onChange={(e) => { this.setState({ searchName: e.target.value }); }} />
  417. <Cascader placeholder="请选择一个行业" style={{ width: 300 }}
  418. options={techFieldList}
  419. value={this.state.searchField}
  420. onChange={(e) => { this.setState({ searchField: e }) }} />
  421. <Input placeholder="职称名字" style={{ width: 160 }}
  422. value={this.state.searchPfs}
  423. onChange={(e) => { this.setState({ searchPfs: e.target.value }); }} />
  424. <Input placeholder="工作单位" style={{ width: 160 }}
  425. value={this.state.searchUnit}
  426. onChange={(e) => { this.setState({ searchUnit: e.target.value }); }} />
  427. <Button type="primary" onClick={this.search}>搜索</Button>
  428. <Button onClick={this.reset}>重置</Button>
  429. <Button type="primary" onClick={() => { this.cleanCache(); }}>清除缓存</Button>
  430. </div>
  431. <Spin spinning={this.state.loading}>
  432. <Table size="middle" columns={this.state.columns}
  433. dataSource={this.state.dataSource}
  434. pagination={this.state.pagination} />
  435. </Spin>
  436. </div>
  437. <div className="clearfix">
  438. <div className="admin-content-warp" style={{ width: '50%', float: 'left' }}>
  439. <div className="admin-content-header">
  440. <span>大咖显示列表</span>
  441. <Button type='danger' disabled={!hotHasSelected} onClick={this.hotDelectRow}>
  442. 删除<Icon type="minus" />
  443. </Button>
  444. </div>
  445. <Spin spinning={this.state.loading}>
  446. <Table size="middle" columns={this.state.otherColumns}
  447. dataSource={this.state.hotTableData}
  448. rowSelection={hotRowSelection}
  449. pagination={false} />
  450. </Spin>
  451. </div>
  452. <div className="admin-content-warp" style={{ width: '50%', float: 'left' }}>
  453. <div className="admin-content-header">
  454. <span>明星显示列表</span>
  455. <Button type='danger' disabled={!starHasSelected} onClick={this.starDelectRow}>
  456. 删除<Icon type="minus" />
  457. </Button>
  458. </div>
  459. <Spin spinning={this.state.loading}>
  460. <Table size="middle" columns={this.state.otherColumns}
  461. dataSource={this.state.starTableData}
  462. rowSelection={starRowSelection}
  463. pagination={false} />
  464. </Spin>
  465. </div>
  466. </div>
  467. <Button onClick={this.submit} type="primary" style={{ marginTop: '20px' }}>保存</Button>
  468. </div >
  469. );
  470. }
  471. });
  472. export default Star;