Ver Fonte

2021-12-06

East há 3 anos atrás
pai
commit
fd55a4f4bb
2 ficheiros alterados com 42 adições e 30 exclusões
  1. 4 3
      src/views/Alarm/AlarmSet.vue
  2. 38 27
      src/views/Alarm/alarm-set/AlarmForm.vue

+ 4 - 3
src/views/Alarm/AlarmSet.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2021-11-29 15:06:41
- * @LastEditTime: 2021-12-01 16:16:56
+ * @LastEditTime: 2021-12-06 16:02:16
  * @LastEditors: Please set LastEditors
  * @Description: 报警阈值设置
  * @FilePath: \hyyfClient\src\views\Alarm\AlarmSet.vue
@@ -66,11 +66,12 @@ export default {
         await this.$refs["regularRef"].actionRegular();
         await this.$refs["alarmFormRef"].addPhonesAction();
         await this.$refs["alarmTableRef"].addAlarmSets();
-        loading.close();
         this.$message.success("设置成功");
       } catch (err) {
         console.log(err);
-        this.$message.error("设置失败");
+        this.$message.error("设置失败:" + err.message);
+      } finally {
+        loading.close();
       }
     },
   },

+ 38 - 27
src/views/Alarm/alarm-set/AlarmForm.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2021-11-29 16:41:38
- * @LastEditTime: 2021-12-06 15:11:12
+ * @LastEditTime: 2021-12-06 16:00:29
  * @LastEditors: Please set LastEditors
  * @Description: 报警设置的 各个报警号码
  * @FilePath: \hyyfClient\src\views\Alarm\alarm-set\AlarmForm.vue
@@ -141,32 +141,43 @@ export default {
       });
     },
     addPhonesAction() {
-      // this.$refs[alarmForm]
-      const secondPhones = this.alarmForm.secondPhones.reduce((prev, item) => {
-        return prev + item.phone + ",";
-      }, "");
-      const thirdPhones = this.alarmForm.thirdPhones.reduce((prev, item) => {
-        return prev + item.phone + ",";
-      }, "");
-      postAlarmPhones([
-        {
-          id: this.secondId || undefined,
-          farmId: Number(localStorage.getItem("lastFarmId")),
-          wraningName: "二级报警",
-          phone: secondPhones,
-          level: 2,
-        },
-        {
-          id: this.thirdId || undefined,
-          farmId: Number(localStorage.getItem("lastFarmId")),
-          wraningName: "三级报警",
-          phone: thirdPhones,
-          level: 3,
-        },
-      ]).then((res) => {
-        console.log(res);
-        if (res.code === 10000) {
-          this.initGetPhones();
+      this.$refs["alarmForm"].validate((valid) => {
+        if (valid) {
+          const secondPhones = this.alarmForm.secondPhones.reduce(
+            (prev, item) => {
+              return prev + item.phone + ",";
+            },
+            ""
+          );
+          const thirdPhones = this.alarmForm.thirdPhones.reduce(
+            (prev, item) => {
+              return prev + item.phone + ",";
+            },
+            ""
+          );
+          postAlarmPhones([
+            {
+              id: this.secondId || undefined,
+              farmId: Number(localStorage.getItem("lastFarmId")),
+              wraningName: "二级报警",
+              phone: secondPhones,
+              level: 2,
+            },
+            {
+              id: this.thirdId || undefined,
+              farmId: Number(localStorage.getItem("lastFarmId")),
+              wraningName: "三级报警",
+              phone: thirdPhones,
+              level: 3,
+            },
+          ]).then((res) => {
+            console.log(res);
+            if (res.code === 10000) {
+              this.initGetPhones();
+            }
+          });
+        } else {
+          throw new Error("手机号有误");
         }
       });
     },