var wid = helper.request.queryString("Str");
var $tableLeft = $('#list');
var $tableLeft1 = $('#lists');
$(document).ready(function() {
	List();
	Right();
	//搜索
	$(".searchGo").click(function() {
		List();
	})
	Select();

	//列表
	function Select() {
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + "Questionnaire/GetQCategoryAlllist",
			dataType: 'json',
			async: true,
			data: {
				token: $.cookie("token")
			},
			success: function(data) {
				/*验证请求*/
				if(data.state == "success") {
					for(var i = 0; i < data.data.length; i++) {
						var html = '<option value="' + data.data[i].F_CategoryId + '">' + data.data[i].F_CategoryName + '</option>'
						$(html).appendTo("#Select");
					}
				}
			}
		});
	}
});

function List() {
	//销毁表格
	$tableLeft.bootstrapTable('destroy');
	//			初始化表格,动态从服务器加载数据
	$tableLeft.bootstrapTable({
		method: "get", //使用get请求到服务器获取数据
		url: huayi.config.callcenter_url + "Questionnaire/GetQuestionNotItemsList",
		striped: true, //表格显示条纹
		pagination: true, //启动分页
		pageSize: 5, //每页显示的记录数
		pageNumber: 1, //当前第几页
		pageList: [5, 10, 50, 100], //记录数可选列表
		contentType: 'application/x-www-form-urlencoded',
		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 = {
				PagerId: wid,
				PageIndex: params.pageNumber,
				PageSize: params.pageSize,
				token: $.cookie("token"),
				Key: $("#KeyWords").val(),
				CategoryId: $("#Select").val(),
				SelectType: $("#Quetions").val(),

			};
			return param;
		},
		onLoadSuccess: function() { //加载成功时执行
			//								layer.msg("加载成功");
		},
		onLoadError: function() { //加载失败时执行
			//layer.msg("加载数据失败", { time: 1500, icon: 2 });
		}
	});
}

function Right() {
	$tableLeft1.bootstrapTable('destroy');
	//			初始化表格,动态从服务器加载数据
	$tableLeft1.bootstrapTable({
		method: "get", //使用get请求到服务器获取数据
		url: huayi.config.callcenter_url + "Questionnaire/GetQuestionPageList",
		striped: true, //表格显示条纹
		pagination: true, //启动分页
		pageSize: 5, //每页显示的记录数
		pageNumber: 1, //当前第几页
		pageList: [5, 10, 50, 100], //记录数可选列表
		contentType: 'application/x-www-form-urlencoded',
		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 = {
				PagerId: wid,
				PageIndex: params.pageNumber,
				PageSize: params.pageSize,
				token: $.cookie("token"),

			};
			return param;
		},
		onLoadSuccess: function() { //加载成功时执行
			//								layer.msg("加载成功");
		},
		onLoadError: function() { //加载失败时执行
			//layer.msg("加载数据失败", { time: 1500, icon: 2 });
		}
	});
}
//序号
function setCode(value, row, index) {
	return index + 1;
}
//修改
function Check(value, row, index) {
	return '<a title="点击移入"  class="username">' + value + '</a>'

}

function Content(val) {
	if(val) {
		var str = '<div '
		if(val.length > 10) {
			str = str + ' title="' + val + '" ';
			val = val.substr(0, 10) + "...";
		}
		return str + '>' + val + '</div>';
	} else {
		return '';
	}
}
//分类
function Type(val) {
	var cs = '';
	var vals = '';
	if(val == 1) {
		cs = 'w';
		vals = "问答题"
	} else if(val == 2) {
		cs = 'd';
		vals = "单选题"
	} else {
		cs = 'du'
		vals = "多选题"
	}

	return '<a class="' + cs + '">' + vals + '</a>'
	console.log(val);
}
//左边移动
$("#leftMove").click(function() {
	var ids = $.map($('#list').bootstrapTable('getSelections'),
		function(row) {
			return row.F_QuestionId;
		});
	console.log(ids);
	if(ids.length <= 0) {
		layer.confirm('请选择一项移入！', {
			btn: ['确定']
		});
		return;
	}
	goRight();
})

//                   

function goRight() {

	/*执行删除*/
	var ids = $.map($('#list').bootstrapTable('getSelections'),
		function(row) {
			return row.F_QuestionId;
		});
	$.ajax({
		type: 'POST',
		url: huayi.config.callcenter_url + "Questionnaire/AddPagerItems",
		data: {
			ids: ids,
			pid: wid,
			token: $.cookie("token")
		},
		dataType: 'JSON',
		success: function(data, textStatus, jqXHR) {
			$('#list').bootstrapTable('refresh');
			$('#lists').bootstrapTable('refresh');
		},
		error: function() {
			alert("error");
		}
	});

}
//右边移动
function rightMove() {
	var changes = $.map($('#lists').bootstrapTable('getSelections'), function(row) {
		return row.F_ItemId;

	});
	if(changes.length <= 0) {
		layer.confirm('请选择一项移出！', {
			btn: ['确定']
		});
		return;
	} else {
		goLeft(changes)
	}

}

function goLeft(ids) {
	$.ajax({
		type: 'POST',
		url: huayi.config.callcenter_url + "Questionnaire/DelPagerItems",
		data: {
			ids: ids,
			token: $.cookie("token")
		},
		dataType: 'JSON',
		success: function(data, textStatus, jqXHR) {
			$('#list').bootstrapTable('refresh');
			$('#lists').bootstrapTable('refresh');
		},
		error: function() {
			alert("error");
		}
	});

}