mui.init({})
var UserCode = helper.cookies.get("usercode");
var id = helper.request.queryString("id");
var itype = helper.request.queryString("itype");
var openid = helper.cookies.get("openid");
//alert(id);
//alert(itype);

$(function() {
	//	接收人员
	$('#order_recive').on('tap', function() {
//		alert("ddd");
		getReceiveUser();
		$("#order_recive option").remove();
	});

	//提交按钮
	$('#submit').on('tap', function() {
		if($('#order_type').val() == '') {
			mui.alert('请输入工单类型！') //请输入工单类型
		} else if($('#order_reception').val() == '') {
			mui.alert('请填写详细描述！') //填写详细描述
		} else {
			$.ajax({
				type: "post",
				dataType: 'json',
				url: huayi.config.callcenter_url + '/WxLogin/DealWorkOrder',
				async: true,
				data: {
					orderid: id, //否	strubg	工单编号
					isend: itype, //否	int	你看一下前端是什么参数
					clbm: $("#complaintOrder_type").attr('data-index'), //是	int	部门Id
					clid: $("#order_responsible").attr('data-index'), //否	int	接收人用户id
					cont: $("#order_reception").text(), //否	int	处理内容
					openid: openid, //微信openid 测试用
				},
				success: function(data) {
					if(data.state == "success") {
						debugger
						mui.toast('处理成功');

					} else {

						mui.toast(data.message);
					}
				}
			});
		}
	})
	
	//	接收部门
	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;
			//alert(JSON.stringify(data));
		}
	});
	//接收人员
function getReceiveUser() {
	renyuan=[]
	$.ajax({
		url: huayi.config.callcenter_url + 'UserAccount/GetDeptUserList',
		type: 'get',
		data: {
			deptid: $('#recive_type').attr('data-index'),
		},
		dataType: "json",
		async: true,
		success: function(res) {
			
			if(res.state.toLowerCase() === "success") {
				res = res.data;
				if(res && res.length > 0) {
					res.forEach(function(v, i) {
						var obj = {};
						obj.value = v.F_UserId;
						obj.text = v.F_UserName;
						renyuan.push(obj);
						//$('<option value="' + v.F_UserId + '">' + v.F_UserName + '</option>').appendTo('#order_recive');
					});
					cityPicker5.setData(renyuan);
				}
			}
		},
	});
}
	(function($, doc) {
		$.init();
		$.ready(function() {
			//接收部门
			var RCiPickers = new $.PopPicker({
							layer: 3
			});
			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[2].text==undefined) {
						RCResults.value =items[1].text;
						RCResults.setAttribute("data-index", items[1].id);
					} else if (items[1].text==undefined) {
						RCResults.value = items[0].text;
						RCResults.setAttribute("data-index", items[0].id);
					} else{
						RCResults.value =items[2].text
						RCResults.setAttribute("data-index", items[2].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) {
					cityResult5.value = items[0].text;
					cityResult5.setAttribute("data-index", items[0].value);
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
			}, false);
			
		})
	})(mui, document);

})

