const app = getApp(); import moment from 'moment' import tool2 from "../../../assets/js/toolClass.js" import { getPublicImage } from "../../../assets/js/middleGround/tool.js"; Page({ /** * 页面的初始数据 */ data: { code: "", list: [], //分页 page: 1, limit: 4, pageTotalCount: 0, bottomLoading: false, isMoreData: false, // 返回顶部 isBackTop: false, setScrollValue: 0, skeletonLoding: true, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options); this.getDataList(false) }, bindTnputBlur: function (e) { this.setData({ code: e.detail.value, }); console.log(this.data.code) }, //激活 onActivation() { var that = this; let lock = true; if (that.data.code == "") { wx.showToast({ title: "请输入激活码!", icon: 'error', duration: 1000, }) } else { if (lock) { lock = false; app.MG.store .userActiveCode({ code: that.data.code, }) .then((res) => { wx.showToast({ title: res, icon: 'none', duration: 1000, success: function () { setTimeout(function () { that.getDataList(false); that.setData({ list: [], code: "" }) lock = true; }, 1000) //延迟时间 } }) }); } } }, //商品列表 getDataList(isReachBottom) { app.MG.store.userActiveCodeList({ start: this.data.page * this.data.limit - this.data.limit, size: this.data.limit, sort: { type: "Desc", field: "CreateDate" } }).then((res) => { try { if (res.datas.length > 0) { console.log(res.datas); res.datas.forEach((item, index) => { item.createDate = moment(item.createDate).format("YYYY-MM-DD HH:mm:ss"); let oldlist = []; oldlist = item.productList oldlist.forEach(istrue => { istrue.icon = getPublicImage(istrue.icon, "", 400) }) }) let dataList = res.datas; //触底加载新数据并保留老数据 if (isReachBottom) { dataList = [...this.data.list, ...dataList] //将新数据加入老数据中 } this.setData({ list: dataList, pageTotalCount: 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; console.log(book) wx.navigateTo({ url: `/packageBookService/pages/bookServices/detail/index?id=${book.id}&name=${book.name}`, }); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { if (this._freshing) return this.setData({ // list: [], page: 1, limit: 4, 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); }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })