<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="tabCut">
          <div
            @click="changeBtn(val.id)"
            :class="tabEvent === val.id ? 'active' : ''"
            v-for="val in tabOptions"
            :key="val.id"
          >
            <span>{{ val.name }}</span>
          </div>
        </div> -->
        <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
              size="mini"
              v-model="pickerTimer"
              type="date"
              value-format="YYYY-MM-DD"
              placeholder="选择日期"
              popper-class="date-select"
              @change="historyTimer = pickerTimer"
            >
            </el-date-picker>
            <!-- <el-date-picker v-if="tabIndex == 0"
              v-if="tabIndex == 1"
              size="mini"
              v-model="pickerTimer"
              type="month"
              value-format="YYYY-MM"
              placeholder="选择月份"
              popper-class="date-select"
            >
            </el-date-picker>
            <el-date-picker
              v-if="tabIndex == 2"
              size="mini"
              v-model="pickerTimer"
              type="year"
              value-format="YYYY"
              placeholder="选择年份"
              popper-class="date-select"
            >
            </el-date-picker> -->
          </div>
        </div>
        <div class="but">
          <el-button round size="mini" class="buttons" @click="seachData"
            >搜 索</el-button
          >
          <el-button
            round
            size="mini"
            class="buttons"
            @click="contrastFn"
            :disabled="chooseList.length === 2 ? false : true"
            >信息对比</el-button
          >
        </div>
      </div>
      <div class="selections">
        <!-- <div
          class="selections_btn"
          @click="tabSelect(0)"
          :class="{ active: tabIndex == 0 }"
        >
          日
        </div> -->
        <!-- <div
          class="selections_btn"
          @click="tabSelect(1)"
          :class="{ active: tabIndex == 1 }"
        >
          月
        </div> -->
        <!-- <div
          class="selections_btn"
          @click="tabSelect(2)"
          :class="{ active: tabIndex == 2 }"
        >
          年
        </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"><span>月度性能等级评估</span></div>
      </div>

      <div class="economicTable1">
        <el-table
          :data="EvaluationData"
          stripe
          @selection-change="handleCurrentChange"
          size="mini"
          height="calc(100% - 40px)"
          ref="Eval_table"
          style="width: 100%"
        >
          <el-table-column type="selection" width="60" align="center">
          </el-table-column>
          <el-table-column prop="nemCode" label="设备编号" align="center">
          </el-table-column>
          <el-table-column prop="dayLevel" label="等级" align="center">
          </el-table-column>
          <el-table-column
            prop="dayRank"
            label="综合排名"
            sortable
            align="center"
          >
          </el-table-column>
          <el-table-column
            v-for="(item, index) in tabEvent === -1
              ? tableHeader
              : tableHeaderGf"
            :key="index"
            sortable
            :prop="item.code"
            :label="item.title"
            align="center"
            header-align="center"
            show-overflow-tooltip
          >
            <template #header="scope">
              <div>
                {{
                  scope.column.label.slice(0, scope.column.label.indexOf("("))
                }}
              </div>
              <div>
                {{ scope.column.label.slice(scope.column.label.indexOf("(")) }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template #default="scope">
              <span
                @click="seachHistoryData(scope.row)"
                style="cursor: pointer; color: #67b9ff"
                >历史</span
              >
            </template>
          </el-table-column>
        </el-table>
        <div style="text-align: right">
          <el-pagination
            @current-change="handlePageChange"
            :current-page="page.currentPage"
            :page-size="page.pagesize"
            @size-change="handleSizeChange"
            :page-sizes="[21, 50, 100, 500]"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.total"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <el-dialog
      v-model="dialogVisible"
      width="100%"
      custom-class="EvaluationhistoryModel"
      :close-on-click-modal="false"
      fullscreen
    >
      <template #title>
        <div class="dialog-title">
          <div class="title">{{ dialogTitle }}</div>
        </div>
      </template>
      <div style="height: 100%">
        <history-detail ref="windhistoryDetail"> </history-detail>
      </div>
    </el-dialog>
    <el-dialog
      v-model="contrastVisible"
      width="70%"
      top="120px"
      custom-class="contrastModal"
      :close-on-click-modal="false"
    >
      <template #title>
        <div class="dialog-title">
          <div class="title">信息对比</div>
        </div>
      </template>
      <div class="dialog-body">
        <img class="dialog-img" src="@assets/imgs/dialog.png" />
        <day-detail-info
          :chooseList="chooseList"
          :tabEvent="tabEvent"
          ref="MessageContrast"
        ></day-detail-info>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getApicompanyslist,
  getApiwpByCplistlist,
  getApiequipmentinfoDayList,
} from "@/api/monthlyPerformanceAnalysis";
import historyDetail from "./historyDetail.vue";
import dayDetailInfo from "./dayDetailInfo.vue";
import dataJson from "./dataJson.json"
import dayjs from "dayjs";
export default {
  name: "PerformanceAssess",
  components: {
    historyDetail,
    dayDetailInfo,
  },
  data() {
    return {
      tabIndex: 1,
      companyVal: "",
      companyOptions: [],
      stationVal: "",
      stationOptions: [],
      pickerTimer: "",
      EvaluationData: [],
      tableHeader: [
        { title: "发电量(万kWh)", code: "dayfdl" },
        { title: "理论发电量(万kWh)", code: "dayllfdl" },
        { title: "平均风速(m/s)", code: "dayfs" },
        { title: "平均功率(KW)", code: "daygl" },
        { title: "故障损失(万kWh)", code: "daygzssdl" },
        { title: "限电损失(万kWh)", code: "dayxdssdl" },
        { title: "检修损失(万kWh)", code: "daywhssdl" },
        { title: "性能损失(万kWh)", code: "dayxnssdl" },
        { title: "利用小时数(h)", code: "daylyxs" },
        { title: "拟合优度(%)", code: "daynhyd" },
        { title: "可利用率(%)", code: "daysbklyl" },
        { title: "等效可用系数(%)", code: "daydxkyxs" },
        { title: "有效风时数(h)", code: "dayyxfss" },
        { title: "平均切入(m/s)", code: "dayxfqr" },
        { title: "静风频率(%)", code: "dayjfpl" },
        { title: "功率一致性(%)", code: "dayglyzxxs" },
      ],
      tableHeaderGf: [
        { title: "发电量(万kWh)", code: "dayfdl" },
        { title: "理论发电量(万kWh)", code: "dayllfdl" },
        { title: "光照强度(W/㎡)", code: "dayfs" },
        { title: "平均功率(KW)", code: "daygl" },
        { title: "故障损失(万kWh)", code: "daygzssdl" },
        { title: "限电损失(万kWh)", code: "dayxdssdl" },
        { title: "检修损失(万kWh)", code: "daywhssdl" },
        { title: "性能损失(万kWh)", code: "dayxnssdl" },
        { title: "利用小时数(h)", code: "daylyxs" },
        { title: "拟合优度(%)", code: "daynhyd" },
        { title: "可利用率(%)", code: "daysbklyl" },
        { title: "等效可用系数(%)", code: "daydxkyxs" },
        { title: "有效光时数(h)", code: "dayyxfss" },
        { title: "功率一致性(%)", code: "dayglyzxxs" },
      ],
      dialogVisible: false,
      dialogTitle: "",
      chooseList: [],
      contrastVisible: false,
      tabEvent: -1,
      tabOptions: [
        { id: -1, name: "风电" },
        { id: -2, name: "光伏" },
      ],
      page: {
        currentPage: 1,
        pagesize: 21,
        total: 0,
      },
      historyTimer: "",
    };
  },
  created() {
    
    //   this.EvaluationData = dataJson.data.data.records;
    //   this.page.total = dataJson.data.data.total;
    this.getCompanyData();
  },
  computed: {
    pageHeight() {
      return {
        height: document.documentElement.clientHeight - 130 + "px",
      };
    },
  },
  methods: {
    handleSizeChange(val) {
      this.page.currentPage = 1;
      this.page.pagesize = val;
      this.seachData();
    },
    handlePageChange(val) {
      this.page.currentPage = val;
      this.seachData();
    },
    // 切换tab
    tabSelect(index) {
      this.tabIndex = index;
      //   if (this.tabIndex == 0) {
      //   this.pickerTimer = dayjs().format("YYYY-MM-DD");
      //   } else if (this.tabIndex == 1) {
      //     this.pickerTimer = dayjs().format("YYYY-MM");
      //   } else if (this.tabIndex == 2) {
      //     this.pickerTimer = dayjs().format("YYYY");
      //   }
      //   this.historyTimer = dayjs().format("YYYY-MM-DD");
      this.page.currentPage = 1;
      this.seachData();
    },
    changeBtn(id) {
      this.tabEvent = id;
      this.stationVal = "";
      this.stationOptions = [];
      this.getStationData();
      this.seachData();
    },
    // 获取公司列表
    async getCompanyData() {
      this.companyOptions = [];
      this.pickerTimer = this.getchangeTime(new Date());
      this.historyTimer = this.getchangeTime(new Date());
      const { data: datas } = await getApicompanyslist();
      this.companyOptions = datas.data;
      this.companyVal = datas.data[0]?.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);
      this.stationOptions = datas.data;
      this.stationVal = datas.data[0].id;
      this.getTableData();
    },
    changeStation(val) {
      this.stationVal = val;
      this.getTableData();
    },
    seachData() {
      this.getTableData();
    },
    async getTableData() {
      let params = {
        companyId: this.companyVal,
        date: this.pickerTimer,
        staType: -1,
        types: this.tabIndex * 1 + 1,
        wpId: this.stationVal,
        type: this.tabEvent,
        pageNum: this.page.currentPage,
        pageSize: this.page.pagesize,
      };

      const { data: datas } = await getApiequipmentinfoDayList(params);
      this.EvaluationData = datas.data.records;
      this.page.total = datas.data.total;
    },
    handleCurrentChange(val) {
      if (val.length > 2) {
        let del_row = val.shift();
        this.$refs.Eval_table.toggleRowSelection(del_row, false);
      }
      let arr = [];
      val.forEach((item, index) => {
        if (index < 2) {
          arr.push(item);
        }
      });
      this.chooseList = arr;
    },
    //转换时间
    getchangeTime(date) {
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      return y + "-" + m + "-" + d;
    },
    seachHistoryData(row) {
      this.dialogVisible = true;
      this.dialogTitle = "历史数据查询";
      this.$nextTick(() => {
        let startT =
          new Date(this.historyTimer).getTime() - 10 * 24 * 60 * 60 * 1000;
        this.$refs.windhistoryDetail.pickerTimer = [
          this.getchangeTime(new Date(startT)),
          this.historyTimer,
        ];
        this.$refs.windhistoryDetail.tabIndex = this.tabIndex * 1 + 1;
        this.$refs.windhistoryDetail.tabEvent = this.tabEvent;
        this.$refs.windhistoryDetail.init(row);
      });
    },
    contrastFn() {
      this.contrastVisible = true;
      this.$nextTick(() => {
        this.$refs.MessageContrast.tabIndex = this.tabIndex * 1 + 1;
        this.$refs.MessageContrast.init();
      });
    },
  },
};
</script>

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

  .Evaluation_title {
    .leftContent {
      width: 242px;
      height: 41px;
      line-height: 41px;
      background: url("~@/assets/imgs/title_left_bg.png") no-repeat;
      span {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #05bb4c;
        margin-left: 25px;
      }
    }
  }
  .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 ::v-deep {
      .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>
