<!--
 * @Author: your name
 * @Date: 2021-10-19 19:05:36
 * @LastEditTime: 2021-11-22 10:04:53
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /data-show/src/views/EventDEC/incidentSpreadSituation/index.vue
-->
<template>
    <div class="iss-outter" v-loading="load">
        <v-label-div title="事件传播态势">
            <!-- <a-select v-model="form.sTimeType" :size="$vuiSize" style="width: 7rem; margin-left: 2.2rem; margin-right: 0.5rem" @change="handleChange">
                <a-select-option :style="{ color: '#fff' }" v-for="item in selDatas" :value="item.key" :key="item.key">
                    {{ item.value }}
                </a-select-option>
            </a-select> -->
        </v-label-div>
        <div class="iss-inner">
            <v-echarts :opt="opt" @clickMark="clickMark"></v-echarts>
        </div>
        <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>
</template>

<script>
import createOpt from "./opt";
import { getSourcetypeTime } from "@/api/EventdEC";
import {doStr} from "@/utils/gol/dataTool"
export default {
    name: "incidentSpreadSituation",
    props: {
        id: {
            type: String,
            default: "",
        },
    },
    data() {
        return {
            //弹出框//
            modelStyle:{
                left: '',
                top: ''
            },
            modelShow: false,
            ecbox:{//图表宽高
                width:1618,
                height:490
            },
            ecmodel:{//弹框宽高
                width:300,
                height:280
            },
            activeCol: 0,
            //-*-//
            opt: {},
            load: false,
            selDatas: [
                {
                    key: 34,
                    value: "小时",
                },
                {
                    key: 20,
                    value: "天",
                },
            ],
            form: {
                token: "",
                sRele: "",
                sTimeType: 20,
            },
            urlArr: [] //url列表
        };
    },
    created() {
        this.form.token = this.getToken;
        this.form.sRele = this.id;
        this.getDdta();
    },
    methods: {
        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 + "px"
            } else {
                this.modelStyle.top = mw.offsetY - this.ecmodel.height + "px"
            }
        },
        closeBox() {
            this.modelShow = false;
        },
        getDdta() {
            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 key = ele.Time;
                    let value = ele.Data;
                    dx.push(key);
                    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: key,
                        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, this.form.sTimeType, hotIndex);
                this.load = false;
            });
        },
        // 选择时间
        handleChange() {
            this.getDdta();
        },
    },
};
</script>

<style lang="less" scoped>
.iss-outter {
    width: 100%;
    height: 460px;
    border: 2px solid #0f2a4d;
    margin-top: 16px;
    overflow: hidden;
    .iss-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>
