leftBottom.vue 3.87 KB
<template>
  <div class="live_item acea-row acea-column" style="height:100%">
    <div class="ctit">
      <p class="tit">楼层客流</p>
      <div class="line"></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 = {
        // tooltip: {
        //   trigger: "axis",
        //   axisPointer: {
        //     type: "shadow",
        //   },
        // },
        grid: {
          left: 70,
          right: 100,
          bottom: 0,
          top: 5,
        },
        xAxis: {
          show: false,
          type: "value",
        },
        yAxis: {
          type: "category",
          data: data.map((item) => item.name),
          show: true,
          axisLable: {
            show: false,
          },
          axisLine: {
            show: false,
            lineStyle: {
              color: "#F9F9F9",
            },
          },
          axisTick: {
            show: false,
          },
        },
        series: [
          {
            name: "Search Engine",
            type: "bar",
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
                  { offset: 0, color: "#122146" }, //柱图渐变色
                  { offset: 1, color: "#4076F7" }, //柱图渐变色
                ]),
              },
            },
            barWidth: 22,
            label: {
              show: true,
              position: "right",
              formatter: function (params) {
                return (
                  "{b|" +
                  data[params.dataIndex].percent +
                  "%/" +
                  params.value +
                  "人次}"
                );
              },
              rich: {
                a: {
                  color: "#fff",
                  fontSize: 13,
                },
                b: {
                  color: "#F9F9F9",
                  fontSize: 13,
                },
              },
            },
            emphasis: {
              focus: "series",
            },
            data: data.map((item) => item.count),
          },
        ],
      };
      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.getFloorPassengerFlow(params).then((res) => {
        this.dealData(res.data.data);
      });
    },
  },
  created() {
    this.addModule(this);
  },
  mounted() {
    this.initChart();
    window.onresize = () => {
      this.chart.resize();
    };
  },
};
</script>

<style lang="less" scoped>
// .live_chart {
//   height: calc(100% - 80px);
//   .chart {
//     width: 100%;

//     height: 100%;
//   }
// }
</style>