<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"
            size="mini"
            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"
            size="mini"
            value-format="YYYY-MM-DD"
            placeholder="选择日期"
            popper-class="date-select"
          >
          </el-date-picker>
        </div>
      </div>
      <div class="date">
        <div
          class="day"
          :class="current === '1' ? 'active' : ''"
          @click="handleChange('1')"
        >
          小于3米风速
        </div>
        <div
          class="mouth"
          :class="current === '2' ? 'active' : ''"
          @click="handleChange('2')"
        >
          大于3米风速
        </div>
        <div
          class="year"
          :class="current === '3' ? 'active' : ''"
          @click="handleChange('3')"
        >
          大于4米风速
        </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>
      <div class="economicTable">
        <el-table
          :data="tableData"
          style="width: 100%"
          size="mini"
          stripe
          height="100%"
        >
          <el-table-column
            align="center"
            prop="wpid"
            label="风场"
            width="200"
            sortable
          ></el-table-column>
          <el-table-column
            align="right"
            header-align="center"
            prop="wfz"
            label="5分钟 / 转换次数(次)"
            sortable
          ></el-table-column>
          <el-table-column
            align="right"
            header-align="center"
            prop="wfzfwl"
            label="5分钟 / 转换率(%)"
            sortable
          ></el-table-column>
          <el-table-column
            align="right"
            header-align="center"
            prop="sfz"
            label="10分钟 / 转换次数(次)"
            sortable
          ></el-table-column>
          <el-table-column
            align="right"
            header-align="center"
            prop="sfzfwl"
            label="10分钟 / 转换率(%)"
            sortable
          ></el-table-column>
          <el-table-column
            align="right"
            header-align="center"
            prop="swfz"
            label="15分钟 / 转换次数(次)"
            sortable
          ></el-table-column>
          <el-table-column
            align="right"
            header-align="center"
            prop="swfzfwl"
            label="15分钟 / 转换率(%)"
            sortable
          ></el-table-column>
          <el-table-column
            align="right"
            header-align="center"
            prop="esfz"
            label="20分钟 / 转换次数(次)"
            sortable
          ></el-table-column>
          <el-table-column
            align="right"
            header-align="center"
            prop="esfzfwl"
            label="20分钟 / 转换率(%)"
            sortable
          ></el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from "dayjs";
import { companys, conversionRate } from "@/api/curveAnalyse";
import dataJson from "./dataJson.json"
export default {
  name: "stateEfficiency",
  components: {},
  data() {
    return {
      starTime: "",
      endTime: "",
      company: "",
      companyOptions: [],
      tableData: [],
      current: "1",
    };
  },
  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 = dayjs().add(-1, "day").format("YYYY-MM-DD");
    this.endTime = dayjs().format("YYYY-MM-DD");
    this.initialization();
  },
  methods: {
    initialization() {
        this.dataChange(dataJson.data)

      companys().then(({ data: res }) => {
        this.companyOptions = res.data;
        this.company = res.data[0].id;
        this.getTableDate();
      });
    },
    getTableDate() {
      conversionRate({
        companyId: this.company,
        beginDate: this.starTime,
        endDate: this.endTime,
      }).then(({ data: res }) => {
        this.dataChange(res)
      });
    },
    dataChange(res) {
        if (res) {
          const current = this.current;
          if (current == "1") {
            this.tableData = res.data.小于3米风速;
          } else if (current == "2") {
            this.tableData = res.data.大于3米风速;
          } else {
            this.tableData = res.data.大于4米风速;
          }
        }
    },
    handleChange(val) {
      this.current = val;
      this.getTableDate();
    },
  },
  mounted() {},
  beforeUnmount() {},
};
</script>

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

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

.parcel-box {
  height: 100%;
  width: 100%;
  padding: 0 30px;
  padding-bottom: 10px;

  .line {
    padding-bottom: 5px;

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

    .rightContent {
      width: 212px;
      height: 28px;
      margin-top: 13px;
      background: url("../../../../assets/imgs/title_right_bg.png");
    }
  }
  .data-bodys {
    display: flex;
    flex-direction: column;
    background-color: rgba(0, 0, 0, 0.45);
    border-radius: 5px;
    height: calc(100% - 45px);
    padding-top: 10px;
    .economicTable {
      width: 100%;
      height: calc(100% - 40px);
    }
  }
}

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

  &:hover {
    background-color: rgba(5, 187, 76, 0.5);
    color: #ffffff;
  }
}

.date {
  display: flex;
  flex-direction: row;
  align-items: center;
  font-size: 12px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #b3b3b3;
  margin: 0 15px;

  .day {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 26px;
    border: 1px solid #3b6c53;
    border-radius: 11px 0px 0px 11px;
    background: rgba(67, 81, 107, 0.2);

    &.active {
      background: rgba(5, 187, 76, 0.4);
      color: #ffffff;
    }
  }

  .mouth {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 26px;
    border-top: 1px solid #3b6c53;
    border-bottom: 1px solid #3b6c53;
    background: rgba(67, 81, 107, 0.2);

    &.active {
      background: rgba(5, 187, 76, 0.4);
      color: #ffffff;
    }
  }

  .year {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 26px;
    border: 1px solid #3b6c53;
    border-radius: 0px 11px 11px 0px;
    background: rgba(67, 81, 107, 0.2);

    &.active {
      background: rgba(5, 187, 76, 0.4);
      color: #ffffff;
    }
  }
}
</style>
