<!--
 * @Author: your name
 * @Date: 2021-10-14 19:06:52
 * @LastEditTime: 2021-10-14 19:14:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /data-show/src/views/WeiboDetails/weiboWordCloud/index.vue
-->
<template>
  <div class="wwc-outter" v-loading="load">
    <v-label-div title="词云分布">
      <div>
        <v-tab-group
          :btns="['正面', '负面']"
          @change="handlerTab"
        ></v-tab-group>
      </div>
    </v-label-div>
    <div class="wwc-inner">
      <v-echarts :opt="opt"></v-echarts>
    </div>
  </div>
</template>

<script>
import { getNegative } from "@/api/WeiboDetails";
import { getPositive } from "@/api/WeiboDetails";
import createWordCloud from "@/utils/gol/bubbleWord";
//import createOpt from "./opt";
export default {
  name: "weiboWordCloud",
  data() {
    return {
      opt: {},
      load: false,
      positiveData: {},
      negativeData: {},
      form: {
        sBrand: "",
        token: "",
      },
    };
  },
  created() {
    this.form.token = this.getToken;
    this.form.sBrand = this.getBrand.brandname || '奥迪';
    this.getData();
  },
  methods: {
    getData() {
      this.load = true;
      Promise.all([this.getH(), this.getF()]).then(() => {
        // 什么也不执行
        this.handlerTab(0);
        this.load = false;
      });
    },
    // 正面
    getH() {
      return new Promise((resolve, reject) => {
        let obj = Object.assign({}, this.getCtime2, this.form);
        getPositive(obj)
          .then((res) => {
            this.positiveData = res.data || {};
            resolve(res);
          })
          .catch(() => {
            reject(false);
          });
      });
    },
    // 负面
    getF() {
      return new Promise((resolve, reject) => {
        let obj = Object.assign({}, this.getCtime2, this.form);
        getNegative(obj)
          .then((res) => {
            this.negativeData = res.data || {};
            resolve(res);
          })
          .catch(() => {
            reject(false);
          });
      });
    },
    // 切换数据
    handlerTab(n) {
      switch (n) {
        case 0:
          this.opt = createWordCloud(this.positiveData);
          break;
        case 1:
          this.opt = createWordCloud(this.negativeData);
          break;
        default:
          this.opt = createWordCloud(this.positiveData);
          break;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.wwc-outter {
  width: 460px;
  height: 460px;
  border: 2px solid #0f2a4d;
  margin-left: 16px;
  .wwc-inner {
    width: 100%;
    height: calc(100% - 48px);
  }
}
</style>