page.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import Block from '@src/components/Block';
  5. // import FilterLayout from '@src/layouts/FilterLayout';
  6. import ActionLayout from '@src/layouts/ActionLayout';
  7. import TableLayout from '@src/layouts/TableLayout';
  8. import { getMap, formatTreeData, flattenObject } from '@src/services/Tools';
  9. import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
  10. import { ServiceKey, ServiceParamMap, SwitchSelect } from '../../../../Constant';
  11. import { Course } from '../../../stores/course';
  12. import { Exercise } from '../../../stores/exercise';
  13. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  14. export default class extends Page {
  15. constructor(props) {
  16. super(props);
  17. this.exerciseMap = {};
  18. this.actionList = [{
  19. key: 'add',
  20. type: 'primary',
  21. name: '创建',
  22. }];
  23. this.itemList = [{
  24. key: 'id',
  25. type: 'hidden',
  26. }, {
  27. key: 'title',
  28. type: 'input',
  29. name: '套餐名称',
  30. }, {
  31. key: 'structId',
  32. type: 'select',
  33. select: [],
  34. name: '套餐学科',
  35. }, {
  36. key: 'description',
  37. type: 'input',
  38. name: '套餐描述',
  39. }, {
  40. key: 'price',
  41. type: 'number',
  42. name: '套餐价格',
  43. }, {
  44. key: 'courseIds',
  45. type: 'multiple',
  46. name: '包含课程',
  47. }];
  48. ServiceKey.forEach((row) => {
  49. const list = ServiceParamMap[row.value];
  50. const item = {
  51. key: `gift.${row.value}`,
  52. type: 'number',
  53. name: `赠送${row.label}`,
  54. };
  55. if (list) {
  56. item.select = list;
  57. item.type = 'select';
  58. }
  59. this.itemList.push(item);
  60. });
  61. this.columns = [{
  62. title: '套餐名称',
  63. dataIndex: 'title',
  64. }, {
  65. title: '套餐学科',
  66. dataIndex: 'structId',
  67. render: (text) => {
  68. return this.exerciseMap[text];
  69. },
  70. }, {
  71. title: '套餐价格',
  72. dataIndex: 'price',
  73. }, {
  74. title: '销售数量',
  75. dataIndex: 'saleNumber',
  76. }, {
  77. title: '首页推荐',
  78. dataIndex: 'isSpecial',
  79. render: (text) => {
  80. return SwitchSelectMap[text] || text;
  81. },
  82. }, {
  83. title: '上架',
  84. dataIndex: 'isShow',
  85. render: (text) => {
  86. return SwitchSelectMap[text] || text;
  87. },
  88. }, {
  89. title: '操作',
  90. dataIndex: 'handler',
  91. render: (text, record) => {
  92. return <div className="table-button">
  93. {(
  94. <a onClick={() => {
  95. this.editAction(record);
  96. }}>编辑</a>
  97. )}
  98. {!!record.isSpecial && (
  99. <a onClick={() => {
  100. this.special(record, 0);
  101. }}>取消推荐</a>
  102. )}
  103. {!record.isSpecial && (
  104. <a onClick={() => {
  105. this.special(record, 1);
  106. }}>首页推荐</a>
  107. )}
  108. {!record.isShow && (
  109. <a onClick={() => {
  110. this.show(record, 1);
  111. }}>上架</a>
  112. )}
  113. {!!record.isShow && (
  114. <a onClick={() => {
  115. this.show(record, 0);
  116. }}>下架</a>
  117. )}
  118. </div>;
  119. },
  120. }];
  121. }
  122. init() {
  123. Exercise.courseStruct().then((result) => {
  124. const list = result.filter(row => row.level === 1).map(row => {
  125. row.title = `${row.titleZh}`;
  126. row.value = row.id;
  127. return row;
  128. });
  129. this.itemList[2].select = list;
  130. this.exerciseMap = getMap(list, 'id', 'title');
  131. this.setState({ exercise: formatTreeData(list, 'id', 'title', 'parentId') });
  132. });
  133. Course.list({ excludeVs: true, excludeOnline: true }).then((result) => {
  134. this.itemList[5].select = result.list.map(row => {
  135. row.value = row.id;
  136. return row;
  137. });
  138. });
  139. }
  140. initData() {
  141. Course.listPackage(this.state.search).then(result => {
  142. this.setTableData(result.list, result.total);
  143. });
  144. }
  145. detailAction(row) {
  146. this.setState({ detail: row });
  147. }
  148. addAction() {
  149. asyncForm('创建', this.itemList, {}, data => {
  150. return Course.addPackage(data).then(() => {
  151. asyncSMessage('添加成功!');
  152. this.refresh();
  153. });
  154. });
  155. }
  156. editAction(row) {
  157. row = flattenObject(row);
  158. asyncForm('编辑', this.itemList, row, data => {
  159. return Course.editPackage(data).then(() => {
  160. asyncSMessage('编辑成功!');
  161. this.refresh();
  162. });
  163. });
  164. }
  165. special(row, isSpecial) {
  166. Course.editPackage({ id: row.id, isSpecial }).then(() => {
  167. asyncSMessage('编辑成功!');
  168. this.refresh();
  169. });
  170. }
  171. show(row, isShow) {
  172. Course.editPackage({ id: row.id, isShow }).then(() => {
  173. asyncSMessage('编辑成功!');
  174. this.refresh();
  175. });
  176. }
  177. renderView() {
  178. return <Block flex>
  179. {/* <FilterLayout
  180. show
  181. itemList={this.filterForm}
  182. data={this.state.search}
  183. onChange={data => {
  184. data.page = 1;
  185. this.search(data);
  186. }} /> */}
  187. <ActionLayout
  188. itemList={this.actionList}
  189. selectedKeys={this.state.selectedKeys}
  190. onAction={key => this.onAction(key)}
  191. />
  192. <TableLayout
  193. columns={this.tableSort(this.columns)}
  194. list={this.state.list}
  195. pagination={this.state.page}
  196. loading={this.props.core.loading}
  197. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  198. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  199. selectedKeys={this.state.selectedKeys}
  200. />
  201. </Block>;
  202. }
  203. }