mui.init({})
var UserCode = helper.cookies.get("usercode");
var id = helper.request.queryString("id");
var itype = helper.request.queryString("itype");
var areaID = helper.request.queryString("areaID");
var openid = helper.cookies.get("openid");
//var openid = "oXF5e1mWpX5DajW5_yjNLPKb8ThE";
//alert(id);
$(function() {
	//	接收人员
	$('#order_recive').on('tap', function() {
		//alert("ddd");
		getReceiveUser();
		$("#order_recive option").remove();
	});
	//返回列表
	$('.return').on('tap', function() {
//		if (itype==0) {
//			window.location.href = "client_index.html"
//		}if (itype==1) {
//			window.location.href = "client_index.html"
//		} else if (itype==2){
//			window.location.href = "pend_index.html"
//		} else if (itype==3){
//			window.location.href = "finsh_index.html"
//		}
		window.location.href = "details.html?id=" + id + '&itype=' + itype;

	});
	$(".order_unit").on("click",function(){
      	var ichk=$("input:checkbox:checked").map(function(){
         return $(this).val();
      	}).get().join(",");
      	$("#zerenSel").val(ichk);
	})
	//提交按钮
	$('#submit').on('tap', function() {
		if($('#recive_type').attr('data-index')== '') {
			mui.alert('请选择部门！') //请输入工单类型
		} else if($('#ower_recive').attr('data-index')== '') {
			mui.alert('请选择接收人！') //请输入工单类型
		} else if($('#order_reception').val() == '') {
			mui.alert('请输入转派理由！') //填写详细描述
		} else {
			$.ajax({
				type: "post",
				dataType: 'json',
				url: huayi.config.callcenter_url + 'WxLogin/AssignWorkOrder',
				async: true,
				data: {
					orderid: id, //否	strubg	工单编号
					OpenId: openid, //微信openid,
					isend: 0, //否	int	你看一下前端是什么参数
					clbm: $('#recive_type').attr('data-index'), //是	int	部门Id
					clid: $("#ower_recive").attr('data-index'), //否	int	接收人用户id
					cont: $("#order_reception").text(), //否	int	指派说明
					overtime:$("#order_Claimnumber").val(), //超时时限
					sms:$('.order_type').find('input[type="radio"]:checked').val(), //是否短信提醒
					isApprovalp:$('.order_rise').find('input[type="radio"]:checked').val(), //高层审批
					hclid:$("#ower_highse").attr('data-index'),
//				投诉类市场管理科
//                  QualityMonth:$("#order_time").val(), //质保期限
                    PreliminaryOpinion: $('#ower_relationship').attr('data-index'), //初审意见
//              投诉类市场管理科   
					isvisit:$('.order_pay').find('input[type="radio"]:checked').val(), //是否回访
					QualityEventLevel: $('#ower_event').attr('data-index'), //事件等级
					ClaimAmount: $('#order_money').attr('data-index'), //索赔金额
					ResponsibleUnit:$("#zerenSel").val(), //责任单位
					ApprovalOpinions: $('.order_opinion').find('input[type="radio"]:checked').val(), //审批意见
					ApprovalDisagree:$("#order_idea").val(), //不同意意见
					CompensationMethod: $('.order_coin').find('input[type="radio"]:checked').val(), //补偿方式
					CompensationMoney:$("#order_make").val(), //补偿钱款
					CResponsibleUnits: $('#ower_ponding').attr('data-index'), //对应责任单位
					Fquantity:$("#order_amount").val(), //实收数量
					ImprovementRequirements:$("#order_demand").val(), //改进要求
					CApprovalNo:$("#order_odd").val(), //审批工作流单号
//			抽检类市场管理科
                    SpotResult: $('#ower_result').attr('data-index'), //抽检结果
					SelfResult:$("#order_spection").val(), //自检结果
					ApprovalNo:$("#order_approve").val(), //对应审批工作流单号
					ReturnAccount:$("#order_sum").val(), //确认返账金额
//			抽检类质量管理部		
                    isvisit: $('.order_return').find('input[type="radio"]:checked').val(), //是否否回访
					IsRecord: $('.order_records').find('input[type="radio"]:checked').val(), //是否备案
					ClaimAmount:$("#order_claim").val(), //索赔金额
//			销售内勤		
					ReturnAccount:$("#order_account").val(), //确认返账金额
//			质量管理科		
					Fquantity:$("#order_receipts").val(), //确认实收数量
					
					
//					openid: 'oXF5e1mWpX5DajW5_yjNLPKb8ThE', //微信openid 测试用
				},
				success: function(data) {
					debugger
					if(data.state == "success") {
						debugger
						mui.toast('成功');
						
						if (itype==2) {
							window.location.href="haveorder_list.html";	
						} else{
							window.location.href="haveorder_list.html";	
						}
						
					} else {
						mui.toast(data.message);
					}
				}
			});
		}
	})

Ajax() 
//获取详情
function Ajax() {
				$.ajax({
					url: huayi.config.callcenter_url + 'WxLogin/GetDetails',
					data: {
						id: id, //工单编号
						OpenId: openid, //微信openid,
					},
					async: true,
					dataType: 'json',
					type: 'get', //HTTP请求类型
					success: function(data) {
						if(data.state.toLowerCase() == "success") {
							var result = data.rows[0];
							if(result.Source == 0) {
								$("#source").hide();
							} else {
								$("#source").show();
							}
							var itype=result.F_State;
//							alert(itype)
							if(itype == 0) {
								$(".dispose1").show();
								$(".dispose2").show();
							}else if(itype == 1) {
								$(".dispose1").hide();      
							} else if(itype == 2) {
								$(".dispose2").show();
							} else if(itype == 3) {
								$(".dispose3").show();
							}
							
							if (result.GDLXName=="咨询") {
								$(".Work_lastDealDiv").hide(); //受理人
								$("#source").hide(); //投诉
							} else{
								$(".Work_lastDealDiv").show(); //受理人
								$("#source").show(); //投诉
							}
							var builName
							if (result.buildingname==null) {
								builName=""
							} else{
								builName=result.buildingname
							}
							var proName
							
							if (result.proname==null) {
								proName=""
							} else{
								proName=result.proname
							}
							var complain
							if (result.ComplaintDepartment==null) {
								complain=""
							} else{
								complain=result.ComplaintDepartment
							}
							$(".WordID").text(result.ID);
							$("#Work_classname").text(result.F_TypeName); //工单类型
							$("#section").text(result.F_DeptName); //部门
						if($("#section").text()=="市场管理科"){
							  $("#gcsp").show(); 
						}	
						if($("#Work_classname").text()=="抽检"){	
						   if($("#section").text()=="市场管理科"){
							  $("#cccc").show(); 
						   }
						}else if($("#Work_classname").text()=="投诉"){
						   if($("#section").text()=="市场管理科"){
							   $("#aaaa").show();
						   }
						}else if($("#Work_classname").text()=="咨询"){
							   if($("#section").text()=="市场管理科"){
								   $("#aaaa").show();
							   }
						}
						
						if($("#Work_classname").text()=="抽检"){	
						   if($("#section").text()=="质量管理部"){
							  $("#dddd").show(); 
						   }
						}else if($("#Work_classname").text()=="投诉"){
						   if($("#section").text()=="质量管理部"){
							   $("#bbbb").show();
						   }
						}else if($("#Work_classname").text()=="咨询"){
							   if($("#section").text()=="质量管理部"){
								   $("#bbbbb").show();
							   }
						}
						
						if($("#Work_classname").text()=="销售内勤"){	
						   if($("#section").text()=="质量管理部"){
							  $("#eeee").show(); 
						   }
						}
							 
							 
				
				
						}
					},
					error: function(xhr, type, errorThrown) {
						//异常处理；
					}
				})
			}


	//	接收部门
	function getDepts() {}
	var recive = [];
	$.ajax({
		type: "get",
		url: huayi.config.callcenter_url + 'Department/GetDeptList',
		async: false,
		data: {
			
		},
		dataType: 'json',
		success: function(data) {
			console.log(data)
			recive = data.data[0].children;
			//alert(JSON.stringify(data));
		}
	});
	//接收人员
	function getReceiveUser() {
		renyuan = []
		$.ajax({
			url: huayi.config.callcenter_url + 'UserAccount/GetDeptUserList',
			type: 'get',
			data: {
				deptid: $('#recive_type').attr('data-index'),
				proid: areaID,
			},
			dataType: "json",
			async: true,
			success: function(res) {

				if(res.state.toLowerCase() === "success") {
					res = res.data;
					if(res && res.length > -1) {
						res.forEach(function(v, i) {
							var obj = {};
							obj.value = v.F_UserId;
							obj.text = v.F_UserName + v.F_WorkNumber;
							renyuan.push(obj);
							//$('<option value="' + v.F_UserId + '">' + v.F_UserName + '</option>').appendTo('#order_recive');
						});
						cityPicker5.setData(renyuan);
					}
				}
			},
		});
	}
	//初审意见
	var keyList = [];
//	console.log(keyList);
	$.ajax({
		type: "get",
		url: huayi.config.callcenter_url + 'Dictionary/GetDicValueListByFlagWx',
		async: false,
		data: {
			flag: 'SCCS'
		},
		dataType: 'json',
		success: function(data) {
			var key_data = data.data;
//			console.log(data.data);
			$(key_data).each(function(i, n) {
				var obj = {};
				obj.value = n.F_DictionaryValueId;
				obj.text = n.F_Name;
				keyList.push(obj)
			})
		}
	});
 //事件等级
       var  grade = [];
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + 'Dictionary/GetDicValueListByFlagWx',
			async: false,
			data: {
				flag: 'ZLSJDJ'
			},
			dataType: 'json',
			success: function(data) {
				var key_data = data.data;
	//			console.log(key_data);
				$(key_data).each(function(i, n) {
					var obj = {};
					obj.value = n.F_DictionaryValueId;
					obj.text = n.F_Name;
					grade.push(obj)
				})
			}
		});			
//对应责任单位
var  parallelism = [];
	$.ajax({
		type: "get",
		url: huayi.config.callcenter_url + 'Dictionary/GetDicValueListByFlagWx',
		async: false,
		data: {
			flag: 'ZLZRDW'
		},
		dataType: 'json',
		success: function(data) {
			var key_data = data.data;
//			console.log(key_data);
			$(key_data).each(function(i, n) {
				var obj = {};
				obj.value = n.F_DictionaryValueId;
				obj.text = n.F_Name;
				parallelism.push(obj)
			})
		}
	});	
//抽检结果
       var  spot = [];
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + 'Dictionary/GetDicValueListByFlagWx',
			async: false,
			data: {
				flag: 'SCCJJG'
			},
			dataType: 'json',
			success: function(data) {
				var key_data = data.data;
	//			console.log(key_data);
				$(key_data).each(function(i, n) {
					var obj = {};
					obj.value = n.F_DictionaryValueId;
					obj.text = n.F_Name;
					spot.push(obj)
				})
			}
		});				
//高层部门
  var  hirise = [];
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + 'WxLogin/GetHighlevel',
			async: false,
			data: {
				
			},
			dataType: 'json',
			success: function(data) {
				var key_data = data.data.user;
				console.log(key_data);
				$(key_data).each(function(i, n) {
					var obj = {};
					obj.value = n.F_UserId;
					obj.text = n.F_UserName+n.F_WorkNumber;
					hirise.push(obj)
				})
			}
		});				




	
	
 
	(function($, doc) {
		$.init();
		$.ready(function() {
			//接收部门
			var RCiPickers = new $.PopPicker({
				layer: 2
			});
			RCiPickers.setData(recive);
			var RCs = doc.getElementById('showUserPicker1');
			var RCResults = doc.getElementById('recive_type');
			var RCResults2 = doc.getElementById('recive_type1');
			var RCResults3 = doc.getElementById('recive_type2');
			RCs.addEventListener('tap', function(event) {
				RCiPickers.show(function(items) {
					console.log(items)
					if(items[1].text == undefined) {
						RCResults.value = items[0].text;
						RCResults.setAttribute("data-index", items[0].id);
					} else {
						RCResults.value = items[1].text
						RCResults.setAttribute("data-index", items[1].id);
					}
					//RCResults.value =items[0].text + "-" + items[1].text + "-" + items[2].text;
					//RCResults.setAttribute("data-index", items[0].id);
					//RCResults2.setAttribute("data-index", items[1].id);
					//RCResults3.setAttribute("data-index", items[2].id);
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
			}, false);
			//	接收人员
			cityPicker5 = new $.PopPicker();
			var showCityPickerButton5 = doc.getElementById('showCityPicker5');
			var cityResult5 = doc.getElementById('ower_recive');
			showCityPickerButton5.addEventListener('tap', function(event) {
				getReceiveUser();
				cityPicker5.show(function(items) {
					if (items[0].text!=undefined) {
						cityResult5.value = items[0].text;
						cityResult5.setAttribute("data-index", items[0].value);
					}
					
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
			}, false);
     //初审意见
     var cityPicker3 = new $.PopPicker();
			cityPicker3.setData(keyList);
			var showCityPickerButton = doc.getElementById('showCityPicker3');
			var cityResult3 = doc.getElementById('ower_relationship');
			showCityPickerButton.addEventListener('tap', function(event) {
				cityPicker3.show(function(items) {
					cityResult3.value = items[0].text;
					cityResult3.setAttribute("data-index", items[0].text);
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
			}, false);
	//事件等级
       	var affair = new $.PopPicker();
			affair.setData(grade);
			var showCityPickerButton4 = doc.getElementById('eventle');
			var cityResultc4 = doc.getElementById('ower_event');
			showCityPickerButton4.addEventListener('tap', function(event) {
				affair.show(function(items) {
					cityResultc4.value = items[0].text;
					cityResultc4.setAttribute("data-index", items[0].value);
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
		}, false); 
	//对应责任单位
//     	var para = new $.PopPicker();
//			para.setData(parallelism);
//			var showCityPickerButton = doc.getElementById('ponding');
//			var cityResultc2 = doc.getElementById('ower_ponding');
//			showCityPickerButton.addEventListener('tap', function(event) {
//				para.show(function(items) {
//					cityResultc2.value = items[0].text;
//					cityResultc2.setAttribute("data-index", items[0].text);
//					//返回 false 可以阻止选择框的关闭
//					//return false;
//				});
//		}, false); 	
	//事件等级
       	var result = new $.PopPicker();
			result.setData(spot);
			var showCityPickerButton6 = doc.getElementById('result');
			var cityResultc6 = doc.getElementById('ower_result');
			showCityPickerButton6.addEventListener('tap', function(event) {
				result.show(function(items) {
					cityResultc6.value = items[0].text;
					cityResultc6.setAttribute("data-index", items[0].value);
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
		}, false); 	
	//高层
	 	var hir = new $.PopPicker();
			hir.setData(hirise);
			var showCityPickerButton7 = doc.getElementById('showCi');
			var cityResultc7 = doc.getElementById('ower_highse');
			showCityPickerButton7.addEventListener('tap', function(event) {
				hir.show(function(items) {
					cityResultc7.value = items[0].text;
					cityResultc7.setAttribute("data-index", items[0].value);
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
		}, false); 	
	
	
	
	
	
	
	
			
	   })
		
	})(mui, document);

})



$('.order_opinion').find('input[type="radio"]').on('change', function() {
	if($(this).val() == "不同意") { //业务办理
		$('.F_Address').show();
	}else{
		$('.F_Address').hide();
	}
});
$('.order_coin').find('input[type="radio"]').on('change', function() {
	if($(this).val() == "钱款") { //业务办理
		$('.make').show();
	}else{
		$('.make').hide();
	}
});

$('.order_rise').find('input[type="radio"]').on('change', function() {
	if($(this).val() == "1") { //业务办理
		$('#showCi').show();
	}else{
		$('#showCi').hide();
	}
});


