<script type="text/javascript" src="/js/StationInfo.js"></script>
<!-- 调用接口查询订单信息 -->
<div style="width:90%;margin:30px auto;">
<div class="panel panel-primary" style="width:60%;margin:0 auto;">
		<div class="panel-heading">
			<h3 class="panel-title">订单状态</h3>
		</div>
		<div class="panel-body">
			<p>途牛订单号：<?php echo $data->orderId?>&nbsp;&nbsp;&nbsp;&nbsp;途牛订单状态：<?php echo $data->orderStatus?></p>
			<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>
			
		</div>
	</div>
</div>

<?php 
	//调用订单异步返回的信息
	//途牛订单状态接口查询不返回订单详细信息，只能在异步返回中查看，非常蛋疼。
	$info = json_decode($grab_callback);
	//print_r($info);
	//print_r($data);
	if($data->orderStatus == '抢票中'){ ?>
		<div style="width:90%;margin:30px auto;">
			<div class="panel panel-primary" style="width:60%;margin:0 auto;">
				<div class="panel-heading">	
					<h3 class="panel-title">途牛操作</h3>
				</div>
				<div class="panel-body">
					<p style="text-align:center;"><a href="#" tuniu_url="/cancelgrabTicket/<?php echo $data->retailOrderId.'/'.$data->orderId?>" style="padding:5px 15px;" class="btn btn-warning btn-sm cancelgrab">取消抢票 <span class="glyphicon glyphicon-forward"></span></a></p>
				</div>
			</div>
		</div>
<?php }else if($data->orderStatus == '出票成功'){ ?>
	<div style="width:90%;margin:30px auto;">
		<div class="panel panel-primary" style="width:60%;margin:0 auto;">
		  <div class="panel-heading">	
			<h3 class="panel-title"><?php echo $info->trainDate;?>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $info->cheCi;?>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo isset($info->orderNumber)?$info->orderNumber:"";?></h3>
		  </div>
		  <div class="panel-body">
				<p style="display:inline-block"><?php echo $info->fromStationName;?><span class="from_station_en"> </span><br><span class="start_time"></span></p><span class="glyphicon glyphicon-arrow-right"> </span><p style="display:inline-block"> <?php echo $info->toStationName;?><span class="to_station_en"> </span><br><span class="arrive_time"></span></p>
				<?php foreach ($info->passengers as $value){
					echo '<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>';
					echo '<p>'.$value->passengerName.'('.$value->piaoTypeName.')&nbsp;&nbsp;&nbsp;&nbsp;'.$value->zwName.'&nbsp;&nbsp;&nbsp;'.$value->cxin.'&nbsp;&nbsp;&nbsp;&nbsp;票价：￥'.$value->price.'<a href="#" tuniu_url="/cancel_ticket/'.$info->retailOrderId.'/'.$info->orderId.'/'.$value->ticketNo.'/" style="padding:5px 15px;" class="btn btn-warning btn-sm cancelticket pull-right">单人退票 <span class="glyphicon glyphicon-forward"></span></a></p>';
				}?>
				<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>
				<p style="text-align:center;"><a href="#" tuniu_url="/cancel_ticket/<?php echo $info->retailOrderId.'/'.$info->orderId?>" style="padding:5px 15px;" class="btn btn-warning btn-sm cancelticket">一键全退 <span class="glyphicon glyphicon-forward"></span></a></p>
		  </div>
		</div>
	</div>   
<script>
var StationInfoArr = StationInfo.split("@");
var StationNameArr = new Array();
var code_name = new Array();
var station_cn_en = new Array();
var form_data = {};
for (var i = 0; i < StationInfoArr.length; ++i) {
	StationNameArr.push(StationInfoArr[i].split("|"));
	code_name[StationNameArr[i][1]] = [StationNameArr[i][2]];
	station_cn_en[StationNameArr[i][3]] = StationNameArr[i][2];
}
$(function(){
	var from_station_en = code_name['<?php echo $info->data->fromStationCode;?>'];
	var to_station_en = code_name['<?php echo $info->data->toStationCode;?>'];
	var start_time = '<?php echo $info->data->trainDate.' '.$info->data->startTime;?>';
	var arrive_time = '<?php echo $info->data->trainDate.' '.$info->data->arriveTime;?>';
	$('.from_station_en').html('('+from_station_en+') ');
	$('.to_station_en').html('('+to_station_en+')');
	$('.start_time').html('('+start_time.substring(0,start_time.length-3)+')');
	$('.arrive_time').html('('+arrive_time.substring(0,arrive_time.length-3)+')');
});	
</script>	
<?php }?>
<script>
$(function(){
	$('.cancelgrab').click(function(){
		var cancel_url = $(this).attr('tuniu_url');
		var url = "<?php echo site_url('apps/train/tuniu_train')?>"+cancel_url;
		var THIS=$(this);
		$.ajax({
			url:url,
			beforeSend:function(data){
			  THIS.html("处理中...");
			  THIS.attr("disabled","disabled");
			},
			success:function(data){
			  THIS.removeAttr("disabled");
			  THIS.html("取消成功");
			  },
			dataType: "json", 
		});
	});
	
	$('.cancelticket').click(function(){
		var cancel_url = $(this).attr('tuniu_url');
		var url = "<?php echo site_url('apps/train/tuniu_train')?>"+cancel_url;
		var THIS=$(this);
		$.ajax({
			url:url,
			beforeSend:function(data){
			  THIS.html("处理中...");
			  THIS.attr("disabled","disabled");
			},
			success:function(data){
			  THIS.removeAttr("disabled");
			  THIS.html("退票成功");
			  },
			dataType: "json", 
		});
	});
});
</script>


