<template>
  <div class="comprehensiveEvaluation">
    <div class="Evaluation_topall">
      <div class="Evaluation_top">
        <el-select
          size="mini"
          v-model="companyVal"
          placeholder="请选择"
          @change="changeCompan"
        >
          <el-option
            v-for="item in companyOptions"
            :key="item.id"
            :label="item.aname"
            :value="item.id"
          >
          </el-option>
        </el-select>
        <div class="station">
          场站：
          <el-select
            size="mini"
            v-model="stationVal"
            placeholder="请选择"
            clearable
            @change="changeStation"
          >
            <el-option
              v-for="item in stationOptions"
              :key="item.id"
              :label="item.aname"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
        <div class="station">
          时间：
          <div class="">
            <el-date-picker
              v-if="tabIndex == 'month'"
              size="mini"
              v-model="pickerTimer"
              type="month"
              value-format="YYYY-MM"
              placeholder="选择月份"
              popper-class="date-select"
            >
            </el-date-picker>
          </div>
        </div>
        <div class="but">
          <el-button round size="mini" class="buttons" @click="seachData"
            >搜 索</el-button
          >
        </div>
      </div>
    </div>
    <div
      style="
        background: rgba(0, 0, 0, 0.4);
        height: calc(100% - 39px);
        padding-bottom: 15px;
      "
    >
      <div class="Evaluation_title clearfix">
        <div class="leftContent floatLeft"><span>性能等级评估</span></div>
      </div>

      <div class="economicTable1">
        <el-table
          :data="EvaluationData"
          stripe
          size="mini"
          height="calc(100% - 40px)"
          ref="Eval_table"
          style="width: 100%"
        >
          <el-table-column prop="equipmentId" label="设备编号" align="center">
          </el-table-column>
          <el-table-column
            v-for="(item, index) in tableHeaderGf"
            :key="index"
            sortable
            :prop="item.code"
            :label="item.title"
            align="center"
          />
        </el-table>
        <div style="text-align: right">
          <el-pagination
            @current-change="handlePageChange"
            @size-change="handleSizeChange"
            :page-sizes="[22, 50, 100, 500]"
            :current-page="page.currentPage"
            :page-size="page.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.total"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getApicompanyslist,
  getApiwpByCplistlist,
} from "@/api/monthlyPerformanceAnalysis";
import { getApiequipmentinfoDayListGf } from "@/api/powerAnalyse.js";
// import historyDetail from "./historyDetail.vue";
// import dayDetailInfo from "./dayDetailInfo.vue";
import dayjs from "dayjs";
export default {
  name: "PerformanceEvaluation",
  components: {
    // historyDetail,
    // dayDetailInfo,
  },
  data() {
    return {
      tabIndex: "month",
      companyVal: "",
      companyOptions: [],
      stationVal: "",
      stationOptions: [],
      pickerTimer: "",
      EvaluationData: [],
      tableHeaderGf: [
        { title: "离散率(%)", code: "scatter" },
        { title: "转换效率(%)", code: "conversionEfficiency" },
        { title: "等价发电时(h)", code: "equivalentGeneratingTime" },
        { title: "设备可利用率(%)", code: "deviceAvailability" },
      ],
      dialogVisible: false,
      dialogTitle: "",
      chooseList: [],
      contrastVisible: false,
      tabEvent: -2,
      tabOptions: [
        { id: -1, name: "风电" },
        { id: -2, name: "光伏" },
      ],
      page: {
        currentPage: 1,
        pagesize: 22,
        total: 0,
      },
      historyTimer: "",
    };
  },
  created() {
    this.getCompanyData();
    this.pickerTimer = dayjs().add(-1, "day").format("YYYY-MM-DD");
    this.historyTimer = dayjs().add(-1, "day").format("YYYY-MM-DD");
  },
  computed: {
    pageHeight() {
      return {
        height: document.documentElement.clientHeight - 130 + "px",
      };
    },
  },
  methods: {
    handlePageChange(val) {
      this.page.currentPage = val;
      this.seachData();
    },
    handleSizeChange(val) {
      this.page.currentPage = 1;
      this.page.pagesize = val;
      this.seachData();
    },

    changeBtn(id) {
      this.tabEvent = id;
      this.stationVal = "";
      this.stationOptions = [];
      this.getStationData();
      this.seachData();
    },
    // 获取公司列表
    async getCompanyData() {
      this.companyOptions = [];

      const { data: datas } = await getApicompanyslist();
      this.companyOptions = datas.data;
      this.companyVal = datas.data[1]?.id;
      this.getStationData();
    },
    changeCompan(val) {
      this.companyVal = val;
      this.stationOptions = [];
      this.stationVal = "";
      this.getStationData();
    },
    // 获取场站列表
    async getStationData() {
      this.stationOptions = [];
      let params = {
        type: this.tabEvent,
        companyid: this.companyVal,
      };
      const { data: datas } = await getApiwpByCplistlist(params);
      if (datas.data.length) {
        this.stationOptions = datas.data;
        this.stationVal = "SXJ_KGDL_HR_GDC_STA";
        this.getTableData();
      } else {
        this.stationOptions = [];
        this.stationVal = "";
        this.EvaluationData = [];
        this.page.total = 0;
      }
    },
    changeStation(val) {
      this.stationVal = val;
      this.getTableData();
    },
    seachData() {
      this.getTableData();
    },
    async getTableData() {
      let params = {
        time: this.pickerTimer,
        timeType: this.tabIndex,
        stationId: this.stationVal,
        type: this.tabEvent,
        pageNum: this.page.currentPage,
        pageSize: this.page.pagesize,
      };
      const { data } = await getApiequipmentinfoDayListGf(params);
      this.EvaluationData = data.records;
      this.page.total = data.total;
    },
  },
};
</script>

<style lang="less">
.comprehensiveEvaluation {
  padding: 0 20px;
  height: 100%;

  .Evaluation_title {
    .leftContent {
      width: 242px;
      height: 41px;
      line-height: 41px;
      background: url("~@/assets/imgs/title_left_bg1.png") no-repeat;
      span {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #05bb4c;
        margin-left: 25px;
      }
    }
    .floatLeft {
      float: left;
    }
    .floatRight {
      float: right;
    }
    .rightContent {
      width: 212px;
      height: 28px;
      margin-top: 13px;
      background: url("../../../../assets/imgs/title_right_bg.png");
    }
  }
  .clearfix::after {
    content: "";
    clear: both;
    height: 0;
    line-height: 0;
    visibility: hidden;
    display: block;
  }
  .clearfix {
    zoom: 1;
  }
  .Evaluation_topall {
    display: flex;
    justify-content: space-between;
    .selections {
      position: relative;
      right: 120px;
      display: flex;
      margin-top: 10px;
      .selections_btn {
        flex: 0 0 55px;
        text-align: center;
        height: 33px;
        line-height: 33px;
        margin-right: 8px;
        color: #b9b9b9;
        font-size: 1.296vh;
        background: fade(#606769, 20);
        border: 1px solid fade(#606769, 20);
        border-radius: 20px;
        &:hover,
        &.active {
          background: fade(#05bb4c, 80);
          border: 1px solid #05bb4c;
          color: #fff;
          cursor: pointer;
        }
      }
    }
    .Evaluation_top {
      display: flex;
      flex-direction: row;
      align-items: center;
      padding-top: 10px;
      padding-bottom: 10px;

      .station {
        display: flex;
        flex-direction: row;
        align-items: center;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #b3b3b3;
        margin-right: 10px;
        margin-left: 10px;
      }

      .search-input {
        margin-left: 10px;
        .el-input__inner {
          width: 175px;
        }
        .el-input__suffix {
          right: -50px;
        }
      }
      .tabCut {
        display: inline-block;
        margin: 0 10px;

        div {
          display: inline-block;
          width: 60px;
          height: 27px;
          border: 1px solid #274934;
          text-align: center;
          line-height: 25px;
          cursor: pointer;
        }

        div:nth-child(1) {
          border-radius: 13px 0px 0px 13px;
          border-right-width: 0;
        }

        div:nth-child(2) {
          border-radius: 0px 13px 13px 0px;
        }

        .active {
          background-color: rgba(5, 187, 76, 0.9);
          color: #fff;
        }
      }

      .but {
        display: flex;
        flex-direction: row;
        align-content: center;
        margin-left: 20px;
        .buttons {
          background-color: rgba(5, 187, 76, 0.2);
          border: 1px solid #3b6c53;
          color: #b3b3b3;
          font-size: 14px;

          &:hover,
          &.active {
            background-color: rgba(5, 187, 76, 0.5);
            color: #ffffff;
          }
        }
      }
    }
  }
  .economicTable1 {
    height: calc(100% - 40px);
    .el-table--mini {
      .el-table__header-wrapper {
        .el-checkbox {
          display: none;
        }
      }
      .el-table__body-wrapper {
        .el-checkbox {
          .el-checkbox__input {
            display: block;
          }
        }
      }
    }

    .historyBtn {
      background: #43516b;
      border-radius: 15px;
      margin-top: 5px;
      border: 1px solid #43516b;
      span {
        color: #fff;
      }
    }
  }
  .el-overlay {
    .el-overlay-dialog {
      overflow-y: hidden !important;
      .EvaluationhistoryModel {
        margin-top: 0 !important;
        .el-dialog__body {
          height: calc(100% - 51px - 50px);
        }
      }
      .contrastModal {
        .el-dialog__header {
          border: none;
        }
        .el-dialog__body {
          padding-top: 10px;
        }
      }
    }
  }

  .el-picker__popper .el-date-range-picker__header .el-picker-panel__icon-btn {
    color: #fff;
  }
  .el-picker__popper .el-date-table .in-range div {
    background: #43516b;
  }
}
</style>
