1
This commit is contained in:
@ -203,7 +203,7 @@ export const GET_GOODS_CATEGORY = "/product/type/list";
|
|||||||
// 商品列表
|
// 商品列表
|
||||||
export const GET_GOODS_LIST = "/douyin/goods/product/online/query";
|
export const GET_GOODS_LIST = "/douyin/goods/product/online/query";
|
||||||
// 商品详情
|
// 商品详情
|
||||||
export const GET_GOODS_DETAIL = "/product/detail";
|
export const GET_GOODS_DETAIL = "/douyin/goods/product/detail";
|
||||||
|
|
||||||
// 获取优惠券列表
|
// 获取优惠券列表
|
||||||
export const GET_COUPON_LIST = "/app/coupon/coupon_list";
|
export const GET_COUPON_LIST = "/app/coupon/coupon_list";
|
||||||
|
|||||||
@ -159,6 +159,8 @@ export default {
|
|||||||
total: 0,
|
total: 0,
|
||||||
page: 1,
|
page: 1,
|
||||||
size: 10,
|
size: 10,
|
||||||
|
nextCursor: '',
|
||||||
|
hasMore: true,
|
||||||
refreshTriggered: false,
|
refreshTriggered: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
petOrderId: '',
|
petOrderId: '',
|
||||||
@ -245,24 +247,39 @@ export default {
|
|||||||
this.changeId = item.id
|
this.changeId = item.id
|
||||||
this.selectCategoryId = item.id;
|
this.selectCategoryId = item.id;
|
||||||
this.page = 1; // 切换分类时重置分页
|
this.page = 1; // 切换分类时重置分页
|
||||||
|
this.nextCursor = '';
|
||||||
|
this.hasMore = true;
|
||||||
this.goodsList = []; // 清空当前商品列表
|
this.goodsList = []; // 清空当前商品列表
|
||||||
this.showAllCategory = false;
|
this.showAllCategory = false;
|
||||||
this.getShopList(true); // 切换分类时强制刷新
|
this.getShopList(true); // 切换分类时强制刷新
|
||||||
},
|
},
|
||||||
// 商品列表
|
// 商品列表
|
||||||
getShopList(forceRefresh = false) {
|
getShopList(forceRefresh = false) {
|
||||||
// 如果不是第一页,直接请求不使用缓存(分页加载)
|
// 如果不是第一页且没有更多数据,直接返回
|
||||||
|
if (this.page > 1 && !this.hasMore) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
type: this.changeId,
|
||||||
|
p: this.page,
|
||||||
|
num: this.size,
|
||||||
|
keyword: "",
|
||||||
|
is_tui: 0,
|
||||||
|
cursor: this.nextCursor,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 第一页使用缓存,后续页直接请求
|
||||||
if (this.page > 1) {
|
if (this.page > 1) {
|
||||||
getGoodsListData({
|
getGoodsListData(params)
|
||||||
type: this.changeId,
|
|
||||||
p: this.page,
|
|
||||||
num: this.size,
|
|
||||||
keyword: "",
|
|
||||||
is_tui: 0,
|
|
||||||
})
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const list = res?.data || [];
|
const list = res?.data.data?.products || res?.data || [];
|
||||||
|
const hasMore = res?.data.data?.has_more;
|
||||||
|
const nextCursor = res?.data.data?.next_cursor || '';
|
||||||
|
|
||||||
this.goodsList = [...this.goodsList, ...list];
|
this.goodsList = [...this.goodsList, ...list];
|
||||||
|
this.hasMore = hasMore;
|
||||||
|
this.nextCursor = nextCursor;
|
||||||
this.total = res?.count || 0;
|
this.total = res?.count || 0;
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@ -273,21 +290,19 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 第一页使用缓存
|
// 第一页使用缓存
|
||||||
const params = {
|
|
||||||
type: this.changeId,
|
|
||||||
p: this.page,
|
|
||||||
num: this.size,
|
|
||||||
keyword: "",
|
|
||||||
is_tui: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
getCategoryGoodsWithCache(params, forceRefresh)
|
getCategoryGoodsWithCache(params, forceRefresh)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const list = res?.data || [];
|
const list = res?.data?.products || res?.data || [];
|
||||||
|
const hasMore = res?.data?.has_more;
|
||||||
|
const nextCursor = res?.data?.next_cursor || '';
|
||||||
|
|
||||||
// 只有当数据有变化时才更新商品列表,避免不必要的刷新
|
// 只有当数据有变化时才更新商品列表,避免不必要的刷新
|
||||||
if (res.hasChanged !== false || this.goodsList.length === 0) {
|
if (res.hasChanged !== false || this.goodsList.length === 0) {
|
||||||
this.goodsList = list;
|
this.goodsList = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.hasMore = hasMore;
|
||||||
|
this.nextCursor = nextCursor;
|
||||||
this.total = res?.count || list.length || 0;
|
this.total = res?.count || list.length || 0;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@ -401,10 +416,12 @@ export default {
|
|||||||
this.page = 1;
|
this.page = 1;
|
||||||
this.size = 10;
|
this.size = 10;
|
||||||
this.total = 0;
|
this.total = 0;
|
||||||
|
this.nextCursor = '';
|
||||||
|
this.hasMore = true;
|
||||||
this.getShopList(true); // 下拉刷新时强制刷新
|
this.getShopList(true); // 下拉刷新时强制刷新
|
||||||
},
|
},
|
||||||
onLoadMore() {
|
onLoadMore() {
|
||||||
if (!this.isLoading && this.total > this.goodsList.length) {
|
if (!this.isLoading && this.hasMore) {
|
||||||
this.page++;
|
this.page++;
|
||||||
this.getShopList();
|
this.getShopList();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<!-- 可拖动联系客服组件 -->
|
<!-- 可拖动联系客服组件 -->
|
||||||
<DraggableContact ref="draggableContact" :onClick="handleContactClick" />
|
<DraggableContact ref="draggableContact" :onClick="handleContactClick" />
|
||||||
|
|
||||||
<scroll-view class="homeContainer" scroll-y :show-scrollbar="false" :enhanced="true">
|
<scroll-view class="homeContainer" scroll-y :show-scrollbar="false" :enhanced="true" @scrolltolower="onLoadMore" :refresher-enabled="true" :refresher-triggered="refreshTriggered" @refresherrefresh="onRefresh">
|
||||||
<view class="swiperWrapper">
|
<view class="swiperWrapper">
|
||||||
<swiper indicator-dots="true" autoplay="true" interval="3000" duration="500" circular="true"
|
<swiper indicator-dots="true" autoplay="true" interval="3000" duration="500" circular="true"
|
||||||
class="swiper">
|
class="swiper">
|
||||||
@ -114,6 +114,8 @@ export default {
|
|||||||
goodsList: [], // 商品列表
|
goodsList: [], // 商品列表
|
||||||
goodsTotal: 0, // 商品总数
|
goodsTotal: 0, // 商品总数
|
||||||
goodPage: 1, // 当前页码
|
goodPage: 1, // 当前页码
|
||||||
|
nextCursor: '', // 下一页游标
|
||||||
|
hasMore: true, // 是否还有更多数据
|
||||||
isLoadingGoods: false, // 是否正在加载商品
|
isLoadingGoods: false, // 是否正在加载商品
|
||||||
refreshTriggered: false, // 刷新是否已触发
|
refreshTriggered: false, // 刷新是否已触发
|
||||||
cartCount: 0, // 购物车数量
|
cartCount: 0, // 购物车数量
|
||||||
@ -178,7 +180,11 @@ export default {
|
|||||||
return this.cartCount > 9 ? "9+" : this.cartCount;
|
return this.cartCount > 9 ? "9+" : this.cartCount;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
this.goodPage = 1;
|
||||||
|
this.nextCursor = '';
|
||||||
|
this.hasMore = true;
|
||||||
|
this.goodsList = [];
|
||||||
this.getGoodsList()
|
this.getGoodsList()
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
@ -188,17 +194,29 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
getGoodsList(forceRefresh = false) {
|
getGoodsList(forceRefresh = false) {
|
||||||
if (this.isLoadingGoods) return;
|
if (this.isLoadingGoods) return;
|
||||||
|
if (!this.hasMore && this.goodPage > 1) return;
|
||||||
this.isLoadingGoods = true;
|
this.isLoadingGoods = true;
|
||||||
const params = {
|
const params = {
|
||||||
type: 0
|
type: 0,
|
||||||
|
cursor: this.nextCursor
|
||||||
}
|
}
|
||||||
getHomeGoodsWithCache(params, forceRefresh)
|
getHomeGoodsWithCache(params, forceRefresh)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const list = res?.data.data.products || [];
|
const list = res?.data.data?.products || res?.data.data || [];
|
||||||
|
const hasMore = res?.data.data?.has_more;
|
||||||
|
const nextCursor = res?.data.data?.next_cursor || '';
|
||||||
|
|
||||||
// 只有当数据有变化时才更新商品列表,避免不必要的刷新
|
// 只有当数据有变化时才更新商品列表,避免不必要的刷新
|
||||||
if (res.hasChanged !== false || this.goodsList.length === 0) {
|
if (this.goodPage === 1) {
|
||||||
this.goodsList = list;
|
if (res.hasChanged !== false || this.goodsList.length === 0) {
|
||||||
|
this.goodsList = list;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.goodsList = [...this.goodsList, ...list];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.hasMore = hasMore;
|
||||||
|
this.nextCursor = nextCursor;
|
||||||
this.goodsTotal = res?.count || list.length || 0;
|
this.goodsTotal = res?.count || list.length || 0;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@ -362,24 +380,23 @@ export default {
|
|||||||
console.error('Error parsing image_list:', e);
|
console.error('Error parsing image_list:', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/client/order/create`,
|
url: `/pages/client/order/create?product_id=${goodsData.product.product_id}`,
|
||||||
success: (res) => {
|
// success: (res) => {
|
||||||
// 通过eventChannel向被打开页面传送数据
|
// // 通过eventChannel向被打开页面传送数据
|
||||||
res.eventChannel.emit("createOrder", {
|
// res.eventChannel.emit("createOrder", {
|
||||||
goodList: [{
|
// goodList: [{
|
||||||
...this.goodsData,
|
// ...this.goodsData,
|
||||||
goods_id:goodsData.product.out_id,
|
// goods_id:goodsData.product.out_id,
|
||||||
// price_id:goodsData.prices[0].price_id,
|
// // price_id:goodsData.prices[0].price_id,
|
||||||
product_pic: firstImageUrl,
|
// product_pic: firstImageUrl,
|
||||||
number:1,
|
// number:1,
|
||||||
goods_name: goodsData.product.product_name,
|
// goods_name: goodsData.product.product_name,
|
||||||
price_name: goodsData?.product.product_name,
|
// price_name: goodsData?.product.product_name,
|
||||||
goods_price: goodsData.sku.actual_amount / 100
|
// goods_price: goodsData.sku.actual_amount / 100
|
||||||
}, ],
|
// }, ],
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -403,6 +420,19 @@ export default {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onLoadMore() {
|
||||||
|
if (!this.isLoadingGoods && this.hasMore) {
|
||||||
|
this.goodPage++;
|
||||||
|
this.getGoodsList();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onRefresh() {
|
||||||
|
this.refreshTriggered = true;
|
||||||
|
this.goodPage = 1;
|
||||||
|
this.nextCursor = '';
|
||||||
|
this.hasMore = true;
|
||||||
|
this.getGoodsList(true);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -11,19 +11,19 @@
|
|||||||
>
|
>
|
||||||
<image
|
<image
|
||||||
class="goods-img"
|
class="goods-img"
|
||||||
:src="item.item_pic || item.product_pic"
|
:src="item.image "
|
||||||
mode="aspectFill"
|
mode="aspectFill"
|
||||||
/>
|
/>
|
||||||
<view class="goods-content">
|
<view class="goods-content">
|
||||||
<view class="goods-name">{{
|
<!-- <view class="goods-name">{{
|
||||||
item.item_name || item.product_name
|
item.name
|
||||||
}}</view>
|
}}</view> -->
|
||||||
<view class="price-wrapper">
|
<view class="price-wrapper">
|
||||||
<text class="final-price-label">到手价</text>
|
<text class="final-price-label">到手价</text>
|
||||||
<text class="final-price">¥{{ item.product_price || item.goods_price }}</text>
|
<text class="final-price">¥{{ item.price }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="sales-info">
|
<view class="sales-info">
|
||||||
<text class="sales-count">{{ item.goods_name }}</text>
|
<text class="sales-count">{{ item.name }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
<view class="order-create-bottom">
|
<view class="order-create-bottom">
|
||||||
<view class="price-info">
|
<view class="price-info">
|
||||||
<text class="current-price">¥{{ payPrice.toFixed(2) }}</text>
|
<text class="current-price">¥{{ orderPrice.toFixed(2) }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="pay-btn" @click="createOrder">
|
<view class="pay-btn" @click="createOrder">
|
||||||
<text class="pay-btn-text">立即购买</text>
|
<text class="pay-btn-text">立即购买</text>
|
||||||
@ -103,6 +103,10 @@ import { getAddressInfo } from "../../../api/address";
|
|||||||
import { COUPON_TYPE_GOODS } from "../../../constants/app.business";
|
import { COUPON_TYPE_GOODS } from "../../../constants/app.business";
|
||||||
import { walletTransaction } from "../../../api/login";
|
import { walletTransaction } from "../../../api/login";
|
||||||
import { imgPrefix, jumpToWeChat } from "@/utils/common";
|
import { imgPrefix, jumpToWeChat } from "@/utils/common";
|
||||||
|
import {
|
||||||
|
addCart,
|
||||||
|
getGoodsDetail,
|
||||||
|
} from "@/api/shop";
|
||||||
|
|
||||||
const sliverList = [
|
const sliverList = [
|
||||||
{
|
{
|
||||||
@ -124,7 +128,9 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
orderData:[],
|
||||||
payPrice: 0,
|
payPrice: 0,
|
||||||
|
orPrice:0,
|
||||||
type: "",
|
type: "",
|
||||||
orderData: [],
|
orderData: [],
|
||||||
addressInfo: {},
|
addressInfo: {},
|
||||||
@ -170,75 +176,89 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
const { type, petOrderId = "", petOrderAddressId = "" } = option;
|
console.log(option,'?')
|
||||||
this.type = type;
|
this.getGoodsList(option.product_id )
|
||||||
this.petOrderId = petOrderId;
|
// const { type, petOrderId = "", petOrderAddressId = "" } = option;
|
||||||
this.petOrderAddressId = petOrderAddressId;
|
// this.type = type;
|
||||||
|
// this.petOrderId = petOrderId;
|
||||||
|
// this.petOrderAddressId = petOrderAddressId;
|
||||||
|
|
||||||
if (petOrderAddressId) {
|
// if (petOrderAddressId) {
|
||||||
getAddressInfo(petOrderAddressId).then((res) => {
|
// getAddressInfo(petOrderAddressId).then((res) => {
|
||||||
this.addressInfo = {
|
// this.addressInfo = {
|
||||||
...res?.info,
|
// ...res?.info,
|
||||||
};
|
// };
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
uni.$on("selectAddress", this.addressChange);
|
// uni.$on("selectAddress", this.addressChange);
|
||||||
|
|
||||||
const eventChannel = this.getOpenerEventChannel();
|
// const eventChannel = this.getOpenerEventChannel();
|
||||||
eventChannel.on("createOrder", (data) => {
|
// eventChannel.on("createOrder", (data) => {
|
||||||
console.log(data,'--=?')
|
// console.log(data,'--=?')
|
||||||
const extractFirstImage = (imageList) => {
|
// const extractFirstImage = (imageList) => {
|
||||||
if (!imageList) return "";
|
// if (!imageList) return "";
|
||||||
try {
|
// try {
|
||||||
const parsedList =
|
// const parsedList =
|
||||||
typeof imageList === "string" ? JSON.parse(imageList) : imageList;
|
// typeof imageList === "string" ? JSON.parse(imageList) : imageList;
|
||||||
if (Array.isArray(parsedList) && parsedList.length > 0) {
|
// if (Array.isArray(parsedList) && parsedList.length > 0) {
|
||||||
return parsedList[0].url || parsedList[0] || "";
|
// return parsedList[0].url || parsedList[0] || "";
|
||||||
}
|
// }
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
console.error("Error parsing image_list:", e);
|
// console.error("Error parsing image_list:", e);
|
||||||
}
|
// }
|
||||||
return "";
|
// return "";
|
||||||
};
|
// };
|
||||||
|
|
||||||
this.orderData = (data?.goodList || []).map((item) => {
|
// this.orderData = (data?.goodList || []).map((item) => {
|
||||||
let processedItem = { ...item };
|
// let processedItem = { ...item };
|
||||||
if (processedItem.product_pic) {
|
// if (processedItem.product_pic) {
|
||||||
if (
|
// if (
|
||||||
typeof processedItem.product_pic === "string" &&
|
// typeof processedItem.product_pic === "string" &&
|
||||||
(processedItem.product_pic.startsWith("[") ||
|
// (processedItem.product_pic.startsWith("[") ||
|
||||||
processedItem.product_pic.startsWith("{"))
|
// processedItem.product_pic.startsWith("{"))
|
||||||
) {
|
// ) {
|
||||||
const extractedUrl = extractFirstImage(processedItem.product_pic);
|
// const extractedUrl = extractFirstImage(processedItem.product_pic);
|
||||||
if (extractedUrl) {
|
// if (extractedUrl) {
|
||||||
processedItem.product_pic = extractedUrl;
|
// processedItem.product_pic = extractedUrl;
|
||||||
}
|
// }
|
||||||
} else if (Array.isArray(processedItem.product_pic)) {
|
// } else if (Array.isArray(processedItem.product_pic)) {
|
||||||
const extractedUrl = extractFirstImage(processedItem.product_pic);
|
// const extractedUrl = extractFirstImage(processedItem.product_pic);
|
||||||
if (extractedUrl) {
|
// if (extractedUrl) {
|
||||||
processedItem.product_pic = extractedUrl;
|
// processedItem.product_pic = extractedUrl;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return processedItem;
|
// return processedItem;
|
||||||
});
|
// });
|
||||||
|
|
||||||
this.payPrice = this.orderData.reduce(
|
// this.payPrice = this.orderData.reduce(
|
||||||
(sum, item) =>
|
// (sum, item) =>
|
||||||
sum +
|
// sum +
|
||||||
Number((item.product_price || item.goods_price) * item.number || 0),
|
// Number((item.product_price || item.goods_price) * item.number || 0),
|
||||||
0
|
// 0
|
||||||
);
|
// );
|
||||||
console.log(data, "--=?");
|
// console.log(data, "--=?");
|
||||||
const price = this.orderData.reduce(
|
// const price = this.orderData.reduce(
|
||||||
(total, prev) => total + +prev.item_price,
|
// (total, prev) => total + +prev.item_price,
|
||||||
0
|
// 0
|
||||||
);
|
// );
|
||||||
this.orderPrice = +price.toFixed(2);
|
// this.orderPrice = +price.toFixed(2);
|
||||||
this.confirmPrice = +(this.orderPrice - this.couponFee).toFixed(2);
|
// this.confirmPrice = +(this.orderPrice - this.couponFee).toFixed(2);
|
||||||
});
|
// });
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getGoodsList(id) {
|
||||||
|
getGoodsDetail({
|
||||||
|
product_id:id,
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
this.orderData = res.data
|
||||||
|
this.orPrice = res.data.price
|
||||||
|
this.orderPrice = res.data[0].price
|
||||||
|
// console.log(res,'--=')
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
createOrder(isPrePay) {
|
createOrder(isPrePay) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!isPrePay) {
|
if (!isPrePay) {
|
||||||
@ -267,14 +287,14 @@ export default {
|
|||||||
tradeOption: res.data.tradeOption,
|
tradeOption: res.data.tradeOption,
|
||||||
payment: res.data.payment,
|
payment: res.data.payment,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
const { orderId, outOrderNo } = res;
|
const { orderId, outOrderNo } = res;
|
||||||
console.log("success res", res);
|
console.log("success res", res);
|
||||||
console.log("orderId", orderId, "outOrderNo", outOrderNo);
|
console.log("orderId", orderId, "outOrderNo", outOrderNo);
|
||||||
this.orderId = orderId;
|
this.orderId = orderId;
|
||||||
this.outOrderNo = outOrderNo;
|
this.outOrderNo = outOrderNo;
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/client/order/list",
|
url: "/pages/client/order/list",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fail: (res) => {
|
fail: (res) => {
|
||||||
console.log("fail res", res);
|
console.log("fail res", res);
|
||||||
|
|||||||
@ -170,6 +170,8 @@ export default {
|
|||||||
total: 0,
|
total: 0,
|
||||||
page: 1,
|
page: 1,
|
||||||
size: 10,
|
size: 10,
|
||||||
|
nextCursor: '',
|
||||||
|
hasMore: true,
|
||||||
showModal: false,
|
showModal: false,
|
||||||
addGoodInfo: null,
|
addGoodInfo: null,
|
||||||
showContactModal: false,
|
showContactModal: false,
|
||||||
@ -263,6 +265,9 @@ export default {
|
|||||||
initData() {
|
initData() {
|
||||||
this.getCategoryList();
|
this.getCategoryList();
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
|
this.nextCursor = '';
|
||||||
|
this.hasMore = true;
|
||||||
|
this.goodsList = [];
|
||||||
this.getGoodsList();
|
this.getGoodsList();
|
||||||
this.getCartListData();
|
this.getCartListData();
|
||||||
},
|
},
|
||||||
@ -281,13 +286,25 @@ export default {
|
|||||||
// 商品列表
|
// 商品列表
|
||||||
getGoodsList() {
|
getGoodsList() {
|
||||||
if (this.isLoading) return;
|
if (this.isLoading) return;
|
||||||
|
if (!this.hasMore && this.page > 1) return;
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
getGoodsListData({
|
getGoodsListData({
|
||||||
type: this.selectCategoryId ? this.selectCategoryId : 0,
|
type: this.selectCategoryId ? this.selectCategoryId : 0,
|
||||||
|
cursor: this.nextCursor,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const list = res?.data.data.products || [];
|
const list = res?.data.data.products || [];
|
||||||
this.goodsList = list;
|
const hasMore = res?.data.data.has_more;
|
||||||
|
const nextCursor = res?.data.data.next_cursor || '';
|
||||||
|
|
||||||
|
if (this.page === 1) {
|
||||||
|
this.goodsList = list;
|
||||||
|
} else {
|
||||||
|
this.goodsList = [...this.goodsList, ...list];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.hasMore = hasMore;
|
||||||
|
this.nextCursor = nextCursor;
|
||||||
this.total = res?.count || 0;
|
this.total = res?.count || 0;
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@ -300,10 +317,12 @@ export default {
|
|||||||
this.page = 1;
|
this.page = 1;
|
||||||
this.size = 10;
|
this.size = 10;
|
||||||
this.total = 0;
|
this.total = 0;
|
||||||
|
this.nextCursor = '';
|
||||||
|
this.hasMore = true;
|
||||||
this.getGoodsList();
|
this.getGoodsList();
|
||||||
},
|
},
|
||||||
onLoadMore() {
|
onLoadMore() {
|
||||||
if (!this.isLoading && this.total > this.goodsList.length) {
|
if (!this.isLoading && this.hasMore) {
|
||||||
this.page++;
|
this.page++;
|
||||||
this.getGoodsList();
|
this.getGoodsList();
|
||||||
}
|
}
|
||||||
@ -378,20 +397,20 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/client/order/create`,
|
url: `/pages/client/order/create?product_id=${goodsData.product.product_id}`,
|
||||||
success: (res) => {
|
// success: (res) => {
|
||||||
// 通过eventChannel向被打开页面传送数据
|
// // 通过eventChannel向被打开页面传送数据
|
||||||
res.eventChannel.emit("createOrder", {
|
// res.eventChannel.emit("createOrder", {
|
||||||
goodList: [{
|
// goodList: [{
|
||||||
goods_id:goodsData.product.out_id,
|
// goods_id:goodsData.product.out_id,
|
||||||
product_pic: firstImageUrl,
|
// product_pic: firstImageUrl,
|
||||||
number:1,
|
// number:1,
|
||||||
goods_name: goodsData.product.product_name,
|
// goods_name: goodsData.product.product_name,
|
||||||
price_name: goodsData?.product.product_name,
|
// price_name: goodsData?.product.product_name,
|
||||||
goods_price: goodsData.sku.actual_amount / 100
|
// goods_price: goodsData.sku.actual_amount / 100
|
||||||
}, ],
|
// }, ],
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 购物车列表
|
// 购物车列表
|
||||||
@ -419,31 +438,31 @@ export default {
|
|||||||
// 立即购买
|
// 立即购买
|
||||||
handleBuyNow(good) {
|
handleBuyNow(good) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/client/order/create`,
|
url: `/pages/client/order/create?product_id=${good.product.product_id}`,
|
||||||
success: (res) => {
|
// success: (res) => {
|
||||||
// 通过 eventChannel 向被打开页面传送数据
|
// // 通过 eventChannel 向被打开页面传送数据
|
||||||
res.eventChannel.emit("createOrder", {
|
// res.eventChannel.emit("createOrder", {
|
||||||
goodList: [
|
// goodList: [
|
||||||
{
|
// {
|
||||||
goods_id: good.product_id,
|
// goods_id: good.product_id,
|
||||||
item_type: good.type,
|
// item_type: good.type,
|
||||||
price_id: good.prices?.[0]?.price_id,
|
// price_id: good.prices?.[0]?.price_id,
|
||||||
price_desc: good.prices?.[0]?.price_desc,
|
// price_desc: good.prices?.[0]?.price_desc,
|
||||||
item_name: good.product_name,
|
// item_name: good.product_name,
|
||||||
item_price: good.prices?.[0]?.actual_price,
|
// item_price: good.prices?.[0]?.actual_price,
|
||||||
item_pic: good.product_pic,
|
// item_pic: good.product_pic,
|
||||||
number: 1,
|
// number: 1,
|
||||||
product_id: good.product_id,
|
// product_id: good.product_id,
|
||||||
product_name: good.product_name,
|
// product_name: good.product_name,
|
||||||
product_pic: good.product_pic,
|
// product_pic: good.product_pic,
|
||||||
goods_price: good.prices?.[0]?.actual_price / 100,
|
// goods_price: good.prices?.[0]?.actual_price / 100,
|
||||||
product_price: good.prices?.[0]?.actual_price / 100,
|
// product_price: good.prices?.[0]?.actual_price / 100,
|
||||||
original_price: good.prices?.[0]?.original_price,
|
// original_price: good.prices?.[0]?.original_price,
|
||||||
yunfei: good.yunfei || 0,
|
// yunfei: good.yunfei || 0,
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -122,7 +122,9 @@ export function getHomeGoodsWithCache(params, forceRefresh = false) {
|
|||||||
|
|
||||||
// 无论是否有缓存,都请求最新数据进行对比
|
// 无论是否有缓存,都请求最新数据进行对比
|
||||||
getGoodsListData(params).then(res => {
|
getGoodsListData(params).then(res => {
|
||||||
const newData = res?.data.data.products || []
|
const newData = res?.data.data?.products || res?.data.data || []
|
||||||
|
const hasMore = res?.data.data?.has_more
|
||||||
|
const nextCursor = res?.data.data?.next_cursor || ''
|
||||||
const newHash = calculateDataHash(newData)
|
const newHash = calculateDataHash(newData)
|
||||||
|
|
||||||
// 检查数据是否有变化
|
// 检查数据是否有变化
|
||||||
@ -136,6 +138,15 @@ export function getHomeGoodsWithCache(params, forceRefresh = false) {
|
|||||||
if (!cache || forceRefresh) {
|
if (!cache || forceRefresh) {
|
||||||
resolve({
|
resolve({
|
||||||
...res,
|
...res,
|
||||||
|
data: {
|
||||||
|
...res.data,
|
||||||
|
data: {
|
||||||
|
...res.data.data,
|
||||||
|
products: newData,
|
||||||
|
has_more: hasMore,
|
||||||
|
next_cursor: nextCursor
|
||||||
|
}
|
||||||
|
},
|
||||||
fromCache: false,
|
fromCache: false,
|
||||||
hasChanged: true
|
hasChanged: true
|
||||||
})
|
})
|
||||||
@ -143,6 +154,15 @@ export function getHomeGoodsWithCache(params, forceRefresh = false) {
|
|||||||
// 如果已有缓存但数据有变化,通知更新
|
// 如果已有缓存但数据有变化,通知更新
|
||||||
resolve({
|
resolve({
|
||||||
...res,
|
...res,
|
||||||
|
data: {
|
||||||
|
...res.data,
|
||||||
|
data: {
|
||||||
|
...res.data.data,
|
||||||
|
products: newData,
|
||||||
|
has_more: hasMore,
|
||||||
|
next_cursor: nextCursor
|
||||||
|
}
|
||||||
|
},
|
||||||
fromCache: false,
|
fromCache: false,
|
||||||
hasChanged: true
|
hasChanged: true
|
||||||
})
|
})
|
||||||
@ -151,7 +171,13 @@ export function getHomeGoodsWithCache(params, forceRefresh = false) {
|
|||||||
// 数据没有变化,更新缓存时间戳
|
// 数据没有变化,更新缓存时间戳
|
||||||
cache.timestamp = Date.now()
|
cache.timestamp = Date.now()
|
||||||
resolve({
|
resolve({
|
||||||
data: { data: { products: cache.data } },
|
data: {
|
||||||
|
data: {
|
||||||
|
products: cache.data,
|
||||||
|
has_more: hasMore,
|
||||||
|
next_cursor: nextCursor
|
||||||
|
}
|
||||||
|
},
|
||||||
fromCache: true,
|
fromCache: true,
|
||||||
hasChanged: false
|
hasChanged: false
|
||||||
})
|
})
|
||||||
@ -160,7 +186,13 @@ export function getHomeGoodsWithCache(params, forceRefresh = false) {
|
|||||||
// 如果请求失败但有缓存,返回缓存
|
// 如果请求失败但有缓存,返回缓存
|
||||||
if (cache) {
|
if (cache) {
|
||||||
resolve({
|
resolve({
|
||||||
data: { data: { products: cache.data } },
|
data: {
|
||||||
|
data: {
|
||||||
|
products: cache.data,
|
||||||
|
has_more: false,
|
||||||
|
next_cursor: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
fromCache: true,
|
fromCache: true,
|
||||||
error: err
|
error: err
|
||||||
})
|
})
|
||||||
@ -194,7 +226,9 @@ export function getCategoryGoodsWithCache(params, forceRefresh = false) {
|
|||||||
|
|
||||||
// 无论是否有缓存,都请求最新数据进行对比
|
// 无论是否有缓存,都请求最新数据进行对比
|
||||||
getGoodsListData(params).then(res => {
|
getGoodsListData(params).then(res => {
|
||||||
const newData = res?.data || []
|
const newData = res?.data.data?.products || res?.data || []
|
||||||
|
const hasMore = res?.data.data?.has_more
|
||||||
|
const nextCursor = res?.data.data?.next_cursor || ''
|
||||||
const newHash = calculateDataHash(newData)
|
const newHash = calculateDataHash(newData)
|
||||||
|
|
||||||
// 检查数据是否有变化
|
// 检查数据是否有变化
|
||||||
@ -207,12 +241,30 @@ export function getCategoryGoodsWithCache(params, forceRefresh = false) {
|
|||||||
if (!cache || forceRefresh) {
|
if (!cache || forceRefresh) {
|
||||||
resolve({
|
resolve({
|
||||||
...res,
|
...res,
|
||||||
|
data: {
|
||||||
|
...res.data,
|
||||||
|
data: {
|
||||||
|
...res.data.data,
|
||||||
|
products: newData,
|
||||||
|
has_more: hasMore,
|
||||||
|
next_cursor: nextCursor
|
||||||
|
}
|
||||||
|
},
|
||||||
fromCache: false,
|
fromCache: false,
|
||||||
hasChanged: true
|
hasChanged: true
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
resolve({
|
resolve({
|
||||||
...res,
|
...res,
|
||||||
|
data: {
|
||||||
|
...res.data,
|
||||||
|
data: {
|
||||||
|
...res.data.data,
|
||||||
|
products: newData,
|
||||||
|
has_more: hasMore,
|
||||||
|
next_cursor: nextCursor
|
||||||
|
}
|
||||||
|
},
|
||||||
fromCache: false,
|
fromCache: false,
|
||||||
hasChanged: true
|
hasChanged: true
|
||||||
})
|
})
|
||||||
@ -221,7 +273,12 @@ export function getCategoryGoodsWithCache(params, forceRefresh = false) {
|
|||||||
// 数据没有变化,更新缓存时间戳
|
// 数据没有变化,更新缓存时间戳
|
||||||
cache.timestamp = Date.now()
|
cache.timestamp = Date.now()
|
||||||
resolve({
|
resolve({
|
||||||
data: cache.data,
|
data: newData,
|
||||||
|
data: {
|
||||||
|
products: cache.data,
|
||||||
|
has_more: hasMore,
|
||||||
|
next_cursor: nextCursor
|
||||||
|
},
|
||||||
count: cache.data.length,
|
count: cache.data.length,
|
||||||
fromCache: true,
|
fromCache: true,
|
||||||
hasChanged: false
|
hasChanged: false
|
||||||
@ -232,6 +289,11 @@ export function getCategoryGoodsWithCache(params, forceRefresh = false) {
|
|||||||
if (cache) {
|
if (cache) {
|
||||||
resolve({
|
resolve({
|
||||||
data: cache.data,
|
data: cache.data,
|
||||||
|
data: {
|
||||||
|
products: cache.data,
|
||||||
|
has_more: false,
|
||||||
|
next_cursor: ''
|
||||||
|
},
|
||||||
count: cache.data.length,
|
count: cache.data.length,
|
||||||
fromCache: true,
|
fromCache: true,
|
||||||
error: err
|
error: err
|
||||||
|
|||||||
Reference in New Issue
Block a user