star.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. import React from 'react';
  2. import { Icon, Button, Spin, message, Table, Cascader, Input } from 'antd';
  3. import { techFieldList } 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: i,
  36. uid: thisdata.uid,
  37. engagedField: thisdata.engagedField,
  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: i,
  79. uid: thisdata.uid,
  80. engagedField: thisdata.engagedField,
  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: i,
  119. uid: thisdata.uid,
  120. engagedField: thisdata.engagedField,
  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. }, {
  172. title: '职称名字',
  173. dataIndex: 'professionalTitle',
  174. key: 'professionalTitle',
  175. }, {
  176. title: '工作单位',
  177. dataIndex: 'workUnit',
  178. key: 'workUnit',
  179. }, {
  180. title: '成果数量',
  181. dataIndex: 'achievementNums',
  182. key: 'achievementNums',
  183. }, {
  184. title: '操作',
  185. dataIndex: 'action',
  186. key: 'action',
  187. render: (text, record, index) => {
  188. return <div>
  189. <Button onClick={() => { this.addIndex(record) }} type="primary" style={{ marginRight: '10px' }}>添加到大咖说</Button>
  190. <Button onClick={() => { this.addStar(record) }} type="primary">添加到明星页</Button>
  191. </div>
  192. }
  193. }
  194. ],
  195. otherColumns: [
  196. {
  197. title: '编号',
  198. dataIndex: 'number',
  199. key: 'number',
  200. }, {
  201. title: '姓名',
  202. dataIndex: 'username',
  203. key: 'username',
  204. }, {
  205. title: '从事领域',
  206. dataIndex: 'engagedField',
  207. key: 'engagedField',
  208. }, {
  209. title: '职称名字',
  210. dataIndex: 'professionalTitle',
  211. key: 'professionalTitle',
  212. }, {
  213. title: '工作单位',
  214. dataIndex: 'workUnit',
  215. key: 'workUnit',
  216. }, {
  217. title: '成果数量',
  218. dataIndex: 'achievementNums',
  219. key: 'achievementNums',
  220. }
  221. ],
  222. dataSource: [],
  223. hotTableData: [],
  224. starTableData: []
  225. };
  226. },
  227. addIndex(record) {
  228. let theBool = true;
  229. this.state.hotTableData.map((item, i) => {
  230. if (item.uid == record.uid) {
  231. message.warning('该条记录已经存在于大咖列表中!');
  232. theBool = false;
  233. return;
  234. };
  235. if (i == 4) {
  236. message.warning('大咖列表最多只能显示4条记录!');
  237. theBool = false;
  238. return;
  239. };
  240. });
  241. if (theBool) {
  242. this.state.hotTableData.push(record);
  243. this.setState({ hotTableData: this.state.hotTableData });
  244. };
  245. },
  246. addStar(record) {
  247. let theBool = true;
  248. this.state.starTableData.map((item, i) => {
  249. if (item.uid == record.uid) {
  250. message.warning('该条记录已经存在于明星列表中!');
  251. theBool = false;
  252. return;
  253. };
  254. if (i == 6) {
  255. message.warning('明星列表最多只能显示6条记录!');
  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. search() {
  347. this.loadData();
  348. },
  349. reset() {
  350. this.state.searchPfs = undefined;
  351. this.state.searchUnit = undefined;
  352. this.state.searchNumber = undefined;
  353. this.state.searchName = undefined;
  354. this.state.searchField = [];
  355. this.loadData();
  356. },
  357. render() {
  358. const hotRowSelection = {
  359. selectedRowKeys: this.state.hotSelectedRowKeys,
  360. onChange: (selectedRowKeys, selectedRows) => {
  361. this.setState({
  362. hotSelectedRows: selectedRows,
  363. hotSelectedRowKeys: selectedRowKeys
  364. });
  365. }
  366. };
  367. const starRowSelection = {
  368. selectedRowKeys: this.state.starSelectedRowKeys,
  369. onChange: (selectedRowKeys, selectedRows) => {
  370. this.setState({
  371. starSelectedRows: selectedRows,
  372. starSelectedRowKeys: selectedRowKeys
  373. });
  374. }
  375. };
  376. const hotHasSelected = this.state.hotSelectedRowKeys.length > 0;
  377. const starHasSelected = this.state.starSelectedRowKeys.length > 0;
  378. return (
  379. <div className="admin-content" >
  380. <div className="admin-content-title">科技明星管理</div>
  381. <div className="admin-content-warp">
  382. <div className="admin-content-header">明星列表</div>
  383. <div className="admin-content-search">
  384. <Input placeholder="编号" style={{ width: 100 }}
  385. value={this.state.searchNumber}
  386. onChange={(e) => { this.setState({ searchNumber: e.target.value }); }} />
  387. <Input placeholder="用户名" style={{ width: 160 }}
  388. value={this.state.searchName}
  389. onChange={(e) => { this.setState({ searchName: e.target.value }); }} />
  390. <Cascader placeholder="请选择一个行业" style={{ width: 300 }}
  391. options={techFieldList}
  392. value={this.state.searchField}
  393. onChange={(e) => { this.setState({ searchField: e }) }} />
  394. <Input placeholder="职称名字" style={{ width: 160 }}
  395. value={this.state.searchPfs}
  396. onChange={(e) => { this.setState({ searchPfs: e.target.value }); }} />
  397. <Input placeholder="工作单位" style={{ width: 160 }}
  398. value={this.state.searchUnit}
  399. onChange={(e) => { this.setState({ searchUnit: e.target.value }); }} />
  400. <Button type="primary" onClick={this.search}>搜索</Button>
  401. <Button onClick={this.reset}>重置</Button>
  402. </div>
  403. <Spin spinning={this.state.loading}>
  404. <Table columns={this.state.columns}
  405. dataSource={this.state.dataSource}
  406. pagination={this.state.pagination} />
  407. </Spin>
  408. </div>
  409. <div className="clearfix">
  410. <div className="admin-content-warp" style={{ width: '50%', float: 'left' }}>
  411. <div className="admin-content-header">
  412. <span>大咖显示列表</span>
  413. <Button type='danger' disabled={!hotHasSelected} onClick={this.hotDelectRow}>
  414. 删除<Icon type="minus" />
  415. </Button>
  416. </div>
  417. <Spin spinning={this.state.loading}>
  418. <Table columns={this.state.otherColumns}
  419. dataSource={this.state.hotTableData}
  420. rowSelection={hotRowSelection}
  421. pagination={false} />
  422. </Spin>
  423. </div>
  424. <div className="admin-content-warp" style={{ width: '50%', float: 'left' }}>
  425. <div className="admin-content-header">
  426. <span>明星显示列表</span>
  427. <Button type='danger' disabled={!starHasSelected} onClick={this.starDelectRow}>
  428. 删除<Icon type="minus" />
  429. </Button>
  430. </div>
  431. <Spin spinning={this.state.loading}>
  432. <Table columns={this.state.otherColumns}
  433. dataSource={this.state.starTableData}
  434. rowSelection={starRowSelection}
  435. pagination={false} />
  436. </Spin>
  437. </div>
  438. </div>
  439. <Button onClick={this.submit} type="primary" style={{ marginTop: '20px' }}>保存</Button>
  440. </div >
  441. );
  442. }
  443. });
  444. export default Star;