<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		*{list-style-type: none; margin: 0; padding: 0; font-size: 14px;}
		input{width: 60px;}
		button{padding: 5px 20px; cursor: pointer; border: 0;}
		li{display: block; width: 48%; float: left; height: 320px; border: 2px solid #ff6600;}
		dt{display: block; float: left; height: 100px; width: 150px; padding: 40px 10px; text-align: center;}
		dt span{font-size: 30px;}
		dd{display: block; float: left; height: 300px; width: 150px; padding: 10px; border-left: 1px solid #ccc;}
		.card-img{width: 30px; height: 42px; display: inline-block;}
		dd.card img{width: 100%; height: 100%;}
	</style>
</head>
<body>
<button onclick="logout()">退出登录</button><div>余分:<span id="money"></span></div>
<div>
	<ul>
		{foreach name="tables" item="v"}
		<li id="table_{$v.id}">
			<dl>
				<dt>{$v.table_name}({$v.id})<br><br><span id="time_{$v.id}" style="color: #129611">0</span></dt>
				<?php if($v['game_id'] == 1) : ?>
				<dd>
					<br>
					<select id="baccarat_type_{$v.id}">
						<option value="0" selected>baccarat_type_0</option>
						<option value="1">baccarat_type_1</option>
					</select>
					<br>
					<br>
					B：<input type="text" id="banker_{$v.id}"><br>
					P：<input type="text" id="player_{$v.id}"><br>
					T：<input type="text" id="tie_{$v.id}"><br>
					BP：<input type="text" id="banker_pair_{$v.id}"><br>
					PP：<input type="text" id="player_pair_{$v.id}"><br>
					LuckSix：<input type="text" id="luck_six_{$v.id}"><br>
					Big：<input type="text" id="big_{$v.id}"><br>
					Small：<input type="text" id="small_{$v.id}"><br>
				</dd>
				<dd>
					<input type="hidden" name="table_id" value="{$v.id}">
					<input type="hidden" name="boot_id" value="">
					<input type="hidden" name="number_tab_id" value="">
					X号：<span name="boot_num"></span>
					P号：<span name="number"></span>
					<br>
					<br>
					<button onclick="toBet({$v.id},{$v.game_id})" style="background-color: #129611; color: #fff;">toBet</button>
					<button onclick="cancelBet({$v.id},{$v.game_id})">cancelBet</button>
				</dd>
				<dd id="card_{$v.id}" class="card">
					<div class="player">
						<div class="card-img"><img id="table_{$v.id}_card_11" src="/static/poker/empty.png" /></div>
						<div class="card-img"><img id="table_{$v.id}_card_12" src="/static/poker/empty.png" /></div>
						<div class="card-img"><img id="table_{$v.id}_card_13" src="/static/poker/empty.png" /></div>
					</div>
					<div class="banker">
						<div class="card-img"><img id="table_{$v.id}_card_21" src="/static/poker/empty.png" /></div>
						<div class="card-img"><img id="table_{$v.id}_card_22" src="/static/poker/empty.png" /></div>
						<div class="card-img"><img id="table_{$v.id}_card_23" src="/static/poker/empty.png" /></div>
					</div>
				</dd>
				<?php elseif($v['game_id'] == 2) : ?>
				<dd>
					B：<input type="text" id="banker_{$v.id}"><br>
					P：<input type="text" id="player_{$v.id}"><br>
					T：<input type="text" id="tie_{$v.id}"><br>
				</dd>
				<dd>
					<input type="hidden" name="table_id" value="{$v.id}">
					<input type="hidden" name="boot_id" value="">
					<input type="hidden" name="number_tab_id" value="">
					X号：<span name="boot_num"></span>
					P号：<span name="number"></span>
					<br>
					<br>
					<button onclick="toBet({$v.id},{$v.game_id})" style="background-color: #129611; color: #fff;">toBet</button>
					<button onclick="cancelBet({$v.id},{$v.game_id})">cancelBet</button>
				</dd>
				<?php elseif($v['game_id'] == 4 || $v['game_id'] == 5) : ?>
				<dd>
					闲一平倍：<input type="text" id="amount_player_1_{$v.id}"><br>
					闲一翻倍：<input type="text" id="amount_player_1_times_{$v.id}"><br>
					<?php if($v['is_rob'] != 1) : ?>
					庄一平倍：<input type="text" id="amount_player_1_banker_{$v.id}"><br>
					庄一翻倍：<input type="text" id="amount_player_1_banker_times_{$v.id}"><br>
					<?php endif; ?>
					<br>
					闲二平倍：<input type="text" id="amount_player_2_{$v.id}"><br>
					闲二翻倍：<input type="text" id="amount_player_2_times_{$v.id}"><br>
					<?php if($v['is_rob'] != 1) : ?>
					庄二平倍：<input type="text" id="amount_player_2_banker_{$v.id}"><br>
					庄二翻倍：<input type="text" id="amount_player_2_banker_times_{$v.id}"><br>
					<?php endif; ?>
					<br>
					闲三平倍：<input type="text" id="amount_player_3_{$v.id}"><br>
					闲三翻倍：<input type="text" id="amount_player_3_times_{$v.id}"><br>
					<?php if($v['is_rob'] != 1) : ?>
					庄三平倍：<input type="text" id="amount_player_3_banker_{$v.id}"><br>
					庄三翻倍：<input type="text" id="amount_player_3_banker_times_{$v.id}"><br>
					<?php endif; ?>
				</dd>
				<dd>
					<input type="hidden" name="table_id" value="{$v.id}">
					<input type="hidden" name="boot_id" value="">
					<input type="hidden" name="number_tab_id" value="">
					靴号：<span name="boot_num"></span>
					铺号：<span name="number"></span>
					<br>
					<br>
					<?php if($v['is_rob'] == 1) : ?>
					<button onclick="toRob({$v.id},{$v.game_id})" style="background-color: #ff9900; color: #fff;">抢庄</button>
					<?php endif; ?>
					<button onclick="toBetNn({$v.id},{$v.game_id})" style="background-color: #129611; color: #fff;">下注</button>
					<button onclick="cancelBet({$v.id},{$v.game_id})">取消下注</button>
				</dd>
				<?php elseif($v['game_id'] == 6) : ?>
				<dd>
					0：<input type="text" id="toning_zero_{$v.id}"><br>
					4：<input type="text" id="toning_four_{$v.id}"><br>
					1：<input type="text" id="toning_one_{$v.id}"><br>
					3：<input type="text" id="toning_three_{$v.id}"><br>
					big：<input type="text" id="toning_big_{$v.id}"><br>
					small：<input type="text" id="toning_small_{$v.id}"><br>
					singular：<input type="text" id="toning_singular_{$v.id}"><br>
					plural：<input type="text" id="toning_plural_{$v.id}"><br>
				</dd>
				<dd>
					<input type="hidden" name="table_id" value="{$v.id}">
					<input type="hidden" name="boot_id" value="">
					<input type="hidden" name="number_tab_id" value="">
					X号：<span name="boot_num"></span>
					P号：<span name="number"></span>
					<br>
					<br>
					<button onclick="toBetToning({$v.id},{$v.game_id})" style="background-color: #129611; color: #fff;">toBet</button>
					<button onclick="cancelBet({$v.id},{$v.game_id})">cancelBet</button>
				</dd>
				<?php elseif($v['game_id'] == 7) : ?>
				<dd>
					<input type="hidden" name="table_id" value="{$v.id}">
					<input type="hidden" name="boot_id" value="">
					<input type="hidden" name="number_tab_id" value="">
					X号：<span name="boot_num"></span>
					P号：<span name="number"></span>
					<br>
					<br>
					<button onclick="toBetDice({$v.id},{$v.game_id})" style="background-color: #129611; color: #fff;">toBet</button>
					<button onclick="cancelBet({$v.id},{$v.game_id})">cancelBet</button>
				</dd>
				<?php elseif($v['game_id'] == 8) : ?>
				<dd>
					下注方式：
					<select id="roulette_type">
						<option value="european" selected>欧式</option>
						<option value="french">法式</option>
					</select>
				</dd>
				<dd>
					<input type="hidden" name="table_id" value="{$v.id}">
					<input type="hidden" name="boot_id" value="">
					<input type="hidden" name="number_tab_id" value="">
					X号：<span name="boot_num"></span>
					P号：<span name="number"></span>
					<br>
					<br>
					<button onclick="toBetRoulette({$v.id},{$v.game_id})" style="background-color: #129611; color: #fff;">toBet</button>
					<button onclick="cancelBet({$v.id},{$v.game_id})">cancelBet</button>
				</dd>
				<?php endif; ?>
			</dl>
		</li>
		{/foreach}
	</ul>
</div>
<script type="text/javascript" src="/static/handle/js/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="/static/handle/js/layer-v3.1.1/layer.js"></script>
<script type="text/javascript" src="/static/handle/js/socket.io-1.4.4.js"></script>
<script type="text/javascript">
	var websocketUrl="{$websocketUrl}";
    var websocketProtocol="{$websocketProtocol}";
	var api_token = "{$api_token}";

	var websocket = io(websocketProtocol+"://"+websocketUrl+"/?connect=user&userid={$user.id}&account={$user.username}&login_token={$login_token}",{transports: ['websocket']});
	var user_id = {$user.id};
	var username = "{$user.username}";
	var lang;
	websocket.on('reconnecting', (timeout) => {
		//触发重连
		layer.msg('服务断开,正在重新连接...', {
			icon: 16,
			shade: 0.6,
			time:0,
		});
	});
	websocket.on('reconnect', (timeout) => {
		//重连成功
		layer.closeAll();
		layer.msg('服务重新连接成功');
	});
	//事件返回 开始*********************************************************************************************************************
	websocket.on('onlineLogin',function(data){
		if(data.status === true){
			$('#money').html(data.money);
			//获取桌子状态
			forGetState();
		}else{
			layer.msg(lang[data.msg]);
		}
	});
	websocket.on('getState',function(data){
		if(data.status === true){
			setNumberTab(data);
			setCard(data);
		}
	});
	websocket.on('startRob',function(data){
		if(data.status === true){
			layer.msg('table_'+data.table_id+'_开始抢庄');
		}
	});
	websocket.on('startRobCountDown',function(data){
		if(data.status === true){
			$('#time_'+data.table_id).html(data.count_down);
		}
	});
	websocket.on('startBetCountDown',function(data){
		if(data.status === true){
			$('#time_'+data.table_id).html(data.count_down);
		}
	});
	websocket.on('endBet',function(data){
		if(data.status === true){
			$('#time_'+data.table_id).html(0);
		}
	});
	websocket.on('opening',function(data){
		if(data.status === true){
			$('#money').html(data.round.money);
		}
	});
	websocket.on('toBet',function(data){
		if(data.status === true){
			$('#money').html(data.money);
			layer.msg('下注成功');
		}else{
			layer.msg(lang[data.msg]);
		}
	});
	websocket.on('cancelBet',function(data){
		if(data.status === true){
			$('#money').html(data.money);
		}
		layer.msg(lang[data.msg]);
	});
	websocket.on('openingBaccaratResult',function(data){
		if(data.status === true){
			setNumberTab(data);
			// 清空牌
			var table_id = data.table_id;
			$('#card_' + table_id).find("img").attr("src", "/static/poker/empty.png");
			// http获取数据
			let query = {
				'table_id' : table_id,
				'user_id' : user_id,
				'api_token' : api_token,
				'number_tab_id' : data.round.previous_number_tab_id,
			}
			$.ajax({
				url:"http://api.fullofpeople.org/Pcapi/user_bet_baccarat",
				type:"POST",
				dataType:"JSON",
				async:false,
				data: query,
				success:function(data){
					console.log(data);
				}
			})
		}
	});
	websocket.on('openingDtResult',function(data){
		if(data.status === true){
			setNumberTab(data);
			// 清空牌
			var table_id = data.table_id;
			$('#card_' + table_id).find("img").attr("src", "/static/poker/empty.png");
			// http获取数据
			let query = {
				'table_id' : table_id,
				'user_id' : user_id,
				'api_token' : api_token,
				'number_tab_id' : data.round.previous_number_tab_id,
			}
			$.ajax({
				url:"http://api.fullofpeople.org/Pcapi/user_bet_dt",
				type:"POST",
				dataType:"JSON",
				async:false,
				data: query,
				success:function(data){
					console.log(data);
				}
			})
		}
	});
	websocket.on('openingNnResult',function(data){
		if(data.status === true){
			setNumberTab(data);
			// 清空牌
			var table_id = data.table_id;
			$('#card_' + table_id).find("img").attr("src", "/static/poker/empty.png");
		}
	});
	websocket.on('openingTcResult',function(data){
		if(data.status === true){
			setNumberTab(data);
			// 清空牌
			var table_id = data.table_id;
			$('#card_' + table_id).find("img").attr("src", "/static/poker/empty.png");
		}
	});
	websocket.on('openingToningResult',function(data){
		if(data.status === true){
			setNumberTab(data);
		}
	});
	websocket.on('openingDiceResult',function(data){
		if(data.status === true){
			setNumberTab(data);
		}
	});
	websocket.on('openingRouletteResult',function(data){
		if(data.status === true){
			setNumberTab(data);
		}
	});
	websocket.on('changeBoot',function(data){
		if(data.status === true){
			setNumberTab(data);
		}
	});
	websocket.on('resetBoot',function(data){
		if(data.status === true){
			setNumberTab(data);
		}
	});
	websocket.on('toRob',function(data){
		layer.msg(data.msg);
	});
	websocket.on('sendScanResult',function (data){
		var table_id = data.table_id;
		var round = data.round;
		$('#table_' + table_id + '_card_' + round.position).attr("src", "/static/poker/" + round.card + ".png");
	});
	//事件返回 结束*********************************************************************************************************************
	function toBet(table_id, game_id){
		var number_tab_id = $('#table_'+table_id).find('input[name="number_tab_id"]').val();
		if(game_id === 1){
			let banker_amount = $('#banker_'+table_id).val();
			let player_amount = $('#player_'+table_id).val();
			let tie_amount = $('#tie_'+table_id).val();
			let banker_pair_amount = $('#banker_pair_'+table_id).val();
			let player_pair_amount = $('#player_pair_'+table_id).val();
			let luck_six_amount = $('#luck_six_'+table_id).val();
			let big_amount = $('#big_'+table_id).val();
			let small_amount = $('#small_'+table_id).val();
			let baccarat_type = $('#baccarat_type_'+table_id).val();
			websocket.emit('toBet',{
				table_id:table_id,
				user_id:user_id,
				number_tab_id:number_tab_id,
				baccarat_type:baccarat_type,
				banker_amount:banker_amount,
				player_amount:player_amount,
				tie_amount:tie_amount,
				banker_pair_amount:banker_pair_amount,
				player_pair_amount:player_pair_amount,
				luck_six_amount:luck_six_amount,
				big_amount:big_amount,
				small_amount:small_amount,
			});
		}else if(game_id === 2){
			let banker_amount = $('#banker_'+table_id).val();
			let player_amount = $('#player_'+table_id).val();
			let tie_amount = $('#tie_'+table_id).val();
			websocket.emit('toBet',{
				table_id:table_id,
				user_id:user_id,
				number_tab_id:number_tab_id,
				banker_amount:banker_amount,
				player_amount:player_amount,
				tie_amount:tie_amount
			});
		}
	}
	function toBetNn(table_id, game_id){
		var number_tab_id = $('#table_'+table_id).find('input[name="number_tab_id"]').val();
		if(game_id === 4 || game_id === 5){
			var amount_player_1 = $('#amount_player_1_'+table_id).val();
			var amount_player_1_times = $('#amount_player_1_times_'+table_id).val();
			var amount_player_1_banker = $('#amount_player_1_banker_'+table_id).val();
			var amount_player_1_banker_times = $('#amount_player_1_banker_times_'+table_id).val();

			var amount_player_2 = $('#amount_player_2_'+table_id).val();
			var amount_player_2_times = $('#amount_player_2_times_'+table_id).val();
			var amount_player_2_banker = $('#amount_player_2_banker_'+table_id).val();
			var amount_player_2_banker_times = $('#amount_player_2_banker_times_'+table_id).val();

			var amount_player_3 = $('#amount_player_3_'+table_id).val();
			var amount_player_3_times = $('#amount_player_3_times_'+table_id).val();
			var amount_player_3_banker = $('#amount_player_3_banker_'+table_id).val();
			var amount_player_3_banker_times = $('#amount_player_3_banker_times_'+table_id).val();

			var event = 'toBet';
			websocket.emit(event,{
				table_id:table_id,
				user_id:user_id,
				number_tab_id:number_tab_id,

				amount_player_1:amount_player_1,
				amount_player_1_times:amount_player_1_times,
				amount_player_1_banker:amount_player_1_banker,
				amount_player_1_banker_times:amount_player_1_banker_times,

				amount_player_2:amount_player_2,
				amount_player_2_times:amount_player_2_times,
				amount_player_2_banker:amount_player_2_banker,
				amount_player_2_banker_times:amount_player_2_banker_times,

				amount_player_3:amount_player_3,
				amount_player_3_times:amount_player_3_times,
				amount_player_3_banker:amount_player_3_banker,
				amount_player_3_banker_times:amount_player_3_banker_times,
			});
		}
	}
	function toRob(table_id, game_id){
		var number_tab_id = $('#table_'+table_id).find('input[name="number_tab_id"]').val();
		websocket.emit('toRob',{table_id:table_id, user_id:user_id, number_tab_id:number_tab_id});
	}
	function toBetToning(table_id, game_id){
		var number_tab_id = $('#table_'+table_id).find('input[name="number_tab_id"]').val();

		var toning_zero = $('#toning_zero_'+table_id).val();
		var toning_four = $('#toning_four_'+table_id).val();
		var toning_one = $('#toning_one_'+table_id).val();
		var toning_three = $('#toning_three_'+table_id).val();

		var toning_big = $('#toning_big_'+table_id).val();
		var toning_small = $('#toning_small_'+table_id).val();
		var toning_singular = $('#toning_singular_'+table_id).val();
		var toning_plural = $('#toning_plural_'+table_id).val();

		var event = 'toBet';
		websocket.emit(event,{
			table_id:table_id,
			user_id:user_id,
			number_tab_id:number_tab_id,

			toning_zero:toning_zero,
			toning_four:toning_four,
			toning_one:toning_one,
			toning_three:toning_three,
			toning_big:toning_big,
			toning_small:toning_small,
			toning_singular:toning_singular,
			toning_plural:toning_plural,
		});
	}
	function toBetDice(table_id, game_id){
		var number_tab_id = $('#table_'+table_id).find('input[name="number_tab_id"]').val();
		var event = 'toBet';
		websocket.emit(event,{
			table_id:table_id,
			user_id:user_id,
			number_tab_id:number_tab_id,
			amount:{
				small:100,
				two_11:100,
				three_111:100,
				leopard:100,
				number_4:100,
				number_10:100,
				two_12:100,
				two_24:100,
				living_1:100,
				living_4:100,
				singular:100
			}
		});
	}

	function toBetRoulette(table_id, game_id){
		var number_tab_id = $('#table_'+table_id).find('input[name="number_tab_id"]').val();
		var event = 'toBet';
		var roulette_type = $('#roulette_type').val();
		if(roulette_type == 'european'){
			websocket.emit(event,{
				table_id:table_id,
				user_id:user_id,
				number_tab_id:number_tab_id,
				roulette_type:'european',
				amount:{
					'straight_8':100,
					'split_13-16':100,
					'street_4-5-6':100,
					'triple_0-2-3':100,
					'four_0-1-2-3':100,
					'corner_2-3-5-6':100,
					'line_4-5-6-7-8-9':100,
					'dozen_1':100,
					'column_1':100,
					'red':100,
					'odd':100,
					'low':100
				},
				french_amount:{}
			});
		}else {
			websocket.emit(event,{
				table_id:table_id,
				user_id:user_id,
				number_tab_id:number_tab_id,
				roulette_type:'french',
				amount:{
					'straight_8':100,
					'zeroGame': 40,
					'neighborsOfZero':90,
					'orphans': 50,
					'theThird':60

				},
				european_amount:{}
			});
		}
	}
	function cancelBet(table_id, game_id){
		var number_tab_id = $('#table_'+table_id).find('input[name="number_tab_id"]').val();
		websocket.emit('cancelBet',{table_id:table_id, user_id:user_id, number_tab_id:number_tab_id});
	}
	function setNumberTab(data){
		var table_id = data.table_id;
		$('#table_'+table_id).find('input[name="boot_id"]').val(data.round.boot_id);
		$('#table_'+table_id).find('span[name="boot_num"]').html(data.round.boot_num);
		$('#table_'+table_id).find('input[name="number_tab_id"]').val(data.round.number_tab_id);
		$('#table_'+table_id).find('span[name="number"]').html(data.round.number_tab_number);
	}
	function setCard(data) {
		var table_id = data.table_id;
		var showCard = data.round.show_card;
		if (showCard.length > 0) {
			for (var i = 0; i < showCard.length; i++) {
				$('#table_' + table_id + '_card_' + showCard[i].position).attr("src", "/static/poker/" + showCard[i].card + ".png");
			}
		}
	}
	function forGetState(){
		$('input[name="table_id"]').each(function(){
			var table_id = $(this).val();
			websocket.emit('getState',{table_id : table_id, userid : user_id});
		});
	}
	function logout(){
		window.location.href="/login/logout";
	}
	function getLang(){
		$.ajax({
			url:"/index/get_lang",
			type:"POST",
			dataType:"JSON",
			async:false,
			success:function(data){
				if(data.status == 1){
					lang = data.lang;
				}
			}
		})
	}
	$(function(){
		getLang();
	})
</script>
</body>
</html>
