<template>
  <div class="booster-station">
    <div class="btn-group-tabs">
      <BtnGroup2
        :btnGroups="btnGroups"
        :rowIndex="rowIndex"
        :index="selectIndex"
        @select="select"
      ></BtnGroup2>
    </div>
    <!-- <bsx6 class="booster-station-body"></bsx6> -->
    <BoosterMCH class="booster-station-body"></BoosterMCH>
  </div>
</template>

<script>
import BtnGroup2 from "@com/coms/btn/btn-group-double.vue";
// import bsx6 from "../components/bsx6.vue";
import BoosterMCH from "../components/boosterstation/mch/mch.vue";

export default {
  // 名称
  name: "BoosterStation",
  // 使用组件
  components: {
    // bsx6,
    BtnGroup2,
    BoosterMCH,
  },
  // 数据
  data() {
    return {
      wpId: undefined,
      selectIndex: 0,
      rowIndex: 0,
      btnGroups: [
        {
          icon: "svg-wind-site",
          btns: [],
        },
        {
          icon: "svg-photovoltaic",
          btns: [],
        },
      ],
    };
  },
  created() {
    let that = this;
    that.wpId = that.$route.params.wpId;
    that.$nextTick(() => {
      that.getWp();
    });
  },
  // 函数
  methods: {
    select(res) {
      this.$router.replace({
      path: `/monitor/windsite/boosterstation/${res.code}`,
    });
    },
    getWp() {
      let that = this;
      that.API.requestData({
        method: "GET",
        subUrl: "powercompare/windfarmAllAjax",
        success(res) {
          let btnGroup = [
            {
              icon: "svg-wind-site",
              btns: [],
            },
            {
              icon: "svg-photovoltaic",
              btns: [],
            },
          ];

          res.data.forEach((ele, index) => {
            if (ele.id.indexOf("FDC") !== -1) {
              btnGroup[0].btns.push({
                text: ele.name,
                code: ele.id,
              });
            } else {
              btnGroup[1].btns.push({
                text: ele.name,
                code: ele.id,
              });
            }
          });

          that.btnGroups = btnGroup;
          that.renderBtnActiveIndex();
        },
      });
    },
    renderBtnActiveIndex() {
      this.btnGroups.forEach((pEle, pIndex) => {
        pEle.btns.forEach((cEle, cIndex) => {
          if (cEle.code === this.wpId) {
            this.rowIndex = pIndex;
            this.selectIndex = cIndex;
          }
        });
      });
    },
  },
  // 生命周期钩子
  beforeCreate() {
    // 创建前
  },
  beforeMount() {
    // 渲染前
  },
  mounted() {
    // 渲染后
  },
  beforeUpdate() {
    // 数据更新前
  },
  updated() {
    // 数据更新后
  },
  watch: {
    $route(res) {
      this.wpId = res.params.wpId;
      if (res.params.wpId) {
        this.renderBtnActiveIndex();
      }
    },
  },
};
</script>

<style lang="less" scoped>
.booster-station {
  width: 100%;
  height: calc(100vh - 90px);
  display: flex;
  flex-direction: column;

  .btn-group-tabs {
    display: flex;
    flex-direction: row;
  }

  .booster-station-body {
    flex-grow: 1;
  }
}
</style>
