feat 添加首页商品和类目推荐
This commit is contained in:
parent
39ff7198f6
commit
9827d07da5
@ -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 = {
|
||||
|
@ -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,8 +171,12 @@ 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}`,
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
19
services/home/getHomeCategoryListApi.js
Normal file
19
services/home/getHomeCategoryListApi.js
Normal file
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
@ -6,7 +6,6 @@ function mockFetchHome() {
|
||||
const { genSwiperImageList } = require('~/model/swiper');
|
||||
return delay().then(() => {
|
||||
return {
|
||||
swiper: genSwiperImageList(),
|
||||
tabList: [
|
||||
{
|
||||
text: '精选推荐',
|
||||
|
Loading…
Reference in New Issue
Block a user