Browse Source

修改价格显示不对的问题

ext.liuqiwen3 1 month ago
parent
commit
b37f017d37

+ 17 - 2
pages/goods/goods_details/index.vue

@@ -754,18 +754,33 @@ const getGoodsDetails = async () => {
 };
 const DefaultSelect = () => {
   let value = [];
-  const keys = Object.keys(productValue.value);
+  // 或者使用 for...in 循环(会按对象属性顺序)
+  const allKeys = Object.keys(productValue.value);
+
+  // 手动排序:按数字部分从小到大排序
+  const keys = allKeys.sort((a, b) => {
+    // 提取数字:5g -> 5, 100g -> 100
+    const numA = parseInt(a.match(/\d+/)[0]);
+    const numB = parseInt(b.match(/\d+/)[0]);
+    return numA - numB;
+  });
+
   for (let i = 0; i < keys.length; i++) {
     const key = keys[i];
+
     if (productValue.value[key].stock > 0) {
-      value = attr.value.productAttr.length ? key.split(",") : [];
+      // 如果规格是单个值(如 "100g"),直接放入数组
+      value = [key];
       break;
     }
   }
+
   attr.value.productAttr.forEach((item, i) => {
     item.index = value[i];
   });
+
   const productSelect = productValue.value[value.join(",")];
+  console.log('productSelect',productSelect)
   if (productSelect && attr.value.productAttr.length) {
     attr.value.productSelect = {
       ...attr.value.productSelect,

+ 6 - 1
pages/merchantCenters/merchant.vue

@@ -61,7 +61,7 @@
             </view>
             <view class="bottom-row">
               <!-- <text class="price">工费: {{ item.price }}/克</text> -->
-              <text class="price">¥ {{ item.totalLaborCost }}</text>
+              <text class="price">¥ {{ item.totalPrice }}</text>
               <text class="sales">
                 销量:{{ Number(item.sales || 0) + Number(item.ficti || 0) }}件
               </text>
@@ -147,9 +147,14 @@ const calculatedProducts = computed(() => {
     // 4. 格式化保留两位小数
     const formattedTotal = roundedTotal.toFixed(2);
 
+    const totalLaborCost = Number(product.totalLaborCost);
+    const additionalAmount = Number(product.additionalAmount);
+    const totalPrice = (totalLaborCost+additionalAmount).toFixed(2);
+
     return {
       ...product,
       calculatedTotal: formattedTotal, // 新增计算结果字段
+      totalPrice
     };
   });
 });

+ 2 - 1
pages/order_addcart/order_addcart.vue

@@ -284,7 +284,7 @@
           <view class="pictrue">
             <image :src="HTTP_REQUEST_URL_IMG+'noCart.png'"></image>
           </view>
-          <recommend :hostProduct="hostProduct"></recommend>
+<!--          <recommend :hostProduct="hostProduct"></recommend>-->
         </view>
       </view>
     </view>
@@ -1292,6 +1292,7 @@ const toMerchant = (obj) => {
       width: 414rpx;
       height: 336rpx;
       margin: 78rpx auto 56rpx auto;
+      padding-bottom: 40rpx;
 
       image {
         width: 100%;