lecture.jsx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. },
  18. success: function (data) {
  19. let theArr = [];
  20. if (!data.data || !data.data.list) {
  21. if (data.error && data.error.length) {
  22. message.warning(data.error[0].message);
  23. };
  24. } else {
  25. for (let i = 0; i < data.data.list.length; i++) {
  26. let thisdata = data.data.list[i];
  27. theArr.push({
  28. key: i,
  29. uid: thisdata.uid,
  30. engagedField: thisdata.engagedField,
  31. username: thisdata.username,
  32. professionalTitle: thisdata.professionalTitle,
  33. workUnit: thisdata.workUnit,
  34. number: thisdata.number,
  35. achievementNums: thisdata.achievementNums,
  36. });
  37. };
  38. };
  39. this.setState({
  40. dataSource: theArr
  41. });
  42. }.bind(this),
  43. }).always(function () {
  44. this.setState({
  45. loading: false
  46. });
  47. }.bind(this));
  48. },
  49. getInitialState() {
  50. return {
  51. loading: false,
  52. hotSelectedRowKeys: [],
  53. hotSelectedRows: [],
  54. starSelectedRowKeys: [],
  55. starSelectedRows: [],
  56. columns: [{
  57. title: '活动标题',
  58. dataIndex: 'title',
  59. key: 'title',
  60. render: (text, record, index) => {
  61. return <Input value={record.title} onChange={(e) => { record.title = e.target.value; this.setState({ data: this.state.data }); }} />
  62. }
  63. }, {
  64. title: '活动简介',
  65. dataIndex: 'dis',
  66. key: 'dis',
  67. render: (text, record, index) => {
  68. return <Input type="area" span={4} value={record.url} onChange={(e) => { record.url = e.target.value; this.setState({ data: this.state.data }); }} />
  69. }
  70. }],
  71. dataSource: [],
  72. hotTableData: [],
  73. starTableData: []
  74. };
  75. },
  76. addIndex(record) {
  77. let theBool = true;
  78. this.state.hotTableData.map((item, i) => {
  79. if (item.uid == record.uid) {
  80. message.warning('该条记录已经存在于大咖列表中!');
  81. theBool = false;
  82. return;
  83. };
  84. if (i == 4) {
  85. message.warning('大咖列表最多只能显示4条记录!');
  86. theBool = false;
  87. return;
  88. };
  89. });
  90. if (theBool) {
  91. this.state.hotTableData.push(record);
  92. this.setState({ hotTableData: this.state.hotTableData });
  93. };
  94. },
  95. addStar(record) {
  96. let theBool = true;
  97. this.state.starTableData.map(item => {
  98. if (item.uid == record.uid) {
  99. message.warning('该条记录已经存在于明星列表中!');
  100. theBool = false;
  101. return;
  102. };
  103. if (i == 6) {
  104. message.warning('明星列表最多只能显示6条记录!');
  105. theBool = false;
  106. return;
  107. };
  108. });
  109. if (theBool) {
  110. this.state.starTableData.push(record);
  111. this.setState({ starTableData: this.state.starTableData });
  112. };
  113. },
  114. hotDelectRow() {
  115. let deletedArr = this.state.hotTableData.concat();
  116. for (let idx = 0; idx < this.state.hotSelectedRows.length; idx++) {
  117. let deleteIndex = this.state.hotSelectedRows[idx];
  118. if (deleteIndex.uid) {
  119. for (let n = 0; n < deletedArr.length; n++) {
  120. if (deleteIndex.uid == deletedArr[n].uid) {
  121. deletedArr.splice(n, 1);
  122. };
  123. };
  124. };
  125. };
  126. this.setState({
  127. hotTableData: deletedArr,
  128. hotSelectedRowKeys: []
  129. });
  130. },
  131. starDelectRow() {
  132. let deletedArr = this.state.starTableData.concat();
  133. for (let idx = 0; idx < this.state.starSelectedRows.length; idx++) {
  134. let deleteIndex = this.state.starSelectedRows[idx];
  135. if (deleteIndex.uid) {
  136. for (let n = 0; n < deletedArr.length; n++) {
  137. if (deleteIndex.uid == deletedArr[n].uid) {
  138. deletedArr.splice(n, 1);
  139. };
  140. };
  141. };
  142. };
  143. this.setState({
  144. starTableData: deletedArr,
  145. starSelectedRowKeys: []
  146. });
  147. },
  148. componentWillMount() {
  149. this.loadData();
  150. },
  151. submit() {
  152. let hotArr = [], starArr = [];
  153. for (let i = 0; i < this.state.hotTableData.length; i++) {
  154. let hotUid = this.state.hotTableData[i].uid;
  155. if (hotUid) {
  156. hotArr.push(hotUid);
  157. };
  158. };
  159. for (let n = 0; n < this.state.starTableData.length; n++) {
  160. let starUid = this.state.starTableData[n].uid;
  161. if (starUid) {
  162. starArr.push({
  163. uid: starUid,
  164. star: 1
  165. });
  166. };
  167. };
  168. this.setState({
  169. loading: true
  170. });
  171. $.ajax({
  172. method: "post",
  173. dataType: "json",
  174. crossDomain: false,
  175. url: globalConfig.context + '/api/admin/star/save',
  176. data: {
  177. star: starArr,
  178. hot: hotArr
  179. },
  180. success: function (data) {
  181. let theArr = [];
  182. if (!data.data || !data.data.list) {
  183. if (data.error && data.error.length) {
  184. message.warning(data.error[0].message);
  185. };
  186. } else {
  187. message.success('保存成功!')
  188. };
  189. }.bind(this),
  190. }).always(function () {
  191. this.setState({
  192. loading: false
  193. });
  194. }.bind(this));
  195. },
  196. render() {
  197. const hotRowSelection = {
  198. selectedRowKeys: this.state.hotSelectedRowKeys,
  199. onChange: (selectedRowKeys, selectedRows) => {
  200. this.setState({
  201. hotSelectedRows: selectedRows,
  202. hotSelectedRowKeys: selectedRowKeys
  203. });
  204. }
  205. };
  206. const starRowSelection = {
  207. selectedRowKeys: this.state.starSelectedRowKeys,
  208. onChange: (selectedRowKeys, selectedRows) => {
  209. this.setState({
  210. starSelectedRows: selectedRows,
  211. starSelectedRowKeys: selectedRowKeys
  212. });
  213. }
  214. };
  215. const hotHasSelected = this.state.hotSelectedRowKeys.length > 0;
  216. const starHasSelected = this.state.starSelectedRowKeys.length > 0;
  217. return (
  218. <div className="admin-content" >
  219. <div className="admin-content-title">科技讲堂管理</div>
  220. <div className="admin-content-warp">
  221. <div className="admin-content-header">
  222. <span>大咖显示列表</span>
  223. <Button type='danger' disabled={!hotHasSelected} onClick={this.hotDelectRow}>
  224. 删除<Icon type="minus" />
  225. </Button>
  226. </div>
  227. <Spin spinning={this.state.loading}>
  228. <Table columns={this.state.columns}
  229. dataSource={this.state.hotTableData}
  230. rowSelection={hotRowSelection}
  231. pagination={false} />
  232. </Spin>
  233. </div>
  234. <div className="admin-content-warp">
  235. <div className="admin-content-header">
  236. <span>明星显示列表</span>
  237. <Button type='danger' disabled={!starHasSelected} onClick={this.starDelectRow}>
  238. 删除<Icon type="minus" />
  239. </Button>
  240. </div>
  241. <Spin spinning={this.state.loading}>
  242. <Table columns={this.state.columns}
  243. dataSource={this.state.starTableData}
  244. rowSelection={starRowSelection}
  245. pagination={false} />
  246. </Spin>
  247. </div>
  248. <Button onClick={this.submit} type="primary" style={{ marginTop: '20px' }}>保存</Button>
  249. </div >
  250. );
  251. }
  252. });
  253. export default Star;