Просмотр исходного кода

取消价格计算中向上进一的算法

ext.liuqiwen3 1 месяц назад
Родитель
Сommit
3ec7dabf37
2 измененных файлов с 2 добавлено и 13 удалено
  1. 1 8
      components/orderGoods/index.vue
  2. 1 5
      components/productWindow/index.vue

+ 1 - 8
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">
-            ¥{{ ceilPrice(item.storePrice) }}
+            ¥{{ Number(item.storePrice).toFixed(2) }}
           </view>
           <view v-else class="money font-color">
             贝币:{{ Number(item.storePrice).toFixed(2) }}
@@ -118,13 +118,6 @@ 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">

+ 1 - 5
components/productWindow/index.vue

@@ -221,15 +221,11 @@ const calcNumPrice = computed(() => {
   const total =
     (Number(price) * Number(weight) + Number(additionalAmount || 0)) *
     Number(cart_num);
-  // 向上取整到小数点后一位
-  const fixedTotal = parseFloat(total.toFixed(10)); // 先修复精度
-  const roundedTotal = Math.ceil(fixedTotal * 10) / 10;
-  return roundedTotal.toFixed(2);
+  return total.toFixed(2);
 });
 
 // 监听 calcNumPrice 变化并传递给父组件
 watch(calcNumPrice, (newPrice) => {
-  console.log('newPrice',newPrice)
   emit("updatePrice", newPrice);
 }, { immediate: true });
 function goCat() {