var Arr = [];
var reg = /,$/gi;
GetTypeList();
GetAreaList();
var openid = helper.cookies.get("openid");
var id = helper.request.queryString("id");
console.log(id);
if(id) {

	//获取工单详情
	$.ajax({
		type: "get",
		url: huayi.config.callcenter_url + 'WxLogin/GetWorkOrder',
		async: true,
		data: {
			//			openid: openid,
			openid: 'oKOqcv31fh76rtNmJDjKc39oIsfA', ///测试 ID
			workorderid: id
		},
		success: function(data) {
			var con = JSON.parse(data);
			var Str = con.data.data;
			$("#question").text(Str[0].Detail);
			//图片展示
			var Files = Str[0].File;
			if(Files) {
				var a;
				var b;
				$(Files).each(function(i, n) {
					a = n.F_FileType.split("\/")[0];
					b = n.F_FileName.split(".")[1];
					console.log(a);
					if(a == 'image') {
						$('<div class="img-box"><img src="' + n.F_FileUrl + '" alt="" class="image-item" data-preview-src="" data-preview-group="1" /><span class="">' + b + '</span><div>').appendTo(".space");
					} else {
						$('<div class="img-box "><span class="">' + b + '</span><div>').appendTo(".space");
					}

				})
			}
		}
	});
	$("#submit").on('tap', function() {
		//多选
		$(".Checkbox").each(function(i, n) {
			var check
			var VAl = $('input[name="checkbox"]:checked');
			$(VAl).each(function(i, n) {
				check += $(this).val() + ",";
				var str_ary = check.split("ed")[1];
				Arr = str_ary.replace(reg, "");

			})
			console.log(Arr);

		})
		if(!$("#clcont").val()) {
			mui.toast("请填写处理意见");
		} else {
			$.ajax({
				type: "post",
				url: huayi.config.callcenter_url + 'WxLogin/DealWorkOrder',
				async: false,
				data: {
					//										openid :helper.cookies.get("openid"),
					openid: 'oKOqcv31fh76rtNmJDjKc39oIsfA', ///测试 ID
					orderid: id, ///工单ID
					clcont: $("#clcont").val(), //处理内容
					isaudit: $('input[name="radio1"]:checked').val(), //是否有效
					infotypeid: Arr, //信息分类
					unitid: $('#GetAreaList').val() //交办单位
				},
				dataType: 'json',
				success: function(data) {
					if(data.state = "success") {
						var btnArray = ['确认', '取消'];
						mui.confirm('确认要处理此工单？', '提示', btnArray, function(e) {
							if(e.index == 0) {
								window.location.href = 'WorkCL.html?'
							} else {
								setTimeout(function() {
									$.swipeoutClose(elem);
								}, 0);
							}
						});

					}
				}
			});
		}

	})
}
/// 信息分类
function GetTypeList() {
	$.ajax({
		type: "get",
		url: huayi.config.callcenter_url + 'WxLogin/GetTypeList',
		async: false,
		data: {
			//							openid :helper.cookies.get("openid"),
			openid: 'oKOqcv31fh76rtNmJDjKc39oIsfA' ///测试 ID

		},
		dataType: 'json',
		success: function(data) {
			var type_data = data.data;
			console.log(type_data);
			$('<option value="">请选择</option>').appendTo("#GetTypeList")
			$(type_data).each(function(i, n) {
				$('<li><span class="Span"><input class="Checkbox" name="checkbox" type="checkbox"value=' + n.F_DictionaryValueId + '></span>' + n.F_Name + '</li>').appendTo(".TypeList");
			})
		}
	});
}
//交办单位
function GetAreaList() {
	$.ajax({
		type: "get",
		url: huayi.config.callcenter_url + 'WxLogin/GetAreaList',
		async: false,
		data: {
			//							openid :helper.cookies.get("openid"), 

			openid: 'oKOqcv31fh76rtNmJDjKc39oIsfA' ///测试 ID
		},
		dataType: 'json',
		success: function(data) {
			var type_data = data.data;
			console.log(type_data);
			$('<option value="">请选择</option>').appendTo("#GetAreaList")
			$(type_data).each(function(i, n) {
				$('<option value="' + n.F_DictionaryValueId + '">' + n.F_Name + '</option>').appendTo("#GetAreaList");

			})
		}
	});
}