const { getShopInfo } = require('./api/index') Page({ /** * 页面的初始数据 */ data: { nav: [ { icon: 'goods_release.png', name: '产品发布', path: 'businessGoodsEdit' }, { icon: 'goods_manage.png', name: '产品管理', path: 'businessGoodsManage' } ], shopInfo: {}, products: [], shopDetail: {}, isFetchLock: false, // 接口调用加锁 isRefresh: false, // 是否下拉刷新 finished: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.fetchShopInfo() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, onPullDownRefresh() { if (this.data.isRefresh) { return } this.setData({ isRefresh: true, finished: false }) this.fetchShopInfo() }, bindCallBack() { this.fetchShopInfo() }, jump(e) { const { path, tabvalue = '' } = e.currentTarget.dataset wx.navigateTo({ url: `/pages/${path}/${path}?tabvalue=${tabvalue}` }) }, handleNav(e) { const { item } = e.currentTarget.dataset const path = item.path wx.navigateTo({ url: `/pages/${path}/${path}` }) }, async fetchShopInfo() { const that = this const isRefresh = that.data.isRefresh if (that.data.isFetchLock) { return } that.setData({ isFetchLock: true }) try { const { status, data, msg } = await getShopInfo() if (status) { this.setData({ shopInfo: data, products: Array.isArray(data.products) ? data.products : [], shopDetail: Object.prototype.toString.call(data.shop_info) === '[object Object]' ? data.shop_info : {} }) } else { wx.showToast({ title: msg, icon: 'none' }) } } catch (err) {} this.setData({ isFetchLock: false, isRefresh: false, finished: true }) if (isRefresh) { wx.stopPullDownRefresh() } }, jumpBusinessInfo() { wx.navigateTo({ url: '/pages/businessInfo/businessInfo' }) } })