Explorar el Código

优惠卷列表

sunshibo hace 1 mes
padre
commit
d570766d6b
Se han modificado 2 ficheros con 11 adiciones y 40 borrados
  1. 3 2
      pages/orderFood/index.vue
  2. 8 38
      pages/placeOrder/index.vue

+ 3 - 2
pages/orderFood/index.vue

@@ -162,14 +162,15 @@ function normalizeCouponItem(item) {
   const raw = item;
   const couponType = Number(raw.couponType) || 0;
   const nominalValue = Number(raw.nominalValue ?? raw.amount ?? 0) || 0;
-  const discountRate = Number(raw.discountRate) || 0;
+  // userOwnedByStore 接口返回的 discountRate 需除以 10(如 55 表示 5.5折)
+  const discountRate = (Number(raw.discountRate) || 0) / 10;
   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 = Math.round(discountRate) + '折';
+    amountDisplay = (discountRate % 1 === 0 ? discountRate : discountRate.toFixed(1)) + '折';
   }
   return {
     id: raw.userCouponId ?? raw.id ?? raw.couponId ?? raw.coupon_id ?? '',

+ 8 - 38
pages/placeOrder/index.vue

@@ -191,11 +191,12 @@ function normalizeCouponItem(item) {
   const raw = item;
   const couponType = Number(raw.couponType) || 0;
   const nominalValue = Number(raw.nominalValue ?? raw.amount ?? 0) || 0;
-  const discountRate = Number(raw.discountRate) || 0;
+  // userOwnedByStore 接口返回的 discountRate 需除以 10(如 55 表示 5.5折)
+  const discountRate = (Number(raw.discountRate) || 0) / 10;
   const minAmount = Number(raw.minimumSpendingAmount ?? raw.minAmount ?? 0) || 0;
   let amountDisplay = nominalValue + '元';
   if (couponType === 1) amountDisplay = nominalValue + '元';
-  else if (couponType === 2 && discountRate > 0) amountDisplay = Math.round(discountRate) + '折';
+  else if (couponType === 2 && discountRate > 0) amountDisplay = (discountRate % 1 === 0 ? discountRate : discountRate.toFixed(1)) + '折';
   return {
     id: raw.userCouponId ?? raw.id ?? raw.couponId ?? '',
     amount: nominalValue,
@@ -222,21 +223,6 @@ const openCouponModal = async () => {
     const list = Array.isArray(res) ? res : (res?.data ?? res?.records ?? res?.list ?? []);
     const normalized = (Array.isArray(list) ? list : []).map(normalizeCouponItem).filter(Boolean);
     couponList.value = normalized;
-    if (normalized.length > 0 && !selectedCouponId.value) {
-      const first = normalized[0];
-      selectedCouponId.value = first.id != null && first.id !== '' ? String(first.id) : null;
-      orderInfo.value.couponId = selectedCouponId.value;
-      selectedCouponDisplay.value = first.amountDisplay || (first.amount ? first.amount + '元' : '');
-      const total = dishTotal.value;
-      const couponType = Number(first.couponType) || 0;
-      if (couponType === 2 && first.discountRate != null && total > 0) {
-        const rate = Number(first.discountRate) || 0;
-        orderInfo.value.discountAmount = Math.round(total * (1 - rate / 10) * 100) / 100;
-      } else {
-        orderInfo.value.discountAmount = Number(first.amount) || 0;
-      }
-      updatePayAmount();
-    }
     couponModalOpen.value = true;
   } catch (err) {
     console.error('获取优惠券失败:', err);
@@ -275,7 +261,7 @@ const updatePayAmount = () => {
   orderInfo.value.payAmount = Math.max(0, dish + utensil - discount);
 };
 
-// 进入页面时调一次优惠券接口:有券则默认选第一张,无券则显示请选择
+// 进入页面时调一次优惠券接口:默认不选中,显示请选择
 const fetchCouponsOnEnter = async () => {
   const storeId = uni.getStorageSync('currentStoreId') || '';
   try {
@@ -283,26 +269,10 @@ const fetchCouponsOnEnter = async () => {
     const list = Array.isArray(res) ? res : (res?.data ?? res?.records ?? res?.list ?? []);
     const normalized = (Array.isArray(list) ? list : []).map(normalizeCouponItem).filter(Boolean);
     couponList.value = normalized;
-    if (normalized.length === 0) {
-      selectedCouponId.value = null;
-      selectedCouponDisplay.value = '';
-      orderInfo.value.couponId = null;
-      orderInfo.value.discountAmount = 0;
-      updatePayAmount();
-      return;
-    }
-    const first = normalized[0];
-    selectedCouponId.value = first.id != null && first.id !== '' ? String(first.id) : null;
-    orderInfo.value.couponId = selectedCouponId.value;
-    selectedCouponDisplay.value = first.amountDisplay || (first.amount ? first.amount + '元' : '');
-    const total = dishTotal.value;
-    const couponType = Number(first.couponType) || 0;
-    if (couponType === 2 && first.discountRate != null && total > 0) {
-      const rate = Number(first.discountRate) || 0;
-      orderInfo.value.discountAmount = Math.round(total * (1 - rate / 10) * 100) / 100;
-    } else {
-      orderInfo.value.discountAmount = Number(first.amount) || 0;
-    }
+    selectedCouponId.value = null;
+    selectedCouponDisplay.value = '';
+    orderInfo.value.couponId = null;
+    orderInfo.value.discountAmount = 0;
     updatePayAmount();
   } catch (err) {
     console.error('获取优惠券失败:', err);