From 9827d07da5cd043c82f5077093bb4621f408e482 Mon Sep 17 00:00:00 2001 From: "AERWEN\\26795" <123456789a> Date: Sat, 14 Oct 2023 20:31:40 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=92=8C=E7=B1=BB=E7=9B=AE=E6=8E=A8=E8=8D=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods/list/index.js | 2 +- pages/home/home.js | 70 ++++++++++++++++++------- pages/order/order-confirm/pay.js | 16 +++--- services/home/getHomeCategoryListApi.js | 19 +++++++ services/home/home.js | 1 - 5 files changed, 79 insertions(+), 29 deletions(-) create mode 100644 services/home/getHomeCategoryListApi.js diff --git a/pages/goods/list/index.js b/pages/goods/list/index.js index e642878..d4a010c 100644 --- a/pages/goods/list/index.js +++ b/pages/goods/list/index.js @@ -1,4 +1,4 @@ -import { fetchGoodsList } from '../../../services/good/fetchGoodsList'; +import { fetchGoodsList } from '~/services/good/fetchGoodsList'; import Toast from 'tdesign-miniprogram/toast/index'; const initFilters = { diff --git a/pages/home/home.js b/pages/home/home.js index 578b3a3..adcf5a2 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -1,6 +1,15 @@ -import { fetchHome } from '~/services/home/home'; -import { fetchGoodsList } from '~/services/good/fetchGoods'; -import { getbannerList } from '~/services/home/getbannerList'; +import { + fetchHome +} from '~/services/home/home'; +import { + fetchGoodsList +} from '~/services/good/fetchGoodsList'; +import { + getbannerList +} from '~/services/home/getbannerList'; +import { + getHomeCategoryListApi +} from '~/services/home/getHomeCategoryListApi'; import Toast from 'tdesign-miniprogram/toast/index'; Page({ @@ -23,8 +32,8 @@ Page({ }, goodListPagination: { - index: 0, - num: 20, + index: 1, + num: 6, }, privateData: { @@ -69,10 +78,18 @@ Page({ } }); - fetchHome().then(({ swiper, tabList }) => { + // 获取首页推荐类目 + getHomeCategoryListApi().then((res) => { this.setData({ - tabList, - // imgSrcs: swiper, + tabList: res.data, + }); + this.data.tabList.unshift({ + text: "精选推荐", + key: 0, + categoryGuid: 1, + }) + this.setData({ + tabList: res.data, pageLoading: false, }); this.loadGoodsList(true); @@ -81,14 +98,15 @@ Page({ tabChangeHandle(e) { this.privateData.tabIndex = e.detail; - this.loadGoodsList(true); + console.log(e.detail.value, 'tab的看看'); + this.loadGoodsList(true, e.detail.value); }, onReTry() { this.loadGoodsList(); }, - async loadGoodsList(fresh = false) { + async loadGoodsList(fresh = false, categoryGuid = 0) { if (fresh) { wx.pageScrollTo({ scrollTop: 0, @@ -100,15 +118,21 @@ Page({ }); const pageSize = this.goodListPagination.num; - let pageIndex = this.privateData.tabIndex * pageSize + this.goodListPagination.index + 1; + let pageIndex = this.goodListPagination.index + 1; if (fresh) { - pageIndex = 0; + pageIndex = 1; } + let params = { + pageNum: pageIndex, + pageSize: pageSize, + goodsCategoryGuid: categoryGuid + } + console.log(params, '看看参数'); try { - const nextList = await fetchGoodsList(pageIndex, pageSize); + const nextList = await fetchGoodsList(params); this.setData({ - goodsList: fresh ? nextList : this.data.goodsList.concat(nextList), + goodsList: fresh ? nextList.result : this.data.goodsList.concat(nextList.result), goodsListLoadStatus: 0, }); @@ -122,8 +146,12 @@ Page({ }, goodListClickHandle(e) { - const { index } = e.detail; - const { spuId } = this.data.goodsList[index]; + const { + index + } = e.detail; + const { + spuId + } = this.data.goodsList[index]; wx.navigateTo({ url: `/pages/goods/details/index?spuId=${spuId}`, }); @@ -143,10 +171,14 @@ Page({ }); }, - navToActivityDetail({ detail }) { - const { index: promotionID = 0 } = detail || {}; + navToActivityDetail({ + detail + }) { + const { + index: promotionID = 0 + } = detail || {}; wx.navigateTo({ url: `/pages/promotion-detail/index?promotion_id=${promotionID}`, }); }, -}); +}); \ No newline at end of file diff --git a/pages/order/order-confirm/pay.js b/pages/order/order-confirm/pay.js index f5f5b6d..ef02ef8 100644 --- a/pages/order/order-confirm/pay.js +++ b/pages/order/order-confirm/pay.js @@ -59,9 +59,9 @@ export const paySuccess = (payOrderInfo) => { .map((k) => `${k}=${params[k]}`) .join('&'); // 跳转支付结果页面 - // wx.redirectTo({ - // url: `/pages/order/pay-result/index?${paramsStr}` - // }); + wx.redirectTo({ + url: `/pages/order/pay-result/index?${paramsStr}` + }); }; export const payFail = (payOrderInfo, resultMsg) => { @@ -97,11 +97,11 @@ export const payFail = (payOrderInfo, resultMsg) => { icon: 'close-circle', }); console.log(resultMsg,'错误信息'); - // setTimeout(() => { - // wx.redirectTo({ - // url: '/pages/order/order-list/index' - // }); - // }, 2000); + setTimeout(() => { + wx.redirectTo({ + url: '/pages/order/order-list/index' + }); + }, 2000); } }; diff --git a/services/home/getHomeCategoryListApi.js b/services/home/getHomeCategoryListApi.js new file mode 100644 index 0000000..7c9229a --- /dev/null +++ b/services/home/getHomeCategoryListApi.js @@ -0,0 +1,19 @@ +import { + request +} from '../_utils/request'; + +/** 获取轮播图列表 */ +export function getHomeCategoryListApi() { + return new Promise((resolve, reject) => { + request({ + url: `HomeApi/getHomeCategoryListApi`, + method: 'GET', + success: function (res) { + resolve(res); + }, + fail: function (error) { + reject(error); + } + }); + }); +} \ No newline at end of file diff --git a/services/home/home.js b/services/home/home.js index 9aef66f..7a4af0b 100644 --- a/services/home/home.js +++ b/services/home/home.js @@ -6,7 +6,6 @@ function mockFetchHome() { const { genSwiperImageList } = require('~/model/swiper'); return delay().then(() => { return { - swiper: genSwiperImageList(), tabList: [ { text: '精选推荐',