let vue_sjcx = new Vue({
    el: '#sjcx',
    data: {
        searchText: '',
        data_sjlxs: [],
        data_table_wfpz: [],
        count: '',
        deptId: getCookie("bjpt_deptId"),
        fy_select: 20,
        state_arr: [],
        cllx_select: '',
        clzt_select: [],
        arr_cllx: [],
        type: '1',
        shows: true,
        bmid: getCookie("bjpt_deptId"),
        count:'',
        countdate_s:'',
    },
    methods: {
        fastSearch: function () {
            $("#tree-xzxq").treeview('search', [this.searchText, {
                ignoreCase: true,      // case insensitive
                exactMatch: false,     // like or equals
                revealResults: true,   // reveal matching nodes
            }]);
        },
        xqs:function (item) {
            this.countdate_s = item.countdate;
            vue_myModal_sj.query(1,true);
            $("#myModal_sj").modal("show");
        },
        query: function (pages, items) {
            let starttime, endtime;
            if (this.type == '1') {
                starttime = $("#kssj").val().substr(0, 10);
                endtime = $("#kssj").val().substr(13, 10);
            } else {
                starttime = $("#kssj1").val().substr(0, 7);
                endtime = $("#kssj1").val().substr(10, 7);
            }
            let arrs = {
                starttime: starttime,
                endtime: endtime,
                page: pages,
                limit: this.fy_select,
                type: this.type,
                eventtype: this.cllx_select.toLocaleLowerCase(),
                areaid: this.bmid,
            };
            $.ajax({
                url: "/TrafficStatistics/list/eventresultBypage",
                dateType: 'json',
                type: "post",
                contentType: 'application/json',
                data: JSON.stringify(arrs),
                success: function (result) {
                    vue_sjcx.data_table_wfpz = [];
                    if (result.code == 0) {
                        let a_sum = result.count;
                        vue_sjcx.count = result.count;
                        vue_sjcx.data_table_wfpz = result.data;
                        if (items) {
                            $("#fy4").bootstrapPaginator({
                                bootstrapMajorVersion: 3, //版本，这里设置为3，大于2即可
                                currentPage: 1,//当前页
                                totalPages: Math.ceil(((a_sum > 0) ? a_sum : 1) / vue_sjcx.fy_select),//总页数
                                // numberofPages: 10,//显示的页数
                                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_sjcx.query(page, false);
                                }
                            });
                        }
                    }
                }
            });
        },
        getChange: function () {
            setTimeout(function () {
                vue_sjcx.query(1, true);
            }, 200);
        },
        getChange_tszt: function () {
            if (this.type == '1') {
                this.shows = true;
            } else {
                this.shows = false;
            }
        },
    },
    mounted(){
        laydate.render({
            elem: '#kssj'
            , theme: '#368ff3'
            , range: true
        });
        laydate.render({
            elem: '#kssj1'
            , type: 'month'
            , theme: '#368ff3'
            , range: true
        });
        $("#kssj").val(getTime_extent(15).pre_rq + ' - ' + getTime().jssj_big);
        $("#kssj1").val(getTime().kssj_ym + ' - ' + getTime().kssj_ym);
        $.ajax({
            url: "/TrafficStatistics/listcode",
            dataType: "json",
            type: "GET",
            data: {
                codeid: 2,
                alarmlevel: '',
            },
            success: function (result) {
                vue_sjcx.arr_cllx = [];
                if (result.code == 0) {
                    if (result.data.length > 0) {
                        vue_sjcx.arr_cllx.push({name: '全部', id: "", type: "",});
                        result.data.forEach((item, index)=> {
                            vue_sjcx.arr_cllx.push(item);
                        });
                        setTimeout(function () {
                            $("#cllxs").selectpicker('refresh');
                            $("#cllxs").selectpicker('render');
                        }, 200);
                    }
                }
            }
        });
        $.ajax({
            url: "/dept/getDeptParent/" + getCookie("bjpt_deptId"),
            dataType: "json",
            type: "GET",
            data: {},
            success: function (result) {
                if (result.code == 0) {
                    let parIds = result.data[0].parentId;
                    $.ajax({
                        url: "/dept/listvideo",
                        dataType: "json",
                        type: "GET",
                        data: {
                            deptId: getCookie("bjpt_deptId"),
                            username: getCookie("bjpt_realName"),
                            tdmc:'',
                        },
                        success: function (result) {
                            let defaultData = [];
                            if (result.code == 0) {
                                defaultData = toTree(result.data, parIds + '');
                                $('#tree-xzxq').treeview({
                                    expandIcon: 'glyphicon glyphicon-triangle-right selected-span',
                                    collapseIcon: 'glyphicon glyphicon-triangle-bottom selected-span',
                                    nodeIcon: 'glyphicon glyphicon-folder-open selected-span',
                                    selectedBackColor: '#ff000000',
                                    selectedColor: '#368ff3',
                                    onhoverColor: '#73a5ff26',
                                    showBorder: false,
                                    data: defaultData,
                                    multiSelect: false,
                                    level: 2,
                                });
                                $('#tree-xzxq').on('nodeSelected', function (event, data) {
                                    vue_sjcx.bmid = data.href;
                                    // alert('点击选中');
                                });
                            }
                        }
                    });
                }
            }
        });
        this.query(1, true);
    },

});
let vue_sjsstx = new Vue({
    el: '#myModal',
    data: {
        sp_src: '',
        data_wfsp: [],
        data_sj: {},
        class_s: 'class_1',
        class_s1: 'class_2',
        show_s: false,
        img_src_s: '',
        video_src: ''
    },
    methods: {
        sp_qh: function (e) {
            if (e == 1) {
                this.class_s = 'class_1';
                this.class_s1 = 'class_2';
                this.show_s = false;
            } else {
                this.class_s = 'class_2';
                this.class_s1 = 'class_1';
                this.show_s = true;
                this.video_src = '/TrafficStatistics/fielagent?ftpPath=' + this.data_sj.videopath;
            }
        },
        click_img_bf: function (src) {
            this.img_src_s = src;
        }
    },
    mounted(){
        if (this.data_wfsp.length > 0) {
            this.data_wfsp[0].kg = true;
            this.sp_src = this.data_wfsp[0].src;
//                document.getElementById("my_video_1").play();
        }
    }
});
let vue_myModal_sj = new Vue({
    el:'#myModal_sj',
    data:{
        data_table_wfpz:[],
        fy_select:20,
        count:'',
    },
    methods:{
        //详情
        xq: function (item) {
            vue_sjsstx.video_src = '';
            vue_sjsstx.data_sj = item;
            vue_sjsstx.class_s = 'class_1';
            vue_sjsstx.class_s1 = 'class_2';
            vue_sjsstx.show_s = false;
            vue_sjsstx.img_src_s = '';
            vue_sjsstx.data_wfsp = [];
            if (item.img1path != null) {
                vue_sjsstx.img_src_s = '/TrafficStatistics/fielagent?ftpPath=' + item.img1path;
                vue_sjsstx.data_wfsp.push({src: '/TrafficStatistics/fielagent?ftpPath=' + item.img1path});
            }
            if (item.img2path != null) {
                vue_sjsstx.data_wfsp.push({src: '/TrafficStatistics/fielagent?ftpPath=' + item.img2path});
            }
            if (item.img3path != null) {
                vue_sjsstx.data_wfsp.push({src: '/TrafficStatistics/fielagent?ftpPath=' + item.img3path});
            }
            if (item.img4path != null) {
                vue_sjsstx.data_wfsp.push({src: '/TrafficStatistics/fielagent?ftpPath=' + item.img4path});
            }
            if (item.img5path != null) {
                vue_sjsstx.data_wfsp.push({src: '/TrafficStatistics/fielagent?ftpPath=' + item.img5path});
            }
            $("#myModal").modal("show");
        },
        getChange:function () {
            setTimeout(function () {
                vue_myModal_sj.query(1, true);
            }, 200);
        },
        query:function (pages,items) {
            let arrs = {
                videoids: "",
                page: pages,
                limit: this.fy_select,
                recordtype: vue_sjcx.cllx_select.toLocaleLowerCase(),
                checkstatus: "",
                starttime: vue_sjcx.countdate_s+' 00:00:00',
                endtime: vue_sjcx.countdate_s+' 23:59:59',
                deptid: vue_sjcx.bmid,
                objlabel:"",
                processstatus:"",
                rectificationtype:'',
                userid:getCookie("bjpt_userId")
            }
            $.ajax({
                url: "/TrafficStatistics/queryTraffalarmrecordByPage/1",
                dateType: 'json',
                type: "POST",
                contentType: 'application/json',
                data: JSON.stringify(arrs),
                success: function (result) {
                    vue_myModal_sj.data_table_wfpz = [];
                    if (result.code == 0) {
                        let a_sum = result.count;
                        vue_myModal_sj.count = result.count;
                        vue_myModal_sj.data_table_wfpz = result.data;
                        if (items) {
                            $("#fy").bootstrapPaginator({
                                bootstrapMajorVersion: 3, //版本，这里设置为3，大于2即可
                                currentPage: 1,//当前页
                                totalPages: Math.ceil(((a_sum > 0) ? a_sum : 1) / vue_myModal_sj.fy_select),//总页数
                                // numberofPages: 10,//显示的页数
                                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_myModal_sj.query(page, false);
                                }
                            });
                        }
                    }
                }
            });
        }
    }
})

function toTree(list, parId) {
    let len = list.length;

    function loop(parId) {
        let res = [];
        for ( let i = 0; i < len; i++) {
            let item = list[i];
            if (item.parentId === parId) {
                if (item.level != null) {
                    item.nodes = loop(item.href);
                    let arr = {
                        href: item.href,
                        text: item.text,
                        level: item.level,
                        parentId: item.parentId,
                    }
                    if (item.level == 0 || item.level == 1) {
                        if (item.nodes.length > 0) {
                            arr.nodes = item.nodes;
                            arr.state = {expanded: true};
                        }
                    } else {

                        arr.selectable = true;
                    }
                    res.push(arr);
                }
            }
        }
        return res
    }

    return loop(parId)
}

//放大缩小图片
$('[data-gallery=manual]').click(function (e) {

    e.preventDefault();

    var items = [],
        options = {
            index: $(this).index()
        };

    $('[data-gallery=manual]').each(function () {
        items.push({
            src: $(this).attr('src'),
            title: '图片查看'
        });
    });
    new PhotoViewer(items, options);
});