mui.ready(function() {
	var openid = getParam('openid'),shareId =getParam('shareId'),userType = getParam('userType');
	mui.previewImage();
	mui.ajax('/iamberry/wechat/share/toShare', {
		dataType: 'json',
		data: {
			"openid": openid,
			"shareId": shareId
		},
		async: false,
		type: 'post',
		timeout: 15000,
		success: function(dt) {
			//console.log(dt)
			if(dt.status) {
				$('.userName').text(decodeURI(dt.data.shareMember.userNickname));
				$('.user_head').html("<img src=" + dt.data.shareMember.userHead + " />");
				$('.share-time').text(formatDate(dt.data.shareInfo.createDate));
				$('.sharecontent').text(dt.data.shareInfo.shareMessage)
				mui.each(dt.data.shareInfo.shareImgUrl.split('|'), function(index) {
					$('#my-img-view').append('<li class="mui-table-view-cell mui-media mui-col-xs-4"><a><img class="mui-media-object" data-preview-src="" data-preview-group="1" src="/iamberry/common/shop/shareImages/' + this + '"></a></li>')
				})
				console.log(dt.data.isShow)
				if(dt.data.isShow == "true") {
					if(dt.data.hasGet == "true") {
						var btnArray = [' ', '已领取,立即使用'];
					} else {
						var btnArray = [' ', '立即使用'];
					}
					$('.btn_rob_marriott').prop('couponId', dt.couponId);
					mui('body').on('tap', '.btn_rob_marriott', function() {
						mui.ajax('/iamberry/wechat/coupon/getCoupon', {
							dataType: 'json',
							data: {
								"couponId": dt.data.couponId
							},
							async: false,
							type: 'post',
							timeout: 15000,
							success: function(res) {
								if(res.status) {
									$('.btn_rob_marriott').prop('disabled', 'disabled');
								}
								mui.confirm('<strong>¥</strong><span>30元</span>优惠券<img class="x-close" src="http://static.iamberry.com/images/shop/x.png" />', '恭喜您成功领取一张', btnArray, function(e) {
									if(e.index == 1) {
										//console.log("立即使用");
										location.href = "http://" + window.location.host + "/iamberry/wechat/wxCart/goProductList"
									} else {
										//console.log("关闭弹窗");
									}
								});
							},
							error: function(xhr, type, errorThrown) {
								errorfn(xhr);
							}
						});
					});
				} else {
					$('.btn_rob_marriott').text('立即分享');
					mui('body').on('tap', '.btn_rob_marriott', function() {
						mask.show(); //显示遮罩
					});
				}
				//添加分享
				var imgUrl = "http://static.iamberry.com/images/shop/shareImages/" + dt.data.shareInfo.shareImgUrl.split('|')[0];
				var linkUrl = encodeURI("http://" + window.location.host + "/iamberry/wechat/sharePage/toSharePage?shareId=" + shareId + "&openid=" + openid + "&userType=" + userType);
				window.repleFlag = false;
				window.wxFriend = {
					"appId": "",
					"imgUrl": imgUrl,
					"link": linkUrl,
					"desc": dt.data.shareInfo.shareMessage, //描述
					"title": "8秒冲好一瓶奶!", //标题
					"netError": "您的网络异常，请刷新重试!如多次刷新无效，请向我们反应 ~",
					"shareTimeSuccess": "分享成功", //分享朋友圈后回调
					"shareTimeCancel": "已取消分享", //取消分享朋友圈后回调
					"shareAppSuccess": "分享成功", //分享好友后回调
					"shareAppCancel": "已取消分享" //取消分享好友后回调
				};
				getConfig();
				document.querySelector('.loading-bg').style.display = 'none';
			}
		},
		error: function(xhr, type, errorThrown) {
			errorfn(xhr);
		}
	});

	mui('body').on('tap', '.x-close', function() {
		mui.closePopup();
	});
});
var mask = mui.createMask(function() {}); //callback