<template>
  <div class="buttonBox">
    <!-- <el-button type="primary" @click="handleDeviceInfo">声光报警 </el-button> -->
    <el-dropdown class="dropgps" trigger="click" @command="handleCommandWarn">
      <el-button type="primary">
        声光报警<i class="el-icon-arrow-down el-icon--right"></i>
      </el-button>
      <el-dropdown-menu slot="dropdown" class="gpsdropStyle">
        <el-dropdown-item command="open">开启</el-dropdown-item>
        <el-dropdown-item command="close">关闭</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>
<script>
// import infoDialog from "./infoDialog.vue";
import { getTermStatus, alarmMarkJoggle } from "@/utils/api/index";
export default {
  components: {
    // infoDialog,
  },
  data() {
    return {};
  },
  watch: {
    termId: {
      handler(newVal, oldVal) {},
      deep: true,
      immediate: true,
    },
    cmdId: {
      handler(newVal, oldVal) {},
      deep: true,
      immediate: true,
    },
  },
  computed: {
    termId() {
      return this.$store.state.termId;
    },
    cmdId() {
      return this.$store.state.cmdId;
    },
  },
  methods: {
    //声光报警开启关闭
    handleCommandWarn(command) {
      switch (command) {
        case "open": //开启
          this.handleWarn(1);
          break;
        case "close": //关闭
          this.handleWarn(0);
          break;
      }
    },
    //声光报警
    handleWarn(val) {
      console.log("声光报警");
      console.log(this.termId);
      getTermStatus({ termId: this.termId }).then((res) => {
        console.log(res);
        if (res.data.isonline) {
          alarmMarkJoggle({
            cmdId: this.cmdId,
            ctrl: val,
            termId: this.termId,
          })
            .then((res) => {
              console.log(res);
              if (res.code == 200) {
                if (val == 1) {
                  this.$message({
                    duration: 1500,
                    showClose: true,
                    message: "声光报警开启成功",
                    type: "success",
                  });
                } else {
                  this.$message({
                    duration: 1500,
                    showClose: true,
                    message: "声光报警关闭成功",
                    type: "warning",
                  });
                }
              }
            })
            .catch((err) => {
              this.$message({
                duration: 1500,
                showClose: true,
                message: "声光报警操作失败",
                type: "error",
              });
            });
        } else {
          this.$message({
            duration: 1500,
            showClose: true,
            message: "装置下线，发送指令失败",
            type: "error",
          });
        }
      });
    },
  },
};
</script>
<style lang="less">
.picdropStyle,
.videodropStyle,
.gpsdropStyle {
  width: 104px;
  margin-top: 0px !important;
}
</style>
