<?php
	session_start();
	require_once("../Wx.Config.php");	//只加载一次
	
	$strselcarttempid = trim($_SESSION["main_defcarttempid"]);
	$_SESSION["main_defcarttempid"]="";
	$_SESSION["main_defcarttempid"] = $strselcarttempid;
	
	$strIndexPage = trim($_SESSION["main_defPageIndex"]);
	if(strlen($strIndexPage)<1)
	{
		$strIndexPage = "index.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

	//加载系统参数信息
	require_once("db/db.php");	
	require_once("common/common.php");
	
	$strselDListNo=trim($_SESSION["main_posChainDListNo"]);
	
	//得到当前部门名称
	$intWXIngegPayFlag=0;
	
	$sql = sprintf("SELECT wxintegprice FROM TCP_Depart_Inform Where ListNo=%s",$strselDListNo);
	$result = querySql($sql);
	
	if($row = fetch_array($result))
	{
		$intWXIngegPayFlag = $row['wxintegprice'];
	}
	freeResult($result);	//释放数据库
	
	$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);	//释放数据库
	}
	
	$fltsumvalue = 0;
	$intsumcount = 0;

?>

<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="20"></td>
				<td height="52" align="center" valign="middle">
	                <span style="color:<?php echo WxMainConfig::colHeadTextColor;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:19px;text-shadow:none;">已点单</span>
               	</td>
				<td height="52" width="20"></td>
		  	</tr>
		</table>
	</header>
	
	<article data-role="none">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                
                <?php 
					$intRowIndex = 0;
					
					$sql = sprintf("select ListNo,Item_No,Item_Name,Item_Unite,Remarks,wximage,Item_Price,Item_Count 
						from WX_Temp_List Where CartTempID='%s' And DListNo=%s",$strselcarttempid,$strselDListNo);
					
					$result = querySql($sql);
	
					while($row = fetch_array($result))
					{
						$strlistno = $row['ListNo'];
						$stritemno = $row['Item_No'];
						$stritemname = $row['Item_Name'];
						$fltprice = $row['Item_Price'];
						$stritemunite = trim($row['Item_Unite']);
						$strremarks = trim($row['Remarks']);
						$stritemimg = trim($row['wximage']);
						
						$intitemcount = $row['Item_Count'];;
						
						//合计金额	
						$fltitemvalue = round($fltprice * $intitemcount,1);
						
						$fltsumvalue = $fltsumvalue + $fltitemvalue;
						$intsumcount = $intsumcount + $intitemcount;
						
						$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)>28)
						{
							$strremarks	=  mb_substr($strremarks,0,28,'utf-8').'...';
						}
					
					
						$intRowIndex = $intRowIndex + 1;
				?>
                <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="140"><a href="#"><IMG src="<?php echo $stritemimg; ?>" width="140" height="90" border="0" style="border-radius:3px;"></a></td>
								<td height="90" width="10"></td>
								<td height="90">
                                
                                	<!---显示商品信息：图片，项目名称，单价，对应积分，项目说明 -->
                                    <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>
													</tr>
												 </table>					
											<?php }  else  { ?>
												<span style="color: #996600;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;">￥<?php echo $stritemprice.$stritemunite; ?></span> 
											<?php } ?>
										</td></tr>
										<tr><td height="2"></td></tr>
                                        <tr><td height="38" valign="top">
											<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                            	<tr>
                                                	<td width="38" height="38" align="right" valign="middle">
                                                         <div onClick="bmtRefreshItemCount('<?php echo $intRowIndex;?>',0,'<?php echo $strlistno;?>')">
	                                                         <img src="images\sub.png" width="26" height="26" border="0" style="margin-top:3px;">
                                                         </div>
                                                    </td>
                                                    
                                                    <td width="37" height="38" align="center" valign="middle">
                                                    	<span id="myspan<?php echo $intRowIndex;?>" style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:18px;text-shadow:none;"><?php echo $intitemcount;?></span> 
                                                    </td>
                                                    <td width="38" height="38" align="left" valign="middle">
                                                    	 <div onClick="bmtRefreshItemCount('<?php echo $intRowIndex;?>',1,'<?php echo $strlistno;?>')">
                                                            <img src="images\add.png" width="26" height="26" border="0" style="margin-top:3px;">
                                                         </div>
                                                    </td>
                                                    <td height="38" align="right" valign="middle">
                                                    	 <div onClick="bmtDeleteOnItem('<?php echo $strlistno;?>')">
                                                            <img src="images\del.png" width="24" height="24" border="0" style="margin-top:3px;">
                                                         </div>
                                                    </td>
                                                    <td width="8" height="38" align="right" valign="middle">

                                                    </td>
                                                </tr>
                                            </table>
										</td></tr>
                                        <tr><td height="4"></td></tr>
									</table>
                                        
                                        
                                    
								</td>
							</tr>
						</table>
					</td>
					<td height="15" width="5"></td>
				</tr>
				
                <tr><td height="1" colspan="3"></td></tr>
                
				<tr>
					<td height="1" width="5"></td>
					<td height="1" align="left" bgcolor="#F2E2E2"></td>
					<td height="1" width="5"></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>
	</article>
	    
	    
	<footer data-role="footer" data-position="fixed" data-tap-toggle="false" style="border-top:0px solid #F6F5F2;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="#FAFAFA">
			<tr height="40" valign="top">
				<td colspan="4" style="border-top:1px solid #F7EEEE;" bgcolor="#fff">
					<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                     	<tr>
                        	<td height="40" width="10%" align="right" valign="middle"></td>
                            <td height="40" align="right" valign="middle">
                            	<span id="spansum1" style="color: #E50015;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:15px;">合计：￥<?php echo number_format($fltsumvalue,1);?></span> 
                            </td>
                            <td height="40" width="5" align="right" valign="middle"></td>
                            <td height="40" width="40%" align="right" valign="middle">
                            	<div data-rel="back" onClick="bmtSaveBillFromCart()" style="border-radius:1px;width:80%; height:38px; background-color:<?php echo WxMainConfig::colHeadBkColor;?>;">
                               		<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                    	<tr>
                                        	<td width="100%" height="100%" align="center">
                                         		<span id="spansum2" style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;text-shadow:none;">下单(<?php echo number_format($intsumcount,0);?>)</span>
                                 			</td>
                                        </tr>
                                 	</table>
                               	</div>
                            </td>
                    	</tr>
                 	</table>
				</td>

			</tr>
			
			<tr height="100%" valign="middle" align="center">
				<td width="25%" style="border-top:1px solid #F6F5F2;">
					<div onClick="window.location='index.php';"  style="width:100%;height:100%;padding-top:5px;">
						<div style="width:24px;height:20px;">
							<img src="images\p1_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>
				<td width="25%" style="border-top:1px solid #F6F5F2;border-left:0px solid #F6F5F2;">
					<div style="width:100%;height:100%;padding-top:5px;">
						<div style="width:24px;height:20px;">
							<img src="images\p3_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;padding-left:4px;">已点单</span>
					</div>
				</td>
				<td width="25%" style="border-top:1px solid #F6F5F2;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="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="25%" style="border-top:1px solid #F6F5F2;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>
	    
    
	 <script type="text/javascript">
		//删除一个项目
		function bmtDeleteOnItem(clistno)
		{
			
			var strurl="delcartitem.php?clistno=" + clistno;
			var strret="";
			//用ajax的“同步方式”调用一般处理程序
			$.ajax({
				url: strurl ,
				async: false,//改为同步方式
				type: "POST",
				//data: {doid:1, rmid: "strRoomNo" },
				success: function (RetData) 
				{
					strret = RetData;
				}
			});
			
			if(strret.length>0)
			{
				//得到新的数量值
				window.location="cartlist.php";
			}
			
		};

		//修改数量
		function bmtRefreshItemCount(myspanid,doid,clistno)
		{						
			//得到要操作的span项目
			var myspan = "myspan" + myspanid.toString().trim();
			//得到原来的数量
			var strCount = document.getElementById(myspan).innerHTML;
			var intNewCount = parseInt(strCount); 
			
			var strurl="";
			
			if(doid>0)
			{
				strurl = "savecartcount.php?doid=1&clistno=" + clistno;
				//intNewCount = intNewCount +1;
			}
			else
			{
				if(intNewCount>0)
				{
					//intNewCount = intNewCount - 1;
					strurl = "savecartcount.php?doid=0&clistno=" + clistno;
				}
			}

			//将数量转为字符
			//strCount = intNewCount.toString().trim();
			
			if(strurl.length>0)
			{
				var strret="";
				//用ajax的“同步方式”调用一般处理程序
				$.ajax({
					url: strurl ,
					async: false,//改为同步方式
					type: "POST",
					//data: {doid:1, rmid: "strRoomNo" },
					success: function (RetData) 
					{
						strret = RetData;
					}
				});
				
				if(strret.length>0)
				{
					//得到新的数量值,开始分解数据 2*8*256.2
					var strNewCount;
					var strSumCount;
					var strSumValue;
					
					var intpos = strret.indexOf("*");
					strNewCount = strret.substr(0,intpos);
					
					strret = strret.substr(intpos+1);
					intpos = strret.indexOf("*");
					strSumCount = strret.substr(0,intpos);
					
					strret = strret.substr(intpos+1);
					strSumValue = strret;
					
					//alert(strret);
					
					//显示新调整后的数量
					document.getElementById(myspan).innerHTML = strNewCount;
					document.getElementById("spansum1").innerHTML = "合计：￥" + strSumValue;
					document.getElementById("spansum2").innerHTML = "结算下单(" + strSumCount + ")";
				}
			}			
		};
		
		
		
		//相应提交按钮事件处理部分
		function bmtSaveBillFromCart()
		{			
						
			//2.判断是否登录系统		
			/*
			var strviplogined = '<?php echo $_SESSION["main_viplogined"];?>';
			var strvipno = '<?php echo $_SESSION["main_vipno"];?>';
			if(strviplogined!="1" | strvipno=="")
			{
				//没有登录开始启动登录
				window.location = 'login.php?stext=';
				return;
			}
			*/
			
			//3.开始从购物车中创建订单			
			var strret;
			//用ajax的“同步方式”调用一般处理程序
			$.ajax({
				url: "ordersave.php",
				async: false,//改为同步方式
				type: "POST",
				//data: {doid:1, rmid: "strRoomNo" },
				success: function (RetData) 
				{
					strret = RetData;
				}
			});

			if(strret.length>10)
			{
				//创建订单成功,得到订单号,启动订单支付界面
				var strResault = strret.substr(0,1);
				var strNewBillNo = strret.substr(1);

				window.location="ordermodify.php?selbillno=" + strNewBillNo;
			}
										
		}
		
	</script>
	
</section>

</body>
	
</html>