Ver código fonte

优惠卷 折扣劵

sunshibo 20 horas atrás
pai
commit
d0e34c268d

+ 3 - 3
src/api/modules/newLoginApi.ts

@@ -105,9 +105,9 @@ export const getFriendCouponList = (params: any) => {
 export const getCouponDetail = (params: any) => {
   return httpLogin.get(`/alienStore/coupon/getCouponDetail`, params);
 };
-// 获取好友优惠券列表
-export const getFriendCouponDetail = (params: any) => {
-  return httpLogin.get(`/alienStore/life-discount-coupon/getCounponDetailById`, params);
+// 获取好友优惠券详情(含持有数量)
+export const getFriendCouponDetail = (params: { couponId: string | number; storeId: string | number }) => {
+  return httpLogin.get(`/alienStore/life-discount-coupon/getCouponDetailWithOwnedQty`, params);
 };
 
 // 好友列表

+ 2 - 1
src/views/dynamicManagement/friendCoupon.vue

@@ -388,7 +388,8 @@ const viewDetail = (row: any) => {
   } else {
     query = {
       couponId: row.couponId,
-      type: activeName.value
+      type: activeName.value,
+      storeId: row.storeId != null && row.storeId !== "" ? row.storeId : localGet("createdId")
     };
   }
   router.push({

+ 66 - 14
src/views/dynamicManagement/friendCouponDetail.vue

@@ -32,8 +32,14 @@
               {{ couponModel.couponName || couponModel.name || "--" }}
             </div>
           </div>
-          <!-- 面值 -->
-          <div class="detail-item">
+          <!-- 折扣券:折扣率;满减券等:面值 -->
+          <div class="detail-item" v-if="Number(couponModel.couponType) === 2">
+            <div class="detail-label">折扣率</div>
+            <div class="detail-value">
+              {{ formatDiscountRateDisplay(couponModel.discountRate) }}
+            </div>
+          </div>
+          <div class="detail-item" v-else>
             <div class="detail-label">面值</div>
             <div class="detail-value" v-if="couponId">
               {{ formatCurrency(couponModel.nominalValue, 2, "¥") }}
@@ -42,11 +48,11 @@
               {{ formatCurrency(couponModel.nominalValue ?? couponModel.price, 2, "¥") }}
             </div>
           </div>
-          <!-- 数量 -->
+          <!-- 数量:优惠券详情接口返回持有数量 ownedQuantity -->
           <div class="detail-item">
             <div class="detail-label">数量</div>
             <div class="detail-value">
-              {{ couponModel.couponNum ?? couponModel.singleQty ?? "--" }}
+              {{ couponModel.ownedQuantity ?? couponModel.couponNum ?? couponModel.singleQty ?? "--" }}
             </div>
           </div>
           <!-- 结束时间 -->
@@ -59,14 +65,14 @@
               {{ couponModel.endDate || "--" }}
             </div>
           </div>
-          <!-- 有效期 -->
+          <!-- 有效期:接口字段 expirationDate -->
           <div class="detail-item">
             <div class="detail-label">有效期</div>
             <div class="detail-value">
-              {{ couponModel.validityPeriod || couponModel.endDate || "--" }}
+              {{ getValidityDisplay() }}
             </div>
           </div>
-          <!-- 最低消费金额(保留原有) -->
+          <!-- 最低消费金额:绑定接口字段 minimumSpendingAmount -->
           <div class="detail-item">
             <div class="detail-label">最低消费金额</div>
             <div class="detail-value">
@@ -100,6 +106,8 @@ const route = useRoute();
 // 页面ID参数
 const couponId = ref<string>("");
 const voucherId = ref<string>("");
+/** 详情接口 getCouponDetailWithOwnedQty 所需店铺 ID(路由 storeId,缺省时为当前登录店铺) */
+const detailStoreId = ref<string>("");
 
 // 优惠券类型(好友赠我 friendMessage / 我赠好友 myGift)
 const type = ref<string>("");
@@ -116,20 +124,24 @@ const couponModel = ref<any>({
   deleteFlag: 0,
   // 结束日期
   endDate: "",
+  // 有效期(接口)
+  expirationDate: "",
   // ID
   id: 0,
   // 图片URL
   imgUrl: "",
   // 详细列表
   lifeDiscountCouponFriendRuleDetailVos: [],
-  // 最低消费金额
-  minimumSpendingAmount: 0,
+  // 最低消费金额(接口字段 minimumSpendingAmount;不设默认数字,未加载时由 formatCurrency 显示为 --)
+  minimumSpendingAmount: undefined,
   // 金额上限
   moneyHigh: 0,
   // 金额下限
   moneyLow: 0,
   // 面值
   nominalValue: 0,
+  // 折扣率(折扣券 couponType=2,接口 discountRate)
+  discountRate: undefined,
   // 状态
   status: "",
   // 店铺ID
@@ -151,7 +163,18 @@ onMounted(async () => {
     couponId.value = (route.query.couponId as string) || "";
   }
   type.value = (route.query.type as string) || "";
-  if (voucherId.value || couponId.value) {
+  detailStoreId.value =
+    (route.query.storeId != null && String(route.query.storeId) !== ""
+      ? String(route.query.storeId)
+      : String(localGet("createdId") ?? "")) || "";
+
+  if (voucherId.value) {
+    await loadDetailData();
+  } else if (couponId.value) {
+    if (!detailStoreId.value) {
+      ElMessage.warning("缺少店铺ID参数");
+      return;
+    }
     await loadDetailData();
   } else {
     ElMessage.warning("缺少优惠券ID参数");
@@ -185,9 +208,9 @@ const loadDetailData = async () => {
         ElMessage.error(res.msg);
       }
     } else if (couponId.value) {
-      // 使用 couponId 获取详情数据
       const res: any = await getFriendCouponDetail({
-        counponId: couponId.value
+        couponId: couponId.value,
+        storeId: detailStoreId.value
       });
 
       if (res.code === 200) {
@@ -201,12 +224,41 @@ const loadDetailData = async () => {
   }
 };
 
+/** 有效期是否有值(0 / "0" 视为有效,仅 null、undefined、"" 视为缺失) */
+const hasValidityValue = (v: unknown) => v !== null && v !== undefined && v !== "";
+
+/**
+ * 有效期展示:优先 expirationDate,且为 0 时显示 0
+ */
+const getValidityDisplay = () => {
+  const m = couponModel.value;
+  if (hasValidityValue(m.expirationDate)) return m.expirationDate;
+  if (hasValidityValue(m.validityPeriod)) return m.validityPeriod;
+  if (hasValidityValue(m.endDate)) return m.endDate;
+  return "--";
+};
+
+/**
+ * 折扣率展示:绑定 discountRate;接口常见为整数 11–100 表示几点几折(与 newCoupon 说明一致),否则原样加「折」
+ */
+const formatDiscountRateDisplay = (rate: unknown) => {
+  if (rate === null || rate === undefined || rate === "") return "--";
+  const n = Number(rate);
+  if (isNaN(n)) return `${rate}折`;
+  if (n > 10 && n <= 100) {
+    const x = n / 10;
+    const s = Number.isInteger(x) ? String(x) : String(Number(x.toFixed(1)));
+    return `${s.replace(/\.0$/, "")}折`;
+  }
+  return `${n}折`;
+};
+
 /**
  * 获取优惠券类型文案
  */
 const getCouponTypeText = (type: number | string | undefined) => {
-  const typeMap: Record<string, string> = { "1": "折扣券", "2": "满减券" };
-  return type != null ? (typeMap[String(type)] ?? String(type)) : "--";
+  const typeMap: Record<string, string> = { "1": "满减券", "2": "折扣券" };
+  return type != null && type !== "" ? (typeMap[String(type)] ?? String(type)) : "--";
 };
 
 /**