|
|
@@ -85,7 +85,8 @@ import CartModal from "./components/CartModal.vue";
|
|
|
import SelectCouponModal from "./components/SelectCouponModal.vue";
|
|
|
import { go } from "@/utils/utils.js";
|
|
|
import { getFileUrl } from "@/utils/file.js";
|
|
|
-import { DiningOrderFood, GetCategoriesWithCuisines, GetStoreDetail, getOrderSseConfig, GetOrderCart, PostOrderCartAdd, PostOrderCartUpdate, PostOrderCartClear, GetUserOwnedCouponList } from "@/api/dining.js";
|
|
|
+import { DiningOrderFood, GetCategoriesWithCuisines, GetStoreDetail, getOrderSseConfig, GetOrderCart, PostOrderCartAdd, PostOrderCartUpdate, PostOrderCartClear, GetUserCouponList } from "@/api/dining.js";
|
|
|
+import { normalizeUserCouponListItem } from "@/utils/couponNormalize.js";
|
|
|
import { createSSEConnection } from "@/utils/sse.js";
|
|
|
|
|
|
// 商品图片:取第一张,若为逗号分隔字符串则截取逗号前的第一张
|
|
|
@@ -129,7 +130,7 @@ const couponModalOpen = ref(false);
|
|
|
const cartModalOpen = ref(false);
|
|
|
const selectCouponModalOpen = ref(false);
|
|
|
const selectCouponViewOnly = ref(false); // true=左下角仅查看,false=购物车内可选
|
|
|
-const discountAmount = ref(12); // 优惠金额,示例数据
|
|
|
+const discountAmount = ref(0);
|
|
|
const selectedCouponId = ref(null); // 选中的优惠券ID
|
|
|
|
|
|
// 分类列表(由接口 /store/info/categories 返回后赋值)
|
|
|
@@ -263,40 +264,11 @@ const displayTotalAmount = computed(() => {
|
|
|
return displayCartList.value.reduce((sum, item) => sum + getItemLinePrice(item), 0);
|
|
|
});
|
|
|
|
|
|
-// 优惠券列表(由接口 /dining/coupon/storeUsableList 返回后赋值)
|
|
|
+// 优惠券列表(CouponModal,与券包同源接口数据)
|
|
|
const couponList = ref([]);
|
|
|
-// 门店可用优惠券列表(选择优惠券弹窗用,与 couponList 同步自同一接口)
|
|
|
+// 门店可用优惠券(SelectCouponModal):GET /dining/coupon/getUserCouponList,tabType=0 未使用
|
|
|
const storeUsableCouponList = ref([]);
|
|
|
|
|
|
-// 规范化接口优惠券项为弹窗所需格式(对接 getUserCouponList 返回的 data:id/couponId/userCouponId、name、couponType、discountRate、minimumSpendingAmount、expirationTime 等)
|
|
|
-// couponType 1=满减券显示 nominalValue 为金额,2=折扣券显示 discountRate 为折扣力度
|
|
|
-function normalizeCouponItem(item) {
|
|
|
- if (!item || typeof item !== 'object') return null;
|
|
|
- const raw = item;
|
|
|
- const couponType = Number(raw.couponType) || 0;
|
|
|
- const nominalValue = Number(raw.nominalValue ?? raw.amount ?? 0) || 0;
|
|
|
- const discountRate = ((Number(raw.discountRate) || 0) / 10) || 0;
|
|
|
- const minAmount = Number(raw.minimumSpendingAmount ?? raw.minAmount ?? raw.min_amount ?? 0) || 0;
|
|
|
- const isReceived = raw.canReceived === false;
|
|
|
- let amountDisplay = nominalValue + '元';
|
|
|
- if (couponType === 1) {
|
|
|
- amountDisplay = nominalValue + '元';
|
|
|
- } else if (couponType === 2 && discountRate > 0) {
|
|
|
- amountDisplay = (discountRate % 1 === 0 ? discountRate : discountRate.toFixed(1)) + '折';
|
|
|
- }
|
|
|
- return {
|
|
|
- id: raw.userCouponId ?? raw.id ?? raw.couponId ?? raw.coupon_id ?? '',
|
|
|
- amount: nominalValue,
|
|
|
- minAmount,
|
|
|
- name: raw.name ?? raw.title ?? raw.couponName ?? '',
|
|
|
- expireDate: raw.expirationTime ?? raw.endGetDate ?? raw.validDate ?? raw.expireDate ?? raw.endTime ?? '',
|
|
|
- isReceived,
|
|
|
- couponType,
|
|
|
- discountRate,
|
|
|
- amountDisplay
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
// 可用的优惠券列表(选择优惠券弹窗用,来自 storeUsableCouponList)
|
|
|
const availableCoupons = computed(() => storeUsableCouponList.value);
|
|
|
|
|
|
@@ -719,15 +691,22 @@ const handleDecrease = (item) => {
|
|
|
if (food && (food.quantity || 0) > 0) updateFoodQuantity(food, -1);
|
|
|
};
|
|
|
|
|
|
-// 拉取用户优惠券列表(GET /dining/coupon/userOwnedByStore,入参 storeId),列表在 SelectCouponModal 中展示
|
|
|
+// 拉取用户优惠券列表(GET /dining/coupon/getUserCouponList,与券包页一致:storeId、tabType、page、size)
|
|
|
const fetchUserOwnedCoupons = async () => {
|
|
|
const storeId = uni.getStorageSync('currentStoreId') || '';
|
|
|
try {
|
|
|
- const res = await GetUserOwnedCouponList({ storeId });
|
|
|
- // 接口返回 { code, data: [...], msg, success },请求层可能只返回 data,故 res 可能为数组
|
|
|
+ const res = await GetUserCouponList({
|
|
|
+ storeId,
|
|
|
+ tabType: 0,
|
|
|
+ page: 1,
|
|
|
+ size: 20
|
|
|
+ });
|
|
|
const list = Array.isArray(res) ? res : (res?.data ?? res?.records ?? res?.list ?? []);
|
|
|
- const normalized = (Array.isArray(list) ? list : []).map((item) => normalizeCouponItem(item)).filter(Boolean);
|
|
|
+ const normalized = (Array.isArray(list) ? list : [])
|
|
|
+ .map((item) => normalizeUserCouponListItem(item, 0))
|
|
|
+ .filter(Boolean);
|
|
|
storeUsableCouponList.value = normalized;
|
|
|
+ couponList.value = normalized;
|
|
|
return true;
|
|
|
} catch (err) {
|
|
|
console.error('获取用户优惠券失败:', err);
|
|
|
@@ -749,7 +728,8 @@ const openSelectCouponModal = async (viewOnly = false) => {
|
|
|
const first = list[0];
|
|
|
const firstId = first.id != null && first.id !== '' ? String(first.id) : null;
|
|
|
selectedCouponId.value = firstId;
|
|
|
- discountAmount.value = first.amount ?? 0;
|
|
|
+ discountAmount.value =
|
|
|
+ Number(first.nominalValue) || Number(first.amount) || 0;
|
|
|
} else {
|
|
|
selectedCouponId.value = null;
|
|
|
discountAmount.value = 0;
|
|
|
@@ -775,7 +755,8 @@ const handleCouponSelect = ({ coupon, index, selectedId }) => {
|
|
|
selectedCouponId.value = selectedId != null && selectedId !== '' ? String(selectedId) : null;
|
|
|
// 根据选中的优惠券更新优惠金额
|
|
|
if (selectedCouponId.value) {
|
|
|
- discountAmount.value = coupon.amount ?? 0;
|
|
|
+ discountAmount.value =
|
|
|
+ Number(coupon.nominalValue) || Number(coupon.amount) || 0;
|
|
|
} else {
|
|
|
discountAmount.value = 0;
|
|
|
}
|