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

根据 this.isFreight = goodsInfo.freightType == '0' // True:收配送费 False:不收配送费。(运费计算方式,0按距离计算 1免运费)做整体逻辑判断修改

shizhongqi 8 месяцев назад
Родитель
Сommit
a81a3f0449
2 измененных файлов с 113 добавлено и 86 удалено
  1. 14 36
      mallApp/src/pages/order/buy.vue
  2. 99 50
      mallApp/src/pages/order/components/app-delivery.vue

+ 14 - 36
mallApp/src/pages/order/buy.vue

@@ -27,8 +27,9 @@
           :showDistance="showDistance"
           :isFreight="isFreight"
           :openIntraCity="openIntraCity"
-          :hcFreeKm="hcFreeKm"
-          :hcMap="hcMap"
+          :hsFreeKm="hsFreeKm"
+          :hsAddFee="hsAddFee"
+
           :totalPrice="goodsTotalPrice"
           :allCountFun="{ bigLength: goodsInfo.buyNum, weight: goodsInfo.weight * goodsInfo.buyNum }"
         />
@@ -87,10 +88,10 @@ export default {
       // 是否收配送费
       isFreight: false,
       openIntraCity: 0,
-      // 免费公里数
-      hcFreeKm: 0,
-      // 免费公里数规则
-      hcMap: [],
+      // 花束多少公里内免费配送
+      hsFreeKm: 0,
+      // 花束超过免费的公里后,每公里加收的金额
+      hsAddFee: 0,
       deliveryPlatform: '', // 跑腿平台
       deliveryPrice: 0, // 跑腿报价
       deliveryDistance: 0, // 跑腿距离
@@ -113,37 +114,15 @@ export default {
       }
       
       // 条件1: 比较距离与免费公里数
-      // showDistance单位是公里,hcFreeKm单位也是公里
+      // showDistance单位是公里,hsFreeKm单位也是公里
       const distanceInKm = Number(this.showDistance) || 0
-      const freeKm = Number(this.hcFreeKm) || 0
+      const freeKm = Number(this.hsFreeKm) || 0
       
-      // 如果距离小于免费公里数,则免运费
-      if(distanceInKm < freeKm){
+      // 如果距离小于等于免费公里数,则免运费
+      if(distanceInKm <= freeKm){
         return true
       }
       
-      // 条件2: 如果距离大于免费公里数,判断hcMap
-      if(distanceInKm > freeKm){
-        // 判断hcMap是否为空
-        if(this.hcMap && Array.isArray(this.hcMap) && this.hcMap.length > 0){
-          // 获取花束数量和总价
-          const flowerCount = Number(this.goodsInfo.buyNum) || 0
-          const flowerPrice = this.goodsTotalPrice || 0
-          
-          // 遍历hcMap,检查是否满足免运费条件
-          for(const rule of this.hcMap){
-            const ruleNum = Number(rule.num) || 0
-            const rulePrice = Number(rule.price) || 0
-            const ruleDistance = Number(rule.distance) || 0 // 单位:公里
-            
-            // 如果花束数量大于等于num,花束总价大于等于price,距离小于等于distance,则免运费
-            if(flowerCount >= ruleNum && flowerPrice >= rulePrice && distanceInKm <= ruleDistance){
-              return true
-            }
-          }
-        }
-      }
-      
       return false
     },
     mayPayAmount(){
@@ -161,7 +140,7 @@ export default {
   methods: {
     init() {
       let goodsInfo = uni.getStorageSync("buyGoodsDetil") || {}
-      this.isFreight = goodsInfo.freightType == '0'
+      this.isFreight = goodsInfo.freightType == '0' // True:收配送费  False:不收配送费。  运费计算方式,0按距离计算 1免运费
 
       getOrderShop()
       //getShopUser();
@@ -181,8 +160,8 @@ export default {
 
         const shopData = res.data.shop || {};
         this.openIntraCity = shopData.openIntraCity || 0;
-        this.hcFreeKm = shopData.hcFreeKm || 0;
-        this.hcMap = shopData.hcMap || [];
+        this.hsFreeKm = shopData.hsFreeKm || 0;
+        this.hsAddFee = shopData.hsAddFee || 0;
       })
     },
 		changeSendType(num){
@@ -223,7 +202,6 @@ export default {
         this.$msg('跑腿暂不可用,请选它方式下单')
         return
       }
-      
       this.createOrderFn()
     },
     createOrderFn() {

+ 99 - 50
mallApp/src/pages/order/components/app-delivery.vue

@@ -29,6 +29,29 @@
         <input v-model="form.floor" placeholder-class="phcolor" placeholder-style="color:#ccc" class="tui-input" name="floor" placeholder="楼号门牌号(选填)" @input="modifyShow" />
       </tui-list-cell>
     </div>
+    
+    <div class="module-com">
+      <tui-list-cell class="line-cell" :hover="false">
+        <div class="tui-title">贺卡内容</div>
+        <textarea v-model="form.cardInfo" placeholder-class="phcolor" placeholder-style="color:#ccc" class="tui-input textarea-input" name="cardInfo" placeholder="请填写" :adjust-position="false" :cursor-spacing="0" :auto-height="false" :disable-default-padding="true" :show-confirm-bar="false" />
+
+      </tui-list-cell>
+
+      <tui-list-cell class="line-cell" :hover="false">
+        <div class="tui-title">派送方式</div>
+        <div class="delivery-mode-wrapper">
+          <switch :checked="form.anonymity == 1" @change="anonymityChange" color="#ff6b35" />
+          <span v-if="form.anonymity == 0" class="mode-text normal">不匿名</span>
+          <span v-else class="mode-text anonymous">要匿名</span>
+        </div>
+      </tui-list-cell>
+
+      <tui-list-cell class="line-cell" :hover="false">
+        <div class="tui-title">备注内容</div>
+        <textarea v-model="form.remark" placeholder-class="phcolor" placeholder-style="color:#ccc" class="tui-input textarea-input" name="remark" placeholder="选填,不要贺卡这里备注" :adjust-position="false" :cursor-spacing="0" :auto-height="false" :disable-default-padding="true" :show-confirm-bar="false" />
+      </tui-list-cell>
+    </div>
+
     <!-- 订花人 -->
     <div class="module-com">
       <tui-list-cell class="line-cell" :hover="false" :arrow="true">
@@ -74,7 +97,7 @@
         </tui-list-cell>
         
         <!-- 跑腿平台报价列表 -->
-        <tui-list-cell class="line-cell" :hover="false" :arrow="false" v-if="deliveryQuotes.length > 0">
+        <tui-list-cell v-if="isFreight && deliveryQuotes.length > 0" class="line-cell" :hover="false" :arrow="false">
           <view class="delivery-quotes-container">
             <view class="delivery-quotes-grid">
               <view 
@@ -95,35 +118,14 @@
             </view>
           </view>
         </tui-list-cell>
-        <tui-list-cell class="line-cell" :hover="false" :arrow="false" v-else-if="deliveryQuotesLoading">
+        <tui-list-cell  v-else-if="isFreight && deliveryQuotesLoading" class="line-cell" :hover="false" :arrow="false">
           <view style="text-align: center; padding: 20rpx 0; color: #999;">正在获取报价...</view>
         </tui-list-cell>
       </block>
       
     </div>
 
-    <div class="module-com">
-
-      <tui-list-cell class="line-cell" :hover="false">
-        <div class="tui-title">贺卡内容</div>
-        <textarea v-model="form.cardInfo" placeholder-class="phcolor" placeholder-style="color:#ccc" class="tui-input textarea-input" name="cardInfo" placeholder="请填写" :adjust-position="false" :cursor-spacing="0" :auto-height="false" :disable-default-padding="true" :show-confirm-bar="false" />
-
-      </tui-list-cell>
-
-      <tui-list-cell class="line-cell" :hover="false">
-        <div class="tui-title">派送方式</div>
-        <div class="delivery-mode-wrapper">
-          <switch :checked="form.anonymity == 1" @change="anonymityChange" color="#ff6b35" />
-          <span v-if="form.anonymity == 0" class="mode-text normal">不匿名</span>
-          <span v-else class="mode-text anonymous">要匿名</span>
-        </div>
-      </tui-list-cell>
-
-      <tui-list-cell class="line-cell" :hover="false">
-        <div class="tui-title">备注内容</div>
-        <textarea v-model="form.remark" placeholder-class="phcolor" placeholder-style="color:#ccc" class="tui-input textarea-input" name="remark" placeholder="选填,不要贺卡这里备注" :adjust-position="false" :cursor-spacing="0" :auto-height="false" :disable-default-padding="true" :show-confirm-bar="false" />
-      </tui-list-cell>
-    </div>
+    
     <!-- 省市联动 -->
     <simple-address ref="simpleAddress" :region="orderShop.region" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onCityConfirm" >
     </simple-address>
@@ -162,17 +164,22 @@ export default {
       type: Number,
       default: 0
     },
+    /**
+     * 是否收配送费
+     * @type {Boolean} True:收配送费  False:不收配送费
+     * @default false
+     */
     isFreight: {
       type: Boolean,
       default: false
     },
-    hcFreeKm: {
+    hsFreeKm: {
       type: Number,
       default: 0
     },
-    hcMap: {
-      type: Array,
-      default: () => []
+    hsAddFee: {
+      type: Number,
+      default: 0
     },
     totalPrice: {
       type: Number,
@@ -221,38 +228,46 @@ export default {
     ...mapGetters({ orderShop: "getOrderShop" }),
     ...mapGetters({ shopUser: "getShopUser" }),
     isFreeDelivery(){
-      // 如果父组件没传isFreight,或者isFreight为false,则直接判定为免运费
+      // 如果父组件isFreight为false,则直接判定为免运费
       if(!this.isFreight) return true;
       
-      const distanceInMeters = (Number(this.showDistance) || 0) * 1000;
-      const freeKmInMeters = (Number(this.hcFreeKm) || 0) * 1000;
+      const distanceInKm = Number(this.showDistance) || 0;
+      const freeKm = Number(this.hsFreeKm) || 0;
       
-      if (distanceInMeters > 0 && distanceInMeters < freeKmInMeters) {
+      // 距离小于等于免费公里数时,免费
+      if (distanceInKm <= freeKm) {
         return true;
       }
       
-      if(distanceInMeters > freeKmInMeters){
-        if (this.hcMap && Array.isArray(this.hcMap) && this.hcMap.length > 0) {
-          const goodsInfo = uni.getStorageSync("buyGoodsDetil") || {};
-          const flowerCount = Number(goodsInfo.buyNum || 0);
-          const flowerPrice = (Number(goodsInfo.price) || 0) * flowerCount;
-          
-          for (const rule of this.hcMap) {
-            const ruleNum = Number(rule.num) || 0;
-            const rulePrice = Number(rule.price) || 0;
-            const ruleDistance = (Number(rule.distance) || 0) * 1000;
-            if (flowerCount >= ruleNum && flowerPrice >= rulePrice && distanceInMeters <= ruleDistance) {
-              return true;
-            }
-          }
-        }
-      }
       return false;
+    },
+    /**
+     * 计算跑腿费(使用 prop 的 showDistance)
+     * 新规则:距离 <= 免费公里数时免费,距离 > 免费公里数时按超出部分计费
+     */
+    calculatedDeliveryCost(){
+      // 如果不收配送费,返回0
+      if(!this.isFreight) return 0;
+      
+      // 如果满足免费条件,返回0
+      if(this.isFreeDelivery) return 0;
+      
+      const distanceInKm = Number(this.showDistance) || 0;
+      const freeKm = Number(this.hsFreeKm) || 0;
+      const addFee = Number(this.hsAddFee) || 0;
+      
+      // 距离大于免费公里数时,计算超出部分的费用
+      if(distanceInKm > freeKm){
+        const extraKm = distanceInKm - freeKm;
+        const cost = extraKm * addFee;
+        return parseFloat(cost.toFixed(2));
+      }
+      
+      return 0;
     }
   },
   watch: {
     orderShop(val) {
-      console.log("val", val);
       this.form.province = val.shop.province ? val.shop.province : "";
       this.form.city = val.shop.city ? val.shop.city : "";
     }
@@ -310,7 +325,35 @@ export default {
     modifyShow(){
 			this.form.showAddress = this.form.province+this.form.city+this.form.address+this.form.floor
 		},
+    /**
+     * 根据指定距离计算跑腿费
+     * @param {Number} distanceInKm - 距离(单位:公里)
+     * @returns {Number} 跑腿费
+     */
+    calculateDeliveryCostByDistance(distanceInKm){
+      // 如果不收配送费,返回0
+      if(!this.isFreight) return 0;
+      
+      const freeKm = Number(this.hsFreeKm) || 0;
+      const addFee = Number(this.hsAddFee) || 0;
+      
+      // 距离小于等于免费公里数时,免费
+      if(distanceInKm <= freeKm){
+        return 0;
+      }
+      
+      // 距离大于免费公里数时,计算超出部分的费用
+      if(distanceInKm > freeKm){
+        const extraKm = distanceInKm - freeKm;
+        const cost = extraKm * addFee;
+        return parseFloat(cost.toFixed(2));
+      }
+      
+      return 0;
+    },
     triggerGetDeliveryQuotes() {
+      if(!this.isFreight) return;
+
       if (this.form.receiveUserName && this.form.receiveMobile && this.form.address) {
         this.getDeliveryQuotes();
       }
@@ -372,11 +415,17 @@ export default {
 			if (!item.isAble) return;
 			this.selectedDeliveryIndex = index
 			this.selectedDeliveryData = item
-      this.form.sendCost = this.isFreeDelivery ? 0 : item.priceNumber;
+      
+      // 使用当前选择的配送平台的距离来计算跑腿费
+      const distanceInKm = item.distance ? parseFloat((item.distance / 1000).toFixed(2)) : 0;
+      const calculatedCost = this.calculateDeliveryCostByDistance(distanceInKm);
+      
+      this.form.sendCost = calculatedCost;
 			this.form.deliveryPlatform = item.en_name;
       this.form.deliveryPrice = item.priceNumber;
       this.form.deliveryDistance = item.distance || 0;
       this.form.deliveryBracketContent = item.bracketContent || '';
+
 			this.$emit("countFreight", {
         sendCost: this.form.sendCost,
         distance: item.distance,