You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
3.9 KiB
149 lines
3.9 KiB
// pages/shop/detail/index.js
|
|
import { getStoreInfo, getProductList, getStoreProductList } from "../../api/ztb"
|
|
const math = require('../../../utils/math')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
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 })
|
|
getStoreInfo(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
|
|
}
|
|
if (this.data.requesting) {
|
|
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 })
|
|
}
|
|
if(this.data.tabIndex == 0){
|
|
getStoreProductList(this.data.form).then(result => {
|
|
this.doResult(result)
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
})
|
|
} else if(this.data.tabIndex == 1){
|
|
getProductList(this.data.form).then(result => {
|
|
this.doResult(result)
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
},
|
|
doResult: function(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
|
|
})
|
|
}
|
|
},
|
|
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 })
|
|
}
|
|
}
|
|
|
|
})
|