/* 问题区 */
<template>
  <gy-card
    title="问题区"
    area-style="problem"
    circle-style="green"
    content-style="89"
    @parentRun="run"
    @contextmenu="contextmenu"
  >
    <ProblemMatrixCard title="故障" :type="5" ref="malfunction"></ProblemMatrixCard>
    <ProblemMatrixCard title="维护" :type="6" ref="maintain"></ProblemMatrixCard>
    <ProblemMatrixCard title="离线" :type="7" ref="offline"></ProblemMatrixCard>
    <ProblemMatrixCard title="挂牌" :type="-1" ref="lock"></ProblemMatrixCard>
  </gy-card>
</template>

<script>
import ProblemMatrixCard from "./windturbine/problem/ProblemMatrixCard.vue";
import BackgroundData from "../../assets/script/BackgroundData";

export default {
  name: "ProblemArea",
  components: {
    ProblemMatrixCard,
  },
  props: {},
  data() {
    return {
      ls: {
        maintain: { key: "维护", value: [] },
        malfunction: { key: "故障", value: [] },
        offline: { key: "离线", value: [] },
        lockd: { key: "挂牌", value: [] },
      },
    };
  },
  computed: {},
  created: function () {
    
  },
  methods: {
    /* 右键菜单 */
    contextmenu() {
      const { remote } = require("electron");
      var that = this;
      const menuTemplate = [
        {
          label: "标注",
          click() {
            that.menuClicked({ type: "marking" });
          },
        },
        {
          label: "挂牌",
          submenu: [
            {
              label: "检修",
              click() {
                that.menuClicked({ type: "lock", value: "CheckLock" });
              },
            },
            {
              label: "故障维修",
              click() {
                that.menuClicked({ type: "lock", value: "FaultLock" });
              },
            },
            {
              label: "场内受累检修",
              click() {
                that.menuClicked({ type: "lock", value: "StationCheckLock" });
              },
            },
            {
              label: "场内受累故障",
              click() {
                that.menuClicked({ type: "lock", value: "StationFaulLock" });
              },
            },
            {
              label: "场外受累电网",
              click() {
                that.menuClicked({ type: "lock", value: "StationPowerLineLock" });
              },
            },
            {
              label: "场外受累天气",
              click() {
                that.menuClicked({ type: "lock", value: "StationWeatherLock" });
              },
            },
          ],
        },
        {
          label: "取消挂牌",
          click() {
            that.menuClicked({ type: "lock",value:"UnLock" });
          },
        },
      ];
      const menu = remote.Menu.buildFromTemplate(menuTemplate);

      menu.popup(remote.getCurrentWindow());
    },

    menuClicked(msg) {
      var bd = BackgroundData.getInstance();
      if (!bd.LoginUser) {
        bd.showdialog("提示", "请登录：", "在控制之前需要先登录！");
        return;
      }
      if (msg.type == "lock") {
        // 挂牌
        var los = this.getSelectedItems();
        for(var id in los){
          los[id].lockType=msg.value;
        }
        bd.windturbineControl(los,true);
      } else if (msg.type == "marking") {
        // 标注
        var vs = this.getSelectedItems();
        bd.marking(vs);
      }
      this.clearSelected();
    },

    /* 获取选中的项目，isControl：是否是控制 */
    getSelectedItems(){
      var ls = new Array();
      this.$refs.malfunction.outputSelectedItems(ls);
      this.$refs.maintain.outputSelectedItems(ls);
      this.$refs.offline.outputSelectedItems(ls);
      this.$refs.lock.outputSelectedItems(ls);
      return ls;
    },
    
    /* 清除所有选择 */
    clearSelected(){
      this.$refs.malfunction.clearSelected();
      this.$refs.maintain.clearSelected();
      this.$refs.offline.clearSelected();
      this.$refs.lock.clearSelected();
    },
  },
};
</script>
