var  edit=false;
let vue_myModal1 = new Vue({
    el: '#myModal1',
    data(){
        return {
            // clzt_select: '',
            optionsdata: [],
            data_s: {
                videoId: '',
                videoName: '',
                qybh: '',
                qymc: '',
                x: '',
                y: '',
                rtsp: '',
                factory: '',
                chargeman: '',
                chargemanlxdh: '',

            }
        }
    },
    methods: {
        add: function () {
            if(edit==false) {
                $.ajax({
                    url: "/video/add",
                    dataType: "json",
                    type: "POST",
                    data: this.data_s,
                    success: function (result) {
                        if (result.code == 0) {
                            vue_right.queryRY(1, true);
                            $("#myModal1").modal("hide");
                            layui.use("layer",()=> {
                                const layer = layui.layer;
                                layer.msg("监控新增成功", {
                                    icon: 1
                                });
                            });
                            // info_new("监控新增成功");
                            // window.setTimeout("$('#info-warning-new').modal('hide')", 2000);
                        }
                    }
                });
            }else{
                edit=false;
                $.ajax({
                    url: "/video/edit",
                    dataType: "json",
                    type: "POST",
                    data: this.data_s,
                    success: function (result) {
                        if (result.code == 0) {
                            vue_right.queryRY(1, true);
                            $("#myModal1").modal("hide");
                            layui.use("layer",()=> {
                                const layer = layui.layer;
                                layer.msg("监控修改成功", {
                                    icon: 1
                                });
                            });
                            // info_new("监控修改成功");
                            // window.setTimeout("$('#info-warning-new').modal('hide')", 2000);
                        }
                    }
                });
            }
        }
    },
    mounted() {
        // setTimeout(function () {
        var _that=this;
        $.ajax({
            url: "/dept/tree",
            type: "get",
            success: function (result) {
                _that.optionsdata = [];
                if (result.code == 0) {
                    _that.optionsdata= result.data;
                }
            }
        });
        // }, 2000);
    }
});

let vue_right = new Vue({
    el: '#page-sy',
    data: {
        data_table_monitor: [],
        xz_jg: getCookie("bjpt_deptId"),
        count: '',
        level: '',
        fy_select:10,
        optionsdata:[],
    },
    methods: {
        add: function () {
            setTimeout(function () {
                // alert(vue_myModal1.options);
                // vue_myModal1.data_s={};
            $("#myModal1").modal("show");
            }, 1000);

        },
        edit: function (item) {
            setTimeout(function () {
                // vue_myModal1.clzt_select=item.qymc;
                // vue_myModal1.data_s=item;
                edit=true;
                vue_myModal1.data_s.id=item.id;
                vue_myModal1.data_s.videoId=item.videoId;
                vue_myModal1.data_s.videoName=item.name;
                vue_myModal1.data_s.qybh=item.qybh;
                vue_myModal1.data_s.qymc=item.qymc;
                vue_myModal1.data_s.rtsp=item.rtsp;
                $("#myModal1").modal("show");
            }, 1000);

        },
        del: function (item) {
            if (!confirm("确认删除监控吗？")) {
                return;
            }
            $.ajax({
                url: "/video/delete/" + item.id,
                dataType: "json",
                type: "GET",
                data: {},
                success: function (result) {
                    vue_right.queryRY(1, true);
                    layui.use("layer",()=> {
                        const layer = layui.layer;
                        layer.msg("监控删除成功", {
                            icon: 1
                        });
                    });
                    // info_new("监控删除成功");
                    // window.setTimeout("$('#info-warning-new').modal('hide')", 2000);

                }
            });
        },
        queryRY: function (pages, items) {
            $.ajax({
                url: "/video/list",
                dataType: "json",
                type: "get",
                data: {
                    page: pages,
                    pageSize: this.fy_select,
                    // deptId: this.xz_jg,
                    videoName: $("#ryxm").val(),
                },
                success: function (result) {
                    vue_right.data_table_monitor = [];
                    if (result.code == 0) {
                        let a_sum = result.count;
                        vue_right.count = result.count;
                        vue_right.data_table_monitor = result.data;
                        if (items) {
                            $("#fy4").bootstrapPaginator({
                                bootstrapMajorVersion: 3, //版本，这里设置为3，大于2即可
                                currentPage: 1,//当前页
                                totalPages: Math.ceil(((a_sum > 0) ? a_sum : 1) / vue_right.fy_select),//总页数
                                // numberofPages: this.fy_select,//显示的页数
                                itemTexts: function (type, page, current) { //修改显示文字
                                    switch (type) {
                                        case "first":
                                            return "首页";
                                        case "prev":
                                            return "上一页";
                                        case "next":
                                            return "下一页";
                                        case "last":
                                            return "末页";
                                        case "page":
                                            return page;
                                    }
                                }, onPageClicked: function (event, originalEvent, type, page) { //异步换页
                                    //请求加载数据
                                    vue_right.queryRY(page, false);
                                }
                            });
                        }
                    }
                }
            });
        },
        getChange:function () {
            // alert(this.fy_select);
            this.queryRY(1,true);
        }
    },
    mounted(){
        // var _that=this;
        // $.ajax({
        //     url: "/dept/tree",
        //     type: "get",
        //     success: function (result) {
        //         _that.optionsdata = [];
        //         if (result.code == 0) {
        //             _that.optionsdata= result.data;
        //         }
        //     }
        // });
        setTimeout(function () {

            vue_right.queryRY(1, true);

        }, 200);

    }
});

var lastSelectedNodeId = null;
//最后一次触发时间
var lastSelectTime = null;
function customBusiness(data) {
//        alert("双击获得节点名字： "+data.text);
}

function clickNode(event, data) {
    if (lastSelectedNodeId && lastSelectTime) {
        var time = new Date().getTime();
        var t = time - lastSelectTime;
        if (lastSelectedNodeId == data.nodeId && t < 300) {
            customBusiness(data);
        }
    }
    lastSelectedNodeId = data.nodeId;
    lastSelectTime = new Date().getTime();
}
