shish 2 ヶ月 前
コミット
79216a01e3
1 ファイル変更118 行追加96 行削除
  1. 118 96
      ghsApp/src/admin/billing/affirm.vue

+ 118 - 96
ghsApp/src/admin/billing/affirm.vue

@@ -428,7 +428,9 @@
         <text style="font-size: 30upx; right: 100upx">
           当前在
           <text style="font-weight: bold; color: red; margin-left: 5upx; font-size: 32upx">{{ currentShop.shopName }}</text></text>
-        <button class="admin-button-com blue big" @click="confirmSubmit">提交</button>
+        <button class="admin-button-com blue big" :disabled="formSubmitting" @click="confirmSubmit">
+          {{ formSubmitting ? '提交中…' : '提交' }}
+        </button>
       </view>
 
       <view
@@ -477,7 +479,9 @@
           </view>
           <view style="text-align: center; margin-top: 30upx; width: 100%">
             <button class="admin-button-com big default" @click="returnCheck()">返回修改</button>
-            <button style="margin-left: 20upx" @click="diffPriceConfirm()" class="admin-button-com big blue">确认提交</button>
+            <button style="margin-left: 20upx" :disabled="formSubmitting" @click="diffPriceConfirm()" class="admin-button-com big blue">
+              {{ formSubmitting ? '提交中…' : '确认提交' }}
+            </button>
           </view>
         </view>
       </uni-popup>
@@ -673,6 +677,8 @@ export default {
     
       // 重量输入防抖定时器
       weightDebounceTimer: null,
+      /** 开单提交中,防止连点/重复请求 */
+      formSubmitting: false,
     };
   },
   onLoad(option) {
@@ -1018,118 +1024,134 @@ export default {
       });
     },
     async formSubmit() {
-      let that = this;
-      let formData = this.form;
-      const product = this.selectList.map((ele) => {
-        return {
-          productId: ele.id,
-          bigNum: ele.bigCount,
-          smallNum: ele.smallCount,
-          classId: ele.classId,
-          itemId: ele.itemId,
-          price: ele.userPrice,
-          remark: ele.remark
-        };
-      });
-      formData.product = JSON.stringify(product);
-      if (!this.getMerchantInfo) {
-        await this.initMerchantInfo();
-      }
-      formData.shopId = this.getMerchantInfo.id;
-      if (Number(this.modifyPrice) <= 0) {
-        this.$msg('收款金额必须大于0');
+      if (this.formSubmitting) {
         return false;
       }
-
-      let Fn = createOrder;
-      let book = this.book;
-      let params = { ...formData, modifyPrice: this.modifyPrice, newVersion: 1, book: book };
-
-      // 如果选择了跑腿配送并且有选中的平台数据,则添加配送平台信息
-      if (this.form.sendType == 2 && this.selectedDeliveryData) {
-        params.deliveryPlatform = this.selectedDeliveryData.en_name; // 平台名称
-        params.deliveryPrice = this.selectedDeliveryData.priceNumber; // 报价金额
-        params.deliveryDistance = this.showDistance; // 配送距离
-        params.deliveryBracketContent = this.selectedDeliveryData.bracketContent; // 配送平台括号里的内容
-        params.deliveryAllParams = this.selectedDeliveryData; // 配送平台所有参数
-        if (this.form.callErrand == 1) {
-          params.pickupTime = this.pickupTime.value;
+      this.formSubmitting = true;
+      let that = this;
+      try {
+        let formData = this.form;
+        const product = this.selectList.map((ele) => {
+          return {
+            productId: ele.id,
+            bigNum: ele.bigCount,
+            smallNum: ele.smallCount,
+            classId: ele.classId,
+            itemId: ele.itemId,
+            price: ele.userPrice,
+            remark: ele.remark
+          };
+        });
+        formData.product = JSON.stringify(product);
+        if (!this.getMerchantInfo) {
+          await this.initMerchantInfo();
         }
-      }
-
-      if(this.form.callErrand == 1){
-        if (this.$util.isEmpty(this.customInfo.long) || this.$util.isEmpty(this.customInfo.lat) || this.$util.isEmpty(this.customInfo.address)) {
-          this.$msg('客户地址不完整,不支持直接发跑腿')
-          return false
+        formData.shopId = this.getMerchantInfo.id;
+        if (Number(this.modifyPrice) <= 0) {
+          this.$msg('收款金额必须大于0');
+          return false;
         }
-      }
 
-      if (this.option && this.option.orderId && this.option.orderId > 0) {
-        Fn = updateOrder;
-        params = { ...params, id: this.option.orderId };
-      }
+        let Fn = createOrder;
+        let book = this.book;
+        let params = { ...formData, modifyPrice: this.modifyPrice, newVersion: 1, book: book };
+
+        // 如果选择了跑腿配送并且有选中的平台数据,则添加配送平台信息
+        if (this.form.sendType == 2 && this.selectedDeliveryData) {
+          params.deliveryPlatform = this.selectedDeliveryData.en_name; // 平台名称
+          params.deliveryPrice = this.selectedDeliveryData.priceNumber; // 报价金额
+          params.deliveryDistance = this.showDistance; // 配送距离
+          params.deliveryBracketContent = this.selectedDeliveryData.bracketContent; // 配送平台括号里的内容
+          params.deliveryAllParams = this.selectedDeliveryData; // 配送平台所有参数
+          if (this.form.callErrand == 1) {
+            params.pickupTime = this.pickupTime.value;
+          }
+        }
 
-      if (book == 1) {
-        if (this.form.hasPay != 2) {
-          this.$msg('预订单只能选择挂账');
-          return false;
+        if (this.form.callErrand == 1) {
+          if (this.$util.isEmpty(this.customInfo.long) || this.$util.isEmpty(this.customInfo.lat) || this.$util.isEmpty(this.customInfo.address)) {
+            this.$msg('客户地址不完整,不支持直接发跑腿');
+            return false;
+          }
         }
-        if (Number(this.form.sendCost) > 0) {
-          this.$msg('预订单不能填写运费');
-          return false;
+
+        if (this.option && this.option.orderId && this.option.orderId > 0) {
+          Fn = updateOrder;
+          params = { ...params, id: this.option.orderId };
         }
-      }
 
-      //多颜色
-      let xj = null;
-      if (this.option && this.option.customId) {
-        xj = uni.getStorageSync('xj' + this.option.customId);
-      }
-      params = { ...params, xj: JSON.stringify(xj) };
-
-      //株数
-      let treeData = null;
-      if (this.option && this.option.customId) {
-        treeData = uni.getStorageSync('tree' + this.option.customId);
-        if (!this.$util.isEmpty(treeData)) {
-          treeData = treeData.map((treeItem) => {
-            let list = treeItem.list ? treeItem.list.filter((item) => {
-              return !this.$util.isEmpty(item.num) && Number(item.num) > 0;
-            }) : [];
-            return { ...treeItem, list: list };
-          }).filter((treeItem) => {
-            return !this.$util.isEmpty(treeItem.list);
-          });
+        if (book == 1) {
+          if (this.form.hasPay != 2) {
+            this.$msg('预订单只能选择挂账');
+            return false;
+          }
+          if (Number(this.form.sendCost) > 0) {
+            this.$msg('预订单不能填写运费');
+            return false;
+          }
         }
-      }
-      params = { ...params, treeData: JSON.stringify(treeData) };
 
-      uni.showLoading({ mask: true });
-      Fn(params).then((res) => {
-        uni.hideLoading();
-        if (res.code == 1) {
-          if (res.data.respondType && res.data.respondType == 'priceError') {
-            that.diffPriceList = res.data.diff;
-            that.$refs.diffPriceRef.open('bottom');
-            return;
+        //多颜色
+        let xj = null;
+        if (this.option && this.option.customId) {
+          xj = uni.getStorageSync('xj' + this.option.customId);
+        }
+        params = { ...params, xj: JSON.stringify(xj) };
+
+        //株数
+        let treeData = null;
+        if (this.option && this.option.customId) {
+          treeData = uni.getStorageSync('tree' + this.option.customId);
+          if (!this.$util.isEmpty(treeData)) {
+            treeData = treeData.map((treeItem) => {
+              let list = treeItem.list ? treeItem.list.filter((item) => {
+                return !this.$util.isEmpty(item.num) && Number(item.num) > 0;
+              }) : [];
+              return { ...treeItem, list: list };
+            }).filter((treeItem) => {
+              return !this.$util.isEmpty(treeItem.list);
+            });
           }
+        }
+        params = { ...params, treeData: JSON.stringify(treeData) };
+
+        uni.showLoading({ mask: true });
+        try {
+          const res = await Fn(params);
+          if (res.code == 1) {
+            if (res.data.respondType && res.data.respondType == 'priceError') {
+              that.diffPriceList = res.data.diff;
+              that.$refs.diffPriceRef.open('bottom');
+              return;
+            }
 
-          this.removeFromSaveDirect();
+            this.removeFromSaveDirect();
 
-          if (res.data && res.data.id) {
-            const {
-              data: { id, orderSn, actPrice }
-            } = res;
-            if (this.form.hasPay == 0) {
-              this.$util.pageTo({ url: '/admin/billing/toPay', type: 2, query: { orderId: id, orderSn: orderSn, actPrice: actPrice } });
+            if (res.data && res.data.id) {
+              const {
+                data: { id, orderSn, actPrice }
+              } = res;
+              if (this.form.hasPay == 0) {
+                this.$util.pageTo({ url: '/admin/billing/toPay', type: 2, query: { orderId: id, orderSn: orderSn, actPrice: actPrice } });
+              } else {
+                this.$util.pageTo({ url: '/admin/billing/result', type: 2, query: { orderId: id, orderSn: orderSn, title: '开单成功' } });
+              }
             } else {
-              this.$util.pageTo({ url: '/admin/billing/result', type: 2, query: { orderId: id, orderSn: orderSn, title: '开单成功' } });
+              this.$msg('提交失败');
             }
-          } else {
-            this.$msg('提交失败');
           }
+        } catch (err) {
+          // luch-request:code==0 等已在封装里 showToast,并 reject(response.data),此处不再重复提示
+          if (err != null && Object.prototype.hasOwnProperty.call(err, 'code')) {
+            return;
+          }
+          this.$msg('提交失败,请重试');
+        } finally {
+          uni.hideLoading();
         }
-      });
+      } finally {
+        this.formSubmitting = false;
+      }
     },
     returnCheck() {
       this.$refs.diffPriceRef.close();