// pages/index/scanResult/selectPage/index.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { options: { styleIsolation: 'apply-shared', }, value: [], optionsData: [], currentPath: "", currentResult: null, selectNum: 0, allowSelectNum: 0, storeId: "", storeChannelId: "", productIds: [], // 加载参数 triggered: false, bottomLoading: false, skeletonLoding: true, isNoData: false, // 返回顶部 isBackTop: false, setScrollValue: 0, //分页 pageSize: 1, pageLimit: 10, pageTotalCount: 0, isMoreData: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (options && options.info && options.result) { const info = JSON.parse(options.info) if (info && info.length > 0) { const { store, storeChannel, allowSelectProductCount } = info[0] this.setData({ currentPath: store.refCode + "\\" + storeChannel.refCode, storeId: store.id, storeChannelId: storeChannel.id, allowSelectNum: allowSelectProductCount, currentResult: options.result }) this.getProductList() } } }, onChange(e) { const { value } = e.detail const arr = [] if (value.length > this.data.allowSelectNum) { return false } if (value && value.length) { for (let index = 0; index < value.length; index++) { const item = value[index]; arr.push(this.data.optionsData[item]?.id) } } this.setData({ productIds: arr, selectNum: arr.length, value: value }); }, activeCode() { const activeInfo = { storeId: this.data.storeId, storeChannelId: this.data.storeChannelId, productIds: this.data.productIds } if (this.data.productIds.length < this.data.allowSelectNum) { wx.showModal({ title: '温馨提示', content: '请选择足够数量的可选商品!', showCancel: false }) return false } let pages = getCurrentPages(); let prevPage = pages[pages.length - 2]; prevPage.setData({ activeInfo }) wx.navigateBack({ delta: 1 }) }, // 获取列表 getProductList(isReachBottom) { app.MG.store .getProductList({ storeInfo: app.config.learnPlatformGoodsStore, path: this.data.currentPath, paging: { start: (this.data.pageSize - 1) * this.data.pageLimit, size: this.data.pageLimit, }, fields: { tourism_paperPrice: [], tourism_productDescription: [], tourism_content: [] }, coverSize: { height: 400 } }) .then(res => { try { res.datas.map(item => { item.price ? item.price = (item.price).toFixed(2) : ""; item.oldPrice ? item.oldPrice = (item.oldPrice).toFixed(2) : ""; item.tourism_paperPrice ? item.tourism_paperPrice = (item.tourism_paperPrice).toFixed(2) : ""; }) let list = res.datas; //触底加载新数据并保留老数据 if (isReachBottom) { list = [...this.data.optionsData, ...list] //将新数据加入老数据中 } this.setData({ optionsData: list, pageTotalCount: res.total, skeletonLoding: false }) } catch (error) { console.log(error) } }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { this.setData({ pageSize: 1, bottomLoading: false, isMoreData: false, isNoData: true }) if (this._freshing) return this._freshing = true; setTimeout(() => { this.setData({ triggered: false, isNoData: false }) this._freshing = false this.getProductList(); }, 500) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { if (this.data.pageTotalCount > this.data.optionsData.length) { this.setData({ pageSize: this.data.pageSize + 1, bottomLoading: true, isMoreData: false }) } else { setTimeout(() => { this.setData({ bottomLoading: false, isMoreData: true }) }, 500) return false; } this.getProductList(true); }, // 监听滚动距离 onPageScroll(e) { if (e.detail.scrollTop >= 1000) { this.setData({ isBackTop: true }) } else { this.setData({ isBackTop: false }) } }, // 返回顶部 onToTop() { this.setData({ setScrollValue: 0 }) }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })