wangfukang 4 weeks ago
parent
commit
91cdb24c2e
  1. 90
      package3/shop/merchantCenter.vue

90
package3/shop/merchantCenter.vue

@ -263,6 +263,7 @@
refreshPage(isPullDown){
this.menuButtonInfo = uni.getMenuButtonBoundingClientRect()
const tasks = [
this.getShopInfo(),
this.getBusinessStatus(),
this.getData()
]
@ -312,20 +313,95 @@
this.shopConfig = shopList.find(item => item.id == uni.getStorageSync('shopId')) || {}
}
},
getRegionId(){
try {
const area = uni.getStorageSync('area')
return area ? JSON.parse(area).id : ''
} catch (e) {
return ''
}
},
normalizeShopResult(result) {
if (result && result.shop) {
const data = Object.assign({}, result.shop, result)
delete data.shop
return data
}
return result || {}
},
getCachedShop(){
const shopId = uni.getStorageSync('shopId')
const shopList = uni.getStorageSync('schoolShop') || []
if(Array.isArray(shopList)){
const item = shopList.find(shop => shop.id == shopId)
if(item) return item
}
return uni.getStorageSync('shop') || {
id: shopId,
shopName: uni.getStorageSync('shopName') || '',
shopIcon: uni.getStorageSync('shopIcon') || ''
}
},
applyShopInfo(data){
const shop = Object.assign({}, this.shop, data || {})
Object.keys(shop).forEach(key => {
if (shop[key] === null) shop[key] = ''
})
this.shop = shop
this.updateLocalShopCache(shop)
},
updateLocalShopCache(shop){
if(!shop || !shop.id) return
let shopList = uni.getStorageSync('schoolShop') || []
if(Array.isArray(shopList)){
shopList = shopList.map(item => item.id == shop.id ? Object.assign({}, item, shop) : item)
uni.setStorageSync('schoolShop', shopList)
}
uni.setStorageSync('shop', shop)
if(shop.shopName !== undefined && shop.shopName !== null){
uni.setStorageSync('shopName', shop.shopName)
}
if(shop.shopIcon !== undefined && shop.shopIcon !== null){
uni.setStorageSync('shopIcon', shop.shopIcon)
}
this.refreshShopConfig()
},
getShopInfo(){
const shopId = uni.getStorageSync('shopId')
if(!shopId){
this.applyShopInfo(this.getCachedShop())
return Promise.resolve()
}
return this.tui.request("/app/shop/getShopInfoById", "POST", {
id: shopId,
regionId: this.getRegionId()
}, false, true).then((res) => {
if (res.code == 200 && res.result) {
this.applyShopInfo(this.normalizeShopResult(res.result))
} else {
this.applyShopInfo(this.getCachedShop())
if(res.message) this.tui.toast(res.message)
}
uni.hideLoading()
}).catch(() => {
this.applyShopInfo(this.getCachedShop())
uni.hideLoading()
})
},
//
getBusinessStatus(){
this.shop.shopName = uni.getStorageSync('shopName')
return this.tui.request("/app/shoptakeaway/getByShopId", "GET", {
shopId: uni.getStorageSync('shopId')
}, false, true).then((res) => {
if (res.code == 200) {
if(res.result != null){
this.shop = res.result
const shopTakeaway = res.result || {}
if(shopTakeaway.status !== undefined && shopTakeaway.status !== null){
this.businessStatus = shopTakeaway.status
this.shop = Object.assign({}, this.shop, {
status: shopTakeaway.status
})
}
this.shop.shopIcon = uni.getStorageSync('shopIcon')
uni.setStorageSync('shopTakeaway',res.result)
this.businessStatus = res.result.status
uni.setStorageSync('shopTakeaway', shopTakeaway)
} else {
this.tui.toast(res.message)
}

Loading…
Cancel
Save