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';
|
import Toast from 'tdesign-miniprogram/toast/index';
|
||||||
|
|
||||||
const initFilters = {
|
const initFilters = {
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
import { fetchHome } from '~/services/home/home';
|
import {
|
||||||
import { fetchGoodsList } from '~/services/good/fetchGoods';
|
fetchHome
|
||||||
import { getbannerList } from '~/services/home/getbannerList';
|
} 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';
|
import Toast from 'tdesign-miniprogram/toast/index';
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@ -23,8 +32,8 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
goodListPagination: {
|
goodListPagination: {
|
||||||
index: 0,
|
index: 1,
|
||||||
num: 20,
|
num: 6,
|
||||||
},
|
},
|
||||||
|
|
||||||
privateData: {
|
privateData: {
|
||||||
@ -69,10 +78,18 @@ Page({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchHome().then(({ swiper, tabList }) => {
|
// 获取首页推荐类目
|
||||||
|
getHomeCategoryListApi().then((res) => {
|
||||||
this.setData({
|
this.setData({
|
||||||
tabList,
|
tabList: res.data,
|
||||||
// imgSrcs: swiper,
|
});
|
||||||
|
this.data.tabList.unshift({
|
||||||
|
text: "精选推荐",
|
||||||
|
key: 0,
|
||||||
|
categoryGuid: 1,
|
||||||
|
})
|
||||||
|
this.setData({
|
||||||
|
tabList: res.data,
|
||||||
pageLoading: false,
|
pageLoading: false,
|
||||||
});
|
});
|
||||||
this.loadGoodsList(true);
|
this.loadGoodsList(true);
|
||||||
@ -81,14 +98,15 @@ Page({
|
|||||||
|
|
||||||
tabChangeHandle(e) {
|
tabChangeHandle(e) {
|
||||||
this.privateData.tabIndex = e.detail;
|
this.privateData.tabIndex = e.detail;
|
||||||
this.loadGoodsList(true);
|
console.log(e.detail.value, 'tab的看看');
|
||||||
|
this.loadGoodsList(true, e.detail.value);
|
||||||
},
|
},
|
||||||
|
|
||||||
onReTry() {
|
onReTry() {
|
||||||
this.loadGoodsList();
|
this.loadGoodsList();
|
||||||
},
|
},
|
||||||
|
|
||||||
async loadGoodsList(fresh = false) {
|
async loadGoodsList(fresh = false, categoryGuid = 0) {
|
||||||
if (fresh) {
|
if (fresh) {
|
||||||
wx.pageScrollTo({
|
wx.pageScrollTo({
|
||||||
scrollTop: 0,
|
scrollTop: 0,
|
||||||
@ -100,15 +118,21 @@ Page({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const pageSize = this.goodListPagination.num;
|
const pageSize = this.goodListPagination.num;
|
||||||
let pageIndex = this.privateData.tabIndex * pageSize + this.goodListPagination.index + 1;
|
let pageIndex = this.goodListPagination.index + 1;
|
||||||
if (fresh) {
|
if (fresh) {
|
||||||
pageIndex = 0;
|
pageIndex = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let params = {
|
||||||
|
pageNum: pageIndex,
|
||||||
|
pageSize: pageSize,
|
||||||
|
goodsCategoryGuid: categoryGuid
|
||||||
|
}
|
||||||
|
console.log(params, '看看参数');
|
||||||
try {
|
try {
|
||||||
const nextList = await fetchGoodsList(pageIndex, pageSize);
|
const nextList = await fetchGoodsList(params);
|
||||||
this.setData({
|
this.setData({
|
||||||
goodsList: fresh ? nextList : this.data.goodsList.concat(nextList),
|
goodsList: fresh ? nextList.result : this.data.goodsList.concat(nextList.result),
|
||||||
goodsListLoadStatus: 0,
|
goodsListLoadStatus: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -122,8 +146,12 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
goodListClickHandle(e) {
|
goodListClickHandle(e) {
|
||||||
const { index } = e.detail;
|
const {
|
||||||
const { spuId } = this.data.goodsList[index];
|
index
|
||||||
|
} = e.detail;
|
||||||
|
const {
|
||||||
|
spuId
|
||||||
|
} = this.data.goodsList[index];
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: `/pages/goods/details/index?spuId=${spuId}`,
|
url: `/pages/goods/details/index?spuId=${spuId}`,
|
||||||
});
|
});
|
||||||
@ -143,10 +171,14 @@ Page({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
navToActivityDetail({ detail }) {
|
navToActivityDetail({
|
||||||
const { index: promotionID = 0 } = detail || {};
|
detail
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
index: promotionID = 0
|
||||||
|
} = detail || {};
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: `/pages/promotion-detail/index?promotion_id=${promotionID}`,
|
url: `/pages/promotion-detail/index?promotion_id=${promotionID}`,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
@ -59,9 +59,9 @@ export const paySuccess = (payOrderInfo) => {
|
|||||||
.map((k) => `${k}=${params[k]}`)
|
.map((k) => `${k}=${params[k]}`)
|
||||||
.join('&');
|
.join('&');
|
||||||
// 跳转支付结果页面
|
// 跳转支付结果页面
|
||||||
// wx.redirectTo({
|
wx.redirectTo({
|
||||||
// url: `/pages/order/pay-result/index?${paramsStr}`
|
url: `/pages/order/pay-result/index?${paramsStr}`
|
||||||
// });
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const payFail = (payOrderInfo, resultMsg) => {
|
export const payFail = (payOrderInfo, resultMsg) => {
|
||||||
@ -97,11 +97,11 @@ export const payFail = (payOrderInfo, resultMsg) => {
|
|||||||
icon: 'close-circle',
|
icon: 'close-circle',
|
||||||
});
|
});
|
||||||
console.log(resultMsg,'错误信息');
|
console.log(resultMsg,'错误信息');
|
||||||
// setTimeout(() => {
|
setTimeout(() => {
|
||||||
// wx.redirectTo({
|
wx.redirectTo({
|
||||||
// url: '/pages/order/order-list/index'
|
url: '/pages/order/order-list/index'
|
||||||
// });
|
});
|
||||||
// }, 2000);
|
}, 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');
|
const { genSwiperImageList } = require('~/model/swiper');
|
||||||
return delay().then(() => {
|
return delay().then(() => {
|
||||||
return {
|
return {
|
||||||
swiper: genSwiperImageList(),
|
|
||||||
tabList: [
|
tabList: [
|
||||||
{
|
{
|
||||||
text: '精选推荐',
|
text: '精选推荐',
|
||||||
|
Loading…
Reference in New Issue
Block a user