<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>
<include file="Public/common_header" />
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>

	// 领取卡券
	wx.config({
		debug: true,
		appId: '<?php echo $getSignPackage["appId"];?>',
		timestamp: '<?php echo $getSignPackage["timestamp"];?>',
		nonceStr: '<?php echo $getSignPackage["nonceStr"];?>',
		signature: '<?php echo $getSignPackage["signature"];?>',
		jsApiList: [
		  // 所有要调用的 API 都要加到这个列表中
		  //'hideOptionMenu',
		  'addCard',
		]
	});
	wx.ready(function (res) {
		console.log(res);
	});
	wx.error(function (res) {
		console.log(res);
	});

	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){
				wx.addCard({
				    cardList: [{
				    	cardId: 'pva6lt1ylcbVXJU7Cdd2psj9BEOI',
				    	cardExt: data.cardext
				    }],
				    //接口调用成功的回调函数
				    success: function(res) {
				    	console.log(res); // 卡券添加结果
				    },
				    // 接口调用失败的回调函数
				    fail:function(res){  
			            console.log('submit fail');  
			        }, 
			        // 接口调用结束的回调函数
			        complete:function(res){  
			            console.log('submit complete');
			        }
				})
				return;
				if(data.status == 1){
					$('#get_coupons_'+id).html(
						"<div class='wm_yhq yel'><a href='{:U('collection/get_coupons')}' class='clearfix'><div class='wm_yhq_yel'><p>已领取</p><span>去使用</span></div></div>"
					);
				}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){
					$.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 id='yilq' href='#'><span onClick='showind("+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"></a>
			<a class="hc-iconfont f_r">&#xe60b;</a>
			<h1 class="title">
				<empty name="shop_id">
					卡券中心
				<else />
					{$shop_id|idtoname="Shops"}:线下卡券
				</empty>
			</h1>
		</header>
		<div class="content bg_write">
			<!--领券中心-->
			<div class="wm_merchant_lqlist">
				<volist name="list" id="vo">
					<dl>
						<dt><img src="{$vo.logo_url|thumb=76,78}"></dt>
						<dd>
							<div class="q_price" onClick="lqwind({$vo.id})" id="sub_{$vo.id}">
							<h4 class="color_ff3957 font_wr"><span class="f_20 f_weight mr5"></span>
								<eq name="vo.rank_id" value="GENERAL_COUPON">优惠券</eq>
								<eq name="vo.rank_id" value="DISCOUNT">折扣券</eq>
								<eq name="vo.rank_id" value="GIFT">礼品券</eq>
								<eq name="vo.rank_id" value="CASH">代金券</eq>
								<eq name="vo.rank_id" value="GROUPON">团购券</eq>
							</h4>
							<!-- <h4 class="color_ff3957 font_wr">¥<span class="f_20 f_weight mr5">{$vo.reduce_cost}</span>满{$vo.least_cost}可用
									</h4> -->
								<p class="mercant_introduce">{$vo.notice}</p>
								<if condition="$vo['type'] eq 1">
									<span class="riqi">
										{$vo['begin_timestamp']|time_format='Y-m-d'}~{$vo['end_timestamp']|time_format='Y-m-d'}
									</span>
								<else/>
									<span class="riqi">领取后{$vo.fixed_term}天后生效,有效期{$vo.fixed_begin_term}天</span>
								</if>
							</div>
							<span id="get_coupons_{$vo.id}">
								<if condition="$vo['coupons_get'] eq 0">
									<div class="wm_yhq" onClick="showind({$vo.id})">
										<div class="wm_yhq_red"><span>免费领取</span></div>
									</div>
								<else/>
									<div class="wm_yhq yel">
									<a href="{:U('collection/get_coupons')}" class="clearfix">
										<div class="wm_yhq_yel"><p>已领取</p><span>去使用</span></div>
									</a>
									</div>
								</if>
							</span>
						</dd>
						<!-- </a> -->
					</dl>
				</volist>
			</div>
			<section id="lingqu" class="winbox" >
				<div class="gbwid" onClick="hidewind()">X</div>
				<div class="wintop">
					<h2>必胜客</h2>
					<p>请到店后使用</p>
					<a id="yilq" href="#">已领取</a>
				</div>
				<p>
					<label>使用门店：</label>
					<span>必胜客</span>
				</p>	
				<p>
					<label>使用提醒 ：</label>
					<span id="notice"></span>
				</p>	
				<p>
					<label>使用说明：</label>
					<span id="description"></span>
				</p>
				<p>
					<label>可用时间：</label>
					<span id="type"></span>
				</p>		
			</section>
			<!--遮罩-->
			<div id="areaMasks" class="mask"></div>
		</div>
	</div>
</div><include file="Public/common_footer"/>
</body>
</html>
