50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
const { getHomeData } = require('../../api/homeApi')
|
|
const { yuan } = require('../../utils/request')
|
|
|
|
Page({
|
|
data: {
|
|
loading: false,
|
|
banners: [],
|
|
notices: [],
|
|
products: [],
|
|
groupBuys: [],
|
|
secondGoods: []
|
|
},
|
|
|
|
onLoad() {
|
|
this.load()
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.load().finally(() => wx.stopPullDownRefresh())
|
|
},
|
|
|
|
load() {
|
|
this.setData({ loading: true })
|
|
return getHomeData()
|
|
.then((data) => {
|
|
this.setData({
|
|
banners: data.banners || [],
|
|
notices: (data.notices || []).slice(0, 3),
|
|
products: (data.products || []).slice(0, 6),
|
|
groupBuys: (data.groupBuys || []).slice(0, 3),
|
|
secondGoods: (data.secondGoods || []).slice(0, 3)
|
|
})
|
|
})
|
|
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
|
.finally(() => this.setData({ loading: false }))
|
|
},
|
|
|
|
go(event) {
|
|
wx.navigateTo({ url: event.currentTarget.dataset.url })
|
|
},
|
|
|
|
goTab(event) {
|
|
wx.switchTab({ url: event.currentTarget.dataset.url })
|
|
},
|
|
|
|
yuan(cent) {
|
|
return yuan(cent)
|
|
}
|
|
})
|