course.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Api from "../../model/api";
  2. import {getDataSet, getEventParam} from "../../utils/utils";
  3. import {htmlTypes} from "../../model/enum";
  4. import Route from "../../model/route";
  5. const app = getApp();
  6. app.Base({
  7. data: {
  8. tabsList: {
  9. "线上课程": [],
  10. "线下课程": []
  11. },
  12. active: 0,
  13. activeFirstName: '',
  14. leftActive: 0,
  15. dictType: '',
  16. dictValue: '',
  17. },
  18. async onLoad() {
  19. const res = await Api.getCourseMngDict(true);
  20. const activeFirstName = Object.keys(res.data)[0];
  21. const dictType = res.data[activeFirstName][0].dictType;
  22. const dictValue = res.data[activeFirstName][0].dictValue;
  23. this.setData({
  24. tabsList: res.data,
  25. activeFirstName: activeFirstName,
  26. dictType, dictValue
  27. })
  28. },
  29. async onChangeCategory(e) {
  30. const dictType = this.data.tabsList[this.data.activeFirstName][getEventParam(e)].dictType;
  31. const dictValue = this.data.tabsList[this.data.activeFirstName][getEventParam(e)].dictValue;
  32. this.setData({
  33. leftActive: getEventParam(e),
  34. dictType, dictValue
  35. }, async () => {
  36. this.changeResetData(this);
  37. })
  38. },
  39. async onChange(e) {
  40. const dictType = this.data.tabsList[getEventParam(e, 'title')][0].dictType;
  41. const dictValue = this.data.tabsList[getEventParam(e, "title")][0].dictValue;
  42. this.setData({
  43. active: getEventParam(e, "index"),
  44. activeFirstName: getEventParam(e, "title"),
  45. leftActive: 0,
  46. dictType, dictValue
  47. }, async () => {
  48. this.changeResetData(this);
  49. })
  50. },
  51. toNewsDetail(e) {
  52. const item = getDataSet(e, "item");
  53. Route.toNews(htmlTypes.COURSE, item.id, item.courseName, "")
  54. },
  55. async requestData() {
  56. const res = await Api.getCourseMngList({
  57. courseModel: this.data.dictType,
  58. courseType: this.data.dictValue,
  59. pageNum: this.pageNum,
  60. pageSize: this.pageSize
  61. })
  62. return res;
  63. },
  64. })