Przeglądaj źródła

修改支付订单中价格向上进一的计算方法

ext.liuqiwen3 1 miesiąc temu
rodzic
commit
a43b7191f2

+ 8 - 1
components/orderGoods/index.vue

@@ -33,7 +33,7 @@
           </view>
           <view class="attr line1" v-if="item.sku">属性: {{ item.sku }}</view>
           <view v-if="mallType === 0" class="money font-color">
-            ¥{{ (Math.ceil(Number(item.storePrice) * 10) / 10).toFixed(2) }}
+            ¥{{ ceilPrice(item.storePrice) }}
           </view>
           <view v-else class="money font-color">
             贝币:{{ Number(item.storePrice).toFixed(2) }}
@@ -118,6 +118,13 @@ function jumpCon(id) {
 const toMerchant = (merchantId) => {
   uni.navigateTo({ url:"/pages/merchantCenters/merchant?merchantId="+merchantId });
 }
+const ceilPrice = (price) => {
+  const num = Number(price);
+  if (isNaN(num)) return "0.00";
+  // 先四舍五入到2位小数修复精度
+  const fixedNum = Math.round(num * 100) / 100;
+  return (Math.ceil(fixedNum * 10) / 10).toFixed(2);
+};
 </script>
 
 <style scoped lang="scss">

+ 2 - 2
components/productWindow/index.vue

@@ -221,9 +221,9 @@ const calcNumPrice = computed(() => {
   const total =
     (Number(price) * Number(weight) + Number(additionalAmount || 0)) *
     Number(cart_num);
-
   // 向上取整到小数点后一位
-  const roundedTotal = Math.ceil(total * 10) / 10;
+  const fixedTotal = parseFloat(total.toFixed(10)); // 先修复精度
+  const roundedTotal = Math.ceil(fixedTotal * 10) / 10;
   return roundedTotal.toFixed(2);
 });