<template>
  <div class="ts-container1" v-loading="load">
      <v-label-div title="渠道分布"></v-label-div>
      <div class="ts-inner">
          <v-echarts :opt="opt" @clickMark="clickMark"></v-echarts>
          <div class="vshow" v-if="modelShow" :style="modelStyle">
            <vLabel-div title="实时热点事件">
                <a-button @click="closeBox">关闭</a-button>
            </vLabel-div>
            <div class="vshow-item" v-for="(item, index) in urlArr" :key="index">
                <a class="vshow-link" :href="item.url" v-if="item.column == activeCol" target="tar">{{item.title}}</a>
            </div>
          </div>
      </div>
  </div>
</template>

<script>
import {getSourcetypeTime} from "@/api/ThemeAnalizeDec"
import {doStr} from "@/utils/gol/dataTool"
import createOpt from "./opt";
export default {
    name: "TotalSource",
    data() {
        return {
            load: false,
            //弹出框//
            modelStyle:{
                left: '',
                top: ''
            },
            modelShow: false,
            ecbox:{//图表宽高
                width:618,
                height:460
            },
            ecmodel:{//弹框宽高
                width:300,
                height:280
            },
            activeCol: 0,
            //-*-//
            opt: {},
            form: {
                token: ''
            },
            urlArr: []
        }
    },
    created() {
        this.form = this.$route.query;
        this.getData()
    },
    methods: {
        getData() {
            let obj = Object.assign({}, this.form);
            this.load = true;
            getSourcetypeTime(obj).then(res => {
                let data = res.data || [];
                let dx = [];
                let ds = [];
                let hotTopArr = [];
                let urlArr = [];
                let hotIndex = [];
                let dataI = 0;
                data.forEach((ele) => {
                    let time = ele.Time;
                    let value = ele.Data;
                    dx.push(time);
                    ds.push(value);
                    if(ele.hotTop[0]) {
                        ele.hotTop.forEach((e) => {
                            let urlObj = {
                                column: dataI,
                                title: doStr(e.title, 30),
                                url: e.url
                            };
                            urlArr.push(urlObj);
                        })
                    }
                    let obj = {
                        label: time,
                        hotTop: ele.hotTop
                    }
                    hotTopArr.push(obj);
                    dataI = dataI + 1;
                });
                this.urlArr = urlArr;
                //获取有热点信息的索引
                for(let i = 0; i<hotTopArr.length; i++) {
                    if(hotTopArr[i].hotTop != '') {
                        hotIndex.push(i)
                    }
                }
                this.opt = createOpt(dx, ds, hotTopArr, hotIndex);
                this.load = false;
            })
        },
        clickMark(data) {
            this.activeCol = data.index
            this.modelShow = true;
            let mw = window.event;
            if((this.ecbox.width - mw.offsetX - 20) > this.ecmodel.width) {
                this.modelStyle.left = mw.offsetX + 20 + "px"
            } else {
                this.modelStyle.left = mw.offsetX - this.ecmodel.width - 20 + "px"
            }
            if((this.ecbox.height - mw.offsetY - 20) > this.ecmodel.height) {
                this.modelStyle.top = mw.offsetY + 1500 + "px"
            } else {
                this.modelStyle.top = mw.offsetY - this.ecmodel.height + 1500 + "px"
            }
        },
        closeBox() {
            this.modelShow = false;
        },
    }
}
</script>

<style lang="less">
.ts-container1 {
    width: 100%;
    height: 460px;
    border: 2px solid #0f2a4d;
    margin-top: 16px;
    overflow: hidden;
    .ts-inner {
        width: 100%;
        height: calc(100% - 48px);
    }
}
.vshow{
    position: absolute;
    width: 300px;
    background: rgb(3, 18, 36);
    border: 4px solid #0f2a4d;
    .vshow-item {
        padding: 11px;
        width: 100%;
        font-size: 15px;
        color: rgb(54, 189, 239);
    }
}
</style>