<template>
  <div class="left2-container">
    <InfoHeader
      name="电梯信息统计"
      eName="Elevator information statistics"
    ></InfoHeader>
    <InfoContent height="7.8rem">
      <div style="padding: 0.1rem 0.2rem;">
        <VantCalendarPicker :isHms="true" @dateChange="dateChange" width="100%"></VantCalendarPicker>
      </div>
      <div >
        <div style="width: 100%; padding: 0.25rem">
          <div class="title1 d-flex jc-center">到场时间比</div>

          <div style="margin-top: 0.25rem">
            <PieChart
              :chartId="'middle'"
              :chartData="chartPieData"
              :chartSetting="chartSetting"
            >
            </PieChart>
          </div>
        </div>
        <div style="width: 100%; padding: 0.25rem">
          <div class="title1 d-flex jc-center">救援时间比</div>

          <div class="order" style="margin-top: 0.25rem">
            <PieChart
              :chartId="'middle2'"
              :chartData="chartPieData2"
              :chartSetting="chartSetting"
            ></PieChart>
          </div>
        </div>
      </div>
    </InfoContent>
  </div>
</template>

<script>
import InfoHeader from "@/components/infoHeader";
import InfoContent from "@/components/infoContent";
import PieChart from "@/components/pieEcharts";
import VantCalendarPicker from '@/components/VantCalendarPicker/index.vue';
import { getTimeRescueAna } from "@/api/elevator";
import moment from "moment";
export default {
  components: {
    InfoHeader,
    InfoContent,
    VantCalendarPicker,
    PieChart,
  },
  data() {
    return {
      chartSetting: {
        showLegend: true,
        radius: ["30%", "50%"],
        pieColor: ["#FF6600", "#0099FF", "#66CC33", "#FFCC33", "#9933FF"],
        height: "2.3rem",
      },
      startTime: moment().subtract(3, "months").format("YYYY-MM-DD HH:mm:ss"),
      endTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      chartPieData: [
        { value: 1, name: "<15分钟" },
        { value: 0, name: "15-30分钟" },
        { value: 0, name: ">15分钟" },
      ],
      chartPieData2: [
        { value: 1, name: "<30分钟" },
        { value: 0, name: "30-2小时" },
        { value: 0, name: ">2小时" },
      ],
      pieTimeMap: { 0: "<15分钟", 1: "15-30分钟", 2: ">15分钟" },
      pieTimeMap2: { 0: "<30分钟", 1: "30-2小时", 2: ">2小时" },
    };
  },
  created() {
    this.getTimeRescueAnaApi();
  },
  methods: {
    getTimeRescueAnaApi() {
      getTimeRescueAna({
        startTime: this.startTime,
        endTime: this.endTime,
      }).then((res) => {
        this.chartPieData = res.data.receiveTimeList.map((item) => {
          return {
            value: item.num,
            name: this.pieTimeMap[item.timeType],
          };
        });
        this.chartPieData2 = res.data.rescueTimeList.map((item) => {
          return {
            value: item.num,
            name: this.pieTimeMap2[item.timeType],
          };
        });
      });
    },
    dateChange(e) {
      console.log(e);
      this.startTime = e[0];
      this.endTime = e[1];
      this.getTimeRescueAnaApi();
    },
  },
};
</script>
<style lang="scss" scoped>
.left2-container {
  pointer-events: all;

  width: 100%;
  margin-top: 0.6rem;
  .title1 {
    background-image: url("../../../assets/images/biaoti-bck.png");
    width: 1.875rem;
    height: 0.375rem;
    line-height: 0.375rem;
    margin: 0 auto;

    font-size: 0.2rem;
    color: white;
  }
  .order {
    height: 3.25rem;
    .item {
      margin: 0.375rem 0;
      .num-title {
        font-size: 0.3rem;
        color: white;
      }
      .num-value {
        font-size: 0.36rem;
        color: white;
        margin-left: 0.15rem;
      }
    }
  }
}
</style>
