let vue_sjcx = new Vue({
    el: '#sjcx',
    data: {
        data_sjlxs: [],
        data_table_wfpz: [],
        data_sjlxs1: [],
        count: '',
        deptId: getCookie("bjpt_deptId"),
        fy_select: 20,
        state_arr: [],
        cllx_select: [],
        clzt_select: 9,
        arr_cllx: [],
        sjlx_select:'',
    },
    methods: {
        tss:function () {
           vue_sjcx.state_arr = [];
                      $(".div-pub-gt").find('input:checked').each(function () {
                          vue_sjcx.state_arr.push($(this).val());
                      });
                      if (vue_sjcx.state_arr.length == 0) {
                          info_new("未选择行");
                          window.setTimeout("$('#info-warning-new').modal('hide')", 2000);
                          return;
                      }
                      vue_ts.data_table_ts = [];
                      vue_sjcx.state_arr.forEach((item, index)=> {
                          vue_sjcx.data_table_wfpz.forEach((items, indexs)=> {
                              if (item == items.xh) {
                                  vue_ts.data_table_ts.push(items);
                              }
                          });


                      });
                      $("#myModal_ts").modal("show");


        },
        getChange_tszt:function () {
            setTimeout(function () {
                vue_sjcx.query(1, true);
            }, 200);
        },
        qx_s:function (e) {
            if(e.currentTarget.checked){
                $(".div-pub-gt").find('input').each(function () {
                    $(this).prop("checked", true);
                });
                vue_sjcx.state_arr = [];
                $(".div-pub-gt").find('input:checked').each(function () {
                    vue_sjcx.state_arr.push($(this).val());
                });
            }else{
                $(".div-pub-gt").find('input').each(function () {
                    $(this).removeAttr("checked", false);
                    $(this).prop("checked", false);
                    vue_sjcx.state_arr = [];
                });
            }
        },
        query: function (pages, items) {
            $.ajax({
                url: "/traffresult/querySbtdspsrResultByPage",
                dateType: 'json',
                type: "POST",
                contentType: 'application/json',
                data: JSON.stringify({
                    xzbh:getCookie("bjpt_deptId"),
                    page: pages,
                    limit: this.fy_select,
                    pushstatus: this.clzt_select
                }),
                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);

        },
    },
    mounted(){
        this.query(1, true);
    },

});


let vue_ts = new Vue({
    el: '#myModal_ts',
    data: {
        data_table_ts: [],
    },
    methods: {
        //删除
        deletes: function (item, index) {
            vue_ts.data_table_ts.splice(index, 1);
        },
        //开始推送
        ts_ok: function () {
            if (!confirm("确认推送当前表格中的设备吗")) {
                return;
            }
            ;
            let arrs = '';
            vue_sjcx.state_arr.forEach((item, index)=> {
                arrs = arrs + item + ',';
            });
            $.ajax({
                url: "/traffresult/sendDevices",
                dataType: "json",
                type: "POST",
                contentType: 'application/json',
                data: JSON.stringify(vue_ts.data_table_ts),
                success: function (result) {
                    if (result.length > 0) {
                        result.forEach((item, index)=> {
                            vue_ts.data_table_ts.forEach((items, indexs)=> {
                                if (item.data == items.xh) {
                                    items.pushdesc = item.msg;
                                    if(item.status==200){
                                        items.pushstatus = 0;
                                    }else{
                                        items.pushstatus = 1;
                                    }
                                }
                            });
                        });

                    }
                }
            });
        },
        //单个推送
        ts_s: function () {

        },
    }
});

$('#myModal_ts').on('hidden.bs.modal', function () {
    vue_sjcx.query(1,true);
});
