<!--
 * @Author: xw
 * @Date: 2021-10-12 09:32:35
 * @LastEditTime: 2021-12-03 18:49:25
 * @LastEditors: Please set LastEditors
 * @Description: 舆情传播趋势
 * @FilePath: /data-show/src/views/BrandInsight/titsopo/index.vue
-->
<template>
    <div class="tit-outter" v-loading="load">
        <div class="tit-header">
            <a-button type="primary" size="small" @click="goIDE" v-has="'btn_model_datalist'">进入数据列表页</a-button>
            <a-button type="primary" :loading="btnLoading" style="margin-left: 1rem;margin-right: 1rem;" size="small" v-has="'btn_model_toppt'" @click="exportData">导出报告</a-button>
        </div>
        <div class="tit-inner">
            <vLabel-div title="舆情传播趋势"></vLabel-div>
            <div class="tit-bd">
                <v-echarts :opt="opt" @clickMark="clickMark" @getData="clickEchars"></v-echarts>
            </div>
        </div>
        <div class="con-box">
            <div id="gxid" @click.prevent="boxss"></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>
    </div>
</template>

<script>
import { getSourcetypeTime } from "@/api/ModelInsight";
import { getToPptTask } from "@/api/BrandInsight";
import {doStr} from "@/utils/gol/dataTool"
import moment from "moment";
import createOpt from "./opt";
export default {
    name: "ml-tts",
    props: ["brand", "model"],
    data() {
        return {
            //弹出框//
            modelStyle:{
                left: '',
                top: ''
            },
            modelShow: false,
            ecbox:{//图表宽高
                width:1618,
                height:1490
            },
            ecmodel:{//弹框宽高
                width:300,
                height:280
            },
            activeCol: 0,
            //-*-//
            load: false,
            btnLoading: false,
            form: {
                sBrand: "",
                sSeriesName: "",
                token: "",
            },
            opt: {},
            urlArr: []
        };
    },
    watch: {
        model: {
            handler(val) {
                if (val) {
                    this.form.token = this.getToken;
                    this.form.sBrand = this.brand;
                    this.form.sSeriesName = this.model;
                    this.getData();
                }
            },
            immediate: true,
        },
    },
    methods: {
        // 前往数据表格
        goIDE() {
            let startTime = "";
            let endTime = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
            let cTime2 = this.getCtime2;
            let sTimeType = 34;
            sTimeType = cTime2.sTimeType 
            if(cTime2.sTimeType == 4) {
                  startTime = cTime2.sStartTime;
                  endTime = cTime2.sEndTime;
            } else {
                startTime = "";
                endTime = ""
            }
            this.$router.push({
                path: "/industryDataExport",
                query: {
                    startTime,
                    endTime,
                    sTimeType,
                    token: this.getToken,
                    action: "getList",
                    sType: "BrandData",
                    //brand: this.form.sBrand,
                    seriesName: this.form.sSeriesName,
                    title: "车型-行业数据",
                },
            });
        },
        // 弹出框
        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;
        },
        boxss() {
            this.modelShow = false;
        },
        //
        // 获取后台数据
        getData() {
            let obj = Object.assign({}, this.getCtime2, 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, hotIndex);
                this.load = false;
            });
        },
        clickEchars(data = []) {
            if (!this.btnPrm("btn_model_datalist")) {
                return;
            }
            let qudao = [];
            let startTime = "";
            let endTime = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
            data.forEach((ele) => {
                let seriesName = ele.seriesName;
                startTime = ele.name;
                qudao.push(seriesName);
            });
            let sTimeType = 4;
            this.$router.push({
                path: "/industryDataExport",
                query: {
                    startTime,
                    endTime,
                    qudao,
                    sTimeType,
                    token: this.getToken,
                    action: "getList",
                    sType: "BrandData",
                    brand: this.form.sBrand,
                    seriesName: this.form.sSeriesName,
                    title: "车型-行业数据",
                },
            });
        },
        // 导出报告
        exportData() {
             let obj = Object.assign({}, this.getCtime2, this.form);
             obj.sType = 'ToSeriesPptV6';
             this.btnLoading = true;
             getToPptTask(obj).then(() => {
                 this.$notification.open({
                    message: `数据生成中`,
                    description: '请前往个人中心查看下载进度',
                    placement: 'bottomRight',
                });
                 this.btnLoading = false;
             })
        }
    },
};
</script>

<style lang="less" scoped>
.tit-outter {
    width: 618px;
    height: 560px;
    margin-left: 16px;
    .tit-header {
        width: 100%;
        height: 48px;
        background: linear-gradient(270deg, #07192f 0%, #010b19 100%);
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .tit-inner {
        width: 100%;
        height: 490px;
        margin-top: 16px;
        border: 2px solid #0f2a4d;
        .tit-bd {
            width: 100%;
            height: calc(100% - 48px);
        }
    }
}

#gxid {
  height: 100%;
  width: 100%;
}
.con_box{
  position: relative;
  height: 600px;
  width: 900px;
  margin: 0 auto;
}
.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>
