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

零售端-附加费收取间隔支持设置N小时

ouyang 18 часов назад
Родитель
Сommit
9dc2522c72
1 измененных файлов с 122 добавлено и 1 удалено
  1. 122 1
      hdApp/src/admin/home/psMethod.vue

+ 122 - 1
hdApp/src/admin/home/psMethod.vue

@@ -156,6 +156,48 @@
             <view class="tui-title">{{ form.unMeet == 2 ? '包装费' : '运费' }}</view>
             <input type="digit" v-model="form.unMeetFee" @focus="form.unMeetFee = ''" class="tui-input" placeholder="请填写金额" />
           </tui-list-cell>
+          <!-- 附加费重收:自然日锁一天 或 按小时间隔冷却后再收 -->
+          <tui-list-cell class="line-cell" :hover="false" v-if="form.unMeet != 1">
+            <view class="tui-title">附加费重收</view>
+            <view class="btn-group">
+              <button
+                class="admin-button-com middle"
+                :class="[form.unMeetLockType == 0 ? 'blue' : 'default']"
+                @click="form.unMeetLockType = 0"
+              >
+                按自然日
+              </button>
+              <button
+                class="admin-button-com middle"
+                :class="[form.unMeetLockType == 1 ? 'blue' : 'default']"
+                @click="form.unMeetLockType = 1"
+                style="margin-left: 10upx;"
+              >
+                按时间间隔
+              </button>
+            </view>
+          </tui-list-cell>
+          <tui-list-cell class="line-cell" :hover="false" v-if="form.unMeet != 1 && form.unMeetLockType == 1">
+            <view class="tui-title">间隔时长</view>
+            <view class="input-row">
+              <input
+                type="digit"
+                v-model="form.unMeetLockHours"
+                @focus="form.unMeetLockHours = ''"
+                class="tui-input-sm"
+                placeholder="0.5"
+              />
+              <text class="unit-text">小时后再收</text>
+            </view>
+          </tui-list-cell>
+          <view
+            class="section-tip"
+            v-if="form.unMeet != 1"
+            style="padding: 0 30upx 20upx;"
+          >
+            <text v-if="form.unMeetLockType == 0">按自然日:同一客户当天收过该附加费后,当日不再收取。</text>
+            <text v-else>按时间间隔:收过附加费后,需间隔填写的小时数才会再次收取(支持小数,如 0.5)</text>
+          </view>
         </block>
 
         <!-- 跑腿 特有字段(花束运费、满减、自定义计费等) -->
@@ -349,6 +391,7 @@
  * 花店配送方式设置
  * 路由:admin/home/psMethod
  * 跑腿保存:无论用跑腿还是用自定义,都必须完整填写自定义计费;启用还需绑定跑腿或自定义完整
+ * 送货/快递:支持附加费重收规则(按自然日 或 按小时间隔冷却)
  */
 import TuiListCell from '@/components/plugin/list-cell'
 import { getPsMethodConfig, savePsMethodConfig, getPsMethodSorts } from '@/api/ps-method'
@@ -381,6 +424,11 @@ export default {
         minNum: 0,
         unMeet: 0,
         unMeetFee: 0.00,
+        /** 附加费重收:0 按自然日;1 按冷却秒(页面用小时录入) */
+        unMeetLockType: 0,
+        unMeetLockSeconds: 1800,
+        /** 仅编辑展示:小时,支持小数如 0.5 */
+        unMeetLockHours: 0.5,
         calcType: 0,
         hsFreeKm: 0.00,
         hsPerKmPrice: 0.00,
@@ -555,6 +603,11 @@ export default {
               minNum: data.minNum != null ? Number(data.minNum) : 0,
               unMeet: data.unMeet != null ? Number(data.unMeet) : 0,
               unMeetFee: data.unMeetFee != null ? parseFloat(data.unMeetFee) : 0.00,
+              unMeetLockType: data.unMeetLockType != null ? Number(data.unMeetLockType) : 0,
+              unMeetLockSeconds: data.unMeetLockSeconds != null ? Number(data.unMeetLockSeconds) : 1800,
+              unMeetLockHours: this.secondsToLockHours(
+                data.unMeetLockSeconds != null ? Number(data.unMeetLockSeconds) : 1800
+              ),
               calcType: data.calcType != null ? Number(data.calcType) : 0,
               hsFreeKm: data.hsFreeKm != null ? parseFloat(data.hsFreeKm) : 0.00,
               hsPerKmPrice: data.hsPerKmPrice != null ? parseFloat(data.hsPerKmPrice) : 0.00,
@@ -699,6 +752,64 @@ export default {
       this.$util.pageTo({ url: "/admin/shop/wl" });
     },
 
+    /**
+     * 冷却秒数 → 配置页小时(保留小数,去掉多余 0)
+     * @param {number} seconds
+     * @returns {number}
+     */
+    secondsToLockHours(seconds) {
+      const s = Number(seconds);
+      if (!(s > 0)) {
+        return 0.5;
+      }
+      return parseFloat((s / 3600).toFixed(4));
+    },
+
+    /**
+     * 配置页小时 → 冷却秒(四舍五入)
+     * @param {number|string} hours
+     * @returns {number}
+     */
+    hoursToLockSeconds(hours) {
+      const h = Number(hours);
+      if (!(h > 0)) {
+        return 0;
+      }
+      return Math.round(h * 3600);
+    },
+
+    /**
+     * 送货/快递附加费重收规则校验;通过则把小时写入 form.unMeetLockSeconds
+     * @returns {string} 错误文案,空表示通过
+     */
+    validateUnMeetLockBeforeSave() {
+      const style = Number(this.form.style);
+      if (style !== 0 && style !== 4) {
+        return "";
+      }
+      if (Number(this.form.unMeet) === 1) {
+        this.form.unMeetLockType = 0;
+        return "";
+      }
+      const lockType = Number(this.form.unMeetLockType) === 1 ? 1 : 0;
+      this.form.unMeetLockType = lockType;
+      if (lockType !== 1) {
+        // 自然日模式仍保留秒数字段默认值,便于切回间隔时有底
+        if (!(Number(this.form.unMeetLockSeconds) > 0)) {
+          this.form.unMeetLockSeconds = 1800;
+          this.form.unMeetLockHours = 0.5;
+        }
+        return "";
+      }
+      const seconds = this.hoursToLockSeconds(this.form.unMeetLockHours);
+      if (!(seconds > 0)) {
+        return "请填写大于 0 的间隔小时(支持小数,如 0.5)";
+      }
+      this.form.unMeetLockSeconds = seconds;
+      this.form.unMeetLockHours = this.secondsToLockHours(seconds);
+      return "";
+    },
+
     /**
      * 保存当前配置
      */
@@ -720,6 +831,12 @@ export default {
         }
       }
 
+      const lockErr = this.validateUnMeetLockBeforeSave();
+      if (lockErr) {
+        this.$msg(lockErr);
+        return;
+      }
+
       const runnerErr = this.validateRunnerBeforeSave()
       if (runnerErr) {
         this.$msg(runnerErr)
@@ -728,7 +845,11 @@ export default {
 
       savePsMethodConfig(this.form).then(res => {
           if (res.code == 1) {
-            this.$msg("保存成功");
+            if (Number(this.form.unMeetLockType) === 1 && (Number(this.form.style) === 0 || Number(this.form.style) === 4)) {
+              this.$msg(`保存成功,间隔 ${this.form.unMeetLockHours} 小时后再收`);
+            } else {
+              this.$msg("保存成功");
+            }
             // 重新加载配置刷新数据
             this.loadConfig(this.form.style);
             // 重新加载排序和别名信息