<?php
require "common.php";
$m=file_get_contents("php://input");if($m=="")$m='{"act":"index"}';$m=Dec($m,true);
if($m["act"]!="index"){$nid=$m["nid"];if(!is_numeric($nid)||$nid*1==0)die('{"msg":"Error Shop ID."}');}
switch($m["act"]){
	case "cfg"://设置
	$p=["msg"=>"ok","Sb"=>[],"Sd"=>[]];
	$q=Qry("Select ID,Bn,Bp From ".$pre."class Where Bh=0 And Si=".$nid." Order By Br Asc");
	while($r=Qra($q))$p["Sb"][]=$r;
	$q=Qry("Select ID,Dn,Dc,Ds,Di,Dm,Dk,Dh From ".$pre."foods Where Dh=0 And Si=".$nid." Order By Dr Asc");
	while($r=Qra($q))$p["Sd"][]=$r;
	$r=Qra(Qry("Select Sn,Sc,Sh From ".$pre."shop Where Si=".$nid));
	if($r["Sh"]>0)die('{"msg":"该店已暂停歇业！"}');
	$p["Sc"]=Dec($r["Sc"]);$p["Sn"]=$r["Sn"];
	echo Enc($p);
	break;

	case "fpp"://排号
	$f=Dec(file_get_contents("images/".$nid."/d.txt"));
	$c=$f["ph"];$j=-1;$k=0;
	for($i=0;$i<count($c);$i++){$j++;if($c[$i][0]*1==$m["Pi"]*1){$k=1;break;}}
	echo '{"msg":"ok","Pu":'.($k?$j:0).'}';
	break;

	default:
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=360, initial-scale=1, user-scalable=yes">
<script type="text/javascript">document.write('<meta name="viewport" content="width=360, initial-scale='+parseInt(document.documentElement.clientWidth)/360+', user-scalable=yes">');</script>
<title>排队预点</title>
<style type="text/css">
html,body {margin:0px;padding:0px;font-size:16px;}
a:link,a:visited {color:#09F;text-decoration:none;}
a:hover,a:active {color:#F00;text_decoration:underline;}
input[type=text],input[type=date],input[type=number],input[type=password],textarea,select {padding:3px;font-size:16px;resize:none;}
#msk {position:fixed;width:360px;left:0px;top:0px;background-color:#000;opacity:0.2;z-index:9;display:none;}
#tip {position:fixed;max-width:300px;background-color:#000;color:#FFF;padding:5px 10px;z-index:99;display:none;}
#cfn {position:fixed;background-color:#FFF;padding:20px;width:280px;border:1px solid #CCC;line-height:24px;box-shadow:2px 2px 2px #666;display:none;z-index:98;}
.bn0 {display:inline-block;line-height:24px;padding:0px 6px;border:1px solid #CCC;text-align:center;cursor:pointer;}
.bn1 {display:inline-block;line-height:24px;padding:0px 6px;border:1px solid #CCC;background-color:#09F;color:#FFF;text-align:center;cursor:pointer;}
.btn {display:inline-block;line-height:28px;text-align:center;font-size:16px;padding:0px 8px;margin:0px 5px;background-color:#F90;color:#FFF;border-radius:5px;box-shadow:2px 2px 2px #CCC;}
.bnc {float:right;line-height:22px;text-align:center;width:22px;border:1px solid #FFF;color:#FFF;margin:4px 0px;}
.fld {position:absolute;width:320px;left:0px;top:0px;display:none;background-color:#FFF;box-shadow:2px 2px 2px #666;}
.flt {line-height:32px;background-color:#F90;color:#FFF;padding:0px 10px;}
.flb {padding:10px;line-height:32px;font-size:16px;}
.flk {line-height:32px;background-color:#FEF7E7;text-align:right;padding:0px 10px;}
.bl0 {margin:2px 0px 2px 2px;line-height:25px;border:1px solid #F90;text-align:center;font-size:14px;border-right:0px;border-top-left-radius:5px;border-bottom-left-radius:5px;}
.bl1 {margin:2px 0px 2px 2px;line-height:25px;border:1px solid #F90;text-align:center;font-size:14px;background-color:#F90;color:#FFF;border-right:0px;border-top-left-radius:5px;border-bottom-left-radius:5px;}
.dl0 {margin:4px;padding:4px;background-color:#FFE;border:1px dashed #FDA;line-height:28px;font-size:14px;}
.dl1 {width:256px;height:144px;overflow:hidden;background-image:url(images/none.jpg);}
.dl2 {float:right;font-size:28px;width:28px;height:28px;line-height:28px;text-align:center;background-color:#F90;color:#FFF;}
.dl3 {font-size:24px;color:#F00;}
.sl1 {margin:2px 5px;border-bottom:1px dashed #CCC;line-height:36px;}
.sl2 {display:inline-block;width:234px;}
.sl3 {display:inline-block;width:40px;height:23px;font-size:12px;text-align:right;overflow:hidden;}
.sl4 {display:inline-block;width:16px;line-height:16px;border-radius:3px;background-color:#F90;color:#FFF;text-align:center;margin-left:4px;}
.sl5 {display:inline-block;width:16px;line-height:16px;text-align:center;margin-left:4px;font-size:12px;}
.sl6 {color:#09F;font-size:11px;}
.kw0 {display:inline-block;line-height:24px;border:1px dashed #F90;background-color:#F90;color:#FFF;margin:3px;padding:0px 5px;text-align:center;}
.kw1 {display:inline-block;line-height:24px;border:1px dashed #F90;background-color:#FFFCF9;margin:3px;padding:0px 5px;text-align:center;}
.dcb {float:right;width:24px;line-height:24px;font-size:24px;text-align:center;border:1px solid #F90;border-radius:4px;margin-top:7px;color:#F90;}
marquee a:link,marquee a:visited {color:#FFF;}
</style>
<script type="text/javascript">
function $(o){return document.getElementById(o);}function $$(o){return document.getElementsByName(o);}
function xml(u,p,f){var x;try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(f){x=false;}}if(!x&&typeof XMLHttpRequest!='undefined'){x=new XMLHttpRequest();}if(!x){alt('创建XHR对象失败！');return;}x.open(p?'Post':'Get',u,true);x.setRequestHeader('Content-Type','application/json;');x.onreadystatechange=function(){if(x.readyState==4&&x.status==200){try{var s=JSON.parse(x.responseText.replace(/\&\#32;/gi,' ').replace(/\&\#34;/gi,'&quot;').replace(/\&\#37;/gi,'%').replace(/\&\#39;/gi,'\''));if(s.msg!='ok'){alt(s.msg);return;}}catch(e){alt('响应JSON解析错误！\n'+x.responseText+'\n'+e);return;}f(s);}};x.send(p?JSON.stringify(p):null);}
function rnd(n,c){var s='';for(var i=0;i<(n||16);i++)s+='1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'.substr(Math.floor((c?10:62)*Math.random()),1);return s;}
function num(n){var o=event.srcElement;if(o.tagName=='INPUT'&&(o.type=='text'||o.type=='number')){if(!n)n=0;var v=parseFloat(o.value);if(!v)v=0;v=Math.round(v*Math.pow(10,n))/Math.pow(10,n);o.value=v;}}
function sck(n,v){var d=new Date();d.setTime(d.getTime()+1080000000);document.cookie=n+'='+encodeURI(v)+'; expires='+d.toGMTString();}
function gck(n){var c=document.cookie.split("; ");for(var i=0;i<c.length;i++){var t=c[i].split("=");if(t[0]==n)return decodeURI(t[1]);}return '';}
function css(n){for(var i=0;i<document.styleSheets.length;i++){var r=document.styleSheets[i].cssRules?document.styleSheets[i].cssRules:document.styleSheets[i].rules;for(var j=0;j<r.length;j++){if(r[j].selectorText==n)return r[j].style;}}}
function psz(o,s){var w=o.width;var h=o.height;if(w<h){h=h*s/w;w=s;}else{w=s*w/h;h=s;}o.width=w;o.height=h;o.style.margin=(s-h)/2+'px '+(s-w)/2+'px';}
function bsz(o,w,h){w=parseInt(w);h=parseInt(h)-4;var s=w>h?w:h;psz(o,s);}
function fio(m,n,o){if(o&&o!=1){o=o.split(',');for(var i=0;i<o.length;i++)$(o[i]).style.display='none';}o=o?1:0;$(m).style.display='block';if(o)msk.style.display='block';var c=Math.round(parseFloat($(m).style.opacity||(n>0?0:1))*100)/100;c+=0.1*n;if(c<=1&&c>0){$(m).style.opacity=c;if(o)msk.style.opacity=c/5;$(m).style.left=(pw-parseInt($(m).offsetWidth))/2+'px';$(m).style.top=(ph-parseInt($(m).offsetHeight))/2+20-c*20+'px';setTimeout('fio(\''+m+'\','+n+','+o+')',20);}if(c==0){$(m).style.display='none';if(o)msk.style.display='none';}}
function alt(n){tip.innerText=n;if(tip.style.display=='block')return;fio('tip',1);setTimeout(function(){fio('tip',-1);},2000);}
function cfm(n,s,c){var m=msk.style.display=='block'?false:1;msk.style.zIndex=97;cfn.innerHTML=n.replace(/\n/gi,'<br>')+'<div style="text-align:right;"><br><span id="cfc" class="bn0">取消</span>　<span id="cfs" class="bn1">确定</span></div>';cfc.addEventListener('click',function(){fio('cfn',-1,m);msk.style.zIndex=9;if(c)c();});cfs.addEventListener('click',function(){fio('cfn',-1,m);msk.style.zIndex=9;s();});fio('cfn',1,m);}
//----------------------------------------------------------------
var uri='guest3.php';
var nid='<?php echo Req("i");?>';
var pid='<?php echo Req("n");?>';
var pw,ph,Sc,Sb,Sd,Mc;
//布局
function rsz(){pw=parseInt(document.documentElement.clientWidth);ph=parseInt(document.documentElement.clientHeight);if(pw>360)pw=360;msk.style.width=pw+'px';msk.style.height=ph+'px';Lb_0.style.height=ph-100-(Da.style.display=='none'?0:24)+'px';Ld.style.height=ph-100-(Da.style.display=='none'?0:24)+'px';AD.style.top=(ph-480)/2+'px';Fi.style.height=ph-20+'px';Fd_l.style.height=ph-172+'px';setTimeout('rsz()',500);}
function jsn(x){return {act:x,nid:nid,rnd:rnd(6)};}
function cfg(){var p=jsn('cfg');xml(uri,p,function(r){Sc=r.Sc;Sb=r.Sb;Sd=r.Sd;Sn.innerText=r.Sn;document.title=r.Sn+' - 排队预点';Da_t.innerHTML=Sc.i[15].replace(/\&quot;/gi,'"');Da.style.display=Sc.i[15]==''?'none':'block';AD.innerHTML=Sc.i[16].replace(/\&quot;/gi,'"')+'<div style="font-size:12px;text-align:center;" onclick="AD.style.display=\'none\';">关闭</div>';AD.style.display=Sc.i[16].indexOf(' on ')<0?'none':'block';var n=gck('Jir_PreOdr');if(n!=''){Mc=JSON.parse(n);fds();}else Mc=[];fcb(0);fpp();});}
//分类
function fcb(n){var s='';for(var i=0;i<Sb.length;i++){if(Sb[i].Bp*1==n)s+='<div id="Db_'+Sb[i].ID+'" class="bl1" onClick="fcb('+Sb[i].ID+');">'+Sb[i].Bn+'</div><div id="Lb_'+Sb[i].ID+'" style="margin-left:6px;"></div>';}$('Lb_'+n).innerHTML=$('Lb_'+n).innerHTML==''?s:'';n?fcd(n):fcb(Sb[0].ID);}
//菜类
function fcd(n,m){for(var i=0;i<Sb.length;i++){if($('Db_'+Sb[i].ID))$('Db_'+Sb[i].ID).className='bl1';}$('Db_'+n).className='bl0';var s='';for(var i=0;i<Sd.length;i++){if(Sd[i].Dc.indexOf(','+n+',')>-1)s+='<div class="dl0"><div class="dl1" onclick="fci('+i+');"><img src="images/'+(Sd[i].Di*1==1?(nid+'/c'+Sd[i].ID+'.jpg'):'none.jpg')+'" onload="psz(this,256);"></div>'+Sd[i].Dn+'<br>￥ <span class="dl3">'+Sd[i].Dm/100+'</span><div class="dl2" onclick="fca('+i+');">+</div></div>';}Ld.innerHTML=s;}
//大图
function fci(n){if(Sd[n].Di*1==0)return;fio('Fi',1,1);Fi_t.style.display='block';Fi_t.innerHTML='<span style="font-size:20px;font-weight:bold;">'+Sd[n].Dn+'</span>'+(Sd[n].Ds==''?'':('<br>　　'+Sd[n].Ds));Fi.innerHTML='<img src="images/'+nid+'/c'+Sd[n].ID+'.jpg" onload="bsz(this,256,144);">';}
//点单
function fca(n){if(Sd[n].Dk.split(',').length>1){fws(Sd[n].Dn,-n-1,Sd[n].Dk);}else fce(n,1,'');}
function fce(n,s,k){var c=0;for(var i=0;i<Mc.length;i++){if(Mc[i][0]*1==Sd[n].ID&&Mc[i][5]==k){Mc[i][3]++;c=1;}}if(!c)Mc.push([Sd[n].ID,Sd[n].Dn,Sd[n].Dm,s,Sd[n].Di,k]);fds();}
//口味
function fws(o,n,w){var k;if(n>-1){var m=Mc[n][0];for(var i=0;i<Sd.length;i++){if(m*1==Sd[i].ID*1)k=Sd[i].Dk;}if(!k)return;}else k=w;var s='';var t=k.split(',');for(var j=0;j<t.length;j++)s+='<span class="kw'+((','+Mc[n]).indexOf(','+t[j]+',')>-1?0:1)+'" onclick="fwc(this);">'+t[j]+'</span>';Fk_s.innerHTML=s;Fk_i.value=n;Fk_c.value=n<0?'':mdc[n][5];Fk_n.innerText=o;fio('Fk',1);}
//味选
function fwc(o){if(o.className=='kw1'){o.className='kw0';Fk_c.value+=(o.innerText+',');}else{o.className='kw1';Fk_c.value=(','+Fk_c.value).replace(','+o.innerText+',',',').substr(1);}}
//已点
function fds(n){var s='';for(var i=0;i<Mc.length;i++)s+='<div class="sl1"><span class="sl2">'+Mc[i][1]+'<span class="sl6" onclick="fws(\''+Mc[i][1]+'\','+i+');">['+(Mc[i][5]==''?'口味':Mc[i][5].substr(0,Mc[i][5].length-1))+']</span></span><span class="sl3">'+Mc[i][2]/100+'元</span><span class="sl4" onclick="fdc('+i+',-1,'+Mc[i][0]+',\''+Mc[i][5]+'\');">-</span><span id="Fd_c'+i+'" class="sl5">'+Mc[i][3]+'</span><span class="sl4" onclick="fdc('+i+',1,'+Mc[i][0]+',\''+Mc[i][5]+'\');">+</span></div>';Fd_l.innerHTML=s;var c=0;var s=0;for(var i=0;i<Mc.length;i++){s+=Mc[i][2]*Mc[i][3];c+=Mc[i][3]*1;}Dm.innerText=s/100;Dn.innerText=c;if(n){if(Mc.length==0){fio('Fd',-1);sck('Jir_PreOdr','');}else fio('Fd',1);}}
//数量
function fdc(o,n,r,k){var m=$('Fd_c'+o).innerText*1;m+=n;$('Fd_c'+o).innerText=m;Mc[o][3]=m;if(m==0){for(var i=0;i<Mc.length;i++){if(Mc[i][0]*1==r*1&&Mc[i][5]==k)Mc.splice(i,1);}}fds(1);}
//排队
function fpp(){var p=jsn('fpp');p.Pi=pid;xml(uri,p,function(r){Sm.innerText='排号：'+pid+' [前面有 '+r.Pu+' 组客人]';setTimeout('fpp()',20000);});}
</script>
</head>
<body onLoad="rsz();cfg();">
<div id="msk"></div><div id="tip"></div><div id="cfn"></div>
<!--顶部-->
<div style="position:absolute;z-index:1;top:0px;left:0px;width:360px;height:50px;background-color:#666;">
  <div style="float:left;margin:3px;width:44px;height:44px;"><img src="images/icon.png" width="44" height="44"></div>
  <div style="float:left;color:#FFF;font-size:18px;line-height:20px;margin-top:6px;"><span id="Sn"></span><br><span id="Sm" style="font-size:14px;"></span></div>
  <div style="float:right;width:45px;line-height:30px;text-align:center;margin:10px 5px;background-color:#F90;color:#FFF;" onClick="window.location='weixin.php';">会员</div>
</div>
<!--底部-->
<div style="position:absolute;z-index:2;bottom:0px;left:0px;line-height:50px;width:360px;height:50px;font-size:18px;color:#FFF;background-color:#333;clear:both;">
  <div style="float:left;width:50px;height:50px;background-image:url(images/cart.png);line-height:18px;margin-right:10px;" onClick="if(Mc.length>0)fds(1);"><span id="Dn" style="font-size:12px;display:inline-block;background-color:#F90;color:#FFF;height:18px;width:18px;text-align:center;margin:3px;border-radius:3px;">0</span></div>
  <div style="float:right;width:90px;background-color:#F90;color:#FFF;text-align:center;font-size:24px;" onClick="if(Mc.length>0){if(Fd.style.display=='none'){fds(1);}else{sck('Jir_PreOdr',JSON.stringify(Mc));alt('预点餐品成功！点餐信息已暂存至您的手机中。\n请稍后入座后扫描餐桌二维码正式下单！');}}">预 点</div><span id="Dm" style="font-size:32px;color:#F90;">0</span> 元
</div>
<!--菜单-->
<div style="position:absolute;z-index:3;top:50px;left:0px;width:360px;">
  <div id="Da" style="width:360px;height:24px;background-color:#F90;color:#FFF;top:50px;border-radius:12px;display:none;"><div style="float:right;width:20px;text-align:center;" onClick="Da.style.display='none';">×</div><marquee style="float:left;width:320px;margin:0px 10px;" id="Da_t"></marquee></div>
  <div id="Lb_0" style="float:left;width:85px;border-right:1px solid #F90;overflow:auto;"></div>
  <div id="Ld" style="float:left;width:274px;overflow:auto;">正在加载，请稍候......</div>
</div>
<!--大图-->
<div id="Fi_t" style="position:absolute;width:320px;left:20px;bottom:20px;color:#FFF;z-index:12;display:none;font-size:14px;text-shadow:2px 2px 2px #666;"></div>
<div id="Fi" style="position:absolute;width:340px;left:10px;top:10px;background-color:#FFF;overflow:auto;z-index:11;display:none;" onClick="fio('Fi',-1,'Fi_t');"></div>
<!--点单-->
<div id="Fd" style="position:absolute;z-index:4;top:55px;left:0px;width:348px;border:1px solid #CCC;background-color:#FFF;display:none;">
  <div style="margin:0px 5px;line-height:39px;border-bottom:1px solid #CCC;text-align:center;font-size:18px;"><div class="dcb" onClick="fio('Fd',-1);">×</div>预点餐品</div>
  <div id="Fd_l" style="overflow:auto;"></div>
  <div style="line-height:25px;text-align:center;font-size:12px;">备注：<input type="text" id="ddb" style="width:290px;font-size:12px;"></div>
</div>
<!--口味-->
<div id="Fk" class="fld" style="width:320px;height:212px;z-index:30;">
  <div class="flt"><div class="bnc" onClick="fio('Fk',-1);">×</div>选择口味</div>
  <div class="flb" style="height:128px;">菜品： <span id="Fk_n"></span><br><span id="Fk_s"></span></div>
  <div class="flk"><input type="hidden" id="Fk_i"><input type="hidden" id="Fk_c"><span class="btn" onClick="if(Fk_i.value*1>-1){Mc[Fk_i.value][5]=Fk_c.value;}else fce(-1*Fk_i.value-1,1,Fk_c.value);fio('Fk',-1);fds(Fd.style.display=='none'?0:1);">确定</span></div>
</div>
<!--广告-->
<div id="AD" style="position:absolute;width:320px;height:480px;z-index:33;left:20px;background-color:#FFF;display:none;" onClick="AD.style.display='none';"></div>
</body>
</html>
<?php
}
?>