$('.header_con .title').html('编辑收货地址');

$('.mui-scroll-wrapper').addClass('scroll_out_t').removeClass('scroll_out');
$('.footer_btn').css('z-index', '10000')

mui.init({
	beforeback: function() { //获得父页面的webview
		//触发父页面的自定义事件(refresh),从而进行刷新

		//返回true,继续页面关闭逻辑
		return true;
	}
});
mui.plusReady(function() {
	window.addEventListener('reload', function(e) { //执行刷新
		location.reload();
	});
	var self = plus.webview.currentWebview();
	var isOrder = self.data_isOrder;
	if (isOrder == true) {
		$('.con').on('tap', '.block', function() {
			var addressId = $(this).attr('data-addressId');
			localStorage.setItem('addressId', addressId);
			var list = plus.webview.currentWebview().opener();
			mui.fire(list, 'setAddress');
			mui.back();
		})
	}
	mui.ajax(qlgUrl('app/useraddress/getList'), {
		data: {},
		dataType: 'json', //服务器返回json格式数据  
		type: 'post', //HTTP请求类型  
		timeout: 10000, //超时时间设置为10秒;  
		success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;  
			var data = toJson(data, 1);
			if (data.status == 1) {
				data = data.data;
				var html = '';
				$.each(data.addressList, function() {
					html += '<div class="block" data-addressId="' + this.addressId + '"><p class="pname">' + this.userName +
						'</p><p class="pphone">' + this.userPhone + '</p><p class="paddress">' + this.areaName + ' ' + this.userAddress +
						'</p><hr /><div class="btnout" data-isDefault="' + this.isDefault +
						'"><div class="btn"></div></div><p class="p1">设为默认地址</p><button class="bj">编辑</button><button class="del">删除</button></div>'
				});
				$('.con').html(html)
				$('.btnout').each(function(num) {
					if ($(this).attr('data-isDefault') == 1) {
						$(this).children('.btn').addClass('on')
					}
				})

			} else {
				mui.alert(data.msg)
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理;  
			//					mui.alert(type);      
		}
	});

	$('body').on('tap', '.footer', function() {
		mui.openWindow({
			url: 'editAddress.html',
			id: 'editAddress.html',
			styles: {
				top: '0px', //新页面顶部位置
				bottom: '0px', //新页面底部位置
				width: '100%', //新页面宽度,默认为100%
				height: '100%' //新页面高度,默认为100%
			},
			extras: {

				//						data_href: data_href
				//					..... //自定义扩展参数,可以用来处理页面间传值
			},
			createNew: false, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
			show: {
				//					autoShow: true, //页面loaded事件发生后自动显示,默认为true
				//					aniShow: animationType, //页面显示动画,默认为”slide-in-right“;
				//					duration: animationTime, //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒;
				//					event: 'titleUpdate', //页面显示时机,默认为titleUpdate事件时显示
				//					extras: {} //窗口动画是否使用图片加速
			},
			waiting: {
				autoShow: true, //自动显示等待框,默认为true
				title: '正在加载...', //等待对话框上显示的提示内容
				options: {
					//						width: waiting - dialog - widht, //等待框背景区域宽度,默认根据内容自动计算合适宽度
					//						height: waiting - dialog - height, //等待框背景区域高度,默认根据内容自动计算合适高度
					//						......
				}
			}
		})
	})

	$('.con').on('tap', '.bj', function(e) {
		e.stopPropagation();
		var data_addressId = $(this).parent().attr('data-addressId');
		mui.openWindow({
			url: 'editAddress.html',
			id: 'editAddress.html',
			styles: {
				top: '0px', //新页面顶部位置
				bottom: '0px', //新页面底部位置
				width: '100%', //新页面宽度,默认为100%
				height: '100%' //新页面高度,默认为100%
			},
			extras: {
				data_addressId: data_addressId
				//						data_href: data_href
				//					..... //自定义扩展参数,可以用来处理页面间传值
			},
			createNew: false, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
			show: {
				//					autoShow: true, //页面loaded事件发生后自动显示,默认为true
				//					aniShow: animationType, //页面显示动画,默认为”slide-in-right“;
				//					duration: animationTime, //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒;
				//					event: 'titleUpdate', //页面显示时机,默认为titleUpdate事件时显示
				//					extras: {} //窗口动画是否使用图片加速
			},
			waiting: {
				autoShow: true, //自动显示等待框,默认为true
				title: '正在加载...', //等待对话框上显示的提示内容
				options: {
					//						width: waiting - dialog - widht, //等待框背景区域宽度,默认根据内容自动计算合适宽度
					//						height: waiting - dialog - height, //等待框背景区域高度,默认根据内容自动计算合适高度
					//						......
				}
			}
		})
	})
	$('.con').on('tap', '.del', function() {
		var data_addressId = $(this).parent().attr('data-addressId');
		if (confirm('确认删除地址?')) {
			mui.ajax(hyhUrl('app/Useraddress/del'), {
				data: {
					id: data_addressId
				},
				dataType: 'json', //服务器返回json格式数据  
				type: 'post', //HTTP请求类型  
				timeout: 10000, //超时时间设置为10秒;  
				success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;  
					var data = toJson(data, 1);
					if (data.status == 1) {
						location.reload()

					} else {
						mui.alert(data.msg)
					}
				},
				error: function(xhr, type, errorThrown) { //异常处理;  
					//					mui.alert(type);      
				}
			});
		}

	})
	$('.con').on('tap', '.btnout', function() {
		$('.btnout').children('.btn').removeClass('on');
		$(this).children('.btn').addClass('on');
		var addressId = $(this).parent().attr('data-addressId')
		mui.ajax(hyhUrl('app/Useraddress/setDefault'), {
			data: {
				id: addressId
			},
			dataType: 'json', //服务器返回json格式数据  
			type: 'post', //HTTP请求类型  
			timeout: 10000, //超时时间设置为10秒;  
			success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;  
				var data = toJson(data, 1);
				if (data.status == 1) {
					location.reload()

				} else {
					mui.alert(data.msg)
				}
			},
			error: function(xhr, type, errorThrown) { //异常处理;  
				//					mui.alert(type);      
			}
		});
	})
})