<?php
	session_start();
	require_once("db/db.php");	
	require_once("common/common.php");
	require_once("..\Wx.Config.php");
	
	ini_set('session.gc_maxlifetime', 99999999); //设置时间 永不过期
	//判断是否登录系统		
	if($_SESSION['main_wx_userlogined']!="1" | $_SESSION['main_wx_userno']=="")
	{
		//没有登录开始启动登录
		header('location:..\loginwx.php?rset=0');
		exit;
	}
	
	
	$strRevChainNo=$_REQUEST["chainno"];
	if(strlen($strRevChainNo)>0)
	{
		$sql=sprintf("SELECT Chain_No,Chain_Name FROM Chain_Infor WHERE Chain_No='%s'",$strRevChainNo);				
		$result = querySql($sql);		
		if($row = fetch_array($result))
		{
			$strNewChainNo= $row['Chain_No'];
			$strNewChainName= $row['Chain_Name'];
		}
		freeResult($result);
		
		$_SESSION["ChainNo"]=$strNewChainNo;
		$_SESSION["ChainName"]=$strNewChainName;
			
	}
	
	$chainno=$_SESSION["ChainNo"];
	
	//手机端显示最近1天的退房记录
	$intShowRoomOfLastDays=WxMainConfig::intShowRoomOfLastDays;
	
	//判断是否有换房，退房，恢复入住的权限
	$intCanReCheckInHours=WxMainConfig::intCanReCheckInHours;
	$intCanReBackRoomFlag=0;	//是否允许恢复入住临时
	
	$userno=$_SESSION['userno']; 
	$sql=sprintf("Select a.Use_Flag FROM Sys_Group_Quanxian a,User_QuanXian b Where a.Group_No=b.Group_No And b.Use_No='%s' And a.Modul_Name='men_bar341'",$userno);
	$result = querySql($sql);
	if($row = fetch_array($result))
	{
		$intCanReBackRoomFlag = $row['Use_Flag'];
	}
	freeResult($result);
	
?>

<!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><?php echo $_SESSION['ChainName']?></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>-->
	
	<link rel="stylesheet" href="css/mycss.css">
	<script src="jsp4/myform.js"></script>
	<!--<link rel="stylesheet" href="jsp4/jquery.mobile.datepicker.css">-->
	<!--<script src="jsp4/jquery.ui.datepicker.js"></script>-->
	<!--<script id="mobile-datepicker" src="jsp4/jquery.mobile.datepicker.js"></script>-->

 
	<style>
	  header {
		position: fixed;
		top: 0;
		width: 100%;
		background-color: #f8f9fa;
		z-index: 1000;
	  }
	  footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		background-color: #f8f9fa;
		z-index: 1000;
	  }
	  body {
		padding-top: 50px; /* 根据header的高度调整 */
		padding-bottom: 50px; /* 根据footer的高度调整 */
	  }
	  
	  input::placeholder {
			color: #c8c8c8; /* 设置占位符文本颜色为灰色 */
		}
		
	.grid-container {
		  display: grid;
		  grid-template-columns: repeat(3, 1fr); /* 创建三列，每列等宽 */
		  gap: 4px; /* 设置列与列之间的间隔 */
		}
	.span-item1 {
		width: 140px; /* 设置每列的宽度 */
		text-align: left;
	}
	.span-item2 {
		width: 70px; /* 设置每列的宽度 */
		text-align: center;
	}
	.span-item3 {
		width: 70px; /* 设置每列的宽度 */
		text-align: right;
	}
		
	</style>

	
</head>

<script type="text/javascript">
	
	var lngNowSelBListNo=0;	//当前选择的项目流水号

	function bmtReturnPage()
	{	
		window.location="../indexm.php?selno=<?php echo $chainno;?>";
	};
	
</script>
	
<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">

<section data-role="page" id="pgorderroomlist" style="background-color:#fff;">		
	<header data-role="header" data-position="fixed" data-tap-toggle="false" style="border-top-width:0px;border-bottom-width:0px;bkc">
        <table width="100%" height="45" border="0" cellpadding="0" cellspacing="0" >
		   	<tr bgcolor="<?php echo WxMainConfig::colHeadBkColor;?>">
				<td height="35" width="50" align="center" valign="middle">
					<div onClick="bmtReturnPage()" style="width:40;height:45px; ">
						<img src="images\back.png" width="12" height="21" border="0" style="margin-top:12px;">
					</div>
				</td>
				
				<td height="35" align="center" valign="middle">
	                <span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:18px;text-shadow:none;">已退房信息</span>
               	</td>
				
				<td height="35" width="30" align="left" valign="middle"></td>
		  	</tr>
			
			<tr bgcolor="<?php echo WxMainConfig::colHeadBkColor;?>">
				<td height="25" width="50" align="center" valign="middle"></td>
				<td height="25" colspan="2">
					<span style="color: #fff;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;text-shadow:none;font-weight: bold;">提醒：此处仅显示最近1天的退房记录！</span>
				</td>
			</tr>
			
			<tr bgcolor="<?php echo WxMainConfig::colHeadBkColor;?>">
				<td colspan="3" height="15">
					<div style="background:#fff;width:100%;height:18px;padding-top:0px;margin-top:0px; border-radius: 15px 15px 0px 0px;">
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td height="30" width="10"></td>
								<td height="30" width="55">
									<span style="color: #B69021;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;;text-shadow:none;font-weight: bold;">房号</span>
								</td>
								<td height="30" align="left">
									<span style="color: #B69021;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;;text-shadow:none;font-weight: bold;">姓名</span>
								</td>
								<td height="30" width="50" align="left">
									<span style="color: #B69021;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;;text-shadow:none;font-weight: bold;">房价</span>
								</td>
								<td height="30" width="40" align="left">
									<span style="color: #B69021;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;;text-shadow:none;font-weight: bold;">方式</span>
								</td>
								<td height="30" width="40" align="center">
									<span style="color: #B69021;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;;text-shadow:none;font-weight: bold;">天数</span>
								</td>
								<td height="30" width="40" align="right">
									<span style="color: #B69021;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;;text-shadow:none;font-weight: bold;">状态</span>
								</td>
								<td height="30" width="10"></td>
							</tr>
						</table>
					</div>
				</td>
		  	</tr>
			
			<tr bgcolor="#fff"><td height="10" colspan="3"></td></tr>
			<tr bgcolor="#f0f0f0"><td height="1" colspan="3"></td></tr>
			
		</table>
		
	</header>
		
	<article data-role="none" >
	
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		
			<tr><td height="52" colspan="8"></td></tr>
			
			<?php 
				$colTextColr='#5e5e5e';
				$colTextColr1='#000';
					
				//得到付款明晰信息
				$strBListNo=0;
				$strSelManName="";
				$strselorderno='';
				$strselroomno="";
				$strselroomtype="";
				$fltselroomprice=0;
				$strselecttime="";
				$strcanceltime="";
				$intTemp=0;
				$strTemp="";
				$strSelRemarks="";
				$intSelDays=0;
				$strBillState="";
				$strRoomBorrowTemp='';
				
				$intSubDaysTemp=0-$intShowRoomOfLastDays;
							
				$sql=sprintf("SELECT b.Order_No,a.ListNo,a.Room_No,a.Man_Name,a.Room_Type,a.RoomPrice,Convert(varchar(16),a.SelectRoomTime,120)As SelectRoomT,
								Convert(varchar(16),a.Cancel_Date,120)As CancelRoomT,a.Sited_Days,a.Sited_LongFlag,a.Sited_TimeFlag,a.RoomBorrowTemp,
								DATEDIFF(HOUR,a.Cancel_Date,GetDate()) AS HadCancelHours,a.Sited_FreeFlag,a.Remarks,a.Room_BillState 
								FROM TR_Order_Room_List a,TR_Order_Inform b WHERE a.Order_No=b.Order_No AND b.Chain_No='%s' And a.Room_BillState=3 
								And a.Cancel_Date>DATEADD(day,%s,GetDate()) ORDER BY a.Cancel_Date DESC",$chainno,$intSubDaysTemp);
				$result = querySql($sql);		
				while($row = fetch_array($result))
				{	
					$strBListNo=$row['ListNo'];
					$strSelManName=$row['Man_Name'];
					$strselorderno=$row['Order_No'];
					$strselroomno=$row['Room_No'];
					$strselroomtype=$row['Room_Type'];
					$fltselroomprice=$row['RoomPrice'];
					$strselecttime=$row['SelectRoomT'];
					$strcanceltime=$row['CancelRoomT'];
					$strSelRemarks=trim($row['Remarks']);
					$intSelDays=$row['Sited_Days'];
					$lngHadCancelHours=$row['HadCancelHours'];
								
					$fltselroomprice=$fltselroomprice+0;
					$strRoomBorrowTemp=trim($row['RoomBorrowTemp']);
							
					$strTemp="日租";
					$intTemp=$row['Sited_LongFlag'];
					if($intTemp>0)
					{
						$strTemp="长包";
					}
					$intTemp=$row['Sited_TimeFlag'];
					if($intTemp>0)
					{
						$strTemp="钟点";
					}
					$intTemp=$row['Sited_FreeFlag'];
					if($intTemp>0)
					{
						$strTemp="免费";
					}
					$strBillState="在住";
					$intTemp=$row['Room_BillState'];
					//0预排,1预订,2入住,3退房,4取消
					if($intTemp==3)
					{
						$strBillState="退房";
					}
					//以下开始显示数据	
					
				?>
			<tr>
				<td height="20" width="10"></td>
				<td height="20" width="55">
					<span style="color: <?php echo $colTextColr1;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;font-weight: bold;"><?php echo $strselroomno;?></span>
				</td>
				<td height="20" align="left">
					<span style="color: <?php echo $colTextColr1;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo $strSelManName;?></span>
				</td>
				<td height="20" width="50" align="left">
					<span style="color: <?php echo $colTextColr1;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo $fltselroomprice;?></span>
				</td>
				<td height="20" width="40" align="left">
					<span style="color: <?php echo $colTextColr1;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo $strTemp;?></span>
				</td>
				<td height="20" width="40" align="center">
					<span style="color: <?php echo $colTextColr1;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo $intSelDays;?></span>
				</td>
				<td height="20" width="40" align="right">
					<span style="color: <?php echo $colTextColr1;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo $strBillState;?></span>
				</td>
				<td height="20" width="10"></td>
			</tr>

			<tr>
				<td height="20" width="10"></td>
				<td height="20" colspan="6">
					<span style="color: <?php echo $colTextColr;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo "单号：".$strselorderno;?></span>
				</td>
				<td height="20" width="10"></td>
			</tr>
			
			<tr>
				<td height="20" width="10"></td>
				<td height="20" colspan="3">
					<span style="color: <?php echo $colTextColr;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo "房型：".$strselroomtype;?></span>
				</td>
				<td height="20" colspan="3" rowspan="2" align="left">
					<?php 
						if($intCanReBackRoomFlag>0) 
						{
							//手机上操作恢复入住仅支持10小时内退房的
							if($lngHadCancelHours<=$intCanReCheckInHours)
							{
					?>
					<div onClick="bntShowMsg(<?php echo $strBListNo;?>,'<?php echo $strselroomno;?>');" style="width:80px;height:28px;border-radius:4px;top:0px;left:0px;background:linear-gradient(225deg, #379ffb 45%, #24d7ff 100%);">
						<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td height="100%" align="center">
									<span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;text-shadow:none;">恢复入住</span> 
								</td>
							</tr>
						</table>
					</div>
					<?php 
							}
						}
					?>
				</td>
				<td height="20" width="10"></td>
			</tr>
							
							
			<!--显示入住时间和天数-->
			<tr>
				<td height="20" width="10"></td>
				<td height="20" colspan="3">
					<span style="color: <?php echo $colTextColr;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo "入住：".$strselecttime;?></span>
				</td>
				<td height="20" width="10"></td>
			</tr>
			<tr>
				<td height="20" width="10"></td>
				<td height="20" colspan="6">
					<span style="color: <?php echo $colTextColr;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo "退房：".$strcanceltime;?></span>
				</td>
				<td height="20" width="10"></td>
			</tr>
							
			<?php if(strlen($strSelRemarks)>1)
				{
			?>
			<tr>
				<td height="20" width="10"></td>
				<td height="20" colspan="6">
					<span style="color: <?php echo $colTextColr;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo "备注：".$strSelRemarks;?></span>
				</td>
				<td height="20" width="10"></td>
			</tr>
			<?php } ?>
							
			<?php if(strlen($strRoomBorrowTemp)>1)
				{
			?>
			<tr>
				<td height="20" width="10"></td>
				<td height="20" colspan="6">
					<span style="color: <?php echo $colTextColr;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:13px;text-shadow:none;"><?php echo "提醒：".$strRoomBorrowTemp;?></span>
				</td>
				<td height="20" width="10"></td>
			</tr>
			<?php } ?>
				
			<tr><td height="5" colspan="8"></td></tr>
			<tr><td height="1" width="10"></td><td height="1" colspan="6"  bgcolor="#f0f0f0"></td><td height="1" width="10"></td></tr>
			<tr><td height="5" colspan="8"></td></tr>
			<?php
				}
				//释放数据库
				freeResult($result);
			?>
			
			<tr><td height="1" colspan="8"></td></tr>
			
		</table>
			
			
			
			
			<!-- 弹出窗体结构 -->
			<div id="openModalBtn" style="width:0px;height:0px;">
    <div id="modalOverlay" class="modal-overlay">
        <div id="modalContent" class="modal-content">
            <div class="modal-header">
                <span style="color: #fff;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:16px;text-shadow:none;font-weight: bold;">恢复入住</span>
                <button id="closeModalBtn" class="close-btn"><i class="fas fa-times">X</i></button>
            </div>
            <div class="modal-body">
				
				<div style="height:70px;width:100%;border-bottom: 1px solid #deecfb; padding-top:18px;">
					<span id="labMsgText" style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:16px;text-shadow:none;font-weight: bold;">确定要将该房间恢复为入住状态吗？</span>
				</div>
				
				
            <div class="modal-footer">
                <button class="btn-secondary" id="exportBtn" onClick="$('#closeModalBtn').click();"><i class="fas fa-download">&nbsp;&nbsp;&nbsp;取消&nbsp;&nbsp;&nbsp;</button>
                <button class="btn-primary" onClick="bntSetRoomCheckIn();"><i class="fas fa-plus"></i> 确定恢复入住</button>
            </div>
			
        </div>
    </div>
				
	</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 #fff;">
			<table width="100%" height="52" border="0" cellpadding="0" cellspacing="0" bgcolor="#fff">
				<tr height="100%" valign="middle" align="center">
					<td width="50%" style="border-top:1px solid #F3EDED;border-left:0px solid #F6F5F2;">
						<div style="width:100%;height:100%;padding-top:6px;">
							<div style="width:23px;height:24px;">
								<img src="images\p3_b.png" width="24" height="26" border="0">
							</div>
							<span style="color:#6a6a6a;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;padding-left:4px;">已退房</span>
						</div>
					</td>
					<td width="50%" style="border-top:1px solid #F3EDED;border-left:0px solid #F6F5F2;">
						<div onClick="window.location='rmroomordernoreckon2.php?chainno=<?php echo $chainno;?>';" style="width:100%;height:100%;padding-top:6px;">
							<div style="width:23px;height:24px;">
								<img src="images\p2_a.png" width="24" height="26" border="0">
							</div>
							<span style="color:#6a6a6a;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;padding-left:3px;">临时账</span>
						</div>
					</td>
				</tr>
			</table>	
	</footer>
	-->
	
	
	<script type="text/javascript">
		
		function bntShowMsg(lngBListNo,strRoomNo)
		{
			lngNowSelBListNo=lngBListNo;
			var labSpan1=document.getElementById("labMsgText");
			labSpan1.textContent= "确定要将 " + strRoomNo + " 恢复为入住状态吗？"
			
			$('#openModalBtn').click();
		};
		
		//将房间恢复入住
		function bntSetRoomCheckIn()
		{	
			//将数据封包成JSON
			const jsondata = {
					chainno: '<?php echo $chainno;?>',
					rblistno: lngNowSelBListNo
					};

			//用ajax的“同步方式”调用一般处理程序
			var strret='';
			$.ajax({
					url: "rmroomrecheckinsave.php",
					async: false,//改为同步方式
					type: "POST",
					data: jsondata,
					success: function (RetData) 
					{
						strret = RetData;
					}
				});
			
			//alert(strret);
				
			if(strret.length>2)
			{
				var strSubHead =strret.substr(0,3);
			
				if(strSubHead=="*1*")
				{
					//关闭界面
					$('#closeModalBtn').click();
					//成功
					window.location.href='repRoomView.php';
				}
				else if(strSubHead=="*2*")
				{
					alert("客房未退房或单据已结账，不能恢复入住！");
				}
				else if(strSubHead=="*3*")
				{
					alert("目标房间已被占用，不能恢复入住！");
				}
				else if(strSubHead=="*4*")
				{
					alert("房间有预排房信息，不能恢复入住！");
				} 
				else
				{
					alert("保存换房操作失败!");
				}
			}

		};
		
	</script>
		
		
</section>

</body>
</html>
