<!--
 * @Author: your name
 * @Date: 2021-10-15 16:56:32
 * @LastEditTime: 2021-11-11 16:44:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /data-show/src/views/BrandComparison/overallWordCloudComparison/index.vue
-->
<template>
  <div class="owcc-outter" v-loading="load">
    <v-label-div title="整体词云对比"> </v-label-div>
    <div class="owcc-inner">
      <div class="owcc-item" v-for="(item, index) in dataSource" :key="index">
        <v-label-div
          :title="item.name"
          :titleColor="colors[index]"
          :showLine="false"
          :eStyle="{ 'border-style': 'none' }"
        >
          <v-tab-group
            :btns="['正面', '负面']"
            @change="(n) => {handlerTab(n,item)}"
          ></v-tab-group>
        </v-label-div>
        <div class="owcc-draw">
          <v-echarts :opt="item.opt"></v-echarts>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getPositiveAndNegative0528C } from "@/api/BrandComparison";
import createWordCloud from "@/utils/gol/bubbleWord";
export default {
  name: "overallWordCloudComparison",
  data() {
    return {
      opt: {},
      load: false,
      form: {
        token: "",
        sBrand: "",
        sSeriesName: "",
        iContrastType: 2
      },
      colors: [
        "#3373CC",
        "#63AECC",
        "#54BF93",
        "#CC9D12",
        "#CC7733",
        "#CC5B41",
      ],
      dataSource: []
    };
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      this.form.token = this.getToken;
      let arr = this.getMComparison;
      let brands = [];
      let models = [];
      arr.forEach((ele) => {
        brands.push(ele.brand);
        models.push(ele.model);
      });
      this.form.sBrand = brands.toString();
      this.form.sSeriesName = models.toString();
      this.getData();
    },
    getData() {
      return new Promise((resolve, reject) => {
        this.load = true;
        let obj = Object.assign({}, this.getCtime2, this.form);
        getPositiveAndNegative0528C(obj)
          .then((res) => {
            let data = res.data || [];
            let arr = [];
            data.forEach(ele => {
                let obj = {
                    name: ele.key,
                    p: ele.value[0].value,
                    s: ele.value[1].value,
                    opt: createWordCloud(ele.value[0].value),
                    tapIndex: 0
                }
                arr.push(obj);
            })
            this.dataSource = arr;
            this.load = false;
            resolve(data);
          })
          .catch(() => {
            reject(false);
          });
      });
    },
    handlerTab(n,item) {
       item.tapIndex = n;
       if(n === 0) {
           item.opt = createWordCloud(item.p)
       } else {
           item.opt = createWordCloud(item.s)
       }
    }
  },
};
</script>

<style lang="less" scoped>
.owcc-outter {
  width: 100%;
  height: 460px;
  border: 2px solid #0f2a4d;
  margin-top: 16px;
  .owcc-inner {
    width: 100%;
    height: calc(100% - 48px);
    display: flex;
    justify-content: flex-start;
    .owcc-item {
      width: 314px;
      height: 412px;
      margin-top: 5px;
      .owcc-draw {
        width: 100%;
        height: calc(100% - 48px);
      }
    }
  }
}
</style>
