<template>
  <div class="maintenance">
    <div class="maintenance_top">
      <!-- <el-select
        size="mini"
        v-model="tabIndex"
        placeholder="请选择"
        clearable
        @change="getTableData"
      >
        <el-option
          v-for="item in tabOptions"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        >
        </el-option>
      </el-select> -->
      <div class="station">
        时间：
        <div class="">
          <el-date-picker
            size="mini"
            v-model="pickerTime"
            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 sousuo"
          @click="getTableData"
          >搜索</el-button
        >
        <el-button round size="mini" class="buttons" @click="downXlsxFn"
          >导出</el-button
        >
      </div>
    </div>
    <div
      style="
        background: rgba(0, 0, 0, 0.4);
        height: calc(100% - 43px);
        padding-bottom: 15px;
      "
    >
      <div class="maintenance_title clearfix">
        <div class="leftContent floatLeft"><span>检修KPI</span></div>
      </div>
      <div class="economicTable1">
        <el-table
          :data="maintenanceData"
          stripe
          size="mini"
          height="calc(100% - 40px - 20px)"
          ref="maintenance_table"
          style="width: 100%"
          border
        >
          <el-table-column
            prop="stationName"
            label="场站"
            align="center"
            show-overflow-tooltip
          />

          <el-table-column
            prop="overhaulTeam"
            label="检修班组"
            align="center"
            width="60px"
            show-overflow-tooltip
          />

          <el-table-column
            prop="years"
            label="年份"
            align="center"
            width="60px"
            show-overflow-tooltip
          />

          <el-table-column
            prop="month"
            label="月份"
            align="center"
            width="60px"
            show-overflow-tooltip
          />

          <el-table-column
            v-for="(item, index) in tableHeader"
            :key="index"
            :label="item.title"
            align="center"
          >
            <el-table-column
              v-for="(subItem, subIndex) in item.children"
              :key="subIndex"
              :prop="subItem.code"
              :label="subItem.title"
              align="center"
              show-overflow-tooltip
            >
              <el-table-column
                v-for="(thiItem, thiIndex) in subItem.children"
                :key="thiIndex"
                sortable
                width="63"
                :prop="thiItem.code"
                :label="thiItem.title"
                align="center"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
          </el-table-column>
          <el-table-column
            prop="remark"
            label="总评分"
            align="center"
            width="100"
            show-overflow-tooltip
          />
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.currentPage"
          :page-size="page.pagesize"
          layout="total, prev, pager, next, jumper"
          :total="page.total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import utils from "@/utills/downXlsx";
import dayjs from "dayjs";
import { maintenanceKPI } from "@/api/kpiApi/index.js";
export default {
  name: "maintenance", //检修KPI
  components: {},
  data() {
    return {
      stationVal: "",
      stationOptions: [],
      pickerTime: "",
      maintenanceData: [],
      tabIndex: -1,
      tabOptions: [
        { id: -1, name: "风电" },
        { id: -2, name: "光伏" },
      ],
      tableHeader: [
        {
          title: "生产效率指标",
          children: [
            {
              title: "风能利用率",
              children: [
                { title: "值(%)", code: "fnlyl_value" },
                { title: "评分", code: "fnlyl_mark" },
              ],
            },
            {
              title: "计划检修损失率",
              children: [
                { title: "值(%)", code: "jhjxssl_value" },
                { title: "评分", code: "jhjxssl_mark" },
              ],
            },
            {
              title: "非计划检修损失率",
              children: [
                { title: "值(%)", code: "fjhjxssl_value" },
                { title: "评分", code: "fjhjxssl_mark" },
              ],
            },
            {
              title: "缺陷单接单及时率",
              children: [
                { title: "值(%)", code: "qxdjdjsl_value" },
                { title: "评分", code: "qxdjdjsl_mark" },
              ],
            },
            {
              title: "到达消缺地点及时率",
              children: [
                { title: "值(%)", code: "ddxqddjsl_value" },
                { title: "评分", code: "ddxqddjsl_mark" },
              ],
            },
            {
              title: "真实消缺及时率",
              children: [
                { title: "值(%)", code: "zsxqjsl_value" },
                { title: "评分", code: "zsxqjsl_mark" },
              ],
            },
            {
              title: "MTBF",
              children: [
                { title: "值(小时)", code: "mtbf_value" },
                { title: "评分", code: "mtbf_mark" },
              ],
            },

            {
              title: "MTTR",
              children: [
                { title: "值(小时)", code: "mttr_value" },
                { title: "评分", code: "mttr_mark" },
              ],
            },
          ],
        },
        {
          title: "综合分析指标",
          children: [
            {
              title: "设备利用小时",
              children: [
                { title: "值(小时)", code: "sblyxs_value" },
                { title: "评分", code: "sblyxs_mark" },
              ],
            },
            {
              title: "设备可利用率",
              children: [
                { title: "值(%)", code: "sbklyl_value" },
                { title: "评分", code: "sbklyl_mark" },
              ],
            },
            {
              title: "等效可用系数",
              children: [
                { title: "值(%)", code: "dxkyxs_value" },
                { title: "评分", code: "dxkyxs_mark" },
              ],
            },
            {
              title: "隐患发现准确率",
              children: [
                { title: "值(%)", code: "yhfxzql_value" },
                { title: "评分", code: "yhfxzql_mark" },
              ],
            },
          ],
        },
      ],
      page: {
        pagesize: 21,
        currentPage: 1,
        total: 0,
      },
    };
  },
  created() {
    this.pickerTime = dayjs().format("YYYY-MM");
  },
  mounted() {
    this.getTableData()
  },
  computed: {},
  methods: {
    handleSizeChange(val) {
      this.page.pagesize = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.getTableData();
    },
    getTableData() {
        let that = this
        let params = {
            pageNum: that.page.currentPage,
            pageSize: that.page.pagesize,
            years: that.pickerTime ? this.pickerTime.substring(0, this.pickerTime.indexOf('-'))*1 : null,
            month: that.pickerTime ? this.pickerTime.substring(this.pickerTime.indexOf('-')+1, this.pickerTime.length)*1 : null
        }
        maintenanceKPI(params).then(res =>{
            if (res) {
                that.maintenanceData = res.data.records
                that.page.total = res.data.total
            }
        })
    },
    downXlsxFn() {
      let header = [];
      this.tableHeader.forEach((it) => {
        if (it.title !== "操作") {
          header.push(it.title);
        }
      });
      if (this.maintenanceData.length > 0) {
        utils.exportExcel(
          this.$refs["maintenance_table"].$el,
          header,
          `${this.pickerTime}检修评价KPI`
        );
      }
    },
  },
};
</script>

<style lang="less" scoped>
.maintenance {
  padding: 0 20px;
  height: 100%;
  .maintenance_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;
      }
    }
  }

  .clearfix::after {
    content: "";
    clear: both;
    height: 0;
    line-height: 0;
    visibility: hidden;
    display: block;
  }

  .clearfix {
    zoom: 1;
  }

  .maintenance_top {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-top: 10px;
    margin-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;
    }

    .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;
      }

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

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

    .search-input {
      margin-left: 10px;

      .el-input__inner {
        width: 175px;
      }

      .el-input__suffix {
        right: -50px;
      }
    }

    .but {
      display: flex;
      flex-direction: row;
      align-content: center;
      margin-left: 20px;

      .buttons:nth-child(1) {
        background: rgba(5, 187, 76, 0.6);
        border: 1px solid #3b6c53;
        border-radius: 13px;
        color: #fff;

        &:hover {
          background: rgba(5, 187, 76, 0.9);
          border-radius: 13px;
          color: #fff;
        }
      }

      .buttons:nth-child(2) {
        background: rgba(67, 81, 107, 0.3);
        border: 1px solid #3b6c53;
        border-radius: 13px;
        font-size: 14px;
        color: #b3b3b3;
      }
    }
  }

  .economicTable1 {
    height: calc(100% - 42px);
    .el-table ::v-deep {
      .el-table__header {
        border-collapse: collapse;
      }
      .el-table__body-wrapper {
        .el-table__body {
          font-size: 13px;
          //   border: 1px solid #eceef5;
          //   border-collapse: collapse;
        }
      }
      th {
        height: 20px;
        line-height: 20px;
        font-size: 14px;
        &.el-table__cell {
          border: 1px solid rgba(255, 255, 255, 0.8) !important;
          &:nth-child(1) {
            border-left-width: 0 !important;
            // border-left-width: 0 !important;
          }
          &.is-leaf {
            // border-bottom-width: 1px !important;
          }
        }
      }
      td {
        height: 25px;
        line-height: 25px;
        font-size: 14px;
        &.el-table__cell {
          border-bottom: 1px solid #434141 !important;
          &:nth-child(1) {
            border-left-width: 0 !important;
            // border-left-width: 0 !important;
          }
          &.is-leaf {
            // border-bottom-width: 1px !important;
          }
        }
      }
    }
    .el-pagination {
      display: flex;
      justify-content: flex-end;
      padding-right: 40px;
      padding-top: 20px;
      .el-pagination__total,
      .el-pagination__jump {
        color: #fff;
      }
    }

    .el-table__fixed,
    .el-table__fixed-right {
      background: rgba(0, 0, 0, 1);
      border-left: 2px solid #000;
      height: calc(100% - 15px) !important;
    }

    .el-table__fixed::before {
      background-color: #2a2a2a;
    }

    .el-table__fixed-right::before {
      background-color: #2a2a2a;
    }
  }

  .el-overlay {
    .el-overlay-dialog {
      overflow-y: hidden !important;

      .el-dialog {
        margin-top: 0 !important;
        .el-dialog__body {
          height: calc(100% - 51px - 32px);
        }
      }
    }
  }

  .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;
  }
}

.historyBtn1 {
  cursor: pointer;
  color: #05bb4c;
}
</style>
