<template>
  <div class="draught-fan-list">
    <div class="btn-group-tabs">
        <BtnGroup2 :btnGroups="btnGroupsss" :rowIndex="rowIndex" :index="selectIndex" @select="select"></BtnGroup2>
    </div>
    <div class="df-table">
      <ComTable :data="data"></ComTable>
    </div>
  </div>
</template>

<script>
import ComTable from "@com/coms/table/table.vue";
import BtnGroup2 from "@com/coms/btn/btn-group-double.vue";
export default {
  // 名称
  name: "DraughtFanList",
  // 使用组件
  components: {
    ComTable,
    BtnGroup2,
  },
  // 数据
  data() {
    return {
      btnGroupsss: [
        {
          icon: "fa fa-fire",
          btns: [
            {
              text: "某某风场",
              code: "mmfdc1",
            },
            {
              text: "某某风场",
              code: "mhsfc",
            },
            {
              text: "某某风场",
              code: "mmfdc2",
            },
            {
              text: "某某风场",
              code: "mmfdc3",
            },
            {
              text: "某某风场",
              code: "mmfdc4",
            },
          ],
        },
        {
          icon: "fa fa-fire-extinguisher",
          btns: [
            {
              text: "某某风场",
              code: "mmgf1",
            },
            {
              text: "某某风场",
              code: "mmgf2",
            },
            {
              text: "某某风场",
              code: "mmgf3",
            },
            {
              text: "某某风场",
              code: "mmgf4",
            },
          ],
        },
      ],
      data: {
        column: [
          {
            name: "风机名称",
            field: "code",
            is_num: false,
            is_light: false,
          },
          {
            name: "冷却风温度",
            field: "FDJLQFWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "有功功率",
            field: "FJGL",
            is_num: true,
            is_light: false,
          },
          {
            name: "液压油温度",
            field: "YYYW",
            is_num: true,
            is_light: false,
          },
          {
            name: "Pcspp温度",
            field: "PCS_WD",
            is_num: true,
            is_light: false,
          },
          {
            name: "U1绕组温度",
            field: "U1YZWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "U2绕组温度",
            field: "U2YZWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "V1绕组温度",
            field: "V1YZWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "V2绕组温度",
            field: "V2YZWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "W1绕组温度",
            field: "W1YZWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "W2绕组温度",
            field: "W2YZWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "轴承A温度",
            field: "FDJZCAWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "轴承B温度",
            field: "FDJZCBWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "齿轮箱温度",
            field: "CLXWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "齿轮箱轴1温度",
            field: "CLXSRZ1WD",
            is_num: true,
            is_light: false,
          },
          {
            name: "齿轮箱轴2温度",
            field: "CLXSRZ2WD",
            is_num: true,
            is_light: false,
          },
          {
            name: "机舱温度",
            field: "JCWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "滑环温度",
            field: "FDJHHWD",
            is_num: true,
            is_light: false,
          },
          {
            name: "环境温度",
            field: "JCWWD",
            is_num: true,
            is_light: false,
          },
        ],
        data: [],
      },
    };
  },
  // 函数
  methods: {
    // 请求服务
    requestData(showLoading) {
      let that = this;
      that.API.requestData({
        showLoading,
        method: "POST",
        subUrl: "monitorwt/findWtInfoList",
        data: {
          wpId: that.wpId
        },
        success(res) {
          res.data.forEach((ele) => {
            for (let key in ele) {
              if (key !== "code" && key !== "lnid" && key !== "model" && key !== "pjid" && key !== "wpid") {
                ele[key] = ele[key] || 0;
              }
            }
          });
          that.data.data = res.data;
        },
      });
    },
    getWp () {
      let that = this;
      that.API.requestData({
        method: "GET",
        subUrl: "powercompare/windfarmAllAjax",
        success (res) {
          let btnGroups = [
            {
              icon: "svg-wind-site",
              btns: [],
            },
            {
              icon: "svg-photovoltaic",
              btns: [],
            },
          ];

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

          that.btnGroupsss = btnGroups;
          that.renderBtnActiveIndex();
        },
      });
    },

    renderBtnActiveIndex () {
      this.btnGroupsss.forEach((pEle, pIndex) => {
        pEle.btns.forEach((cEle, cIndex) => {
          if (cEle.code === this.wpId) {
            this.rowIndex = pIndex;
            this.selectIndex = cIndex;
          }
        });
      });
    },

    select (res) {
      debugger;
      this.$router.replace({
        path: `/monitor/windsite/draughtfanlist/${res.code}`,
      });
    },

  },

  created() {
    let that = this;
    that.wpId = that.$route.params.wpId;
     that.getWp();
    that.$nextTick(() => {
      that.requestData(false);
      that.timmer = setInterval(() => {
        that.requestData(false);
      }, that.$store.state.websocketTimeSec);
    });
  },

  mounted() {},

  unmounted() {
    clearInterval(this.timmer);
    this.timmer = null;
  },  watch: {
    $route (res) {
      this.wpId = res.params.wpId;
      if (res.params.wpId) {
        this.requestData(false);
        this.renderBtnActiveIndex();
      }
    },
  },
};

</script>

<style lang="less">
.draught-fan-list {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

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

  .df-table {
    border: 0.093vh solid fade(@darkgray, 50%);
    position: relative;
    overflow: auto;
    flex-grow: 1;
    margin-top: 1.481vh;

    &:before {
      content: "";
      width: 0.37vh;
      height: 0.37vh;
      background: @write;
      position: absolute;
      left: 0.278vh;
      top: 0.278vh;
    }

    tbody {
      height: calc(100vh - 166px);
    }
  }
}
</style>
