Explorar el Código

修改商品详情页,价格展示问题

ext.liuqiwen3 hace 2 semanas
padre
commit
009aaa855e
Se han modificado 1 ficheros con 13 adiciones y 14 borrados
  1. 13 14
      pages/goods/goods_details/index.vue

+ 13 - 14
pages/goods/goods_details/index.vue

@@ -33,7 +33,7 @@
 								<view style="width:100%;">
 									<view class="share acea-row row-between row-bottom">
 										<view class="money font-color">
-											<text class="num">¥{{ attr.productSelect.storePrice }}</text>
+											<text class="num">¥{{ calcNumPrice }}</text>
 										</view>
 										<!--                    <view @click="listenerActionSheet" class="share share-top">-->
 										<!--                      <uni-icons size="24" type="redo"></uni-icons>-->
@@ -1334,19 +1334,18 @@
 			current: item[0],
 		});
 	};
-	const calcNumPrice = (productSelect) => {
-		const {
-			price,
-			cart_num,
-			additionalAmount,
-			weight
-		} = productSelect;
-		``;
-		// 计算总价并保留两位小数
-		const total =
-			Number(price) * Number(weight) * Number(cart_num) + additionalAmount;
-		return total.toFixed(2);
-	};
+  const calcNumPrice = computed(() => {
+    if (!attr.value?.productSelect) {
+      return "0.00";
+    }
+    const { price, cart_num, additionalAmount, weight } = attr.value.productSelect;
+
+    // 计算总价:工费 * 重量 * 数量 + 附加费
+    const total =
+        (Number(price) * Number(weight) + Number(additionalAmount || 0)) *
+        Number(cart_num);
+    return total.toFixed(2);
+  });
 	const selectValue = () => {
 		let val = '',
 			name = '';