瀏覽代碼

手动输入步进器结果保存失败问题

xiaohaizhao 1 年之前
父節點
當前提交
66a7c788eb

+ 10 - 2
pages/index/collect/modules/custom.js

@@ -43,8 +43,16 @@ Component({
           };
           //是否为定制项
           custom = this.selectComponent("#customMade").getResult(true);
-          if (typeof custom == "boolean") return resolve(false);
-          getApp().globalData.customizedProduct(item, custom).then(res => resolve(true))
+          let count = setInterval(() => {
+            if (custom != 'wait') {
+              if (typeof custom == "boolean") return resolve(false);
+              getApp().globalData.customizedProduct(item, custom).then(res => resolve(true))
+              clearInterval(count)
+            } else {
+              custom = this.selectComponent("#customMade").getResult(true);
+            }
+          }, 100);
+
         } else {
           resolve(false);
           this.setData({

+ 34 - 22
pages/index/collect/modules/customMade/index.js

@@ -17,7 +17,9 @@ Component({
   },
   externalClasses: ["external-custom-box", "external-custom-label", "external-custom-stepper-box", "external-explain", "external-active", "external-custom-option"],
   data: {
-    list: []
+    list: [],
+    focus: false,
+    isSubmit: false
   },
   methods: {
     init(data, prefix = '') {
@@ -42,26 +44,35 @@ Component({
       });
       this.getResult();
     },
-    getResult(isSubmit) {
-      let obj = {};
-      let breakOff = false;
-      this.data.list.filter(v => {
-        if (breakOff) return;
-        if (v.type == '自定义') {
-          if (!v.value) v.value = 0;
-          if (v.value < v.min) v.value = v.min;
-        }
-        obj[v.key] = v.value || '';
-        if (isSubmit && !obj[v.key]) {
-          wx.showToast({
-            title: `请完成定制"${v.label}"选项`,
-            icon: "none"
-          })
-          breakOff = true;
-        }
-      })
-      this.triggerEvent("onChange", breakOff ? false : obj)
-      return breakOff ? false : obj
+    onFocus(e) {
+      this.data.focus = true;
+    },
+    getResult(isSubmit = false) {
+      if (isSubmit && this.data.focus) {
+        this.data.isSubmit = isSubmit;
+        return "wait"
+      } else {
+        let obj = {};
+        let breakOff = false;
+        this.data.list.filter(v => {
+          if (breakOff) return;
+          if (v.type == '自定义') {
+            if (!v.value) v.value = 0;
+            if (v.value < v.min) v.value = v.min;
+          }
+          obj[v.key] = v.value || '';
+          if (isSubmit && !obj[v.key]) {
+            wx.showToast({
+              title: `请完成定制"${v.label}"选项`,
+              icon: "none"
+            })
+            breakOff = true;
+          }
+        })
+        this.triggerEvent("onChange", breakOff ? false : obj)
+        this.data.isSubmit = false;
+        return breakOff ? false : obj
+      }
     },
     /* 定制步进器 */
     changeStepper(e) {
@@ -76,6 +87,7 @@ Component({
         item.value -= 1
       } else {
         item.value = (e.detail.value - 0).toFixed(item.decimalplaces);
+        this.data.focus = false;
       }
       item.value = item.value - 0;
       if (item.value > item.max) item.value = item.max;
@@ -83,7 +95,7 @@ Component({
       this.setData({
         [`list[${index}]`]: item
       })
-      this.getResult();
+      this.getResult(this.data.isSubmit);
     },
   }
 })

+ 1 - 1
pages/index/collect/modules/customMade/index.wxml

@@ -13,7 +13,7 @@
 		</navigator>
 	</block>
 	<view class="stepper-box external-custom-stepper-box" wx:elif="{{item.type=='自定义'}}">
-		<van-stepper value="{{item.value||0}}" data-item="{{item}}" data-index="{{index}}" input-width="60px" min="{{item.min}}" max="{{item.max}}" decimal-length="{{ item.decimalplaces }}" bind:plus='changeStepper' bind:blur='changeStepper' bind:minus='changeStepper' />
+		<van-stepper value="{{item.value||0}}" data-item="{{item}}" data-index="{{index}}" input-width="60px" min="{{item.min}}" max="{{item.max}}" decimal-length="{{ item.decimalplaces }}" bind:focus='onFocus' bind:plus='changeStepper' bind:blur='changeStepper' bind:minus='changeStepper' />
 		<view class="explain external-explain">{{item.min+'mm ~ '+ item.max}}mm,<text wx:if="{{item.decimalplaces}}">保留{{item.decimalplaces}}位小数</text><text wx:else>不保留小数</text></view>
 	</view>
 </view>