// pages/shop/detail/index.js const request = require('../../../utils/request')//导入模块 const math = require('../../../utils/math') const util = require('../../../utils/util') const app = getApp() const urlList = ['/recycle-service/get/store-product-list', '/recycle-service/purchase/get/product-list'] Page({ /** * 页面的初始数据 */ data: { height: app.globalData.fragmentHeight, kg: app.globalData.kg, imageHeight: 0, imgList: [], detail: null, tabList: [ '供应', '采购', '联系'], tabIndex: 0, orderList: [], loading: true, requesting: false, finished: false, form: { storeId: null, pageNum: 1 } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.data.form.storeId = options.storeId wx.showLoading({ title: '加载中', mask: true }) request.get('/recycle-service/get/store-information/' + options.storeId).then(result => { //成功回调 this.setData({ detail: result.data, imgList: result.data.coverImgUrlList, imageHeight: math.divide(math.times(750, 9), 16), height: app.globalData.fragmentHeight, kg: app.globalData.kg, }) wx.hideLoading() }).catch(err => { //异常回调 wx.hideLoading() }) this.fetchGoodList() }, viewImage: function(event){ wx.previewImage({ urls: this.data.imgList, current: event.currentTarget.dataset.url }) }, onTabChange: function({detail}){ if (this.data.tabIndex == Number(detail.index)) { return } this.data.tabIndex = Number(detail.index) if(this.data.tabIndex != 2){ this.onRefreshList() } else { this.setData({ tabIndex: this.data.tabIndex }) } }, onRefreshList: function () { if(this.data.tabIndex == 2){ this.setData({ requesting: false }) return } this.setData({ orderList: [], tabIndex: this.data.tabIndex, ['form.pageNum']: 1, loading: true, finished: false }) this.fetchGoodList() }, fetchGoodList: function () { if (this.data.requesting || this.data.finished) { return } if (this.data.loading) { this.data.requesting = true } else { this.setData({ requesting: true }) } // /product/cheapList特价产品列表 request.get(urlList[this.data.tabIndex], this.data.form).then(result => { //成功回调 if (result.data.records.length) { var respList = result.data.records let nowList = `orderList[${this.data.orderList.length}]` var num = this.data.form.pageNum var finished = this.data.form.pageNum >= result.data.pages if(this.data.form.pageNum == 1){ this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), top: 0, finished, requesting: false, loading: false }) } else { this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false }) } } else { this.setData({ finished: true, requesting: false, loading: false }) } }).catch(err => { //异常回调 this.setData({ requesting: false, loading: false }) util.showToast(err) }) }, lookItem: function(event){ var item = this.data.orderList[event.currentTarget.dataset.page][event.currentTarget.dataset.index] if(item.bidType == 3){ wx.navigateTo({ url: '/pages/purchase/detail/index?id=' + item.id }) } else { wx.navigateTo({ url: '/pages/mall/detail/index?id=' + item.id }) } } })