闫增涛
2024-09-18 c96612e8a63ecef9590be0f8b5199277ec94e5b9
pages/digitalCourses/index.js
@@ -17,9 +17,37 @@
    tabList: [],
    courseList: [],
    searchValue: '',
    active: 0,
    activeItem: null,
    loading: false,
    shoppingCartGetId: []
    contentLoading: false,
    noData:false,
    shoppingCartGetId: [],
    sorter: {
      value: "*",
      options: [{
          value: "*",
          label: "默认排序",
        },
        {
          value: "nameAsc",
          label: "点击量正序",
        },
        {
          value: "nameDesc",
          label: "点击量倒序",
        },
        {
          value: "timeAsc",
          label: "创建时间正序",
        },
        {
          value: "timeDesc",
          label: "创建时间倒序",
        },
      ],
    },
    sortActive: '',
  },
  /**
@@ -34,6 +62,11 @@
      barHeight: systInfo.statusBarHeight,
      navBarHeight: navBarHeight,
    });
    if (options.courseTypeActive) {
      this.setData({
        active: JSON.parse(options.courseTypeActive),
      });
    }
    this.getCourseTypeListList()
    this.getShoppingCartList()
  },
@@ -88,6 +121,9 @@
  },
  onTabsChange(event) {
    const value = event.detail.value
    this.setData({
      contentLoading: true
    })
    this.getCourseList(this.data.tabList[value])
  },
@@ -96,16 +132,15 @@
    wx.navigateBack();
  },
  getCourseTypeListList() {
    this.setData({
      loading: true
      loading: true,
    })
    const data = {
      path: '*',
      filterList: [{
        value: 'Normal',
        field: 'state'
      }],
      // filterList: [{
      //   value: 'Normal',
      //   field: 'state'
      // }],
      queryType: '\\',
      searchList: [],
      size: '20',
@@ -117,51 +152,63 @@
      }
    }
    app.MG.store.getStoreChannelList(data).then((res) => {
      // 去除数组最后一个元素
      const newData = res.datas.slice(0, res.datas.length - 1)
      newData.unshift({
        name: "全部",
        pathList: newData[0].pathList[0],
        id: ""
      })
      this.setData({
        tabList: newData,
        activeItem: newData[0],
        loading: false
      })
      this.getCourseList(newData[0])
      if (this.data.active) {
        this.getCourseList(newData[this.data.active])
      } else {
        this.setData({
          activeItem: newData[0],
        })
        this.getCourseList(newData[0])
      }
    })
  },
  getCourseList(item) {
    let searchObj = {}
    // let sort = {}
    let sort = {}
    // // 搜索框
    if (this.data.searchValue) {
      searchObj = {
        'Name*': this.data.searchValue.trim()
        // '||subtitle*': searchInputValue.value.trim()
        'Name*': this.data.searchValue.trim(),
        '||isbn*': this.data.searchValue.trim(),
        '||courseLeader*': this.data.searchValue.trim()
      }
    }
    // if (timeSort.value) {
    //     sort = {
    //         CreateDate: timeSort.value || 'Desc'
    //     }
    // } else {
    //     sort = {
    //         ViewCount: nameSort.value || 'Desc'
    //     }
    if (this.data.sortActive == 'nameAsc') {
      sort = {
        ViewCount: 'Asc'
      }
    } else if (this.data.sortActive == 'nameDesc') {
      sort = {
        ViewCount: 'Desc'
      }
    } else if (this.data.sortActive == 'timeAsc') {
      sort = {
        CreateDate: 'Asc'
      }
    } else if (this.data.sortActive == 'timeDesc') {
      sort = {
        CreateDate: 'Desc'
      }
    }
    //     // 组合的写法 要查询的字段:升序和降序
    //     // Name: "Desc"
    //     //一般的排序传法
    //     // type: "Asc",
    //     // field: "CreateDate",
    // }
    // courseList.value = [];
    const obj = {
      storeInfo: app.config.goodsStore,
      path: item.pathList + '\\' + item.id,
      // path: item.pathList + '\\' + item.id,
      path: item.id ? item.pathList + '\\' + item.id : item.pathList,
      queryType: "*",
      coverSize: {
        width: 260
      },
@@ -173,7 +220,7 @@
        value: 'Normal',
        field: 'state'
      }],
      // sort: sort,
      sort: sort,
      fields: {
        courseLeader: [],
        affiliatedUnit: [],
@@ -184,25 +231,38 @@
      }
    }
    app.MG.store.getProductList(obj).then((res) => {
      if(!res.datas.length) {
        return this.setData({
          noData:true,
          contentLoading:false
        })
      }
      res.datas.forEach(item => {
        item.price = item.price.toFixed(2)
        item.productLinkInfo = JSON.parse(item.productLinkInfo)
      })
      // 排除其他分类里的数据
      this.setData({
        courseList: res.datas
        courseList: res.datas,
        contentLoading: false,
      })
    })
  },
  searchBook() {
    this.getCourseList(this.data.activeItem)
  },
  onSort(e) {
    this.setData({
      "sortActive": e.detail.value,
    });
    this.getCourseList(this.data.activeItem);
  },
  courseDetail(e) {
    const item = e.currentTarget.dataset.item
    setNewView('productId', item.id)
    this.getCourseTypeListList()
    wx.navigateTo({
      url: '/pages/digitalCourses/digitalCoursesDetails/index?id=' + item.id,
      url: '/pages/digitalCourses/digitalCoursesDetails/index?id=' + item.id + '&path=' + item.idPath
    })
  },