page.js 5.5 KB

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