<?php
	session_start();
	ini_set('session.gc_maxlifetime', 99999999); //设置时间 永不过期
	//判断是否登录系统		
	if($_SESSION['main_wx_userlogined']!="1" | $_SESSION['main_wx_userno']=="")
	{
		//没有登录开始启动登录
		header('location:..\loginwx.php?rset=0');
		exit;
	}
	header("Content-type: text/html; charset=gb2312"); 
?>
<!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">
	
	<Meta http-equiv="Page-Enter" Content="blendTrans(Duration=0.5)"> 
	<Meta http-equiv="Page-Exit" Content="blendTrans(Duration=0.5)">
	
	<title>客房管理</title>
	
	<link rel="stylesheet" href="jsp4/jquery.mobile-1.4.3.min.css">
	<script src="jsp4/jquery.js"></script>
	<script src="jsp4/jquery.mobile-1.4.3.min.js"></script>
</head>

<script>	
		//隐藏维信右上角菜单
		function onBridgeReady(){
			WeixinJSBridge.call('hideOptionMenu');
		}

		if (typeof WeixinJSBridge == "undefined")
		{
			if( document.addEventListener )
			{
				document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
			}
			else if (document.attachEvent)
			{
				document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
				document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
			}
		}
		else
		{
			onBridgeReady();
		}
</script>

<script>
		//禁止页面上下滑动,整个页面都不能滑动了
		document.addEventListener('touchmove', function(e) {
			e.preventDefault();
		});
</script>
	
<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">

<section data-role="page" id="roomorder">			
	<article data-role="none">
		<?php				
				require_once("db/db.php");	
				require_once("common/common.php");
	
				$chainno=$_SESSION["ChainNofw"];
				$roomno=$_REQUEST["rmid"];
				$strroomstate="空净房";
				
				$intClearFlag=0;	//清扫完成
				$intBarCode=0;		//扫描入账
				$intScoreFlag=0;	//商品入账
				$intSetOkRoom=0;	//查房结束
				$intCheckOkFlag=0;	//查房检测
				$intCanClearRoom=0;
				
				$intCanCheckRoom=0;		//启用查房检测功能
				
				$sql=sprintf("Select Item_Value From TR_Config WHERE Chain_No='%s' And Item_Name='手机房务管理启用清扫检查房'",$chainno);
				$result = querySql($sql);		
				if($row = fetch_array($result))
				{
					$intCanCheckRoom=$row['Item_Value'];	
				}
				//释放数据库
				freeResult($result);
				
				//1.开始去房间状态数量
				$sql=sprintf("SELECT a.Room_State,a.Dirty_Flag,a.Fault_Flag,a.CheckOk FROM TR_Room_Inform a,TR_Room_Type b WHERE a.TypeListNo=b.ListNo And b.Chain_No='%s' And a.Room_No='%s'",$chainno,$roomno);
				$result = querySql($sql);		
				if($row = fetch_array($result))
				{
					$inttemp1=$row['Room_State'];		
					$intDirty=$row['Dirty_Flag'];
					$intFault=$row['Fault_Flag'];
					$intCheckOkFlag=$row['CheckOk'];
					
					//生成状态颜色
					switch($inttemp1)
					{
						case 0:
							$strroomstate="空净房";
							break;
						case 5:
							$strroomstate="退客房";
							$intClearFlag=1;	//清扫完成
							break;
						case 6:
							$strroomstate="维修房";
							break;
						case 1:
							$strroomstate="预订房";
							break;
						case 2:
							if($intDirty==1)
							{
								$strroomstate="住脏房";
								$intClearFlag=1;	//清扫完成
							}
							else
							{
								$strroomstate="住客房";
							}
							$intBarCode=1;		//扫描入账
							$intScoreFlag=1;	//商品入账
							$intSetOkRoom=1;	//查房结束
							break;
						case 3:
							$strroomstate="钟点房";
							$intBarCode=1;		//扫描入账
							$intScoreFlag=1;	//商品入账
							$intSetOkRoom=1;	//查房结束
							break;
						default:
							if($inttemp1==5)
							{
								$strroomstate="免费房";
								$intBarCode=1;		//扫描入账
								$intScoreFlag=1;	//商品入账
								$intSetOkRoom=1;	//查房结束
							}
							if($inttemp1==7)
								$strroomstate="锁房";
							else
								$strroomstate="其他";
							break;
					}
					
					if($intDirty==1)
					{
						$intClearFlag=1;	//清扫完成
					}
				}
				//释放数据库
				freeResult($result);
								
				$RoomOldState=$strroomstate;	//房间当前状态

				//2.获取住房信息
				$strBListNo="0";
				$strOrderNo="";
				$sql=sprintf("SELECT a.ListNo,a.Order_No FROM TR_Order_Room_List a,TR_Order_Inform b WHERE a.Order_No=b.Order_No And b.Chain_No='%s' And b.Order_State<2 And a.Room_BillState=2 And a.Room_No='%s'",$chainno,$roomno);
				$result = querySql($sql);		
				if($row = fetch_array($result))
				{
					$strBListNo=$row['ListNo'];		
					$strOrderNo=$row['Order_No'];
				}
				//释放数据库
				freeResult($result);
				
				//3.
				
				closeDb();	//关闭数据库
				
				if($_SESSION["main_canclearroomflag"]=="1")
				{
					$intCanClearRoom=1;
				}
		?>
		<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
			<tr bgcolor="#E7E7E7">
				<td height="6" width="15"></td>
				<td height="6" align="left"></td>
				<td height="6" width="15"></td>
			</tr>
				
			<tr bgcolor="#E7E7E7">
				<td height="35" width="15"></td>
				<td height="35" align="left">
					<table width="100%" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td height="30" width="55%">
								<span style="color: #000000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:16px;text-shadow:none;">房号：<?php echo $roomno;?></span>
							</td>
							<td height="30" width="45%" align="right">
								<span style="color: #000000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:16px;text-shadow:none;">状态：<?php echo $strroomstate;?></span>
							</td>
						</tr>
					</table>
				</td>
				<td height="35" width="15"></td>
			</tr>
			
			<tr  bgcolor="#E7E7E7"><td height="2" colspan="3"></td></tr>
			
			<tr><td height="1" colspan="3" align="left" bgcolor="#F2E2E2"></td></tr>
			
			<tr>
				<td height="260" width="15"></td>
				<td height="260" align="center" valign="top">
					<div style="position:relative;width:250px;height:250px;margin:0 auto;margin-top:10px;">
						<img src="images/cfbg.png" style="width:100%;height:100%"/>
						<!--清扫完成-->
						<div style="position:absolute;width:70px;height:80px;top:20px;left:30px;">
							<?php if($intClearFlag>0 && $intCanClearRoom>0) {?>
								<img id="SetStateEnable" onclick="SubClick(1)" src="images/qingsao1.png" style="width:100%;height:100%"/>
							<?php } else {?>
								<img id="SetStateEnable" src="images/qingsao0.png" style="width:100%;height:100%"/>
							<?php }?>
						</div>
						<!--扫描入账-->
						<div style="position:absolute;width:65px;height:80px;top:20px;left:150px;">
							<?php if($intBarCode>0) {?>
								<img id="ScaleEnable" onclick="SubClick(2)" src="images/saomiao1.png" style="width:100%;height:100%"/>
							<?php } else {?>
								<img id="ScaleEnable" src="images/saomiao0.png" style="width:100%;height:100%"/>
							<?php }?>
						</div>
						<!--商品入账-->
						<div style="position:absolute;width:70px;height:80px;top:150px;left:30px;">
							<?php if($intScoreFlag>0) {?>
								<img id="ItemListEnable" onclick="SubClick(3)" src="images/shangpin1.png" style="width:100%;height:100%"/>
							<?php } else {?>
								<img id="ItemListEnable" src="images/shangpin0.png" style="width:100%;height:100%"/>
							<?php }?>
						</div>
						<!--查房结束-->
						<div style="position:absolute;width:70px;height:80px;top:150px;left:150px;">
							<?php if($intCheckOkFlag>0) {?>
								<img id="CheckRoomEnable" onclick="SubClick(4)" src="images/cfwc1.png" style="width:100%;height:100%"/>
							<?php } else {?>
								<img id="CheckRoomEnable" src="images/cfwc0.png" style="width:100%;height:100%"/>
							<?php }?>
						</div>
					</div>
				</td>
				<td height="260" width="15"></td>
			</tr>

			<tr bgcolor="#fff"><td height="10" colspan="3"></td></tr>
			<tr bgcolor="#E7E7E7"><td height="1" colspan="3"></td></tr>
			<tr bgcolor="#fff"><td height="10" colspan="3"></td></tr>
			<?php if($intCanCheckRoom>0) { ?>
			<tr>
				<td height="25" width="15"></td>
				<td height="25" align="center">
						<div onClick="CheckRoomFinish('<?php echo $roomno;?>')" style="border-radius:5px;width:80%; height:38px; background-color:#3C2778;">
                           	<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
								<tr><td width="100%" height="100%" align="center">
									<span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:16px;text-shadow:none;">查房完成</span>                            	
                                </td></tr>
                            </table>
                        </div>
				</td>
				<td height="25" width="15"></td>
			</tr>
			<tr><td height="30" colspan="3"></td></tr>
			<?php } else { ?>
			<tr><td height="10" colspan="3"></td></tr>
			<?php } ?>
			<tr>
				<td height="25" width="15"></td>
				<td height="25" align="center">
						<div onClick="window.location = 'index.php';" style="border-radius:5px;width:80%; height:38px; background-color:#D7AA28;">
                           	<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
								<tr><td width="100%" height="100%" align="center">
									<span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:16px;text-shadow:none;">返回</span>                            	
                                </td></tr>
                            </table>
                        </div>
				</td>
				<td height="25" width="15"></td>
			</tr>
			<tr bgcolor="#fff"><td height="10" colspan="3"></td></tr>
		</table>
		
	</article>
	
	<script type="text/javascript">
		
		var intSetStateEnable;
		var intScaleEnable;
		var intItemListEnable;
		var intCheckRoomEnable;
		
		intSetStateEnable=0;
		intScaleEnable=0;
		intItemListEnable=0;
		intCheckRoomEnable=0;
		
		function SubClick(subid)
		{		
				
			var strret;
			var strRoomNo;
			var strOldState;
			
			strRoomNo="<?php echo $roomno;?>";
			//strOldState"<?php echo $RoomOldState;?>";
			
			if(subid==1)	//清扫完成
			{	
				if(intSetStateEnable==1)
				{
					return;	//已经成功执行过清扫，不允许再提交
				}
				
				//用ajax的“同步方式”调用一般处理程序
				$.ajax({
					url: "clearroom.php?doid=1&rmid=" + strRoomNo,
					async: false,//改为同步方式
					type: "POST",
					//data: {doid:1, rmid: "<?php echo $roomno;?>" },
					success: function (RetData) 
					{
						strret = RetData;
					}
				});
										
				//alert(strret);
				if(strret==1)
				{
					intSetStateEnable=1;
					var img = document.getElementById('SetStateEnable');
					img.src="images/qingsao0.png";
					alert("打扫房间成功!");
					window.location="index.php";
				}
				else
				{
					alert("打扫房间失败!");
				}
										
			}
			else if(subid==2)
			{
				var urlroom='barcodescore.php?rmid=' + strRoomNo;
				window.location.href=urlroom;
			}
			else if(subid==3)
			{
				var urlroom='itemlist.php?rmid=' + strRoomNo;
				window.location.href=urlroom;
			}
			else if(subid==4)	//清扫完成
			{
				if(intCheckRoomEnable==1)
				{
					return;	//已经成功执行过查房完成，不允许再提交
				}
				//用ajax的“同步方式”调用一般处理程序
				$.ajax({
					url: "clearroom.php?doid=4&rmid=" + strRoomNo,
					async: false,//改为同步方式
					type: "POST",
					//data: {doid:4, rmid: "<?php echo $roomno;?>" },
					success: function (RetData) 
					{
						strret = RetData;
					}
				});
									
				//alert(strret);
				if(strret==1)
				{
					intCheckRoomEnable=1;
					var img = document.getElementById('CheckRoomEnable');
					img.src="images/cfwc0.png";
					alert("提交查房完成成功!");
					window.location="index.php";
				}
				else
				{
					alert("提交查房完成失败!");
				}
			}
			
		};
	
		//查房完成 
		function CheckRoomFinish(strRoomNo)
		{
			//开始保存项目到购物车中
				var strret;
				//用ajax的“同步方式”调用一般处理程序
				$.ajax({
					url: "saveroomoklist.php?selromid=" + strRoomNo ,
					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');
					window.location="index.php";
				}
		
		};
		
		</script>
	
</section>

</body>
</html>
