litian
2024-04-02 6a734d758720185f538e672c879121adb6732274
pages/student/index.js
@@ -1,18 +1,38 @@
// pages/student/index.js
const app = getApp();
import {
  getPublicImage
} from "../../assets/js/middleGround/tool.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    learningDuration: 0,
    lastLoginTime: '2024-03-25 20:00:09',
    active: 0,
    titleBook: "图书(0本)",
    titleCourse: "课程(0门)",
    titleTextBook: "数字教材(0本)",
    list: [],
    //分页
    page: 1,
    limit: 18,
    pageTotalCount: 0,
    bottomLoading: false,
    isMoreData: false,
    // 返回顶部
    isBackTop: false,
    setScrollValue: 0,
    skeletonLoding: true,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  onLoad() {
    this.getStaticsSum();
    this.getDataList(false);
  },
  /**
@@ -31,36 +51,161 @@
        active: 2
      })
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },
  getStaticsSum() {
    const data = {
      start: 0,
      size: 10,
      filterList: [{
        value: "LearningTime",
        field: "type",
      }],
    };
    app.MG.app.getStaticsSum(data).then((res) => {
      if (res) {
        let minutes = Number(res) / (1000 * 60)
        let hours = Number(res) / (1000 * 60 * 60)
        if (minutes > 0 && minutes < 60) {
          this.setData({
            learningDuration: Math.round(minutes) + "分钟"
          })
        } else if (minutes > 60) {
          this.setData({
            learningDuration: Math.round(hours) + "小时"
          })
        } else {
          this.setData({
            learningDuration: "0小时"
          })
        }
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
      }
    })
  },
  tabClick(item) {
    let that = this;
    that.setData({
      active: item.detail.value,
    })
    that.setData({
      skeletonLoding: true,
      list: [],
      page: 1,
      bottomLoading: false,
      isMoreData: false,
    })
    that.getDataList(false);
  },
  getDataList(isReachBottom) {
    let keywords = "jsek_mediaBook";
    if (this.data.active == '0') {
      keywords = "jsek_mediaBook";
    } else if (this.data.active == '1') {
      keywords = "jsek_digitalCourses";
    } else if (this.data.active == '2') {
      keywords = "jsek_digitalTextbooks";
    }
    let searchData = [{
      keywords: keywords,
      field: "ProductType",
    }, ];
    let data = {
      Size: this.data.limit,
      Start: this.data.page * this.data.limit - this.data.limit,
      sort: {
        type: "Desc",
        field: "CreateDate",
      },
      searchList: searchData,
    }
    app.MG.store.getPurchasedProductList(data).then((res) => {
      try {
        if (res.datas.length > 0) {
          res.datas.forEach((item, index) => {
            item.product.icon = getPublicImage(item.product.icon, "", 200)
          })
          let dataList = res.datas;
          //触底加载新数据并保留老数据
          if (isReachBottom) {
            dataList = [...this.data.list, ...dataList] //将新数据加入老数据中
          }
          this.setData({
            list: dataList,
            pageTotalCount: res.totalSize,
            titleBook: "图书(" + res.totalSize + "本)",
            bottomLoading: false,
            isMoreData: dataList.length > 0 ? false : true,
            skeletonLoding: false,
            loading: false
          })
        } else {
          this.setData({
            skeletonLoding: false,
            loading: false
          })
        }
      } catch (error) {
        console.log(error)
      }
    })
  },
  goBookDetails(e) {
    const {
      book
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/packageBookService/pages/bookServices/detail/index?id=${book.product.id}&name=${book.product.name}`,
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    if (this._freshing) return
    this.setData({
      // list: [],
      page: 1,
      limit: 18,
      pageTotalCount: 0,
      bottomLoading: false,
      isMoreData: false
    })
    this._freshing = true;
    this.setData({
      triggered: false,
    })
    this.getDataList(false);
    this._freshing = false
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      bottomLoading: true,
      isMoreData: false
    })
    let bool = false;
    if (this.data.pageTotalCount > this.data.list.length) {
      bool = true;
      this.setData({
        page: this.data.page + 1,
      })
    } else {
      setTimeout(() => {
        this.setData({
          bottomLoading: false,
          isMoreData: true
        })
      }, 100)
      return false;
    }
    this.getDataList(bool);
  },
  /**
   * 用户点击右上角分享
   */