From 374bbdd9332dd4972abad4c0b47b643d77b1c702 Mon Sep 17 00:00:00 2001 From: callmeyan Date: Mon, 28 Nov 2022 11:41:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8B=E6=8B=89=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=92=8C=E5=88=86=E9=A1=B5=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/pages/index/index.json | 4 ++- miniprogram/pages/index/index.ts | 47 +++++++++++++++++++++++++----- miniprogram/pages/index/index.wxml | 4 +-- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/miniprogram/pages/index/index.json b/miniprogram/pages/index/index.json index e1bc229..5fc86dc 100644 --- a/miniprogram/pages/index/index.json +++ b/miniprogram/pages/index/index.json @@ -2,5 +2,7 @@ "usingComponents": {}, "navigationBarBackgroundColor": "#ceb17f", "navigationBarTitleText": "积分商城", - "navigationBarTextStyle": "white" + "navigationBarTextStyle": "white", + "enablePullDownRefresh": true, + "backgroundTextStyle": "dark" } \ No newline at end of file diff --git a/miniprogram/pages/index/index.ts b/miniprogram/pages/index/index.ts index 50b9acb..504f7d3 100644 --- a/miniprogram/pages/index/index.ts +++ b/miniprogram/pages/index/index.ts @@ -3,7 +3,7 @@ import { queryGoodsList } from "../../service/shop-api" // 获取应用实例 -const app = getApp() +// const app = getApp() Page({ data: { swiperList: [ @@ -25,22 +25,53 @@ Page({ } ], 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() { // 推荐商品 queryGoodsList(2, 1, 3).then((result) => { + wx.stopPullDownRefresh(); this.setData({ // @ts-ignore recommendItems: result.records }) }) // 所有其他的商品 - queryGoodsList(1, 1, 10).then((result) => { - this.setData({ - // @ts-ignore - goodsItems: result.records - }) - }) + this.loadGoodsList(this.data.page); } }) diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml index 6427ba6..6f4dfb9 100644 --- a/miniprogram/pages/index/index.wxml +++ b/miniprogram/pages/index/index.wxml @@ -1,8 +1,6 @@ - - - +