panhui 4 лет назад
Родитель
Сommit
6010c1ce38
1 измененных файлов с 16 добавлено и 16 удалено
  1. 16 16
      src/main/h5/src/views/TrainingInstitution.vue

+ 16 - 16
src/main/h5/src/views/TrainingInstitution.vue

@@ -417,15 +417,7 @@ export default {
     let data = JSON.parse(
       window.localStorage.getItem("trainingInstitution") || "{}"
     );
-    if (data.specialty) {
-      data.specialty = data.specialty.split(",");
-      data.specialty.forEach((item, index) => {
-        if (!this.specialtyOptions.includes(item)) {
-          data.specialty[index] = "其他";
-          this.extra = item;
-        }
-      });
-    }
+    data.specialty = this.setSpecialty(data.specialty);
     this.form = data;
   },
   computed: {
@@ -461,6 +453,20 @@ export default {
           }, 500);
         });
     },
+    setSpecialty(specialty) {
+      if (specialty) {
+        specialty = specialty.split(",");
+        specialty.forEach((item, index) => {
+          if (!this.specialtyOptions.includes(item)) {
+            specialty[index] = "其他";
+            this.extra = item;
+          }
+        });
+        return specialty;
+      } else {
+        return [];
+      }
+    },
     byUscc() {
       this.$refs.form.validate().then(() => {
         this.$toast.loading({
@@ -474,13 +480,7 @@ export default {
             `/trainingInstitution/byUscc?name=${this.form.name}&uscc=${this.form.uscc}`
           )
           .then(res => {
-            res.specialty = res.specialty.split(",");
-            res.specialty.forEach((item, index) => {
-              if (!this.specialtyOptions.includes(item)) {
-                res.specialty[index] = "其他";
-                this.extra = item;
-              }
-            });
+            res.specialty = this.setSpecialty(res.specialty);
             this.$toast.clear();
             this.form = { ...res, ...this.form };
             if (!this.form.engagedInTraining) {