<!--
 * @Author: your name
 * @Date: 2021-10-14 11:25:20
 * @LastEditTime: 2021-11-10 17:13:41
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /data-show/src/views/WeiboDetails/weiboUserActiveArea/index.vue
-->
<template>
  <div class="wua-outter" v-loading="load">
    <v-label-div title="用户活跃地区"> </v-label-div>
    <div class="wua-inner">
      <div class="d1">
        <v-echarts :opt="opt1"></v-echarts>
      </div>
      <div class="d2">
        <v-echars-map :opt="opt2"></v-echars-map>
      </div>
    </div>
  </div>
</template>

<script>
import {getUserRegionGroupBy} from "@/api/KeyMediaEvent/index.js"
import createOptD1 from "./opt1";
import createOptD2 from "./opt2";
export default {
  name: "weiboUserActiveArea",
  data() {
    return {
      load: false,
      form: {
        token: "",
        sSource: '',
        sRele: '',
        ilimitType: 0,
      },
      opt1: createOptD1(),
      opt2: createOptD2(),
    };
  },
  created() {
        this.form.token = this.getToken;
        this.form.sRele = this.$route.query.id || '';
        this.form.sSource = this.$route.query.source || "抖音";
        if(this.form.sSource == '汽车之家') {
        this.form.ilimitType = 1;
        } else if (this.form.sSource == '懂车帝' && this.getCarCircle == 1) {
        this.form.ilimitType = 2;
        }
        this.getData();
  },
  methods: {
    getData() {
      this.load = true;
      let obj = Object.assign({}, this.form);
      getUserRegionGroupBy(obj).then((res) => {
        let data = res.data || {};
        let dx = []; //省份
        let ds = []; //数据
        let arr = [];
        data.forEach((ele) => {
          dx.push(ele.Key);
          ds.push(ele.Value);
          let obj = {
            name: ele.Key,
            value: ele.Value,
          };
          arr.push(obj)
        });
        let dm = arr //省份和数据
        this.opt1 = createOptD1(dx, ds);
        this.opt2 = createOptD2(dm);
        this.load = false;
      });
    },
    // 将对象变成数组
    toArr(obj) {
      let arr = [];
      for (let key in obj) {
        let o = {
          name: key,
          value: obj[key] * 1,
        };
        arr.push(o);
      }
      return arr;
    },
  },
};
</script>

<style lang="less" scoped>
.wua-outter {
  width: 936px;
  height: 460px;
  border: 2px solid #0f2a4d;
  .wua-inner {
    width: 100%;
    height: calc(100% - 48px);
    display: flex;
    justify-content: flex-start;
    .d1 {
      width: 479px;
      height: 100%;
    }
    .d2 {
      width: 420px;
      height: 100%;
      margin-left: 16px;
    }
  }
}
</style>
