Formats.vue 3.98 KB
<template>
  <div class="live_item acea-row acea-column">
    <div class="ctit">
      <p class="tit">业态客流</p>
      <div class="line"></div>
      <div class="subtit">单位(人次)</div>
    </div>
    <div class="live_chart">
      <div class="chart" :id="chartId"></div>
    </div>
  </div>
</template>
<script>
import { optionFormatter } from "@/utils/dealChart";
import echarts from "@/third-party/echart_lib";
export default {
  inject: ["addModule"],
  props: {
    mallId: Number,
  },
  data() {
    return {
      chartId: "chart_" + Math.random().toString(16).substr(2, 5),
    };
  },
  components: {},
  watch: {
    mallId: {
      handler(newVal) {
        if (newVal) {
          this.loadData();
        }
      },
      immediate: true,
    },
  },
  methods: {
    initChart() {
      this.chart =
        echarts.getInstanceByDom(document.getElementById(this.chartId)) ||
        echarts.init(document.getElementById(this.chartId));
      window.chart = this;
    },
    resizeChart() {
      this.chart.resize();
    },
    drawChart(options) {
      this.chart.setOption(options);
      window.addEventListener("resize", this.resizeChart);
    },
    dealData(data) {
      let options = {
        grid: { top: 30, left: 22, right: 0, bottom: 45 },
        animationDuration: 300,
        animationDurationUpdate: 300,
        animation: true,
        legend: { show: false },
        color: [
          new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: "#00DBF8",
            },
            {
              offset: 1,
              color: "#081e25",
            },
          ]),
        ],
        xAxis: {
          type: "category",
          data: data.map((item) => item.name),
          axisLine: {
            show: true,
            lineStyle: {
              color: "#0C6C74",
            },
          },
          axisLabel: {
            show: true,
            color: "#fff",
            interval: 0,
            rotate: 40,
          },

          axisTick: {
            show: false,
            color: "#fff",
          },
        },
        yAxis: {
          type: "value",
          axisLabel: {
            show: false,
          },
          splitLine: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        series: [
          {
            data: data.map((item) => item.count),
            type: "bar",
            showBackground: true,
            backgroundStyle: {
              color: "rgba(180, 180, 180, 0.2)",
            },
            barWidth: 28,
            label: {
              show: true,
              position: "top",
              formatter: function (params) {
                return (
                  "{a|" +
                  data[params.dataIndex].percent +
                  "%\n" +
                  params.value +
                  "}"
                );
              },
              rich: {
                a: {
                  color: "#fff",
                  align: "center",
                },
                b: {
                  color: "#353438",
                  fontWeight: "normal",
                  fontSize: 12,
                },
              },
            },
          },
        ],
      };
      this.drawChart(options);
    },
    loadData() {
      let dateStr = dateUnit.dateFormat(new Date(), "yyyy-MM-dd");
      // let params = {
      //   chartIds: 471,
      //   orgType: "mall",
      //   orgIds: this.mallId,
      //   dateType: "day",
      //   startDate: dateStr,
      //   endDate: dateStr,
      // };
      let params = {
        mallId: this.mallId,
        countDate: dateStr,
      };
      this.$api.bigScreen.getFormatPassengerFlow(params).then((res) => {
        this.dealData(res.data.data);
      });
    },
  },
  created() {
    this.addModule(this);
  },
  mounted() {
    this.initChart();
  },
};
</script>

<style lang="less" scoped>
</style>