<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">
      <table-2 :data="data" :height="'100%'" @headerClick="headerClick"></table-2>
    </div>
  </div>
</template>

<script>
import Table2 from "@com/coms/table/table2.vue";
import BtnGroup2 from "@com/coms/btn/btn-group-double.vue";
export default {
  // 名称
  name: "DraughtFanList",
  // 使用组件
  components: {
    Table2,
    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",
            sortable: false,
            is_num: false,
            is_light: false,
          },
          {
            name: "冷却风温度",
            field: "FDJLQFWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "有功功率",
            field: "FJGL",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "液压油温度",
            field: "YYYW",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "Pcspp温度",
            field: "PCS_WD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "U1绕组温度",
            field: "U1YZWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "U2绕组温度",
            field: "U2YZWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "V1绕组温度",
            field: "V1YZWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "V2绕组温度",
            field: "V2YZWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "W1绕组温度",
            field: "W1YZWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "W2绕组温度",
            field: "W2YZWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "轴承A温度",
            field: "FDJZCAWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "轴承B温度",
            field: "FDJZCBWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "齿轮箱温度",
            field: "CLXWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "齿轮箱轴1温度",
            field: "CLXSRZ1WD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "齿轮箱轴2温度",
            field: "CLXSRZ2WD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "机舱温度",
            field: "JCWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "滑环温度",
            field: "FDJHHWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
          {
            name: "环境温度",
            field: "JCWWD",
            sortable: false,
            is_num: true,
            is_light: false,
          },
        ],
        data: [],
        total: 1000,
      },
    };
  },
  // 函数
  methods: {
    // 请求服务
    requestData(showLoading) {
      if (this.wpId.indexOf("GDC") != -1) {
        this.requestDataGDC(showLoading);
        return 0;
      }
      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,
            column: [
              {
                name: "风机名称",
                field: "code",
                width: 100,
                is_num: false,
                is_light: false,
              },
              {
                name: "冷却风温度",
                field: "FDJLQFWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "有功功率",
                field: "FJGL",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "液压油温度",
                field: "YYYW",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "Pcspp温度",
                field: "PCS_WD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "U1绕组温度",
                field: "U1YZWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "U2绕组温度",
                field: "U2YZWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "V1绕组温度",
                field: "V1YZWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "V2绕组温度",
                field: "V2YZWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "W1绕组温度",
                field: "W1YZWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "W2绕组温度",
                field: "W2YZWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "轴承A温度",
                field: "FDJZCAWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "轴承B温度",
                field: "FDJZCBWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "齿轮箱温度",
                field: "CLXWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "齿轮箱轴1温度",
                field: "CLXSRZ1WD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "齿轮箱轴2温度",
                field: "CLXSRZ2WD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "机舱温度",
                field: "JCWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "滑环温度",
                field: "FDJHHWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
              {
                name: "环境温度",
                field: "JCWWD",
                width: 100,
                is_num: true,
                is_light: false,
              },
            ],
          };
        },
      });
    },
    // 光伏电站列表
    async requestDataGDC(showLoading) {
      let res = await this.API.requestData({
        showLoading,
        method: "POST",
        subUrl: "monitorinverter/findInverterInfoList",
        data: {
          wpId: this.wpId,
        },
      });
      let column = [
        { name: "逆变器", field: "code" },
        { name: "光照强度", field: "JSSSFS" },
        { name: "有功功率", field: "AI130" },
        { name: "功率因数", field: "AI067" },
        { name: "机内温度", field: "AIG071" },
        { name: "逆变效率", field: "AIG072" },
        { name: "日发电量", field: "RFDL" },
        { name: "月发电量", field: "YFDL" },
        { name: "年发电量", field: "NFDL" },
        { name: "累计发电量", field: "AIG064" },
      ];
      this.data = { data: res.data.data, column: column };
    },
    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) {
      this.$router.replace({
        path: `/monitor/windsite/draughtfanlist/${res.code}`,
      });
    },

    headerClick(param) {
      this.data.column.forEach((item) => {
        item.sortable = false;
      });
      this.data.column[param.index].sortable = true;
    },
  },

  created() {
    let that = this;
    that.wpId = that.$route.params.wpId;
    that.getWp();
    that.$nextTick(() => {
      that.requestData(false);
      that.timmer = setInterval(() => {
        that.$nextTick(() => {
          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>
