let state_sj = true;
String.prototype.endWith=function(s){
    if(s==null||s==""||this.length==0||s.length>this.length)
        return false;
    if(this.substring(this.length-s.length)==s)
        return true;
    else
        return false;
    return true;
};

let vue_sjcx = new Vue({
    el: '#sjcx',
    data: {
        show: true,
        data_table_wfpz: [],
        count: '',
        fy_select: 21,
        show_nums: false,
        clzt_select: ["人员离岗","人员攀高" ,"倒地检测","边界入侵"],
        options: [{
            value: "人员离岗",
            text: "重点人员离开检测"
        }, {
            value: "人员攀高",
            text: "人员攀高"
        },  {
            value: "倒地检测",
            text: "人员倒地"
        },{
            value: "边界入侵",
            text: "边界入侵"
        }],
        colorArray:[{
            "id":"人员离岗",
            "color":"#48AFE4"
        },
            {
                "id":"人员聚集",
                "color":"#00C7E6"
            }
            ,
            {
                "id":"倒地检测",
                "color":"#FFA167"
            } ,
            {
                "id":"攀高检测",
                "color":"#FF878B"
            },
            {
                "id":"人员靠近",
                "color":"#00B9B8"
            },
            {
                "id":"边界入侵",
                "color":"#92004a"
            }
        ]
    },
    methods: {

        getclolor:function(item){
            let  arr=vue_sjcx.colorArray.filter((e)=>e.id==item);
            return arr.length>0?arr[0].color:"#7583D0";
        },
        query: function (pages, items) {

            this.show_nums = false;
            // arr_nodes = arr_nodes.substring(0,arr_nodes.length -1);
            let starttime = $("#kssj").val().substr(0, 19);
            let endtime = $("#kssj").val().substr(22, 19);

            let processstatus = "";
            if (this.clzt_select.length == 0) {
                processstatus = "人员离岗,人员攀高 ,倒地检测,边界入侵";
            } else {
                this.clzt_select.forEach((item, index)=> {
                    processstatus = processstatus + item + ',';
                });
            }

            $.ajax({
                url: "/alarm/getAlarm",
                dateType: 'json',
                type: "POST",
                contentType: 'application/json',
                data: JSON.stringify({kssj:starttime,jssj:endtime,labelText:processstatus,menuid:'4',//监室
                    pageInfo: {pageNum:pages,pageSize:this.fy_select}}),
                success: function (result) {
                    vue_sjcx.data_table_wfpz = [];
                    // if (result.total > 0) {
                        let a_sum = result.data.total;
                        vue_sjcx.count = result.data.total;
                        vue_sjcx.data_table_wfpz = result.data.list;
                        vue_sjcx.data_table_wfpz.forEach(function(item) {
                            try {
                                let labels = JSON.parse(item.label_text);
                                item.labels = labels;
                            }catch (ex){}
                        });
                    if (result.data.total == 0) {
                        layui.use("layer",()=> {
                            const layer = layui.layer;
                            layer.msg("无数据", {
                                icon: 0
                            });
                        });

                    }
                        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);
        },
    showimg:function(src){
        var items = [],
            options = {
                index: 1
            };
            items.push({
                src: src,
                title: '图片查看'
            });
        new PhotoViewer(items, options);
    },

    },
    mounted(){
        $("#kssj").val(getTime_extent(6).pre_rq_start + ' - ' + getTime().jssj);
        this.getChange();
    },

});

laydate.render({
    elem: '#kssj'
    , type: 'datetime'
    , theme: '#368ff3'
    , range: true
});
