<?php
	session_start();
	require_once("../Wx.Config.php");	//只加载一次

	ini_set('session.gc_maxlifetime', 99999999); //设置时间 永不过期
	
	$_SESSION["main_defPageIndex"]='index2.php';
	//得到部门流水号
	$strselDListNo=trim($_REQUEST['dlistno']);
	if(strlen($strselDListNo)>0)
	{
		$_SESSION["main_posChainDListNo"]=$strselDListNo;
	}
	else
	{
		$strselDListNo=trim($_SESSION["main_posChainDListNo"]);
	}
	if(strlen($strselDListNo)<1)
	{
		$strselDListNo='0';
	}
	if($strselDListNo=='0')
	{
		//进入选择部门的页面
		header('Location: indexSelD.php');
	}
		
	//得到项目类型流水号
	$strTypeListNo=trim($_REQUEST['tlistno']);
	if(strlen($strTypeListNo)<1)
	{
		$strTypeListNo='0';
	}
	
	//得到购物车号
	$strdefcartid=trim($_REQUEST['cartid']);
	if(strlen($strdefcartid)>16)
	{
		$_SESSION["main_defcarttempid"] = $strdefcartid;
	}
	$strdefcartid = trim($_SESSION["main_defcarttempid"]);
	if(strlen($strdefcartid) < 16)
	{
		header('Location: loadpage.php');
	}
	
	//加载系统参数信息
	require_once("db/db.php");	
	require_once("common/common.php");
	
	//得到当前部门名称
	$strDepartName='';
	$intWXIngegPayFlag=0;
	$strSubChain_No='';
	
	$sql = sprintf("SELECT DepartName,wxintegprice,Chain_No FROM TCP_Depart_Inform Where ListNo=%s",$strselDListNo);
	$result = querySql($sql);
	
	if($row = fetch_array($result))
	{
		$strDepartName = $row['DepartName'];
		$intWXIngegPayFlag = $row['wxintegprice'];
		$strSubChain_No = trim($row['Chain_No']);
	}
	freeResult($result);	//释放数据库
	
	
	//判断当前是否是允许点单的 
	$strStopWeiXinOrderFlag='0';
	$sql = sprintf("SELECT Item_Value FROM TR_Config WHERE Chain_No='%s' And Item_Name='TCP:微信点单当前是否停用'",$strSubChain_No);
	
	$result = querySql($sql);
	if($row = fetch_array($result))
	{
		$strStopWeiXinOrderFlag = trim($row['Item_Value']);
	}
	freeResult($result);	//释放数据库
	if($strStopWeiXinOrderFlag=='1')
	{
		//当前不允许点单
		header('Location: nocanorder.php');
	}
	
	
?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="gb2312">	
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
	<meta name="apple-mobile-web-app-capable" content="1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=0">
	<meta name="apple-touch-fullscreen" content="1">

	<title>微信点单</title>
	
	<link rel="stylesheet" href="css/mycss.css"> 
	<script src="jsp4/jquery.js"></script>
	<!--<link rel="stylesheet" href="jsp5/jquery.mobile-1.4.5.min.css">-->
	<!--<script src="jsp4/jquery.mobile-1.4.3.min.js"></script>-->
	<script src="jsp5/jquery.mobile-1.4.5.min.js"></script>
	<link rel="stylesheet" href="jsp5/jquery.mobile-1.4.5.min.css">
		
	<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	  
    
	<script language="JavaScript"> 
		//不允许进行后退
		javascript:window.history.forward(0); 
	</script>
	
		
</head>

<?php

	
	
	
	$fltintegralcashrate = 0;
	if($intWXIngegPayFlag>0)
	{
		$sql=sprintf("SELECT IntegralCashRate from VIP_Config");
		$result = querySql($sql);
		
		if($row = fetch_array($result))
		{
			$fltintegralcashrate = $row['IntegralCashRate'];
		}
		freeResult($result);	//释放数据库
	}
	
	//得到当前购物车数量
	$strCartCount = '';
	$sql=sprintf("SELECT SUM(Item_Count)AS SumCount FROM WX_Temp_List Where CartTempID='%s' And DListNo=%s",$strdefcartid,$strselDListNo);
	$result = querySql($sql);
	if($row = fetch_array($result))
	{
		$strCartCount  = $row['SumCount'];
	}
	freeResult($result);	//释放数据库
	
	$intNumLeft = 4;
	if($strCartCount=='')
	{
		$strCartImg='images/cart1.png';
	}
	else
	{
		$strCartImg='images/cart2.png';

		
		if($strCartCount>9)
		{
			$intNumLeft=0;
		}
	}
	
	//得到已点数量
	if($strCartCount>0)
	{
		$strSubItemNo='';
		$strSubHadCount=0;
		$strSubHadNumBuf='';
		$intSubRowIndex=0;
		
		$sql = sprintf("select Item_No,SUM(Item_Count)AS HadCount from WX_Temp_List WHERE CartTempID='%s' GROUP BY Item_No",$strdefcartid);
		$result = querySql($sql);
	
		while($row = fetch_array($result))
		{
			$strSubItemNo = $row['Item_No'];
			$strSubHadCount = $row['HadCount'];
			
			if($intSubRowIndex>0)
			{
				$strSubHadNumBuf = $strSubHadNumBuf.",{ItemNo:'".$strSubItemNo."',HadCount:'".$strSubHadCount."'}";
			}
			else
			{
				$strSubHadNumBuf = $strSubHadNumBuf."{ItemNo:'".$strSubItemNo."',HadCount:'".$strSubHadCount."'}";
			}
			
			$intSubRowIndex = $intSubRowIndex +1;
		}

		freeResult($result);	//释放数据库
	}
?>

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">		
<!--第一个页面的内容实现---------------------------->
<section data-role="page" id="page1">
	<header data-role="header" data-position="fixed" data-tap-toggle="false" style="border-top-width:0px;border-bottom-width:0px;">
        <table width="100%" height="52" border="0" cellpadding="0" cellspacing="0" bgcolor="<?php echo WxMainConfig::colHeadBkColor;?>">
		   	<tr>
				<td height="52" width="52" align="center">
					<a target="_blank" data-transition="flip" href="index.php?dlistno=<?php echo $strselDListNo;?>">
						<div>
							<img src="images\seld.png" width="21" height="15" border="0" style="margin-top:3px;">
						</div>
					</a>
					
				</td>
				<td height="52" align="center" valign="middle">
	                <span id="MsgTxt" style="color:<?php echo WxMainConfig::colHeadTextColor;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:19px;text-shadow:none;"><?php echo $strDepartName;?></span>
               	</td>
				<td height="52" width="52" valign="middle">
					<div onClick="window.location='cartlist.php';" id="MyCart" width="45" height="45" style="width:45px; height:45px; background-image:url(<?php echo $strCartImg;?>);">
						<div id="MyNumDiv" style="width:30px;height:40px;padding-top:3px;padding-left:<?php echo $intNumLeft;?>px;">
							<span id="spansumg" style="color:#fff;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:15px;text-shadow:none; margin-left:10px;"><?php echo $strCartCount;?></span> 
						</div>
					</div>
										
				</td>
		  	</tr>
		</table>
	</header>
	
	<script>
		var itemhadnum=[<?php echo $strSubHadNumBuf;?>]
		//alert(itemhadnum.length);
	</script>
	
	
	<article data-role="none">
	
		<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                
                <?php 
					$intRowIndex = 0;
					$strolditemtype ='';
					
					
					
					
					//if($strTypeListNo=='' | $strTypeListNo=='0')
					//{ ,a.SellClearFlag,a.SellClearCount
						$sql = sprintf("SELECT a.ItemNo,a.ItemName,a.ItemUnite,a.ItemPrice,a.Remarks,a.wximage,b.TypeName,b.TypeNo
									FROM TCP_Item_List a,TCP_Item_Type b Where a.TypeListNo=b.ListNo And a.wxmall>0 
									And (a.SellClearFlag=0 OR (a.SellClearFlag=1 And a.SellClearCount>0))
									And b.DListNo=%s Order By b.TypeNo ASC",$strselDListNo);
					//}
					//else
					//{
					//	$sql = sprintf("SELECT a.ItemNo,a.ItemName,a.ItemUnite,a.ItemPrice,a.Remarks,a.wximage,b.TypeName
					//			FROM TCP_Item_List a,TCP_Item_Type b Where a.TypeListNo=b.ListNo And a.wxmall>0 And b.ListNo=%s Order By b.TypeName ASC",$strTypeListNo);
					//}
					$result = querySql($sql);
	
					while($row = fetch_array($result))
					{
						$stritemno = $row['ItemNo'];
						$stritemname = $row['ItemName'];
						$fltprice = $row['ItemPrice'];
						$stritemunite = trim($row['ItemUnite']);
						$strremarks = trim($row['Remarks']);
						$stritemimg = trim($row['wximage']);
						$stritemtype = trim($row['TypeName']);
						
						//估清
						//$SellClearCount = $row['SellClearCount'];
						//$SellClearFlag = $row['SellClearFlag'];
						
						$stritemimg = 'mall_images/'.$stritemimg ;
						
						//处理数据转换和显示
						$fltintegralval =  round($fltprice * $fltintegralcashrate,0);
					
						$stritemprice =  number_format($fltprice,1);
						$striteminteg =  number_format($fltintegralval,0);
						$stritemprice = str_replace(',','',$stritemprice);
						$striteminteg = str_replace(',','',$striteminteg);
										
						if(strlen($stritemunite)>0)
							$stritemunite ='/'.$stritemunite;
					
						$strremarks2 = $strremarks;
						if(strlen($strremarks)>26)
						{
							$strremarks	=  mb_substr($strremarks,0,26,'gb2312').'...';
						}
										
						$intRowIndex = $intRowIndex + 1;
												
						if($stritemtype!=$strolditemtype)
						{
				?>
				<tr bgcolor="#F4EFEF">
					<td height="50" width="5"></td>
					<td height="50" align="center">
						<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:24px;text-decoration: none;text-shadow:none;"><?php echo $stritemtype; ?></span> 
					</td>
					<td height="50" width="5"></td>
				</tr>
				
				<!--<tr><td height="1" colspan="3" align="left" bgcolor="#F2E2E2"></td></tr>-->
				
				<?php 
							$strolditemtype = $stritemtype;
						} 
				?>
                <tr><td height="5" colspan="3"></td></tr>
                <tr>
					<td height="15" width="5"></td>
					<td height="15" align="left">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td height="90" width="110">
									<!--<div onClick="bmtSelItem('<?php echo $stritemno;?>')" style="background-color:#FFFFFF;">-->
									<div style="background-color:#FFFFFF;">
										<IMG src="<?php echo $stritemimg; ?>" width="110" height="90" border="0" style="border-radius:3px;">
									</div>
								</td>
								<td height="90" width="10"></td>
								<td height="90">
									<!---显示商品信息：图片，项目名称，单价，对应积分，项目说明 -->
									<a data-transition="slide" data-rel="popup" data-position-to="window" style="width:100%;height:10px;margin:0px auto 0px auto;color:#666666;text-decoration: none;">
										<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
											<tr><td height="25"> 
													<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:15px;"><?php echo $stritemname; ?></span> 
											</td></tr>
                                            
											<tr><td height="20"> 
												<?php if($intWXIngegPayFlag>0) { ?>
                                            		<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                                    	<tr>
                                                        	<td width="100" height="100%">
                                                            	<span style="color: #996600;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;">￥<?php echo $stritemprice.$stritemunite; ?></span> 
                                                            </td>
                                                            
                                                            <td width="13" height="100%">
																<?php if($striteminteg>0) {?>
	                                                            <img src="images\jfimg.png" width="12" height="15" border="0" style="margin-top:3px;">
																<?php } ?>
                                                            </td>
                                                            <td height="100%">
																<?php if($striteminteg>0) {?>
	                                                            <span style="color: #996600;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;"><?php echo $striteminteg; ?></span> 
																<?php } ?>
                                                            </td>
															
															<td width="30" height="100%" align="center">
																<!--<span id="hadcounttext_<?php echo $stritemno;?>" style="color: #2934dc;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:10px;"></span> -->
																<img id="bmtAdd_<?php echo $stritemno;?>" onClick="bmtSaveToTempTable('<?php echo $stritemno;?>',<?php echo $intRowIndex;?>)" src="images\add9.png" width="24" height="24" border="0" style="margin-top:3px;">
															</td>
															<td width="36" height="100%" align="center">
																<span id="hadcount_<?php echo $stritemno;?>" style="color: #7c7c7c;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:20px;"></span> 
															</td>
															<td width="30" height="100%" align="center">
																<!--<span id="hadcounttext_<?php echo $stritemno;?>" style="color: #2934dc;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:10px;"></span> -->
																<img id="bmtSub_<?php echo $stritemno;?>" onClick="bmtSubFromTempTable('<?php echo $stritemno;?>',<?php echo $intRowIndex;?>)" src="images\sub9.png" width="24" height="24" border="0" style="margin-top:3px;display:none;">
															</td>
															<td width="20" height="100%" align="center"></td>
                                                        </tr>
                                                    </table>		
												<?php } else { ?>
													<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                                    	<tr>
                                                        	<td height="100%">
																<span style="color: #996600;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;">￥<?php echo $stritemprice.$stritemunite; ?></span> 
															</td>
															<td width="30" height="100%" align="center">
																<!--<span id="hadcounttext_<?php echo $stritemno;?>" style="color: #2934dc;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:10px;"></span> -->
																<img id="bmtAdd_<?php echo $stritemno;?>" onClick="bmtSaveToTempTable('<?php echo $stritemno;?>',<?php echo $intRowIndex;?>)" src="images\add9.png" width="24" height="24" border="0" style="margin-top:3px;">
															</td>
															<td width="36" height="100%" align="center">
																<span id="hadcount_<?php echo $stritemno;?>" style="color: #7c7c7c;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:20px;"></span> 
															</td>
															<td width="30" height="100%" align="center">
																<!--<span id="hadcounttext_<?php echo $stritemno;?>" style="color: #2934dc;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:10px;"></span> -->
																<img id="bmtSub_<?php echo $stritemno;?>" onClick="bmtSubFromTempTable('<?php echo $stritemno;?>',<?php echo $intRowIndex;?>)" src="images\sub9.png" width="24" height="24" border="0" style="margin-top:3px;display:none;">
															</td>
															<td width="20" height="100%" align="center"></td>
														</tr>
													</table>
												<?php } ?>
											</td></tr>
											
                                            <tr><td height="45" valign="top">
													<span style="color: #999999;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;"><?php echo $strremarks; ?></span> 
											</td></tr>
										</table>
                                    </a>    
                                   
                                    <!----------------------------------------------------->
								</td>
							</tr>
						</table>
					</td>
					<td height="15" width="5"></td>
				</tr>
				
                <tr><td height="1" colspan="3"></td></tr>
                
				<tr><td height="1" colspan="3" bgcolor="#f5f5f5"></td></tr>
                
                <?php	
						
					}
					freeResult($result);	//释放数据库
					closeDb();				//关闭数据库
				?>
                
                
			<tr>
				<td height="8" width="5"></td>
				<td height="8" align="left"></td>
				<td height="8" width="5"></td>
			</tr>
		</table>
		
		<script type="text/javascript">
				
			//相应提交按钮事件处理部分
			function bmtSaveToTempTable(selitemno,myboxid)
			{			
				//开始保存项目到购物车中
				var strret;
				//用ajax的“同步方式”调用一般处理程序
				$.ajax({
					url: "savetotemp.php?selitno=" + selitemno + "&subflag=0",
					async: false,//改为同步方式
					type: "POST",
					//data: {doid:1, rmid: "strRoomNo" },
					success: function (RetData) 
					{
						strret = RetData;
					}
				});

				//alert(strret);
				if(strret==1)
				{
					//关闭弹出窗口
					//var $myd = $("#ShowRoomInput" + myboxid);
					//$myd.popup('close');
					
					//更新购物车数量
					var strCount = document.getElementById("spansumg").innerHTML;
					if(strCount=='')
					{
						strCount=0;
					}
					var intNewCount = parseInt(strCount); 
					intNewCount = intNewCount + 1;
					
					if(intNewCount<1)
					{
						document.getElementById('MyCart').style.backgroundImage = 'url(images/cart1.png)';
					}
					else
					{
						document.getElementById('MyCart').style.backgroundImage = 'url(images/cart2.png)';	
					}
					
					if(intNewCount>0)
					{
						document.getElementById("spansumg").innerHTML = intNewCount;
					}
					else
					{
						document.getElementById("spansumg").innerHTML = '';
					}

					if(intNewCount>9)
					{
						$("#MyNumDiv").css("padding-left","0px");
					}
					
					//个更新已点数量 
					var strHadCount = document.getElementById("hadcount_" + selitemno).innerHTML;
					if(strHadCount=='')
					{
						strHadCount=0;
					}
					intNewCount = parseInt(strHadCount); 
					intNewCount = intNewCount + 1;
					document.getElementById("hadcount_" + selitemno).textContent = intNewCount;
					document.getElementById("bmtSub_" + selitemno).style.display="block";	//display:block; none
				}
											
			};
			
			
			function bmtSubFromTempTable(selitemno,myboxid)
			{			
				//开始保存项目到购物车中
				var strret;
				//用ajax的“同步方式”调用一般处理程序
				$.ajax({
					url: "savetotemp.php?selitno=" + selitemno + "&subflag=1" ,
					async: false,//改为同步方式
					type: "POST",
					//data: {doid:1, rmid: "strRoomNo" },
					success: function (RetData) 
					{
						strret = RetData;
					}
				});

				//alert(strret);
				if(strret==1)
				{
					//关闭弹出窗口
					//var $myd = $("#ShowRoomInput" + myboxid);
					//$myd.popup('close');
					
					//更新购物车数量
					var strCount = document.getElementById("spansumg").innerHTML;
					if(strCount=='')
					{
						strCount=0;
					}
					var intNewCount = parseInt(strCount); 
					intNewCount = intNewCount - 1;
					
					if(intNewCount<1)
					{
						document.getElementById('MyCart').style.backgroundImage = 'url(images/cart1.png)';
					}
					else
					{
						document.getElementById('MyCart').style.backgroundImage = 'url(images/cart2.png)';	
					}
					
					document.getElementById("spansumg").innerHTML = intNewCount;

					if(intNewCount>9)
					{
						$("#MyNumDiv").css("padding-left","0px");
					}
					
					//个更新已点数量 
					var strHadCount = document.getElementById("hadcount_" + selitemno).innerHTML;
					if(strHadCount=='')
					{
						strHadCount=0;
					}
					intNewCount = parseInt(strHadCount); 
					intNewCount = intNewCount - 1;
					if(intNewCount>0)
					{
						document.getElementById("hadcount_" + selitemno).textContent = intNewCount;					
						document.getElementById("bmtSub_" + selitemno).style.display="block";	//display:block; none
					}
					else
					{
						document.getElementById("hadcount_" + selitemno).textContent = "";					
						document.getElementById("bmtSub_" + selitemno).style.display="none";	//display:block; none
					}
				}
											
			};
			
			
			function bmtSelItem(strItemNo)
			{	
				window.location="itemview.php?itmno=" + strItemNo;										
			};
		</script>
		
		<script type="text/javascript">
			function RefItemHadCount()
			{	
				var itmCount = itemhadnum.length;
				if (itmCount>0)
				{
					for(var i=0;i<itmCount;i++)
					{
						if (itemhadnum[i].HadCount>0)
						{
							document.getElementById("hadcount_" + itemhadnum[i].ItemNo).textContent = itemhadnum[i].HadCount;
							document.getElementById("bmtSub_" + itemhadnum[i].ItemNo).style.display="block";	//display:block; none
						}
					}
				}
			};
			
			//首次打开现实已电单 
			RefItemHadCount();
		</script>
	</article>

	<footer data-role="footer" data-position="fixed" data-tap-toggle="false" style="border-top:0px solid #F3EDED;border-bottom:0px solid #F6F5F2;border-left:0px solid #F6F5F2;border-right:0px solid #F6F5F2;">
		<table width="100%" height="45" border="0" cellpadding="0" cellspacing="0" bgcolor="#F6F6F6">
			<tr height="100%" valign="middle" align="center">
				<td width="33%" style="border-top:1px solid #F3EDED;">
					<div style="width:100%;height:100%;padding-top:5px;">
						<div style="width:24px;height:20px;">
							<img src="images\p1_b.png" width="20" height="20" border="0">
						</div>
						<span style="color:#747474;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:11px;text-shadow:none;">首页</span>
					</div>
				</td>
				
				<td width="34%" style="border-top:1px solid #F3EDED;border-left:0px solid #F6F5F2;">
					<div onClick="window.location='cartlist.php';" style="width:100%;height:100%;padding-top:5px;">
						<div style="width:24px;height:20px;">
							<img src="images\p3_a.png" width="20" height="20" border="0">
						</div>
						<span style="color:#747474;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:11px;text-shadow:none;padding-left:4px;">已点单</span>
					</div>
				</td>
				<td width="33%" style="border-top:1px solid #F3EDED;border-left:0px solid #F6F5F2;">
					<div onClick="window.location='orderlist.php?bstat=0';" style="width:100%;height:100%;padding-top:5px;">
						<div style="width:24px;height:20px;">
							<img src="images\p2_a.png" width="24" height="20" border="0">
						</div>
						<span style="color:#747474;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:11px;text-shadow:none;">我的帐单</span>
					</div>
				</td>
				<!--
				<td width="25%" style="border-top:1px solid #F3EDED;border-left:0px solid #F6F5F2;">
					<div onClick="window.location='vipmain.php';" style="width:100%;height:100%;padding-top:5px;">
						<div style="width:24px;height:20px;">
							<img src="images\p4_a.png" width="20" height="20" border="0">
						</div>
						<span style="color:#747474;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:11px;text-shadow:none;">我的</span>
					</div>
				</td>
				-->
			</tr>
		</table>						
	</footer>
	
</section>



</body>
	
</html>