$(function(){
var table = $('#table1');
var token = $.cookie("token");
laydate.render({
	elem: '#greetingTimes',
	range: '~',
	theme: '#00a1cb',
});
$('.search').on('click',function(){
	initTable(token);
})
//列表
initTable(token);
function initTable(token) {
    //先销毁表格
    table.bootstrapTable('destroy');
    //初始化表格,动态从服务器加载数据
    table.bootstrapTable({
        method: "get", //使用get请求到服务器获取数据
        url: huayi.config.callcenter_url + "NoticeCriticism/GetList", //获取数据的Servlet地址
        contentType: 'application/x-www-form-urlencoded',
        //			url: "kehu.json", //获取数据的Servlet地址
        striped: true, //表格显示条纹
        pagination: true, //启动分页
        pageSize: 10, //每页显示的记录数
        pageNumber: 1, //当前第几页
        pageList: [10, 15, 20, 50, 100], //记录数可选列表
        search: false, //是否启用查询
        showColumns: false, //显示下拉框勾选要显示的列
        showRefresh: false, //显示刷新按钮
        sidePagination: "server", //表示服务端请求
        //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
        //设置为limit可以获取limit, offset, search, sort, order
        queryParamsType: "undefined",
        queryParams: function queryParams(params) { //设置查询参数
            var param = {
                page: params.pageNumber,
                pagesize: params.pageSize,
                token: token,
                startdate:$('#greetingTimes').val() && $('#greetingTimes').val().split(' ~ ')[0],//开始时间
	            enddate:$('#greetingTimes').val() && $('#greetingTimes').val().split(' ~ ')[1],//结束时间
                //logindate: $('.loginTime').val() //登录时间
            };
            return param;
        },
        responseHandler: function (res) {
         return {
             "total": res.total,
             "rows": res.dt   
             };
 
        },
        onLoadSuccess: function () { //加载成功时执行
            //layer.msg("加载成功");
        },
        onLoadError: function () { //加载失败时执行
            //layer.msg("加载数据失败", { time: 1500, icon: 2 });
        }
    });
}
//添加
$('.add').click(function () {
    layer.open({
        type: 2,
        title: '添加通报信息',
        maxmin: true, //开启最大化最小化按钮
        area: ['40%', '40%'],
        content: '../CommonHtml/addNotification.html'
        //content: 'addZhiShiKuManger.html?addId=' + id + '&addPid='+ pid +'&addName='+ name +''
    });
})
//修改
var did;
$('.change').click(function () {
    var ids = $.map(table.bootstrapTable('getSelections'), function (row) {
        return row.F_Id;
    });
    did = ids.toString();
    if (ids.length != 1) {
        layer.confirm('请选择一行进行修改！', {
            btn: ['确定']
        });
        return;
    } else {
        layer.open({
            type: 2,
            title: '修改通报信息',
            maxmin: true, //开启最大化最小化按钮
            area: ['40%', '40%'],
            content: '../CommonHtml/addNotification.html?ids=' + did
        });
    }
})
//删除
var delid;
$('.del').click(function () {
    var ids = $.map(table.bootstrapTable('getSelections'), function (row) {
        return row.F_Id;
    });
    delid = ids;
    if (ids.length <= 0) {
        layer.confirm('请选择要删除的行！', {
            btn: ['确定']
        });
        return;
    } else {
        var laye = layer.confirm('您确定要删除吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function () {
            //按钮【按钮一】的回调
            $.ajax({
                type: "post",
                url: huayi.config.callcenter_url + "NoticeCriticism/DelNotice",
                async: true,
                dataType: "json",
                data: {
                    token: token,
                    ids: delid
                },
                success: function (data) {
                    if (data.state.toLowerCase() == 'success') {
                        layer.msg("删除成功！");
                        table.bootstrapTable('refresh');
                    }
                }
            });
        }, function (index) {
            //按钮【按钮二】的回调
            layer.close(laye)
        });
    }
})
})
function shensu(val,row) {
	console.log(row);
	return '<div><a class="xg" onclick= appeal("' + row.F_WorkOrderId + ','+row.F_Id+'") >申诉</a></div>';
}
//申诉添加
function appeal(str){
	var wid=str.split(',')[0];
	var fid=str.split(',')[1];
	if(wid=='undefined'){
		wid=''
	}
	layer.open({
        type: 2,
        content: "../CommonHtml/addAppealOrder.html?wid=" + wid+"&assessment_list=8&fid="+fid, //iframe的url，no代表不显示滚动条
        title: '申诉添加',
        area: ['40%', '60%'], //宽高
    });
}