<template>
  <div class="right1-container">
    <InfoHeader
      name="困人故障原因分析"
      eName="Statistics of trapped elevators in each community"
    ></InfoHeader>
    <InfoContent height="3.1rem">
      <div>
        <RangeDatePicker
          :width="'5.22rem'"
          :isHms="true"
          @dateChange="dateChange"
        ></RangeDatePicker>
      </div>
      <div class="d-flex">
        <BarCharts
          chartId="rightsssssw2ss"
          :chartXData="chartXData"
          :chartYData="chartYData"
          :chartSettings="chartSettings"
        ></BarCharts>
      </div>
    </InfoContent>
  </div>
</template>
  
  <script>
import InfoHeader from "@/components/infoHeader";
import InfoContent from "@/components/infoContent";
import BarCharts from "@/components/barCharts";
import RangeDatePicker from "@/components/rangeDatePicker";
import { getReasonOfBad } from "@/api/elevator";
import moment from "moment";
export default {
  components: {
    InfoHeader,
    InfoContent,
    BarCharts,
    RangeDatePicker,
  },
  data() {
    return {
      chartXData: [],
      chartYData: [],
      startTime: moment().subtract(3, "months").format("YYYY-MM-DD HH:mm:ss"),
      endTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      chartSettings: { legendTextArr: ["次数"], height: "2.8rem" },
      reasonMap: {
        1: "人为原因",
        2: "外部原因",
        3: "门系统",
        4: "曳引系统",
        5: "控制系统",
        6: "安全保护装置",
        7: "其他",
      },
    };
  },

  created() {
    this.getRankRescueAnaApi();
  },
  methods: {
    getRankRescueAnaApi() {
      getReasonOfBad({
        startTime: this.startTime,
        endTime: this.endTime,
      }).then((res) => {
        if (res.data.length > 0) {
          this.chartXData = res.data.map((item) => {
            return this.reasonMap[item.faultCause];
          });
          this.chartYData = res.data.map((item) => {
            return item.rescueNum;
          });
        } else {
          this.chartXData = ["无数据"];
          this.chartYData = [0];
        }
      });
    },
    dateChange(e) {
      console.log(e);
      this.startTime = e[0];
      this.endTime = e[1];
      this.getRankRescueAnaApi();
    },
  },
};
</script>
  <style lang="scss" scoped>
.right1-container {
  position: fixed;
  top: 7.1rem;
  right: 00.25rem;
  width: 7.5rem;
  pointer-events: all;
  .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 {
    background: url("../../../assets/images/guzhang_bck.png");
    background-repeat: no-repeat;
    background-size: 100% 35%;
    background-position: bottom;
    height: 3.25rem;
    .rate {
      font-size: 0.55rem;
      color: white;
      font-weight: bolder;
    }
    .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>
  