78 lines
2.0 KiB
TypeScript
78 lines
2.0 KiB
TypeScript
// index.ts
|
|
|
|
import { queryGoodsList } from "../../service/shop-api"
|
|
|
|
// 获取应用实例
|
|
// const app = getApp<IAppOption>()
|
|
Page({
|
|
data: {
|
|
swiperList: [
|
|
{
|
|
image: 'https://m15.360buyimg.com/mobilecms/jfs/t1/160398/4/32302/103427/6374d1f3E5b1ecb32/a593b9982d8378cc.jpg!cr_1125x449_0_166!q70.jpg',
|
|
url: null,
|
|
},
|
|
{
|
|
image: 'https://m15.360buyimg.com/mobilecms/jfs/t1/203775/20/26428/95041/637fab4dEf6a4434d/3f8770efe691537b.jpg!cr_1053x420_4_0!q70.jpg',
|
|
url: null,
|
|
},
|
|
{
|
|
image: 'https://m15.360buyimg.com/mobilecms/jfs/t1/160398/4/32302/103427/6374d1f3E5b1ecb32/a593b9982d8378cc.jpg!cr_1125x449_0_166!q70.jpg',
|
|
url: null,
|
|
},
|
|
{
|
|
image: 'https://m15.360buyimg.com/mobilecms/jfs/t1/203775/20/26428/95041/637fab4dEf6a4434d/3f8770efe691537b.jpg!cr_1053x420_4_0!q70.jpg',
|
|
url: null,
|
|
}
|
|
],
|
|
goodsItems: [],
|
|
recommendItems: [],
|
|
page: 1,
|
|
hasMore: true,
|
|
pageSize: 10
|
|
},
|
|
onPullDownRefresh() {
|
|
this.setData({
|
|
page: 1
|
|
})
|
|
this.onLoad()
|
|
},
|
|
onReachBottom() {
|
|
if (!this.data.hasMore) return;
|
|
const page = this.data.page + 1;
|
|
this.setData({page})
|
|
this.loadGoodsList(page)
|
|
},
|
|
loadGoodsList(page: number) {
|
|
|
|
// 所有其他的商品
|
|
queryGoodsList(1, page, this.data.pageSize).then((result) => {
|
|
//判断是否还有数据没有查询到
|
|
const count = page * this.data.pageSize;
|
|
if (count >= result.total) {
|
|
this.setData({
|
|
hasMore: false
|
|
})
|
|
}
|
|
this.setData({
|
|
// @ts-ignore
|
|
goodsItems: [
|
|
...this.data.goodsItems,
|
|
...result.records
|
|
]
|
|
})
|
|
})
|
|
},
|
|
onLoad() {
|
|
// 推荐商品
|
|
queryGoodsList(2, 1, 3).then((result) => {
|
|
wx.stopPullDownRefresh();
|
|
this.setData({
|
|
// @ts-ignore
|
|
recommendItems: result.records
|
|
})
|
|
})
|
|
// 所有其他的商品
|
|
this.loadGoodsList(this.data.page);
|
|
}
|
|
})
|