<?xml version="1.0"?>
<labeltemplate>
  
    <cartbox type="3g">
   <![CDATA[
	 <form name="buyform" id="buyform" action="shoppingcart.aspx" method="post">
		   [!--showlimitbuy--]
		   [!--showjsstr--]
			<div class="carbox" id="carbox">
			[!--showattrstr--]
			<script>
			 var maxordernum='[!--maxordernum--]';
			 $(document).ready(function(){
			   if (maxordernum=='1'){
			     $("#setbuynum").hide();
			   }
			   if ("{KS:Field:IsLimitBuy}" != "0" || ("{KS:Field:IsBookCode}" == "1" && "{KS:Field:BookCodeTypeID}" != "0") || "{KS:Field:LimitCityNum}" != "0"){
			     $("#carbtn").hide();
			   }
			 });
			</script>
			<div id='setbuynum'>
				<input type='hidden' name='maxordernum' id='maxordernum' value='[!--maxordernum--]'/>
				我要买：<a href='javascript:shop.buynum(0)'><img border='0' src='{M:HomeDir}images/ico_close.gif'/></a> 
				<input type="text" onkeyup="this.value=this.value.replace(/\D/,'');" name="Q_{KS:Field:InfoID}" id="num" size="4" value="1" style="text-align:center"> 
				<a href='javascript:shop.buynum(1)'><img src='{M:HomeDir}images/ico_open.gif' border='0'/></a> {KS:Field:Unit}
				<label class="showstock">(库存<label id='stock' class='stock'><script src='{M:HomeDir}Shop/getstock.aspx?id={KS:Field:InfoID}'></script></label>
				<font id='unit'>{KS:Field:Unit}</font>)</label>
			</div>
			<div id="buyselect"></div>
			<div>
			 <input type='hidden' name='ID' id='ID' value='{KS:Field:InfoID}'>
			 <input type="button" value="立即购买" onclick="shop.gobuy([!--alen--])" id="buybtn">
			 <input type="button" value="加入购物车" id="carbtn" onclick="shop.addCart(event,{KS:Field:InfoID},[!--alen--],{KS:Field:ChannelID})">
			</div>
		</form>
   ]]>
  </cartbox>


  <wholesale>
   <head>
    <![CDATA[
	<style type="text/css">
        table.gridtable {
	        font-family: verdana,arial,sans-serif;
	        font-size:14px;
	        color:#333333;
	        border-width: 1px;
	        border-color: #ccc;
	        border-collapse: collapse;
        }
        table.gridtable tr.CTitle td{
	        border-width: 1px;
	        padding: 2px;
	        border-style: solid;
	        border-color: #ccc;
            height:22px;
			text-align:center;
			background:#f1f1f1;
        }
        table.gridtable td {
	        border-width: 1px;
	        padding: 8px;
	        border-style: solid;
	        border-color: #ccc;
	        background-color: #ffffff;
			text-align:center;
        }
		 table.gridtable td span{
		 cursor:pointer;
		 }
		.gwxgjh{ padding:1px 7px; background: #C00; color:#FFF}
		.gwxgjh a:hover{ color:#FFF}
		.gwxgjh a{ color:#FFF}
		.buyNum{ border:1px solid #C00; height:20px; text-align:center; line-height:18px;}
		.hasTotalPrice{ color:#C00; font-size:20px; font-weight:bold}
    #hasSelectNum{ color:#C00; font-size:20px; font-weight:bold}
		#buybutton{cursor:pointer;width:140px;height:40px;background:url(/Home/Shop/images/buy_button.png) no-repeat;border:0px}
     #cartbutton{cursor:pointer;width:142px;height:40px;background:url(/Home/Shop/images/buy_button.png) no-repeat -140px;border:0px}

        </style>
	<div class="carbox" id="carbox">
	 <form name="buyform" id="buyform" action="/Home/index.aspx?app=shoppingcart" method="post">
         <input type="hidden" name="id" value="{KS:Field:InfoID}" />
	   <div>批量订购</div>
      <table class="gridtable" id="specialtable" border='1' cellspacing='1' cellpadding='1' width="99%">
	    <tr class="CTitle">
		  [!--property--]
		  <td nowrap>货号</td>
	      <td  width='100' nowrap>市场价</td>
          <td  width='100' nowrap>销售价</td>
		  <td  width='100' nowrap>库存</td>
		  <td  width='100' nowrap>重量</td>
		  <td  width='100' nowrap>购买</td>
	　　</tr>
	     [!--looplist--]
	  </table>
	  
	 <div style="height:35px;line-height:35px;border:1px solid #f1f1f1;">
	 已选 <font id="hasSelectNum">0</font> {KS:Field:Unit}&nbsp;&nbsp;共计 <font class="hasTotalPrice">{$GetCurrencySymbol}<font id="hasTotalPrice">0.00</font></font> {$GetCurrencyUnit}
	 </div>
	 <div style="text-align:center;height:50px;line-height:50px">
	  <input type="submit" value=""  id="buybutton" onclick="return(checkWholesale());">
	  <input type="button" value="" id="cartbutton" onclick="return(addWholeCart({KS:Field:ChannelID},{KS:Field:InfoID}));">
	 </div>
	 </form>
	 
	 <script>
	 var DecimalPlaces={$DecimalPlaces};               //保留小数位数
	 function changeBuyNum(flag,id){
	  var num=parseInt($("#num_"+id).html());
	  var v=parseInt($("#amount_"+id).val());
	  if (flag=='+'){
	   if (v+1>num){
	     KesionJS.Alert('对不起，库存不足！');
	   }else{
	     $("#amount_"+id).val(v+1);
	    }
	  }else{
	   if (v>=0) $("#amount_"+id).val(v-1);
	  }
	  culTotalPrice();
	 }
	 function changeInputNum(id,v){
	  var num=parseInt($("#num_"+id).html());
	  if (v>num){
	     KesionJS.Alert('对不起，库存不足！');
		 $("#amount_"+id).val(num);
	  }
	  culTotalPrice();
	 }
	  var attids='';
	  var attnums='';
	 function culTotalPrice(){
	  var totalNum=0;
	  var totalPrice=0;
	  attids='';
	  attnums=''
	  $("#specialtable .buyNum").each(function(){
	     totalNum+=parseInt($(this).val());
		 var price=parseFloat($("#price_"+$(this).attr("attrid")).html());
		 totalPrice+=price*parseInt($(this).val());
		 if (parseInt($(this).val())>0){
		  	 attids+=(attids!=''?',':'')+$(this).attr("attrid");
		     attnums+=(attids!=''?',':'')+parseInt($(this).val());
		 }
	  });
	  $("#hasSelectNum").html(totalNum);
	  $("#hasTotalPrice").html(totalPrice.toFixed(DecimalPlaces));
	 }
	 function checkWholesale(){
	   var hasNum=parseInt($("#hasSelectNum").html());
	   if (hasNum<=0){
	    KesionJS.Alert('您没有选择要购买的商品!','');
		return false;
	   }
	   return true;
	 }
	 //加入购物车
	 function addWholeCart(m,id){
	  if (checkWholesale()){
	            var top=$('#cartbutton').offset().top - $(document).scrollTop()+28;
				if (top<0) top=28;
				var left=parseInt($('#cartbutton').offset().left);
				if (left+400-parseInt($(document.body).width())>0) left=left-300;
				 var str="<img src='"+appurl+"/Home/Shop/images/suc.gif' align='absmiddle'><span style='font-size:14px;color:#000;'>已成功加入购物车！</span><div id='cartShow' style='width:360px;height:160px;'></div><div class='jrgwc'> <a href=\'"+appurl+"/Home/index.aspx?app=orderinfo\'><img src=\'"+appurl+"/Home/Shop/images/hesuan.gif\'></a> <a href=\'"+appurl+"/Home/index.aspx?app=shoppingcart\'><img src=\'"+appurl+"/Home/Shop/images/chakangouwuche.gif\'></a></form></div>";

			
jQuery.getScript(appurl+'Plus/Ajaxs.ashx?id='+id+'&attrid='+attids+'&m='+m+'&a=addCart&num='+attnums+'&AttributeCart='+escape($("#AttributeCart").val()),function(){
				  if (data.flag=='error'){
						    alert('参数出错啦!');
					}else if (data.flag=='error1'){
						    alert('对不起，您没有登录!');
							showuserlogin();
					   }else{
					    	$.dialog({id:'mycart',title:'购物车内商品',max:false,min:false,content:str,left: left,top: top});
				            $("#cartShow").html(unescape(data.str));
					   }																														                 
				 });
	  }
	  
	 }
	 </script>
	 
	]]>
   </head>
   
   <loop>
    <![CDATA[
	    <tr>
		  [!--property--]
		  <td style="text-align:center" nowrap>{KS:Field:ItemNo}</td>
	      <td style="text-align:center" nowrap>{$GetCurrencySymbol}{KS:Field:Price_Market}</td>
	      <td style="text-align:center" nowrap>
		  {$GetCurrencySymbol}
		  <font id="price_{KS:Field:ID}">{KS:Field:Price}</font>
		  </td>
	      <td style="text-align:center" nowrap><font id="num_{KS:Field:ID}">{KS:Field:Num}</font></td>
	      <td style="text-align:center" nowrap>{KS:Field:Weight} KG</td>
	      <td style="text-align:center" nowrap>
		   <a href="javascript:void(0)"  onclick="changeBuyNum('-',{KS:Field:ID})" target="_self" class="gwxgjh">-</a>
		  <input type='text' class="buyNum" name='amount_{KS:Field:ID}' attrid='{KS:Field:ID}' id='amount_{KS:Field:ID}' value='0' onKeyDown='if(event.keyCode == 13) event.returnValue = false' onchange="changeInputNum('{KS:Field:ID}',this.value)" onkeypress="javascript:return isNumber(event);"/>
		   <a href="javascript:void(0)"  onclick="changeBuyNum('+',{KS:Field:ID})" target="_self" class="gwxgjh">+</a>
      <input type="hidden" name="attrids" value="{KS:Field:ID}"/>  <!--属性ID-->
		   
		  </td>
	　　</tr>
	]]>
   </loop>
</wholesale>

</labeltemplate>