<php>$JSARR[]=THEME_PATH."common/js/jquery.min.js";</php>
<php>$CSSARR[]=THEME_PATH."common/css/common.css";</php>
<php>$CSSARR[]=THEME_PATH."common/css/goods_sevice.css";</php>
<php>$JSARR[]=THEME_PATH."common/js/get_goods_list.js";</php>
<include file="Public/common_header" />
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">var queryurl = APP+"Mobile/Index/get_quan_list";</script>
<script>

	// 领取卡券
	wx.config({
		debug: false,
		appId: '<?php echo $getSignPackage["appId"];?>',
		timestamp: '<?php echo $getSignPackage["timestamp"];?>',
		signature: '<?php echo $getSignPackage["signature"];?>',
		nonceStr: '<?php echo $getSignPackage["nonceStr"];?>',
		jsApiList: [
		  // 所有要调用的 API 都要加到这个列表中
		  'addCard',
		]
	});
	function showind_wx(id){
		var query = new Object();
		query.id = id;
		$.ajax({
			type:'GET',
			url: APP+"Mobile/Index/get_coupons_wx.html",
			data:query,
			success:function(data){
				if(data.status == 0){
					window.location.href = data.url;
				}
				if(data.status == 2){
					$.showSuccess(data.msg,3,'hc');return;
				}
				if(data.wx == 1){
					wx.addCard({
					    cardList: [
					    {
					        cardId : data.cardId,
					        cardExt: '{"timestamp":"'+data.cardExt.timestamp+'","signature":"'+data.cardExt.signature+'","nonce_str":"'+data.cardExt.nonce_str+'"}'
					    }
					    ], // 需要添加的卡券列表
					    success: function (res) {
					        // alert('已添加卡券：' + JSON.stringify(res.errMsg)); // 添加的卡券列表信息
					        if(res.errMsg == 'addCard:ok'){
					        	showind(id)
					        }
					    }
					});
				}else{
					showind(id)
				}
			}
		});	
	}

	function showind(id){
		hidewind();
		var obj = '#sub_'+id;
		if($(obj).hasClass('submitting_'+id)){return;}
		$(obj).addClass('submitting_'+id);
		var num = $(obj).val();
		var query = new Object();
		query.id = id;
		$.ajax({
			type:'GET',
			url: APP+"Mobile/Index/get_coupons.html",
			data:query,
			success:function(data){
				if(data.status == 1){
					$.showSuccess('领取成功',3,'hc');
				}else if(data.status == 0){
					window.location.href = data.url;
				}else if(data.status == 2){
					$.showSuccess(data.msg,3,'hc');
				}
			}
		});		
		$(obj).removeClass('submitting_'+id);
	}
	function xswind(){
		$(".mask").hide();
		$("#weilq").hide();	
	}
	function lqwind(id){
		var query = new Object();
		query.id = id;
		$.ajax({
			type:'GET',
			url: APP+"Mobile/Index/employ.html",
			data:query,
			success:function(data){
				if(data.status == 0){
					a$.showSuccess(data.msg,3,'hc');
				}else if(data.status == 1){
					$('#description').html(data.data.description);
					$('#notice').html(data.data.notice);
					if(data.data.type == 1){
						$('#type').html(data.data.begin_timestamp+'-'+data.data.end_timestamp+'&nbsp;周一至周日');					
					}else{
						$('#type').html("领取后"+data.data.fixed_term+"天后生效,有效期"+data.data.fixed_begin_term+"天");	
					}
					if(data.data.coupons_get == 1){
						$(".wintop").html(
							"<h2>"+data.data.title+"</h2><p>请到店后使用</p><a id='yilq' href='#'>已领取</a>"
						);
					}else{
						$(".wintop").html(
							"<h2>"+data.data.title+"</h2><p>请到店后使用</p><a href='#'><span onClick='showind_wx("+id+")'>立即领取<span/></a>"
						);
					}
					
				$(".mask").show();
				$("#lingqu").show();
				}
			}
		});	
	}
	function hidewind(){
		$(".mask").hide();
		$("#lingqu").hide();	
	}
	function closed(){
		$(".mask").hide();
		$("#lingqu").hide();
		$("#weilq").hide();	
	}



</script>

<div class="page-group">
	<div class="page page-current">
		<header class="bar bar-nav">
			<a class="hc-iconfont f_l" href="javascript:history.back()"></a>
			<h1 class="title">领取卡券</h1>
		</header>
		<div class="content bg_write">
			<section id="lingqu" class="winbox" style="display:block">
				<div class="wintop">
					<h2>{$data['brand_name']}</h2>
					<p>请到店后使用</p>
					<a onClick="showind_wx({$data['id']})" href="#">立即领取</a>
				</div>	
				<p>
					<label>使用提醒 ：</label>
					<span id="notice">{$data['notice']}</span>
				</p>	
				<p>
					<label>使用说明：</label>
					<span id="description">{$data['description']}</span>
				</p>
				<p>
					<label>可用时间：</label>
					<span id="type">{$data['validity']}</span>
				</p>		
			</section>
			<!--遮罩-->
			<div id="areaMasks"></div>
		</div>
	</div>
</div><include file="Public/common_footer"/>
</body>
</html>
