var openid = helper.cookies.get("openid");
var custome = helper.request.queryString("custome");
//alert(openid);
//alert(custome);
mui.plusReady(function() {})
Ajax();
//获取数据
function Ajax() {
	
	$.ajax({
		url: huayi.config.callcenter_url + '/WxLogin/GetProCustomerList',
		data: {
			openid: openid, //微信openid,
			customerid:custome,
		},
		async: true,
		dataType: 'json',
		type: 'get', //HTTP请求类型
		success: function(data) {
			if(data.state.toLowerCase() == "success") {

				if(data.rows && data.rows.length > 0) {
					var arr = [];
					$(data.rows).each(function(i, n) {
						if(n.ParentId == 0) {
							$('<ul class="mui-table-view">'+
							'<li class="mui-table-view-cell mui-table-view-cell-line tit">'+
							'<div class="mui-input-row">'+
							'<label class="label">房源信息：</label>'+
							'<label class="label-1">'+n.areaname+n.ProName+n.buldingname+
							'</label></div></li>'+
							'<li></li><div><ul class="mui-table-view" id="house_' + n.F_CustomerId + '">'+
							'<li class="mui-table-view-cell mui-table-view-cell-line con">'+
							'<div class="mui-input-row"><div class="editfl" data-index="'+n.F_CustomerId+'">'+
							'<div class="editfl_tit">'+
							'<span id="" class="houses_line">'+n.F_CustomerName+
							'</span><span id="">'+n.CustomerTypeName+
							'</span><span class="font-color1">'+n.F_Mobile+
							'</span></div><p>'+n.areaname+n.ProName+n.buldingname+n.F_BusinessLicenseID+
							'</p></div></div></li>'+
							'</ul></div></ul>').appendTo('#userList');
							console.log(n.F_CustomerId);
						} else {
							arr.push(n);
						}
						$.each(arr, function(i, v) {
							if(n.F_CustomerId == v.ParentId) {
								console.log(v);
								if(v) {
									$('<li class="mui-table-view-cell mui-table-view-cell-line con">'+
									'<div class="mui-input-row"><div class="editfl order_detail" data-index="'+v.F_CustomerId+'">'+
									'<div class="editfl_tit">'+
									'<span id="" class="houses_line">'+v.F_CustomerName+
									'</span><span id="">'+v.CustomerTypeName+
									'</span><span class="font-color1">'+v.F_Mobile+
									'</span></div><p>'+n.areaname+n.ProName+n.buldingname+n.F_BusinessLicenseID+
									'</p></div><div class="editfr order_edit" data-index="'+v.F_CustomerId+'">编辑'+
									'</div></div></li>').appendTo('#house_' + n.F_CustomerId);
								}
							} else {
								$('#house_' + n.F_CustomerId).html('暂无信息')
							}
						});
					});
					//添加住户
					$('.order').on('tap', function() {
						
						// + '&itype=' + itype
						window.location.href = "tenant.html?custome="+ custome;
					});
					//查看住户详情
					$('.order_detail').on('tap', function() {
						var user_custome= $(this).attr('data-index');
						//alert(custome);
						// + '&itype=' + itype
						window.location.href = "tenant_details.html?user_custome="+ user_custome+ '&custome=' + custome;
																		
					});
					//修改住户
					$('.order_edit').on('tap', function() {
						var user_custome= $(this).attr('data-index');
						// + '&itype=' + itype
						window.location.href = "tenant_addedit.html?user_custome="+ user_custome+ '&custome=' + custome;
					});
				}
			}
		},
		error: function(xhr, type, errorThrown) {
			//异常处理；

		}
	})
}