classPanel.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import Api from "../../model/api";
  2. import {formatYMD, getDataSet} from "../../utils/utils";
  3. import {classStatus, logicStatus} from "../../model/enum";
  4. import Route from "../../model/route";
  5. const app = getApp();
  6. app.Base({
  7. type: classStatus.NO_START,
  8. dict: {
  9. [classStatus.NO_START]: {title: '即将开班', tagTxt: '未开始', tagBg: 'tag-bg1', method: Api.getClassList},
  10. [classStatus.RUNNING]: {title: '正在开班', tagTxt: '进行中', tagBg: 'tag-bg0', method: Api.getClassList},
  11. [classStatus.HISTORY]: {title: '历史开班', tagTxt: '已结束', tagBg: 'tag-bg2', method: Api.getClassList},
  12. [classStatus.MY_HISTORY]: {title: '往期培训', tagTxt: '已结束', tagBg: 'tag-bg2', method: Api.getMyHistoryClass},
  13. },
  14. data: {
  15. title: "",
  16. tagTxt: '',
  17. tagBg: '',
  18. },
  19. async onLoad(options) {
  20. const {type} = options;
  21. this.type = type;
  22. const title = this.dict[this.type].title;
  23. wx.setNavigationBarTitle({title})
  24. this.setData({
  25. tagTxt: this.dict[this.type].tagTxt,
  26. tagBg: this.dict[this.type].tagBg,
  27. })
  28. },
  29. toDetail(e) {
  30. if (this.type == classStatus.MY_HISTORY) {
  31. const item = getDataSet(e, "item");
  32. Route.toEduDetail(item.id, logicStatus.YES)
  33. }
  34. },
  35. async requestData() {
  36. let res;
  37. if (this.type == classStatus.MY_HISTORY) {
  38. res = await this.dict[this.type].method(2, {
  39. pageNum: this.pageNum,
  40. pageSize: this.pageSize
  41. });
  42. } else {
  43. res = await this.dict[this.type].method({
  44. teamState: this.type,
  45. pageNum: this.pageNum,
  46. pageSize: this.pageSize
  47. });
  48. }
  49. res.data.rows.forEach(item => {
  50. item.teamStart = formatYMD(item.teamStart);
  51. item.teamEnd = formatYMD(item.teamEnd);
  52. })
  53. return res;
  54. },
  55. })