lecture.jsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. loadUserData(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.userPagination.pageSize,
  19. number: this.state.searchUserNumber, //编号
  20. username: this.state.searchUserName, //名称
  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.userPagination.current = data.data.pageNo;
  46. this.state.userPagination.total = data.data.totalCount;
  47. };
  48. this.setState({
  49. dataSource: theArr,
  50. userPagination: this.state.userPagination
  51. });
  52. }.bind(this),
  53. }).always(function () {
  54. this.setState({
  55. loading: false
  56. });
  57. }.bind(this));
  58. },
  59. loadLectureData(pageNo) {
  60. this.setState({
  61. loading: true
  62. });
  63. $.ajax({
  64. method: "get",
  65. dataType: "json",
  66. crossDomain: false,
  67. url: globalConfig.context + '/api/admin/lecture/list',
  68. data: {
  69. pageNo: pageNo || 1,
  70. pageSize: this.state.lecturePagination.pageSize,
  71. username: this.state.searchLectureUser, //用户名称
  72. name: this.state.searchLectureName, //讲座名称
  73. startLectureTime: this.state.startTime ? this.state.startTime.format("yyyy-MM-dd HH:MM:SS") : undefined,
  74. endLectureTime: this.state.endTime ? this.state.endTime.format("yyyy-MM-dd HH:MM:SS") : undefined,
  75. },
  76. success: function (data) {
  77. let theArr = [];
  78. if (!data.data || !data.data.list) {
  79. if (data.error && data.error.length) {
  80. message.warning(data.error[0].message);
  81. };
  82. } else {
  83. for (let i = 0; i < data.data.list.length; i++) {
  84. let thisdata = data.data.list[i];
  85. theArr.push({
  86. id: thisdata.id,
  87. uid: thisdata.uid,
  88. lectureTime: thisdata.lectureTime,
  89. name: thisdata.name,
  90. summary: thisdata.summary,
  91. username: thisdata.username,
  92. lectureUrl: thisdata.lectureUrl,
  93. lectureTimeFormattedDate: thisdata.lectureTimeFormattedDate,
  94. });
  95. };
  96. this.state.lecturePagination.current = data.data.pageNo;
  97. this.state.lecturePagination.total = data.data.totalCount;
  98. };
  99. this.setState({
  100. lectureTableData: theArr,
  101. lecturePagination: this.state.lecturePagination
  102. });
  103. }.bind(this),
  104. }).always(function () {
  105. this.setState({
  106. loading: false
  107. });
  108. }.bind(this));
  109. },
  110. loadHotData() {
  111. this.setState({
  112. loading: true
  113. });
  114. $.ajax({
  115. method: "get",
  116. dataType: "json",
  117. crossDomain: false,
  118. url: globalConfig.context + '/api/admin/star/hotList',
  119. success: function (data) {
  120. let theArr = [];
  121. if (!data.data) {
  122. if (data.error && data.error.length) {
  123. message.warning(data.error[0].message);
  124. };
  125. } else {
  126. for (let i = 0; i < data.data.length; i++) {
  127. let thisdata = data.data[i];
  128. theArr.push({
  129. key: i,
  130. uid: thisdata.uid,
  131. engagedField: thisdata.engagedField,
  132. username: thisdata.username,
  133. professionalTitle: thisdata.professionalTitle,
  134. workUnit: thisdata.workUnit,
  135. number: thisdata.number,
  136. achievementNums: thisdata.achievementNums,
  137. });
  138. };
  139. };
  140. this.setState({
  141. hotTableData: theArr
  142. });
  143. }.bind(this),
  144. }).always(function () {
  145. this.setState({
  146. loading: false
  147. });
  148. }.bind(this));
  149. },
  150. loadStarData() {
  151. this.setState({
  152. loading: true
  153. });
  154. $.ajax({
  155. method: "get",
  156. dataType: "json",
  157. crossDomain: false,
  158. url: globalConfig.context + '/api/admin/star/starList',
  159. success: function (data) {
  160. let theArr = [];
  161. if (!data.data) {
  162. if (data.error && data.error.length) {
  163. message.warning(data.error[0].message);
  164. };
  165. } else {
  166. for (let i = 0; i < data.data.length; i++) {
  167. let thisdata = data.data[i];
  168. theArr.push({
  169. key: i,
  170. uid: thisdata.uid,
  171. engagedField: thisdata.engagedField,
  172. username: thisdata.username,
  173. professionalTitle: thisdata.professionalTitle,
  174. workUnit: thisdata.workUnit,
  175. number: thisdata.number,
  176. achievementNums: thisdata.achievementNums,
  177. });
  178. };
  179. };
  180. this.setState({
  181. starTableData: theArr
  182. });
  183. }.bind(this),
  184. }).always(function () {
  185. this.setState({
  186. loading: false
  187. });
  188. }.bind(this));
  189. },
  190. getInitialState() {
  191. return {
  192. loading: false,
  193. addVisible: false,
  194. hotSelectedRowKeys: [],
  195. hotSelectedRows: [],
  196. starSelectedRowKeys: [],
  197. starSelectedRows: [],
  198. userPagination: {
  199. defaultCurrent: 1,
  200. defaultPageSize: 10,
  201. showQuickJumper: true,
  202. pageSize: 10,
  203. onChange: function (page) {
  204. this.loadUserData(page);
  205. }.bind(this),
  206. showTotal: function (total) {
  207. return '共' + total + '条数据';
  208. }
  209. },
  210. lecturePagination: {
  211. defaultCurrent: 1,
  212. defaultPageSize: 10,
  213. showQuickJumper: true,
  214. pageSize: 10,
  215. onChange: function (page) {
  216. this.loadLectureData(page);
  217. }.bind(this),
  218. showTotal: function (total) {
  219. return '共' + total + '条数据';
  220. }
  221. },
  222. userColumns: [
  223. {
  224. title: '编号',
  225. dataIndex: 'number',
  226. key: 'number',
  227. }, {
  228. title: '姓名',
  229. dataIndex: 'username',
  230. key: 'username',
  231. }, {
  232. title: '从事领域',
  233. dataIndex: 'engagedField',
  234. key: 'engagedField',
  235. }, {
  236. title: '职称名字',
  237. dataIndex: 'professionalTitle',
  238. key: 'professionalTitle',
  239. }, {
  240. title: '工作单位',
  241. dataIndex: 'workUnit',
  242. key: 'workUnit',
  243. }, {
  244. title: '成果数量',
  245. dataIndex: 'achievementNums',
  246. key: 'achievementNums',
  247. }, {
  248. title: '操作',
  249. dataIndex: 'action',
  250. key: 'action',
  251. render: (text, record, index) => {
  252. return <div>
  253. <Button onClick={() => { this.addIndex(record) }} type="primary" style={{ marginRight: '10px' }}>添加到大咖说</Button>
  254. <Button onClick={() => { this.addStar(record) }} type="primary">添加到明星页</Button>
  255. </div>
  256. }
  257. }
  258. ],
  259. lectureColumns: [
  260. {
  261. title: '讲堂名称',
  262. dataIndex: 'name',
  263. key: 'name',
  264. }, {
  265. title: '开讲人姓名',
  266. dataIndex: 'username',
  267. key: 'username',
  268. }, {
  269. title: '描述',
  270. dataIndex: 'summary',
  271. key: 'summary',
  272. }, {
  273. title: '展示图',
  274. dataIndex: 'lectureUrl',
  275. key: 'lectureUrl',
  276. render: text => {
  277. if (text) {
  278. return '已上传'
  279. } else {
  280. return '未上传'
  281. };
  282. }
  283. }
  284. ],
  285. userTableData: [],
  286. lectureTableData: [],
  287. hotTableData: [],
  288. starTableData: []
  289. };
  290. },
  291. addIndex(record) {
  292. let theBool = true;
  293. this.state.hotTableData.map((item, i) => {
  294. if (item.uid == record.uid) {
  295. message.warning('该条记录已经存在于大咖列表中!');
  296. theBool = false;
  297. return;
  298. };
  299. if (i == 4) {
  300. message.warning('大咖列表最多只能显示4条记录!');
  301. theBool = false;
  302. return;
  303. };
  304. });
  305. if (theBool) {
  306. this.state.hotTableData.push(record);
  307. this.setState({ hotTableData: this.state.hotTableData });
  308. };
  309. },
  310. addStar(record) {
  311. let theBool = true;
  312. this.state.starTableData.map((item, i) => {
  313. if (item.uid == record.uid) {
  314. message.warning('该条记录已经存在于明星列表中!');
  315. theBool = false;
  316. return;
  317. };
  318. if (i == 6) {
  319. message.warning('明星列表最多只能显示6条记录!');
  320. theBool = false;
  321. return;
  322. };
  323. });
  324. if (theBool) {
  325. this.state.starTableData.push(record);
  326. this.setState({ starTableData: this.state.starTableData });
  327. };
  328. },
  329. hotDelectRow() {
  330. let deletedArr = this.state.hotTableData.concat();
  331. for (let idx = 0; idx < this.state.hotSelectedRows.length; idx++) {
  332. let deleteIndex = this.state.hotSelectedRows[idx];
  333. if (deleteIndex.uid) {
  334. for (let n = 0; n < deletedArr.length; n++) {
  335. if (deleteIndex.uid == deletedArr[n].uid) {
  336. deletedArr.splice(n, 1);
  337. };
  338. };
  339. };
  340. };
  341. this.setState({
  342. hotTableData: deletedArr,
  343. hotSelectedRowKeys: []
  344. });
  345. },
  346. starDelectRow() {
  347. let deletedArr = this.state.starTableData.concat();
  348. for (let idx = 0; idx < this.state.starSelectedRows.length; idx++) {
  349. let deleteIndex = this.state.starSelectedRows[idx];
  350. if (deleteIndex.uid) {
  351. for (let n = 0; n < deletedArr.length; n++) {
  352. if (deleteIndex.uid == deletedArr[n].uid) {
  353. deletedArr.splice(n, 1);
  354. };
  355. };
  356. };
  357. };
  358. this.setState({
  359. starTableData: deletedArr,
  360. starSelectedRowKeys: []
  361. });
  362. },
  363. componentWillMount() {
  364. this.loadData();
  365. this.loadHotData();
  366. this.loadStarData();
  367. },
  368. submit() {
  369. let hotArr = [], starArr = [];
  370. for (let i = 0; i < this.state.hotTableData.length; i++) {
  371. let hotUid = this.state.hotTableData[i].uid;
  372. if (hotUid) {
  373. hotArr.push(hotUid);
  374. };
  375. };
  376. for (let n = 0; n < this.state.starTableData.length; n++) {
  377. let starUid = this.state.starTableData[n].uid;
  378. if (starUid) {
  379. starArr.push({
  380. uid: starUid,
  381. star: 1
  382. });
  383. };
  384. };
  385. this.setState({
  386. loading: true
  387. });
  388. $.ajax({
  389. method: "post",
  390. dataType: "json",
  391. crossDomain: false,
  392. url: globalConfig.context + '/api/admin/star/save',
  393. data: {
  394. data: JSON.stringify(starArr),
  395. hot: hotArr
  396. },
  397. success: function (data) {
  398. if (data.error && data.error.length) {
  399. message.warning(data.error[0].message);
  400. } else {
  401. message.success('保存成功!')
  402. };
  403. }.bind(this),
  404. }).always(function () {
  405. this.setState({
  406. loading: false
  407. });
  408. }.bind(this));
  409. },
  410. search() {
  411. this.loadData();
  412. },
  413. reset() {
  414. this.state.searchPfs = undefined;
  415. this.state.searchUnit = undefined;
  416. this.state.searchNumber = undefined;
  417. this.state.searchName = undefined;
  418. this.state.searchField = [];
  419. this.loadData();
  420. },
  421. userTableRowClick(record, index) {
  422. this.state.userData = record;
  423. this.setState({
  424. addVisible: true
  425. });
  426. },
  427. render() {
  428. const hotRowSelection = {
  429. selectedRowKeys: this.state.hotSelectedRowKeys,
  430. onChange: (selectedRowKeys, selectedRows) => {
  431. this.setState({
  432. hotSelectedRows: selectedRows,
  433. hotSelectedRowKeys: selectedRowKeys
  434. });
  435. }
  436. };
  437. const starRowSelection = {
  438. selectedRowKeys: this.state.starSelectedRowKeys,
  439. onChange: (selectedRowKeys, selectedRows) => {
  440. this.setState({
  441. starSelectedRows: selectedRows,
  442. starSelectedRowKeys: selectedRowKeys
  443. });
  444. }
  445. };
  446. const hotHasSelected = this.state.hotSelectedRowKeys.length > 0;
  447. const starHasSelected = this.state.starSelectedRowKeys.length > 0;
  448. return (
  449. <div className="admin-content" >
  450. <div className="admin-content-title">科技讲堂管理</div>
  451. <div className="admin-content-warp">
  452. <div className="admin-content-header">专家明星列表</div>
  453. <div className="admin-content-search">
  454. <Input placeholder="编号" style={{ width: 100 }}
  455. value={this.state.searchUserNumber}
  456. onChange={(e) => { this.setState({ searchUserNumber: e.target.value }); }} />
  457. <Input placeholder="专家明星名称" style={{ width: 160 }}
  458. value={this.state.searchUserName}
  459. onChange={(e) => { this.setState({ searchUserName: e.target.value }); }} />
  460. <Cascader placeholder="请选择一个行业" style={{ width: 300 }}
  461. options={techFieldList}
  462. value={this.state.searchField}
  463. onChange={(e) => { this.setState({ searchField: e }) }} />
  464. <Input placeholder="职称名字" style={{ width: 160 }}
  465. value={this.state.searchPfs}
  466. onChange={(e) => { this.setState({ searchPfs: e.target.value }); }} />
  467. <Input placeholder="工作单位" style={{ width: 160 }}
  468. value={this.state.searchUnit}
  469. onChange={(e) => { this.setState({ searchUnit: e.target.value }); }} />
  470. <Button type="primary" onClick={this.search}>搜索</Button>
  471. <Button onClick={this.reset}>重置</Button>
  472. </div>
  473. <Spin spinning={this.state.loading}>
  474. <Table columns={this.state.userColumns}
  475. dataSource={this.state.userTableData}
  476. pagination={this.state.userPagination}
  477. onRowClick={this.userTableRowClick} />
  478. </Spin>
  479. </div>
  480. <div className="clearfix">
  481. <div className="admin-content-warp" style={{ width: '50%', float: 'left' }}>
  482. <div className="admin-content-header">
  483. <span>讲堂列表</span>
  484. <Button type='danger' disabled={!hotHasSelected} onClick={this.hotDelectRow}>
  485. 删除<Icon type="minus" />
  486. </Button>
  487. </div>
  488. <Spin spinning={this.state.loading}>
  489. <Table columns={this.state.lectureColumns}
  490. dataSource={this.state.lectureTableData}
  491. rowSelection={hotRowSelection}
  492. pagination={this.state.lecturePagination} />
  493. </Spin>
  494. </div>
  495. <div className="admin-content-warp" style={{ width: '50%', float: 'left' }}>
  496. <div className="admin-content-header">
  497. <span>明星显示列表</span>
  498. <Button type='danger' disabled={!starHasSelected} onClick={this.starDelectRow}>
  499. 删除<Icon type="minus" />
  500. </Button>
  501. </div>
  502. <Spin spinning={this.state.loading}>
  503. <Table columns={this.state.otherColumns}
  504. dataSource={this.state.starTableData}
  505. rowSelection={starRowSelection}
  506. pagination={false} />
  507. </Spin>
  508. </div>
  509. </div>
  510. <Button onClick={this.submit} type="primary" style={{ marginTop: '20px' }}>保存</Button>
  511. <Modal
  512. title="新建科技讲堂" width={600}
  513. visible={this.state.addVisible}
  514. footer={null}
  515. onCancel={() => { this.setState({ addVisible: false }) }} >
  516. <div className="modal-box">
  517. <span className="modal-box-title">开讲人</span>
  518. <div className="modal-box-detail">
  519. {this.state.userData.name}
  520. </div>
  521. </div>
  522. <div className="modal-box">
  523. <span className="modal-box-title">讲堂标题</span>
  524. <div className="modal-box-detail">
  525. <Input value={this.state.addModal.title}
  526. onChange={(e) => {
  527. this.state.addModal.title = e.target.value;
  528. this.setState({ addModal: this.state.addModal });
  529. }} />
  530. </div>
  531. </div>
  532. <div className="modal-box">
  533. <span className="modal-box-title">开讲时间</span>
  534. <div className="modal-box-detail">
  535. {this.state.userData.name}
  536. </div>
  537. </div>
  538. </Modal>
  539. </div>
  540. );
  541. }
  542. });
  543. export default Star;