<!--
 * @Author: your name
 * @Date: 2021-10-16 14:56:13
 * @LastEditTime: 2021-10-19 11:52:43
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /data-show/src/views/BrandComparison/tailTOPMedia/index.vue
-->

<template>
    <div class="ttm-outter" v-loading="load">
        <v-label-div title="尾翼TOP媒体" :showLine="false" :eStyle="{'border-style': 'none'}" />
        <div class="ttm-inner">
            <div class="ttm-item" v-for="(item,index) in showData" :key="index">
                <span class="s1" :style="{color: colors[index]}">{{item.name}}</span>
                <div class="d1">
                    <v-echarts :opt="item.drawOpt"></v-echarts>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {getSourceTopCount0528C} from "@/api/BrandComparison/BrandWeiyi.js"
import {createSingleColumnar} from "@/utils/gol/singleColumnar"
export default {
    name: "tailTOPMedia",
    data() {
        return {
            form: {
                token: "",
                sBrand: "",
                iSize: 8  //最多显示的条数，默认为5
            },
            colors: ['#3373CC', '#63AECC', '#54BF93', '#CC9D12', '#CC7733', '#CC5B41'],
            showData: [],
            load: false
        };
    },
    created() {
        this.initData();
    },
    methods: {
        initData() {
            this.form.token = this.getToken;
            let arr = this.getBComparison;
            let brands = [];
            arr.forEach(ele => {
                brands.push(ele.name)
            });
            this.form.sBrand = brands.toString();
            this.getData();
        },
        getData() {
            return new Promise((resolve, reject) => {
            let obj = Object.assign({}, this.getCtime2, this.form);
            this.load = true;
            getSourceTopCount0528C(obj).then((res) => {
            let data = res.data || [];
            let sourceData = [];
            let colorList = this.colors;
            let index = 0;
            data.forEach( ele => {
                let mediaList = [];
                let valueList = [];
                ele.value.forEach( e => {
                    mediaList.push(e.key);
                    valueList.push(e.value);
                });
                let o = {
                    name: ele.key,
                    drawOpt: createSingleColumnar(mediaList,valueList,colorList[index])
                };
                index += 1;
                sourceData.push(o);
                this.showData = sourceData;
            });
            this.load = false;
            resolve(data)
            }).catch(() => {
                reject(false)
            });
        });
      }
    }

};
</script>

<style lang="less" scoped>
.ttm-outter {
    width: 100%;
    height: auto;
    .ttm-inner {
        width: 100%;
        height: auto;
        display: flex;
        justify-content: flex-start;
        flex-wrap: wrap;
        .ttm-item {
            width: 628px;
            height: 380px;
            .s1 {
                padding-left: 16px;
                width: 100%;
                height: 40px;
                line-height: 40px;
                font-size: 16px;
                color: #fff;
            }
            .d1 {
                width: 100%;
                height: calc(100% - 40px);
            }
        }
    }
}
</style>
