mui.init({})
var state=1;
//var Staff=1;
var openid = helper.cookies.get("openid");
var roleCode = helper.cookies.get("RoleCode");
var typeUser = helper.cookies.get("typeUser");
var Itype = helper.request.queryString("Itype");
var turn = helper.request.queryString("turn");
//var turn=1;
//var typeUser=5;
//var openid = "oXF5e1mWpX5DajW5_yjNLPKb8ThE";
$(function () {
	if (turn) {
		$(".mui-nav").show();
		$(".cont-margin").css("margin-top","44px");
		$("#OA_task").css("margin-top","88px");
	}else{
		$("#OA_task").css("margin-top","0px");
		$(".cont-margin").css("margin-top","44px");
	}
	if (Itype=="1") {
		$(".titdyna li").removeClass("tab_color");
		$(".titdyna li:eq(0)").addClass("tab_color");
		state=1;
		Ajax(state);
	}else if(Itype=="2"){
		$(".titdyna li").removeClass("tab_color");
		$(".titdyna li:eq(1)").addClass("tab_color");
		state=2;
		Ajax(state);
	}else if(Itype=="3"){
		state=3;
		$(".titdyna li").removeClass("tab_color");
		$(".titdyna li:eq(2)").addClass("tab_color");
		Ajax(state);
	}else if(Itype=="4"){
		state=4;
		$(".titdyna li").removeClass("tab_color");
		$(".titdyna li:eq(3)").addClass("tab_color");
		Ajax(state);
	}
	if(typeUser==5){
		$(".titdyna").hide();
		$("#OA_task").css("margin-top","45px");
		state="";
		Staff=1;
		Ajax(state);
	}else if(typeUser==1){
		$(".titdyna").show();
		$("#OA_task").css("margin-top","85px");
		state=1;
		Staff="";
		Ajax(state);
	}
})
$(".titdyna ul li").click(function () {
	$(".titdyna li").removeClass("tab_color");
	$(this).addClass("tab_color");
	state=$(this).attr('data-index');
	$.ajax({
		url: huayi.config.callcenter_url + 'WxLogin/GetWoList',
		data: {
			openid: openid, //微信openid,
			states:state,
			//openid: 'oXF5e1mWpX5DajW5_yjNLPKb8ThE',
		},
		async: true,
		dataType: 'json',
		type: 'get', //HTTP请求类型
		success: function(data) {
			$("#OA_task").empty();
			if(data.rows && data.rows.length > 0) {
				$(".noinfor").text("");
				$(data.rows).each(function(i, n) {
					var stateText
					if (n.State==0) {
						stateText="待指派"
					}else if (n.State==1) {
						stateText="待接单"
					}else if(n.State==2){
						stateText="待处理"
					}else if(n.State==3){
						stateText="退回待处理"
					}else if(n.State==4){
						stateText="异常退回待处理"
					}else if(n.State==5){
						stateText="处理中"
					}else if(n.State==10){
						stateText="已完成"
					}
				
					if (n.TypeClassName=="") {
						titleText=n.GDLXName;
					}else{
						titleText=n.TypeClassName;
					}
					$('<li class="mui-table-view-cell order" data-index="' + n.ID + '">' +
						'<div class="mui-table">' +
						'<div class="mui-table-cell mui-col-xs-8">' +
						'<h4 class="mui-ellipsis">' + titleText +
						'</h4><h5>' + n.CreateTime +
						'</h5></div>'+
						'<div class="mui-table-cell mui-col-xs-4 mui-text-right">'+
						'<span class="mui-h5">'+stateText+
						'</span></div></div></li>').appendTo('#OA_task');
				});
				//工单跳转
				$('.order').on('tap', function() {
					
					var index = $(this).attr('data-index');
					window.location.href = "orderDetail.html?id="  + index+'&type='+state;
				});
			} else {
				$(".noinfor").text("暂无信息");
			}
		},
		error: function(xhr, type, errorThrown) {
			//异常处理；
		}
	})
})
function Ajax(state) {
	//$(".order").remove();
	$.ajax({
		url: huayi.config.callcenter_url + 'WxLogin/GetWoList',
		data: {
			openid: openid, //微信openid,
			states:state
			//openid: 'oXF5e1mWpX5DajW5_yjNLPKb8ThE',
		},
		async: true,
		dataType: 'json',
		type: 'get', //HTTP请求类型
		success: function(data) {
			if(data.rows && data.rows.length > 0) {
				$(".noinfor").text("");
				$("#OA_task").empty();
				$(data.rows).each(function(i, n) {
					var stateText;
					var titleText;
					if (n.State==0) {
						stateText="待指派"
					}else if (n.State==1) {
						stateText="待接单"
					}else if(n.State==2){
						stateText="待处理"
					}else if(n.State==3){
						stateText="退回待处理"
					}else if(n.State==4){
						stateText="异常退回待处理"
					}else if(n.State==5){
						stateText="处理中"
					}else if(n.State==10){
						stateText="已完成"
					}
					if (n.TypeClassName=="") {
						titleText=n.GDLXName;
					}else{
						
						titleText=n.TypeClassName;
					}
					$('<li class="mui-table-view-cell order" data-index="' + n.ID + '">' +
						'<div class="mui-table">' +
						'<div class="mui-table-cell mui-col-xs-8">' +
						'<h4 class="mui-ellipsis">' + titleText +
						'</h4><h5>' + n.CreateTime +
						'</h5></div>'+
						'<div class="mui-table-cell mui-col-xs-4 mui-text-right">'+
						'<span class="mui-h5">'+stateText+
						'</span></div></div></li>').appendTo('#OA_task');
				});
				//工单跳转
				$('.order').on('tap', function() {
					var index = $(this).attr('data-index');
					window.location.href = "orderDetail.html?id=" + index+'&type='+state+'&typeStaff='+Staff;
				});
			} else {
				$(".noinfor").text("暂无信息");
			}
		},
		error: function(xhr, type, errorThrown) {
			//异常处理；
		}
	})

}