Procházet zdrojové kódy

fix(mall): 统一无价格商品的询价提示

- 商品列表、专区和首页以¥--展示无价格商品,避免显示误导性价格
- 加购与购买前拦截无价格商品,并统一引导用户向商家询价
- 保留商品原始价格类型,确保购物车校验使用正确的商品属性
shizhongqi před 20 hodinami
rodič
revize
8fba6e8541

+ 25 - 4
mallApp/src/components/home/goodsSection.vue

@@ -18,7 +18,7 @@
           <text class="row-name">{{ g.name }}</text>
           <text class="row-sold">已售 {{ formatSold(g.sold) }}</text>
         </view>
-        <text class="price">¥{{ formatPrice(g.price) }}</text>
+        <text class="price">¥{{ displayPrice(g) }}</text>
         <view class="add-btn" @click.stop="handleCartClick(g)">+</view>
       </view>
     </view>
@@ -33,7 +33,7 @@
           <text class="grid-name">{{ g.name }}</text>
           <view class="grid-bottom-row">
             <view class="grid-price-col">
-              <text class="price">¥{{ formatPrice(g.price) }}</text>
+              <text class="price">¥{{ displayPrice(g) }}</text>
               <text class="sold">已售 {{ formatSold(g.sold) }}</text>
             </view>
             <!-- 加购:圆形底 + 白色购物车 SVG,与设计稿一致 -->
@@ -96,11 +96,28 @@ export default {
     }
   },
   methods: {
+    /**
+     * 无价格商品(priceType=0):列表不展示数字价,统一用 -- 提示需询价
+     * @param {Object} g 商品
+     * @returns {boolean}
+     */
+    isNoPrice(g) {
+      return Number(g && g.priceType) === 0
+    },
     formatPrice(val) {
       const n = parseFloat(val)
       if (isNaN(n)) return '0'
       return n % 1 === 0 ? String(n) : n.toFixed(2)
     },
+    /**
+     * 列表价格文案:无价格商品显示 --,其余走数字格式化
+     * @param {Object} g 商品
+     * @returns {string}
+     */
+    displayPrice(g) {
+      if (this.isNoPrice(g)) return '--'
+      return this.formatPrice(g && g.price)
+    },
     formatSold(val) {
       const n = parseInt(val, 10) || 0
       if (n >= 10000) return (n / 10000).toFixed(1) + '万+'
@@ -109,13 +126,17 @@ export default {
     goDetail(g) {
       this.pageTo({ url: `/pages/goods/detail?id=${g.id}&account=${this.account}&hdId=${this.hdId}` })
     },
-    /** 单规格直接加购,多规格跳转详情选规格 */
+    /** 单规格直接加购,多规格跳转详情选规格;无价格商品拦截并提示询价 */
     handleCartClick(g) {
       if (!g || !g.id) return
       if (Number(g.specEnabled) === 1) {
         this.goDetail(g)
         return
       }
+      if (this.isNoPrice(g)) {
+        this.$msg('暂无价格,请向商家询价')
+        return
+      }
       if (!(Number(g.price) > 0)) {
         this.$msg('商品还没有价格哦')
         return
@@ -128,7 +149,7 @@ export default {
       }
       const goods = {
         ...g,
-        priceType: 1,
+        priceType: g.priceType != null ? g.priceType : 1,
         cover: g.coverUrl || g.cover,
         smallCover: g.coverUrl || g.cover
       }

+ 2 - 2
mallApp/src/mixins/cgProduct.js

@@ -492,9 +492,9 @@ export default {
 			const buyNum = Number(num) > 0 ? Number(num) : 1;
 			const saleGoods = spec && spec.id ? spec : goods;
 			const price = Number(saleGoods.price != null ? saleGoods.price : goods.price);
-			// 无价格类型或价格类型为0时,提示不能加入购物车
+			// 无价格类型(priceType=0):不能加购,引导向商家询价
 			if (Number(goods.priceType) === 0) {
-				this.$msg('无价格商品不能加入购物车');
+				this.$msg('暂无价格,请向商家询价');
 				return null;
 			}
 			// 有价格类型且价格为0时,提示商品还没有价格

+ 7 - 1
mallApp/src/pages/goods/components/sel-popup.vue

@@ -184,7 +184,13 @@ export default {
         this.$msg('请选择规格');
         return null;
       }
-      if (Number((spec || this.info).price) <= 0) {
+      const sale = spec || this.info;
+      // 无价格商品不能加购/购买,引导询价
+      if (Number(sale.priceType) === 0) {
+        this.$msg('暂无价格,请向商家询价');
+        return null;
+      }
+      if (Number(sale.price) <= 0) {
         this.$msg("商品还没有价格哦");
         return null;
       }

+ 2 - 0
mallApp/src/pages/goods/detail.vue

@@ -21,6 +21,8 @@
           </text>
           <text v-if="isSeckillActive && data.originPrice > 0" class="app-price-origin">¥{{ parseFloat(data.originPrice).toFixed(2) }}</text>
         </view>
+        <!-- 无价格商品:不展示数字价,引导底部询价 -->
+        <view class="app-price app-bold" v-else>¥--</view>
         <view class="tui-pro-titbox">
           <view class="tui-pro-title-wrap">
             <view class="tui-pro-title app-size-32">{{ data.name }}</view>

+ 23 - 2
mallApp/src/pages/goods/list.vue

@@ -58,8 +58,8 @@
             <view class="price-sold-col">
               <text class="price">
                 <text class="price-symbol">¥</text>
-                {{ formatPrice(item.price) }}
-                <text class="price-suffix">起</text>
+                {{ displayPrice(item) }}
+                <text v-if="!isNoPrice(item)" class="price-suffix">起</text>
               </text>
               <text class="sold">已售{{ formatSold(item.totalSold) }}件</text>
             </view>
@@ -508,11 +508,28 @@ export default {
       this.resetList()
       this.loadGoods()
     },
+    /**
+     * 无价格商品(priceType=0):列表不展示数字价,统一用 -- 提示需询价
+     * @param {Object} item 商品
+     * @returns {boolean}
+     */
+    isNoPrice(item) {
+      return Number(item && item.priceType) === 0
+    },
     formatPrice(val) {
       const n = parseFloat(val)
       if (isNaN(n)) return '0'
       return n % 1 === 0 ? String(n) : n.toFixed(2)
     },
+    /**
+     * 列表价格文案:无价格商品显示 --,其余走数字格式化
+     * @param {Object} item 商品
+     * @returns {string}
+     */
+    displayPrice(item) {
+      if (this.isNoPrice(item)) return '--'
+      return this.formatPrice(item && item.price)
+    },
     formatSold(val) {
       const n = parseInt(val, 10) || 0
       if (n >= 10000) return (n / 10000).toFixed(1) + '万+'
@@ -536,6 +553,10 @@ export default {
         this.goDetail(item)
         return
       }
+      if (this.isNoPrice(item)) {
+        this.$msg('暂无价格,请向商家询价')
+        return
+      }
       if (!(Number(item.price) > 0)) {
         this.$msg('商品还没有价格哦')
         return

+ 23 - 2
mallApp/src/pages/goods/section-list.vue

@@ -26,9 +26,9 @@
             <view class="price-wrap">
               <text class="price">
                 <text class="price-symbol">¥</text>
-                {{ formatPrice(item.price) }}
+                {{ displayPrice(item) }}
               </text>
-              <text v-if="isActivity && item.originPrice" class="origin-price">
+              <text v-if="isActivity && item.originPrice && !isNoPrice(item)" class="origin-price">
                 ¥{{ formatPrice(item.originPrice) }}
               </text>
             </view>
@@ -176,11 +176,28 @@ export default {
           this.list.finished = true
         })
     },
+    /**
+     * 无价格商品(priceType=0):列表不展示数字价,统一用 -- 提示需询价
+     * @param {Object} item 商品
+     * @returns {boolean}
+     */
+    isNoPrice(item) {
+      return Number(item && item.priceType) === 0
+    },
     formatPrice(val) {
       const n = parseFloat(val)
       if (isNaN(n)) return '0'
       return n % 1 === 0 ? String(n) : n.toFixed(2)
     },
+    /**
+     * 列表价格文案:无价格商品显示 --,其余走数字格式化
+     * @param {Object} item 商品
+     * @returns {string}
+     */
+    displayPrice(item) {
+      if (this.isNoPrice(item)) return '--'
+      return this.formatPrice(item && item.price)
+    },
     formatSold(val) {
       const n = parseInt(val, 10) || 0
       if (n >= 10000) return (n / 10000).toFixed(1) + '万+'
@@ -217,6 +234,10 @@ export default {
         this.goDetail(item)
         return
       }
+      if (this.isNoPrice(item)) {
+        this.$msg('暂无价格,请向商家询价')
+        return
+      }
       if (!(Number(item.price) > 0)) {
         this.$msg('商品还没有价格哦')
         return

+ 2 - 2
mallApp/src/pages/home/category.vue

@@ -47,7 +47,7 @@
               <view class="goods-sales">已售 {{ itemData.totalSold }}</view>
             </view>
             <view class="goods-price" v-if="Number(itemData.priceType) == 1">¥{{ itemData.price?parseFloat(itemData.price):0 }}</view>
-            <view class="goods-price" v-else>--</view>
+            <view class="goods-price" v-else>--</view>
             <view class="buy-btn">购买</view>
           </view>
         </view>
@@ -74,7 +74,7 @@
                 <view class="goods-sales">已售 {{ itemData.totalSold }}</view>
               </view>
               <view class="goods-price" v-if="Number(itemData.priceType) == 1">¥{{ itemData.price?parseFloat(itemData.price):0 }}</view>
-              <view class="goods-price" v-else>--</view>
+              <view class="goods-price" v-else>--</view>
               <view class="buy-btn">购买</view>
             </view>
           </view>

+ 5 - 1
mallApp/src/pages/home/shop-category.vue

@@ -205,7 +205,7 @@
                 <text class="goods-desc goods-desc--placeholder" v-else>精选花束,品质之选</text>
                 <view class="goods-bottom">
                   <text class="goods-price" v-if="Number(item.priceType) == 1">¥{{ formatPrice(item.price) }} 起</text>
-                  <text class="goods-price" v-else>--</text>
+                  <text class="goods-price" v-else>--</text>
                 </view>
               </view>
               <view class="goods-cart-btn" @tap.stop="handleBouquetAddToCart(item)">
@@ -814,6 +814,10 @@ export default {
         this.toBouquetDetail(item)
         return
       }
+      if (Number(item.priceType) === 0) {
+        this.$msg('暂无价格,请向商家询价')
+        return
+      }
       if (Number(item.priceType) !== 1 || !(Number(item.price) > 0)) {
         this.$msg('商品还没有价格哦')
         return