添加下拉刷新和分页加载
This commit is contained in:
parent
247a8eade9
commit
374bbdd933
@ -2,5 +2,7 @@
|
|||||||
"usingComponents": {},
|
"usingComponents": {},
|
||||||
"navigationBarBackgroundColor": "#ceb17f",
|
"navigationBarBackgroundColor": "#ceb17f",
|
||||||
"navigationBarTitleText": "积分商城",
|
"navigationBarTitleText": "积分商城",
|
||||||
"navigationBarTextStyle": "white"
|
"navigationBarTextStyle": "white",
|
||||||
|
"enablePullDownRefresh": true,
|
||||||
|
"backgroundTextStyle": "dark"
|
||||||
}
|
}
|
@ -3,7 +3,7 @@
|
|||||||
import { queryGoodsList } from "../../service/shop-api"
|
import { queryGoodsList } from "../../service/shop-api"
|
||||||
|
|
||||||
// 获取应用实例
|
// 获取应用实例
|
||||||
const app = getApp<IAppOption>()
|
// const app = getApp<IAppOption>()
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
swiperList: [
|
swiperList: [
|
||||||
@ -25,22 +25,53 @@ Page({
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
goodsItems: [],
|
goodsItems: [],
|
||||||
recommendItems: []
|
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() {
|
onLoad() {
|
||||||
// 推荐商品
|
// 推荐商品
|
||||||
queryGoodsList(2, 1, 3).then((result) => {
|
queryGoodsList(2, 1, 3).then((result) => {
|
||||||
|
wx.stopPullDownRefresh();
|
||||||
this.setData({
|
this.setData({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
recommendItems: result.records
|
recommendItems: result.records
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
// 所有其他的商品
|
// 所有其他的商品
|
||||||
queryGoodsList(1, 1, 10).then((result) => {
|
this.loadGoodsList(this.data.page);
|
||||||
this.setData({
|
|
||||||
// @ts-ignore
|
|
||||||
goodsItems: result.records
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
<!--index.wxml-->
|
<!--index.wxml-->
|
||||||
<view class="container">
|
<view class="container">
|
||||||
<view class="content-bg">
|
<view class="content-bg"></view>
|
||||||
|
|
||||||
</view>
|
|
||||||
<view class="content-wrapper">
|
<view class="content-wrapper">
|
||||||
<view class="top-swiper">
|
<view class="top-swiper">
|
||||||
<swiper indicator-dots="{{true}}" indicator-color="#fff" autoplay="{{true}}">
|
<swiper indicator-dots="{{true}}" indicator-color="#fff" autoplay="{{true}}">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user