From 10db09788d74b441a2efd85f5d4614e944b07bb3 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期二, 26 三月 2024 20:07:11 +0800 Subject: [PATCH] 问题修改 --- pages/student/index.js | 147 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 128 insertions(+), 19 deletions(-) diff --git a/pages/student/index.js b/pages/student/index.js index 9a56f81..f3cc83e 100644 --- a/pages/student/index.js +++ b/pages/student/index.js @@ -1,18 +1,36 @@ -// 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.getDataList(false); }, /** @@ -26,37 +44,128 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ onShow() { - + if (typeof this.getTabBar === 'function' && this.getTabBar()) { + this.getTabBar().setData({ + active: 2 + }) + } }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 - */ - onHide() { - + 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); }, - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 - */ - onUnload() { - + 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) + } + }) }, - /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ 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); }, - /** * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� */ -- Gitblit v1.9.1