var token = $.cookie("token");
var table=$('#table1');
var action=$('#action').val();//动作
var isPass=$('#isPass').val();//是否审核

//搜索
$('.searchGo').click(function(){
	action=$('#action').val();
	isPass=$('#isPass').val();
	initTable(action,isPass);
})

initTable(action,isPass);
function initTable(action,isPass) {
	//先销毁表格
	table.bootstrapTable('destroy');
	//初始化表格,动态从服务器加载数据
	table.bootstrapTable({
		method: "get", //使用get请求到服务器获取数据
		url: huayi.config.callcenter_url+"Knowledge/GetAuditList", //获取数据的Servlet地址
		contentType: "application/x-www-form-urlencoded",striped: true, //表格显示条纹
		pagination: true, //启动分页
		pageSize:10, //每页显示的记录数
		pageNumber: 1, //当前第几页
		pageList: [10, 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: $.cookie("token"),
				action:action,
				ispass:isPass
			
			};
			return param;
		},
		onLoadSuccess: function() { //加载成功时执行
			//layer.msg("加载成功");
		},
		onLoadError: function() { //加载失败时执行
			//layer.msg("加载数据失败", { time: 1500, icon: 2 });
		}
	});
}
function setCode(val, row, index) {
	return index + 1;
}
function oper(val,row) {
    if (val) {
        var con = helper.filter.Transcoding(val);
        return '<div pre=\'' + encodeURIComponent(row.F_PreDescription) + '\' aft=\'' + encodeURIComponent(row.F_AfterDescription) +'\' onclick="seeConDetail(this)"> '+ con.substr(0, 20) + "..."; +'</div>'
        
    }
    else {
        return '<div pre=\'' + encodeURIComponent(row.F_PreDescription) + '\' aft=\'' + encodeURIComponent(row.F_AfterDescription) +'\' onclick="seeConDetail(this)"></div>';
    }
}

function shaction(val) {
    if (val == 1) {
        return '<div class="imgs">添加</div>';
    } else if (val == 2) {
        return '<div class="imgs">修改</div>';
    }
    else if (val == 3) {
        return '<div class="imgs">删除</div>';
    }
}

function shstates(val) {
    if (val == 0) {
        return '<div class="imgs">未审核</div>';
    } else if (val == 1) {
        return '<div class="imgs">通过审核</div>';
    }
    else if (val == -1) {
        return '<div class="imgs">未通过审核</div>';
    }
}

function caoZuo(val, row) {
    if (row.F_ISPass == 0)
        return '<div><button class="btns"  onclick="shenHe(1,' + row.F_AuditId + ')">审核通过</button><button class="btns"  onclick="shenHe(-1,' + row.F_AuditId + ')">审核不通过</button>  </div>'
    else
        return "";
}

$('.pass').click(function(){
	check(1)
})
$('.noPass').click(function(){
	check(-1)
})

function check(state){
	     var did = $.map($('#table1').bootstrapTable('getSelections'), function (row) {
        return row.F_AuditId;
    });
    if (did.length <= 0) {
        layer.confirm('请选择一项内容！', {
            btn: ['确定']
        });
        return;
    } else {
        shenHe(state,did)
    }   
}
var strs='<textarea class="detail" rows="5"  placeholder="请输入审核详情......"></textarea>'
function shenHe(state, did) {
    var lay = layer.open({
        title: '审核详情'
        , content: strs,
        area: ['60%', '80%'], //宽高
        yes: function () {
            $.ajax({
                type: "post",
                url: huayi.config.callcenter_url + "Knowledge/AuditR",
                async: true,
                dataType: 'json',
                data: {
                    ids: did,
                    auditremark: $('.detail').val(),
                    ispass: state,
                    token: $.cookie("token")
                },
                success: function (data) {
                    if (data.state.toLowerCase() == 'success') {
                        layer.msg(data.message);
                        initTable(action, isPass);
                    }
                }
            });
        }
    });
}

function seeConDetail(obj) {
    $("#pre").val($(obj).attr("pre"));
    $("#aft").val($(obj).attr("aft"));
    layer.open({
        type: 2,
        content: "conDetail.html", //iframe的url，no代表不显示滚动条
        title: '查看内容详情',
        area: ['60%', '70%'], //宽高
    });
}