// pages/quality/index/index.js var app = getApp(); var util = require("../../../utils/util.js"); Page({ /** * 页面的初始数据 */ data: { id: null, tabs: [], currentTab: 0, scrollIntoView: null, pageParams: { pageSize: 10, pageNum: 1, categoryId: 0, status: true, }, noMore: false, list: [], total: 0, totalPage: 0, nodata: util.nodata(), }, /** * 生命周期函数--监听页面加载 */ onLoad(options) {}, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() {}, /** * 生命周期函数--监听页面显示 */ onShow() { this.getClassfiy(); // if (!wx.getStorageSync("classfiyId")) { // this.init(true); // } }, getClassfiy() { app._get("goodscategory/select", {}, (res) => { if (res.code == 0) { this.setData({ tabs: [{ name: "全部", id: 0, }, ...res.list, ], }); const classfiyId = wx.getStorageSync("classfiyId"); if (classfiyId && this.data.tabs.some((el) => el.id == classfiyId)) { this.data.tabs.map((item, index) => { if (item.id == classfiyId) { this.setData({ currentTab: index, "pageParams.categoryId": classfiyId, scrollIntoView: 'location' + classfiyId }); this.init(true); } }); } else { this.setData({ currentTab: 0, "pageParams.categoryId": 0, scrollIntoView: 'location' + 0 }); wx.setStorageSync('classfiyId', 0) this.init(true); } } }); }, init(isRefresh) { if (!isRefresh && this.data.noMore) { wx.showToast({ title: "没有更多了~", icon: "none", }); return false; } this.setData({ list: isRefresh ? [] : this.data.list, "pageParams.pageNum": isRefresh ? 1 : this.data.pageParams.pageNum + 1, noMore: isRefresh ? false : this.data.noMore, }); this.getList(); }, getList() { wx.showLoading({ title: "努力加载中...", }); app._get( "goods/page", this.data.pageParams, (res) => { if (res.code == 0) { let listData = this.data.list; listData.push(...res.page.list); this.setData({ list: listData, total: res.page.totalCount, totalPage: res.page.totalPage, noMore: res.page.totalPage == res.page.currPage, }); } }, function () { wx.hideLoading(); } ); }, handleClassfiy(e) { let categoryId = this.data.tabs[e.currentTarget.dataset.index].id; this.setData({ currentTab: e.currentTarget.dataset.index, "pageParams.categoryId": categoryId, scrollIntoView: 'location' + categoryId }); wx.setStorageSync("classfiyId", categoryId); if (wx.getStorageSync("classfiyId") || categoryId != null) { this.init(true); } }, goodsDetail(e) { wx.navigateTo({ url: `/pages/quality/detail/index?id=${e.currentTarget.dataset.id}`, }); }, /** * 生命周期函数--监听页面隐藏 */ onHide() {}, /** * 生命周期函数--监听页面卸载 */ onUnload() {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { // wx.removeStorageSync('classfiyId') // this.getClassfiy(); // setTimeout(() => { // wx.stopPullDownRefresh // }, 1000); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { this.init(); }, /** * 用户点击右上角分享 */ onShareAppMessage() {}, });