<template>
  <div class="parcel-box">
    <div class="title">
      <el-select
        size="mini"
        v-model="company"
        placeholder="请选择"
        @change="getTableDate"
      >
        <el-option
          v-for="item in companyOptions"
          :key="item.id"
          :label="item.aname"
          :value="item.id"
        >
        </el-option>
      </el-select>
      <div class="station">
        开始日期
        <div class="search-input">
          <el-date-picker
            v-model="starTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="选择日期"
            popper-class="date-select"
          >
          </el-date-picker>
        </div>
      </div>
      <div class="station">
        结束日期
        <div class="search-input">
          <el-date-picker
            v-model="endTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="选择日期"
            popper-class="date-select"
          >
          </el-date-picker>
        </div>
      </div>
      <el-button round size="mini" class="searchColor" @click="getTableDate"
        >搜索</el-button
      >
      <!-- <el-button round size="mini">导出</el-button> -->
    </div>
    <div class="data-bodys">
      <div class="line clearfix">
        <div class="leftContent left"><span>复位及时率</span></div>
        <div class="rightContent right"></div>
      </div>
      <div class="economicTable">
        <el-table
          :data="tableData"
          style="width: 100%"
          size="mini"
          stripe
          height="85vh"
        >
          <el-table-column
            align="center"
            prop="unit"
            label="风场"
            width="200"
            sortable
          ></el-table-column>
          <el-table-column
            align="center"
            prop="five"
            label="5分钟 / 复位次数"
            sortable
          ></el-table-column>
          <el-table-column
            align="center"
            prop="fives"
            label="5分钟 / 复位率"
            sortable
          ></el-table-column>
          <el-table-column
            align="center"
            prop="ten"
            label="10分钟 / 复位次数"
            sortable
          ></el-table-column>
          <el-table-column
            align="center"
            prop="tens"
            label="10分钟 / 复位率"
            sortable
          ></el-table-column>
          <el-table-column
            align="center"
            prop="fifteen"
            label="15分钟 / 复位次数"
            sortable
          ></el-table-column>
          <el-table-column
            align="center"
            prop="fifteens"
            label="15分钟 / 复位率"
            sortable
          ></el-table-column>
          <el-table-column
            align="center"
            prop="twenty"
            label="20分钟 / 复位次数"
            sortable
          ></el-table-column>
          <el-table-column
            align="center"
            prop="twentys"
            label="20分钟 / 复位率"
            sortable
          ></el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from "dayjs";
import { companys, timelyRate } from "@/api/curveAnalyse";
export default {
  name: "restorationEfficiency",
  components: {},
  data() {
    return {
      starTime: "",
      endTime: "",
      company: "",
      companyOptions: [],
      tableData: [],
    };
  },
  watch: {},
  filters: {},
  computed: {},
  created() {
    let date = new Date();
    date.setDate(1);
    let month = parseInt(date.getMonth() + 1);
    let day = date.getDate();
    if (month < 10) {
      month = "0" + month;
    }
    if (day < 10) {
      day = "0" + day;
    }
    this.starTime = date.getFullYear() + "-" + month + "-" + day;
    this.endTime = dayjs(new Date().getTime()).format("YYYY-MM-DD");
    this.initialization();
  },
  methods: {
    initialization() {
      companys().then(({ data: res }) => {
        this.companyOptions = res.data;
        this.company = res.data[0].id;
        this.getTableDate();
      });
    },
    getTableDate() {
      timelyRate({
        companyId: this.company,
        beginDate: this.starTime,
        endDate: this.endTime,
      }).then(({ data: res }) => {
        if (res) {
          let data = [];
          res.data.forEach((item, index) => {
            data[index] = {
              unit: item.wpid,
              five: item.wfz,
              fives: item.wfzfwl,
              ten: item.sfz,
              tens: item.sfzfwl,
              fifteen: item.swfz,
              fifteens: item.swfzfwl,
              twenty: item.esfz,
              twentys: item.esfzfwl,
              is_light: false,
            };
          });
          this.tableData = data;
        }
      });
    },
  },
  mounted() {},
  beforeUnmount() {},
};
</script>

<style lang="less" scoped>
.title {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-top: 10px;
  padding-left: 20px;

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

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

  .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 {
      background-color: rgba(5, 187, 76, 0.5);
      color: #ffffff;
    }
  }
}

.data-bodys {
  display: flex;
  flex-direction: column;
  background-color: rgba(0, 0, 0, 0.45);
  border-radius: 5px;
  padding: 5px;
}

.parcel-box {
  padding: 0 20px;
  box-sizing: border-box;

  .line {
    padding-bottom: 5px;
    .leftContent {
      width: 242px;
      height: 41px;
      line-height: 41px;
      background: url("../../../../assets/imgs/title_left_bg.png");

      span {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #ffffff;
        margin-left: 25px;
      }
    }

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

.left {
  float: left;
}

.right {
  float: right;
}

.searchColor {
  background-color: rgba(5, 187, 76, 0.2);
  border: 1px solid #3b6c53;
  color: #b3b3b3;
  font-size: 14px;
  margin-left: 10px;
  &:hover {
    background-color: rgba(5, 187, 76, 0.5);
    color: #ffffff;
  }
}
</style>
