Browse Source

fix: 赠送好友插件问题修复

Signed-off-by: tangshizhe <48740614+tangshizhe@users.noreply.github.com>
tangshizhe 4 months ago
parent
commit
e68523c18c
1 changed files with 32 additions and 17 deletions
  1. 32 17
      plugins/gift-friends/src/components/GiftSubmitDialog.vue

+ 32 - 17
plugins/gift-friends/src/components/GiftSubmitDialog.vue

@@ -339,25 +339,40 @@ export default {
       })
       })
     },
     },
     addPerson() {
     addPerson() {
-      this.personList.map((item, index) => {
-        return this.$refs[`form${index}`][0].validate((valid) => {
-          if (!valid) {
-            this.$toast('请先完成当前未完善的手机号和时长信息')
-            this.addFormStyle(index, !valid)
-          }
-          else {
-            this.personList.push({
-              phone: '',
-              monthnum: '',
-              status: '',
-              error: '',
-              phoneValid: false,
-              monthnumValid: false
-            })
-            this.updateFormValidity()
-          }
+      const validationPromises = this.personList.map((item, index) => {
+        return new Promise((resolve) => {
+          this.$refs[`form${index}`][0].validate((valid) => {
+            // 将 index 和 valid 封装成对象传递
+            resolve({ index, valid })
+          })
         })
         })
       })
       })
+      Promise.all(validationPromises).then((results) => {
+        // 判断是否有未完成的信息
+        const hasIncomplete = results.some(({ valid }) => !valid)
+
+        if (hasIncomplete) {
+          // 处理未完成信息的逻辑
+          results.forEach(({ index, valid }) => {
+            if (!valid) {
+              // 对未完成信息的表单添加样式
+              this.addFormStyle(index, !valid)
+            }
+          })
+          return this.$toast('请先完成当前未完善的手机号和时长信息')
+        }
+        else {
+          this.personList.push({
+            phone: '',
+            monthnum: '',
+            status: '',
+            error: '',
+            phoneValid: false,
+            monthnumValid: false
+          })
+          this.updateFormValidity()
+        }
+      })
     },
     },
     /**
     /**
      * 重置人员列表
      * 重置人员列表