/* 控制区 */
<template>
  <gy-card
    title="控制区"
    area-style="control"
    circle-style="green"
    content-style="44"
  >
    <MatrixCard title="待启动" :datas="ls.start"></MatrixCard>
    <MatrixCard title="待停机" :datas="ls.stop"></MatrixCard>
    <MatrixCard title="待维护" :datas="ls.maintain"></MatrixCard>
    <MatrixCard title="待取消维护" :datas="ls.unmaintain"></MatrixCard>
    <MatrixCard title="待复位" :datas="ls.reset"></MatrixCard>
  </gy-card>
</template>

<script>
import MatrixCard from "./windturbine/MatrixCard.vue";
import MessageBridge from "../../assets/script/MessageBridge";

export default {
  name: "ControlArea",
  components: {
    MatrixCard,
  },
  created: function () {
    this.initData();
  },
  data() {
    return {
      ls: {
        start: { key: "待启动", value: [] },
        stop: { key: "待停机", value: [] },
        maintain: { key: "待维护", value: [] },
        unmaintain: { key: "待取消维护", value: [] },
        reset: { key: "待复位", value: [] },
      },
    };
  },
  methods: {
    initData: function () {
      var mb = MessageBridge.getInstance();
      var vs = [
        { key: "/topic/windturbine", action: this.windturbineMessage },
        { key: "/topic/suggestion", action: this.suggestion },
      ];
      mb.register(vs);
    },
    windturbineMessage: function (msg) {
        var val = JSON.parse(msg);
        for(var v in this.ls){
            var vv = this.ls[v];
            for(var it in vv.value){
                vv.value[it].status = val[it].status;
            }
        }
    },
    suggestion: function (msg) {
      var val = JSON.parse(msg);
      var ll = {
        start: { key: "待启动", value: [] },
        stop: { key: "待停机", value: [] },
        maintain: { key: "待维护", value: [] },
        unmaintain: { key: "待取消维护", value: [] },
        reset: { key: "待复位", value: [] },
      };
      for (var vv in val) {
          var v = val[vv];
        if (v.adviceOperateStyle == "UnMaintain") {
          // 推荐取消维护
          ll.unmaintain.value.push(this.getCardValue(v));
        } else if (v.adviceOperateStyle == "Start") {
          //推荐启动
          ll.start.value.push(this.getCardValue(v));
        } else if (v.adviceOperateStyle == "Stop") {
          // 推荐停机
          ll.stop.value.push(this.getCardValue(v));
        } else if (v.adviceOperateStyle == "Reset") {
          // 推荐复位
          ll.reset.value.push(this.getCardValue(v));
        } else if (v.adviceOperateStyle == "Maintain") {
          // 推荐维护
          ll.maintain.value.push(this.getCardValue(v));
        }
      }
      this.ls=ll;
    },
    getCardValue(val){
        return {
            status:0,
            power:0,
            windSpeed:0,
            rollSpeed:0,
            windturbineId:val.windturbineId,
        }
    }
  },
};
</script>

