<template>
    <div :id="winIdStr" class="hidden go_win_obj" :style="extendStyle">
        <div :id="msgIdStr"  class="toast-ctl toast-top-right" aria-live="polite" role="alert" :style="getMaxZIndex" style="position: absolute"></div>
        <slot></slot>
    </div>
</template>

<script>
    import { GoingUtils } from "goingutils";
    import WinMixins from "../ctlMixins/WinMixins";


    export default {
        name: "go-win",
        mixins: [WinMixins],
        data() {
            let _winIdStr = GoingUtils.getUUid(10);
            return {
                dialogWinId:"",
                winIdStr: _winIdStr,
                msgIdStr:GoingUtils.getUUid(10)
            };
        },
        props: {
            iframe:{ type: Boolean, default: false },
            url:{ },
        },
        computed: {
            getMaxZIndex(){
                return {zIndex:GoingUtils.getMaxZIndex()};
            },
            extendStyle() {
                let json = {};
                json["width"] = this.width + "px";
                let curHeight = this.height;
                if (this.footerBar) {
                    curHeight = parseFloat(this.height) - 40;
                }
                curHeight = curHeight - 42;
                json["height"] = curHeight + "px";
                //缓存宽高
                let winInfo = { height: curHeight, width: this.width };
                GoingUtils.setTotalParams(this.winIdStr, JSON.stringify(winInfo));
                return json;
            }
        },
        methods: {
            //窗口区域弹出错误信息
            showErrorMessage(msg){
                GoingUtils.showWinErrorMessage(msg,this.msgIdStr,{"timeOut": "1000"});
            },
            showInfoMessage(msg){
                GoingUtils.showWinInfoMessage(msg,this.msgIdStr,{"timeOut": "1000"});
            },
            //获取窗口的id
            getWinId(){
                if(this.url!=null){
                    return this.url;
                }
                return this.winIdStr;
            },
            hideWin() {
                //    关闭窗口
                this.$WinUtils.closeParentCurWin(true,this.winIdStr);
            },
            closeLoading(){
                this.$WinUtils.closeLoading(this.dialogWinId);
            },
            showWin() {
                //执行回调前的命令
                this.$emit("showBefore", {});
                let opts = {
                    width: this.width,
                    height: this.height,
                    url: this.getWinId(),
                    iframe:this.iframe,
                    showBottomBar: this.footerBar,
                    title: this.title,
                    closeWin: () => {},
                    anim: null
                };

                //关闭函数
                opts["closeWin"] = () => {
                    this.$emit("input", false);
                    this.$emit("close", true);
                };
                //判断是否存在 继续的按钮
                if (this.continueBtn) {
                    opts["continueBtn"] = () => {
                        this.$emit("continue", false);
                    };
                }
                //判断是否存在确定按钮
                if (this.confirmBtn) {
                    opts["confirmBtn"] = () => {
                        this.$emit("ok", false);
                    };
                }
                let dialogWinId=this.$WinUtils.showInfoOnWin(opts);
                if(this.showLoading){
                    this.dialogWinId=dialogWinId;
                    this.$WinUtils.showLoading(dialogWinId);
                }
            }
        },
        mounted() {

        },
        beforeDestroy(){
            //销毁窗口组件
            if($("#"+this.winIdStr).get(0)!=null){
                $("#"+this.winIdStr).remove();
                this.winIdStr=null;
            }
            this.dialogWinId=null;
        },
        watch: {
            value(newVal) {
                if (newVal) {
                    this.showWin();
                } else {
                    this.hideWin();
                }

            }
        }
    };
</script>
