<template>
    <div class="table-toolbar" style="text-align:left;" name="ButtonGroup">
        <template v-for="(button,index) in Buttons">
            <div class="widget-buttons ">
                <button v-bind:id="button.Control_ID" v-bind:title="button.FullName" v-bind:data-url="button.Config" v-bind:class="'authbutton btn '+ (index==0?'btn-primary':'btn-default')" v-bind:event="button.Event"><i v-bind:class="button.Img"></i>{{button.FullName}}</button>
            </div>
        </template>
    </div>
</template>
<script>

    export default{
        data(){
            var ret;
            getDataSync(window.FrameSGHost+"WRPFrame-GetButton", "post",
                {"MenuId":this.mid}, function (result) {
                    if (result.state == "1") {
                        ret = result.data;
                    } else {
                        NotifyError(result.errmsg);
                        ret = "[]";
                    }
                });

            return {"Buttons":ret};
        },
        props: {
            mid:{
                type: String,
                required: true
            }
        },
        mounted(){
            var that = this;
            $(".authbutton").click(function () {
                var ev = $(this).attr("event");
                var url = $(this).attr("data-url");
                var buttonName = $(this).attr("title");
                that.reportOprator(buttonName)
                var returnVal = !url || url.length==0 ? {}:JSON.parse(url);
                that.$emit(ev,returnVal);
            });
        },
        methods:{
            reportOprator:function (buttonName) {
                var pageName = this.$route.name;
                var module = p_context.SubApplication?p_context.SubApplication:"platform"
                var domain = document.domain;
                var pageAccessParam = {
                    "filter": JSON.stringify({
                        "PageName": pageName,
                        "ModuleName": module,
                        "WebSite": domain,
                        "FuncId":window.patchNo || "",
                        "WebUrl" : window.location.hash,
                        "ResponseTime": 0,
                        "Ext4": buttonName
                    })
                };


                window.PVCount(pageAccessParam)
            }
        }
    }
</script>
