<template>
  <div class="l-m flex-d-b bb">
    <div class="t">
      <CharsAndTitle :titleText="optionsData[0].name" :options="options" />
    </div>
    <div class="t2 flex-b">
      <div v-for="item in data1" :key="item.b" class="item">
        <div class="u">{{ item.a }}</div>
        <div class="d">{{ item.b }}</div>
      </div>
    </div>
    <div class="t">
      <CharsAndTitle :titleText="optionsData2[0].name" :options="options2" />
    </div>
    <div class="t2 flex-b">
      <div v-for="item in data2" :key="item.b" class="item">
        <div class="u">{{ item.a }}</div>
        <div class="d">{{ item.b }}</div>
      </div>
    </div>

    <!-- <div class="t">
      <CharsAndTitle
        titleText="2023年度上半年居民安检任务进度"
        :options="options"
      />
    </div> -->
    <!-- <div class="b">
      <CharsAndTitle titleText="当前安检任务统计" :options="options2" />
    </div> -->
  </div>
</template>

<script>
import CharsAndTitle from "@/components/CharsCom/CharsAndTitle.vue/";
import {
  userCurrentTaskStatistic,
} from "@/api/screenstatistic/statistic.js";

export default {
  name: "",
  components: {
    CharsAndTitle,
  },
  data() {
    return {
      optionsData: [
        {
          name: "楼道存在安全隐患住宅",
          value: "0",
        },
      ],
      optionsData2: [
        {
          name: "楼道存在安全隐患住宅",
          value: "0",
        },
      ],
      options: {},
      options2: {},
      data1: [
        { a: 0, b: "用户总量" },
        { a: 0, b: "已安检" },
        { a: 0, b: "未安检" },
      ],
      data2: [
        { a: 0, b: "用户总量" },
        { a: 0, b: "已安检" },
        { a: 0, b: "未安检" },
      ],
    };
  },
  mounted() {
    // this.setOptions(this.optionsData);
    // this.setOptions2(this.optionsData2);
    this.userCurrentTaskStatistic({ type: 3, checkType: 1 }).then((res) => {
      if(!res.data) {
         this.setOptions(this.optionsData);
         return;
      }
      this.optionsData = [
        {
          name: res.data.title,
          value: res.data.percent,
        },
      ];
      this.data1[0].a = res.data.totalUserNum;
      this.data1[1].a = res.data.inspectNum;
      this.data1[2].a = res.data.noInspectNum;
      this.setOptions(this.optionsData);
    });
    this.userCurrentTaskStatistic({ type: 3, checkType: 2 }).then((res) => {
      if(!res.data) {
        this.setOptions2(this.optionsData2);
        return;
      }
      this.optionsData2 = [
        {
          name: res.data.title,
          value: res.data.percent,
        },
      ];
      this.data2[0].a = res.data.totalUserNum;
      this.data2[1].a = res.data.inspectNum;
      this.data2[2].a = res.data.noInspectNum;
      this.setOptions2(this.optionsData2);
    });

  },
  methods: {
    // userCurrentInspectStatistic(obj) {
    //   return userCurrentInspectStatistic(obj);
    // },
    userCurrentTaskStatistic(obj) {
      return userCurrentTaskStatistic(obj);
    },
    setOptions(optionsData) {
      const leftText = optionsData.map((item) => {
        return item.name;
      });
      const rightValue = optionsData.map((item) => {
        return item.value;
      });
      console.log("rightValue", rightValue);
      this.options = {
        xAxis: {
          show: false,
          type: "value",
          lineStyle: {
            color: "#ffffff",
            type: "dashed",
          },
          axisTick: {
            show: true,
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "rgba(19, 135, 167, 1)",
            },
          },
          // 是否显示刻度延长线
          splitLine: {
            show: false,
          },
          min: 0,
          max: 100,
          // 文字样式
          axisLabel: {
            show: true,
            color: "#ffffff",
          },
        },
        yAxis: [
          {
            type: "category",
            data: ["当前任务进度"],
            // 轴线样式
            axisLine: {
              show: false,

              lineStyle: {
                color: "rgba(19, 135, 167, 1)",
              },
            },

            // 文字样式
            axisLabel: {
              color: "#ffffff",
              align: "left",
              margin: 78,
            },
            // 刻度延长线样式
            splitLine: {
              show: false,
              lineStyle: {
                color: "rgba(19, 135, 167, .5)",
                type: "dashed",
              },
            },
            //刻度
            axisTick: {
              show: false,
            },
          },
          // 最右边的y轴
          {
            type: "category",
            name: "right",
            // data: rightValue,
            data: [...rightValue].reverse(),

            position: "right",
            show: true,
            axisLabel: {
              formatter: "{value}" + "%",
              align: "right",
              margin: 40,
              fontSize: 18,
              fontWeight: 500,
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: "rgba(19, 250, 223, 1)",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        // 位置与大小
        grid: {
          left: "20%",
          right: "10%",
          top: "0%",
          bottom: "0%",
        },
        series: [
          {
            // realtimeSort: true,
            // 是否显示底黑
            showBackground: true,
            backgroundStyle: {
              color: "rgba(0,0,0,1)",
            },
            barWidth: 15,

            name: "X",
            type: "bar",
            data: rightValue.reverse(),
            // data: [20, 7, 7, 7, 9],
            // 柱形样式
            itemStyle: {
              color: new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [
                {
                  offset: 0,
                  color: "rgba(19, 250, 223, 1)",
                },
                {
                  offset: 1,
                  color: "rgba(2, 137, 255, 1)",
                },
              ]),
              barBorderRadius: [0, 13, 13, 0],
            },
            // 跟随文字
            // label: {
            //   show: false,
            //   gridIndex: 1,
            //   position: "right",
            //   color: "#ffffff",
            //   valueAnimation: true,
            //   formatter: "{c} ",
            // },
          },
        ],
      };
    },

    setOptions2(optionsData) {
      const leftText = optionsData.map((item) => {
        return item.name;
      });
      const rightValue = optionsData.map((item) => {
        return item.value;
      });
      console.log("rightValue", rightValue);
      this.options2 = {
        xAxis: {
          show: false,
          type: "value",
          lineStyle: {
            color: "#ffffff",
            type: "dashed",
          },
          axisTick: {
            show: true,
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "rgba(19, 135, 167, 1)",
            },
          },
          // 是否显示刻度延长线
          splitLine: {
            show: false,
          },
          min: 0,
          max: 100,
          // 文字样式
          axisLabel: {
            show: true,
            color: "#ffffff",
          },
        },
        yAxis: [
          {
            type: "category",
            data: ["当前任务进度"],
            // 轴线样式
            axisLine: {
              show: false,

              lineStyle: {
                color: "rgba(19, 135, 167, 1)",
              },
            },

            // 文字样式
            axisLabel: {
              color: "#ffffff",
              align: "left",
              margin: 78,
            },
            // 刻度延长线样式
            splitLine: {
              show: false,
              lineStyle: {
                color: "rgba(19, 135, 167, .5)",
                type: "dashed",
              },
            },
            //刻度
            axisTick: {
              show: false,
            },
          },
          // 最右边的y轴
          {
            type: "category",
            name: "right",
            // data: rightValue,
            data: [...rightValue].reverse(),

            position: "right",
            show: true,
            axisLabel: {
              formatter: "{value}" + "%",
              align: "right",
              margin: 40,
              fontSize: 18,
              fontWeight: 500,
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: "rgba(19, 250, 223, 1)",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        // 位置与大小
        grid: {
          left: "20%",
          right: "10%",
          top: "0%",
          bottom: "0%",
        },
        series: [
          {
            // realtimeSort: true,
            // 是否显示底黑
            showBackground: true,
            backgroundStyle: {
              color: "rgba(0,0,0,1)",
            },
            barWidth: 15,

            name: "X",
            type: "bar",
            data: rightValue.reverse(),
            // data: [20, 7, 7, 7, 9],
            // 柱形样式
            itemStyle: {
              color: new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [
                {
                  offset: 0,
                  color: "rgba(19, 250, 223, 1)",
                },
                {
                  offset: 1,
                  color: "rgba(2, 137, 255, 1)",
                },
              ]),
              barBorderRadius: [0, 13, 13, 0],
            },
            // 跟随文字
            // label: {
            //   show: false,
            //   gridIndex: 1,
            //   position: "right",
            //   color: "#ffffff",
            //   valueAnimation: true,
            //   formatter: "{c} ",
            // },
          },
        ],
      };
    },
  },
};
</script>
<style lang="scss" scoped>
.l-m {
  width: 100%;
  height: 100%;
  justify-content: space-around;
  .t {
    height: 60px;
  }
  .t2 {
    color: #fff;
    .item {
      text-align: center;
      .u {
        font-size: 16px;
        font-weight: 600;
        color: #48f7fc;
      }
      .d {
        font-size: 14px;
      }
    }
  }
  // .b {
  //   flex: 1;
  // }
}
</style>
