<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <title>{$title}</title>
    <meta name="keywords" content="{$keywords}" />
    <meta name="description" content="{$description}" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no">
    <meta name="apple-mobile-web-app-title" content="{$site_name}" />
    <meta name="generator" content="fireshop {$version}" />
    <meta name="author" content="fireshop team" />
    <meta name="copyright" content="2019-2039 FireShop Inc." />
    <!--#include file="include.css.html"-->
    <link rel="stylesheet" href="../css/om.groupbuy.css?v={$version_sn}" />
</head>
<body>
<!--#include file="include.header.html"-->
<section class="mbody">
    <div class="om-groupbuy-detail clearfix">
        <div class="groupbuy-goods clearfix">
            <div class="thumb" name="goods"><a href="{$data:goods_link}"><img src="{$data:thumbnail}" alt="{$data:title}" title="{$data:title}" /></a></div>
            <div class="info">
                <h3 class="title"><a href="{$data:goods_link}">{$data:title}</a></h3>
                {if:OW.isNotNul("{$data:subtitle}")}<p class="subtitle">{$data:subtitle}</p>{/if}
                <div class="price"><i class="icon-text icon-text-seckill">拼团价</i><span class="money"><em>{$moneysb}</em><b>{$data:groupbuy_price}</b></span><span class="money groupbuy-price"><em>{$moneysb}</em><b>{$data:price}</b></span></div>
                {if:OW.parseMoney("{$data:groupbuy_price}")>OW.parseMoney("{$data:groupbuy_myprice}")}
                <div class="price"><i class="icon-text icon-text-seckill">我的会员拼团价</i><span class="money"><em>{$moneysb}</em><b>{$data:groupbuy_myprice}</b></span></div>
                {/if}
            </div>
        </div>
        <div class="groupbuy-invite clearfix">
            {$data:groupbuy_invite_html}
        </div>
        <div class="groupbuy-explain clearfix">
            <span class="hd">拼团规则</span>
            <span class="bd">好友拼团 人满发货 不满退款</span>
        </div>
        <div class="ow-groupbuy-invite" id="ow_groupbuy_invite" style="display:none;">
            <div class="ow-groupbuy-invite-in">
                <div class="close"><a href="javascript:;">关闭</a></div>
                <div class="top">点击右上角发送给好友或分享到朋友圈</div>
                <div class="hd">或者复制以下内容分享给微信好友：</div>
                <div class="bd"><textarea id="groupbuy_invite_text">【仅差{$data:remainder}人】{$data:title} 每件仅需{$data:groupbuy_price}元，{$data:groupbuy_num}人成团。<%=OW.currentURL()%></textarea></div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
$(document).ready(function(){
	$("a[name='btn_groupbuy_invite']").click(function(){
		$("#ow_groupbuy_invite").show(100);
		return false;
	});
	//立即参团
	$("a[name='btn_groupbuy_now']").click(function(){
		var gid   = "{$data:gid}",
		pid       = "{$data:pid}",
		amount    = 1,
		isMulSkus = <%=lcase(OS.SHOP.isMulSkus("{$data:gid}"))%>,
		gbid      = $(this).attr("gbid");
		groupBuy(gid,pid,isMulSkus,amount,gbid);
	});
	//参团
	var groupBuy = function(gid,pid,isMulSkus,amount,gbid){
		if(isMulSkus){
			var $dialog = OWDialog({close:false}).loading();
			OW.ajax({
				url:OW.sitePath +"ow-includes/ow.ajax.shop.asp?ctl=goods&act=get_goods_sku&gid="+gid,data:"",
				success:function(){
					$dialog.close();
					OW.shop.productsData = OW.ajaxData.products_data;
					goodsSpecDisplay({gbid:gbid,gid:gid,thumbnail:OW.ajaxData.thumbnail,data:OW.ajaxData.spec_data});
				},
				failed:function(msg){
					$dialog.error('获取商品SKU出错，请查看以下信息：',msg).position().timeout(3);
				}
			});
		}else{
			OW.shop.cartOrderSubmit({is_groupbuy:'1',gbid:gbid,data:'[{"suit_id":"0","gid":"'+gid+'","pid":"'+pid+'","m":"'+amount+'"}]'});
		};
	};
	//获取商品规格信息
	var goodsSpecDisplay = function(opt){
		var gbid  = opt.gbid,
		gid       = opt.gid,
		thumbnail = opt.thumbnail,
		specHtml  = OW.shop.getSpecHtml(opt.data);
		OW.shop.specCount = opt.data.length;
		OW.shop.dialog = OWDialog({
			content:'<div class="ow-goods-spec"><div class="hd"><div class="goods-view"><div class="thumb"><img id="ow_sku_thumb" src="'+thumbnail+'" /></div><div class="info"><div class="price"><span class="money"><em>{$moneysb}</em><b id="sku_price"></b></span></div><div class="stock"><span class="stock">库存<b id="sku_stock"></b></span></div></div></div></div><div class="bd" id="ow_goods_sku"></div></div>',
			id:"d_goods_sku",title:false,padding:"0px",initialize:function(){$("#ow_goods_sku").html(specHtml);},cancel:false,okValue:'确定',
			ok:function(){
				if(OW.shop.pid==0){
					alert("请选择规格！");
					return false;
				}else{
					if(OW.shop.productStock==0){
						alert("库存不足！");
						return false;
					}else{
						OW.shop.cartOrderSubmit({is_groupbuy:'1',gbid:gbid,data:'[{"suit_id":"0","gid":"'+gid+'","pid":"'+OW.shop.pid+'","m":"1"}]'});
					};
				};
			}
		});
		OW.shop.dialog.footerFix({height:"70%"});
		OW.shop.pid = 0;
		OW.shop.thumbImg       = $("#ow_sku_thumb");
		OW.shop.specSection    = $("#ow_goods_sku");
		OW.shop.myPriceSection = $("#sku_price");
		OW.shop.stockSection   = $("#sku_stock");
		var $spec = OW.shop.specSection;
		$spec.find("a").click(function(){
			OW.shop.pid = 0;
			if($(this).parent().attr("disabled")=="true"){ return false; };
			var i,valid  = false,
			specId       = $(this).attr("spec_id"),
			valueId      = $(this).attr("value_id"),
			valueImage   = $(this).attr("value_image"),
			$specDisplay = $("div[name='selected_spec_display']"),
			$specValue   = $specDisplay.find("[name='selected_spec_value']"),
			$json        = OW.shop.productsData;
			$(this).parent().parent().find("li").removeClass("current").attr("selected",false);
			$(this).parent().addClass("current").attr("selected",true);
			$spec.find("dl[spec_id!='"+specId+"']").find("li").removeClass("disabled").attr("disabled",false);
			if(OW.isNotNull(valueImage)){OW.shop.thumbImg.attr("src",valueImage);};
			var valueIds = OW.shop.getSelectValueId();
			if(valueIds.split(",").length==OW.shop.specCount){
				//检查库存是否充足
				OW.shop.productStock = 0;
				for(i=0;i<$json.length;i++){
					if(valueIds==$json[i].spec_value_id){
						valid = true;
						OW.shop.pid          = $json[i].pid;
						OW.shop.productSn    = $json[i].product_sn; 
						OW.shop.productStock = $json[i].stock;
						OW.shop.myPriceSection.html(OW.parsePrice($json[i].my_activity_price));
						break;
					};
				};
				if(OW.shop.productStock>0){
					OW.shop.stockSection.html(OW.shop.productStock);
				}else{
					OW.shop.stockSection.html(OW.shop.productStock);
					$(this).parent().removeClass("current").attr("selected",false).addClass("disabled").attr("disabled",true);
				};
			};
		});
		OW.shop.goodsSpecValueClick($spec);
	};
});
</script>
<% if OS.isWeixinShare then %>
<%=OS.getWXShareTicket%>
<script type="text/javascript">
wx.config({
    debug:false,appId:'<%=OS.wxShareAppid%>',timestamp:'<%=OS.wxShareTimestamp%>',nonceStr:'<%=OS.wxShareNonceStr%>',signature:'<%=OS.wxShareSignature%>',
    jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareQZone']
});
wx.ready(function(){
	var wxTitle = "【仅剩{$data:remainder}个名额】我{$data:groupbuy_price}元拼了{$data:title}",
	wxDesc      = "我买了{$data:title}，每件仅需{$data:groupbuy_price}元，{$data:groupbuy_num}人成团。"
	wxLink      = OW.currentURL(),
	wxImgUrl    = '<%=OW.validImageUrl("{$goods:thumbnail}")%>';
	wx.onMenuShareTimeline({title:wxTitle,link:wxLink,imgUrl:wxImgUrl});
	wx.onMenuShareAppMessage({title:wxTitle,desc:wxDesc,link:wxLink,imgUrl:wxImgUrl});
	wx.onMenuShareQQ({title:wxTitle,desc:wxDesc,link:wxLink,imgUrl:wxImgUrl});
	wx.onMenuShareQZone({title:wxTitle,desc:wxDesc,link:wxLink,imgUrl:wxImgUrl});
});
</script>
<% end if %>
<!--#include file="include.footer.html"-->
</body>
</html>
