Browse Source

Update index.tsx

lex 1 year ago
parent
commit
2317462e3c
1 changed files with 102 additions and 98 deletions
  1. 102 98
      src/views/student-register/index.tsx

+ 102 - 98
src/views/student-register/index.tsx

@@ -131,7 +131,8 @@ export default defineComponent({
       schoolInstrumentSetType: null as any,
       // bugGoods: false, // 是否购买AI
 
-      isRegister: '' as 'create' | 'update' | '', // 是否注册学生
+      isRegister: 'create' as 'create' | 'update' | '', // 是否注册学生
+      isTipRegister: true, // 是否显示名字不一致 - 默认显示
       isChangeSchool: false, // 是否切换学校
 
       registerType: '', // 报名类型
@@ -244,7 +245,6 @@ export default defineComponent({
       time: forms.activeOverTime,
       onFinish() {
         forms.activeOverStatus = true;
-        console.log(forms.submitLoading, 'forms.submitLoading');
         if (forms.submitLoading) return;
         applyOver();
       }
@@ -431,6 +431,12 @@ export default defineComponent({
       };
     });
 
+    // 格式化提示状态
+    const changeTipStatus = (register: boolean, school: boolean) => {
+      forms.isTipRegister = register;
+      forms.isChangeSchool = school;
+    };
+
     const checkForm = (status = true) => {
       if (!checkPhone(studentInfo.username)) {
         status && showToast('请输入正确的手机号码');
@@ -451,80 +457,87 @@ export default defineComponent({
       return false;
     };
 
+    //
+    const checkSubmit = () => {
+      const { extra } = studentInfo;
+      // console.log(
+      //   forms.studentItem.nickname,
+      //   extra.nickname,
+      //   forms.isRegister,
+      //   forms.isTipRegister,
+      //   'isRegister'
+      // );
+      if (
+        forms.studentItem.nickname !== extra.nickname &&
+        forms.isTipRegister
+      ) {
+        otherParams.showOtherMessage =
+          '学生姓名与上次提交信息不一致,请确认修改学生信息或创建新的学生账号';
+        otherParams.showOtherSchool = true;
+        otherParams.showCancelButton = true;
+        otherParams.cancelButtonColor =
+          'linear-gradient( 224deg, #3FE1E6 0%, #00CDD4 100%)';
+        otherParams.cancelButtonText = '新建学生';
+        otherParams.confirmButtonColor =
+          'linear-gradient( 305deg, #40C8FF 0%, #3192FF 100%)';
+        otherParams.confirmButtonText = '修改信息';
+        otherParams.otherType = 'nickname';
+        otherParams.messageAlign = 'left';
+        return true;
+      }
+
+      // 判断新建学员是否上限了
+      if (
+        forms.isRegister === 'create' &&
+        forms.studentList.length >= forms.multi_user_limit
+      ) {
+        otherParams.showOtherMessage = `同一手机号最多创建${forms.multi_user_limit}个学生`;
+        otherParams.showOtherSchool = true;
+        otherParams.showCancelButton = false;
+        otherParams.confirmButtonColor =
+          'linear-gradient( 305deg, #40C8FF 0%, #3192FF 100%)';
+        otherParams.confirmButtonText = '我知道了';
+        otherParams.otherType = 'limit';
+        otherParams.messageAlign = 'center';
+        return true;
+      }
+
+      // 判断是否为同一个学校
+      if (
+        forms.studentItem.schoolId !== forms.registerDetails.schoolId &&
+        !forms.isChangeSchool &&
+        forms.isRegister === 'update'
+      ) {
+        otherParams.showOtherMessage = `您已绑定【${
+          forms.registerDetails.schoolName || ''
+        }】,提交后将更换到【${
+          forms.studentItem?.schoolName
+        }】,是否确认提交?`;
+        otherParams.showOtherSchool = true;
+        otherParams.showCancelButton = true;
+        otherParams.cancelButtonColor = '';
+        otherParams.cancelButtonText = '取消';
+        otherParams.confirmButtonColor = '';
+        otherParams.confirmButtonText = '确定';
+        otherParams.otherType = 'change';
+        otherParams.messageAlign = 'left';
+        return true;
+      }
+      return false;
+    };
+
     /**
      * 登记成功之后购买
      */
     const onSubmit = async () => {
       forms.submitLoading = true;
       try {
-        if (checkForm()) {
+        if (checkForm() || checkSubmit()) {
           forms.submitLoading = false;
           return;
         }
         const { extra, loginType, autoRegister, password, multiUser, ...res } =
           studentInfo;
-        if (
-          forms.studentItem.nickname !== extra.nickname &&
-          forms.isRegister === ''
-        ) {
-          otherParams.showOtherMessage =
-            '学生姓名与上次提交信息不一致,请确认修改学生信息或创建新的学生账号';
-          otherParams.showOtherSchool = true;
-          otherParams.showCancelButton = true;
-          otherParams.cancelButtonColor =
-            'linear-gradient( 224deg, #3FE1E6 0%, #00CDD4 100%)';
-          otherParams.cancelButtonText = '新建学生';
-          otherParams.confirmButtonColor =
-            'linear-gradient( 305deg, #40C8FF 0%, #3192FF 100%)';
-          otherParams.confirmButtonText = '修改信息';
-          otherParams.otherType = 'nickname';
-          otherParams.messageAlign = 'left';
-          return;
-        }
-
-        // 判断新建学员是否上限了
-        console.log(
-          forms.studentItem.userId,
-          forms.studentList.length,
-          forms.multi_user_limit
-        );
-        if (
-          forms.isRegister === 'create' &&
-          forms.studentList.length >= forms.multi_user_limit
-        ) {
-          otherParams.showOtherMessage = `同一手机号最多创建${forms.multi_user_limit}个学生`;
-          otherParams.showOtherSchool = true;
-          otherParams.showCancelButton = false;
-          otherParams.confirmButtonColor =
-            'linear-gradient( 305deg, #40C8FF 0%, #3192FF 100%)';
-          otherParams.confirmButtonText = '我知道了';
-          otherParams.otherType = 'limit';
-          otherParams.messageAlign = 'center';
-          return;
-        }
-
-        // 判断是否为同一个学校
-        if (
-          forms.studentItem.schoolId !== forms.registerDetails.schoolId &&
-          !forms.isChangeSchool &&
-          forms.isRegister !== 'create'
-        ) {
-          otherParams.showOtherMessage = `您已绑定【${
-            forms.registerDetails.schoolName || ''
-          }】,提交后将更换到【${
-            forms.studentItem?.schoolName
-          }】,是否确认提交?`;
-          otherParams.showOtherSchool = true;
-          otherParams.showCancelButton = true;
-          otherParams.cancelButtonColor = '';
-          otherParams.cancelButtonText = '取消';
-          otherParams.confirmButtonColor = '';
-          otherParams.confirmButtonText = '确定';
-          otherParams.otherType = 'change';
-          otherParams.messageAlign = 'left';
-          return;
-        }
-
         /*
           新用户:
           autoRegister: true
@@ -609,9 +622,8 @@ export default defineComponent({
           await onRegisterSubmit();
         }
       } catch {
-        // 重置信息
-        forms.isRegister = '';
-        forms.isChangeSchool = false;
+        // 重置信息 - 如果是新建则不提示
+        changeTipStatus(forms.isRegister === 'create' ? false : true, false);
       } finally {
         forms.submitLoading = false;
       }
@@ -651,10 +663,8 @@ export default defineComponent({
 
         await paymentContinue();
       } catch {
-        //
-        // 重置信息
-        forms.isRegister = '';
-        forms.isChangeSchool = false;
+        // 重置信息 - 如果是新建则不提示
+        changeTipStatus(forms.isRegister === 'create' ? false : true, false);
       }
     };
 
@@ -695,18 +705,13 @@ export default defineComponent({
           });
           studentInfo.extra.gender = firstStudent.gender;
 
-          // forms.isRegister = 'update';
+          forms.isRegister = 'update';
+          changeTipStatus(true, false);
+        } else {
+          forms.isRegister = 'create';
+          changeTipStatus(true, false);
+          forms.studentItem = [];
         }
-        //  else {
-        //   forms.isRegister = 'create';
-        //   forms.isChangeSchool = false;
-        //   studentInfo.extra.nickname = '';
-        //   studentInfo.extra.currentGradeNum = '';
-        //   studentInfo.extra.currentClass = '';
-        //   studentInfo.extra.gender = 1;
-        //   forms.currentClassText = '';
-        //   forms.gradeNumText = '';
-        // }
       } catch {
         //
       }
@@ -788,10 +793,8 @@ export default defineComponent({
           return false;
         }
       } catch {
-        //
-        // 重置信息
-        forms.isRegister = '';
-        forms.isChangeSchool = false;
+        // 重置信息 - 如果是新建则不提示
+        changeTipStatus(forms.isRegister === 'create' ? false : true, false);
       }
       return result;
     };
@@ -886,9 +889,8 @@ export default defineComponent({
         }
       } catch (e: any) {
         console.log(e, 'any');
-        // 重置信息
-        forms.isRegister = '';
-        forms.isChangeSchool = false;
+        // 重置信息 - 如果是新建则不提示
+        changeTipStatus(forms.isRegister === 'create' ? false : true, false);
       }
     };
 
@@ -925,10 +927,8 @@ export default defineComponent({
           onCallback();
         }
       } catch {
-        //
-        // 重置信息
-        forms.isRegister = '';
-        forms.isChangeSchool = false;
+        // 重置信息 - 如果是新建则不提示
+        changeTipStatus(forms.isRegister === 'create' ? false : true, false);
       }
     };
 
@@ -1836,24 +1836,27 @@ export default defineComponent({
             otherParams.showOtherSchool = false;
             if (otherParams.otherType === 'nickname') {
               forms.isRegister = 'create'; // 新建
+              changeTipStatus(false, false);
               onSubmit();
             } else if (otherParams.otherType === 'limit') {
             }
           }}
           onConfirm={() => {
             otherParams.showOtherSchool = false;
+            // 名字
             if (otherParams.otherType === 'nickname') {
               forms.isRegister = 'update'; // 修改
+              changeTipStatus(false, false);
               // 直接注册
               onSubmit();
             } else if (otherParams.otherType === 'change') {
+              // 学校更换
               forms.isChangeSchool = true;
               // 直接注册
               onSubmit();
             } else if (otherParams.otherType === 'limit') {
               // 人数超限制
-              forms.isRegister = '';
-              forms.isChangeSchool = false;
+              changeTipStatus(true, false);
             }
           }}
         />
@@ -1892,10 +1895,11 @@ export default defineComponent({
                   }
                 });
                 studentInfo.extra.gender = firstStudent.gender;
-                // forms.isRegister = 'update';
+                forms.isRegister = 'update';
+                changeTipStatus(true, false);
               } else {
                 forms.isRegister = 'create';
-                forms.isChangeSchool = false;
+                changeTipStatus(true, false);
                 studentInfo.extra.nickname = '';
                 studentInfo.extra.currentGradeNum = '';
                 studentInfo.extra.currentClass = '';