<div style="width:90%;margin:30px auto;">
	<div class="panel panel-primary" style="border-color: #337ab7;">
		<div class="panel-heading">
			<h3 class="panel-title">携程火车改签申请</h3>
		</div>

		<div class="panel-body">
			<div class="row">
				<form method="get">
					<div class="col-md-6">
						<input type="text" class="form-control" placeholder="请输入携程订单号" name="order" value="<?php echo $order?>"/>
					</div>
					<div class="col-md-6">
						<button type="submit" id="sub" class="btn btn-success btn-sm">
							<span class="glyphicon glyphicon-search"></span> 获取订单信息
						</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	<?php if(!empty($detail)){ ?>	
	<div class="panel panel-primary" style="border-color: #337ab7;">
		<div class="panel-heading">
			<h3 class="panel-title">火车数据详情</h3>
		</div>
	
		<div class="panel-body">
			<div class="row">
				<div class="col-md-4">
					<div class="form-group form-inline">
						<label for="exampleInputName2">订单号</label>
						<input style="width:161px;" type="text" class="form-control" name="ordernumber" value="<?php echo $detail['0']->ts_ordernumber; ?>" readonly>
					</div>
				</div>
				<div class="col-md-3 form-inline">
					<div class="form-group">
						<label>出发城市</label>
						<input style="width:85px;" type="text" class="form-control" name="departcity" value="<?php echo $detail['0']->ts_fromstationame; ?>" />
					</div>
				</div>
				<div class="col-md-3 form-inline">
					<div class="form-group">
						<label>到达城市</label>
						<input style="width:85px;" type="text" class="form-control" name="arrivecity" value="<?php echo $detail['0']->ts_tostationame; ?>" />
					</div>
				</div>
				<div class="col-md-4 form-inline">
					<div class="form-group">
						<label>出发时间</label>
						<input style="width:140px" type="text" class="form-control" name="departime" value="<?php echo $detail['0']->ts_startdate.' '.$detail['0']->ts_startime; ?>"  />
					</div>
				</div>
				
				<div class="col-md-4 form-inline">
					<div class="form-group">
						<label>到达时间</label>
						<input style="width:140px" type="text" class="form-control" name="arrivetime" value="<?php echo $detail['0']->ts_startdate.' '.$detail['0']->ts_endtime; ?>" />
					</div>
				</div>
				
				<div class="col-md-3 form-inline">
					<div class="form-group">
						<label>车次</label>
						<input style="width:80px" type="text" class="form-control" name="checi" value="<?php echo $detail['0']->ts_checi ?>" />
					</div>
				</div>
				
				<div class="col-md-3 form-inline">
					<div class="form-group">
						<label>票价</label>
						<input style="width:80px" type="text" class="form-control" name="price" value="<?php echo $detail['0']->tst_ticketprice ?>" readonly />
					</div>
				</div>
			</div>
			<hr>
			<?php 
				foreach ($detail as $passpagerItems){
			?>
				<div class="row">
					<div class="col-md-1">
						<div>
							<input style="margin-top:15px" type="checkbox" class="singleselect">
						</div>
					</div>
					
					<div class="col-md-4 form-inline">
						<div class="form-group">
							<label>姓名</label>
							<input style="width:150px;" type="text" name="passgername[]" class="form-control" value="<?php echo $passpagerItems->tst_realname?>" readonly>
						</div>
					</div>
					
					<div class="col-md-3 form-inline">
						<div class="form-group">
							<label>车票类型</label>
							<input style="width:80px;" type="text" name="ticketype[]" class="form-control" value="<?php echo $passpagerItems->tst_ticketype?>" readonly>
						</div>
					</div>
					
					<div class="col-md-3 form-inline">
						<div class="form-group">
							<label>证件类型</label>
							<input style="width:85px;" type="text" name="identitytype[]" class="form-control" value="<?php echo $passpagerItems->tst_identitytype?>" readonly>
						</div>
					</div>
					
					<div class="col-md-5 form-inline">
						<div class="form-group">
							<label>乘客证件号码</label>
							<input style="width:150px;" type="text" name="passagerid[]" class="form-control" value="<?php echo $passpagerItems->tst_numberid ?>" readonly>
						</div>
					</div>
					
					<div class="col-md-3 form-inline">
						<div class="form-group">
							<label>座位类型</label>
							<input style="width:80px;" type="text" name="seatype[]" class="form-control" value="<?php echo $passpagerItems->tst_seatstype ?>" />
						</div>
					</div>
					
					<?php 
						$coachLength = strrpos($passpagerItems->tst_seatdetail,'车厢');
						$coach = mb_substr($passpagerItems->tst_seatdetail,0,$coachLength);
						$seat = mb_substr($passpagerItems->tst_seatdetail,$coachLength+2,mb_strlen($passpagerItems->tst_seatdetail));
					?>
					<div class="col-md-2 form-inline">
						<div class="form-group">
							<label>车厢</label>
							<input style="width:50px;" type="text" name="coach[]" class="form-control" value="<?php echo $coach ?>" readonly>
						</div>
					</div>
					<div class="col-md-3 form-inline">
						<div class="form-group">
							<label>座位号</label>
							<input style="width:80px;" type="text" name="seat[]" class="form-control" value="<?php echo $seat ?>" readonly>
						</div>
					</div>
				</div>
				<hr>
			<?php } ?>
			
			<div class="row" style="margin-top:20px;">
				<!--<div class="col-md-2">
					<button class="btn btn-success checked_pay">一键改签</button>
				</div>-->
				<div class="col-md-3">
					<button class="btn btn-success" id="reschedule_select">单个改签</button>
				</div>
			</div>
		</div>
		
	</div>
	<?php } ?>
</div>

<script>
$(function(){
	//发起改签流程
	$('#reschedule_select').click(function(){
		//获取改签所需要的数据
		var ordernumber = $('input[name="ordernumber"]').val();
		var departcity = $('input[name="departcity"]').val();
		var arrivecity = $('input[name="arrivecity"]').val();
		var departime = $('input[name="departime"]').val();
		var arrivetime = $('input[name="arrivetime"]').val();
		var checi = $('input[name="checi"]').val();
		var price = $('input[name="price"]').val();
		
		//判断是否有勾选改签的乘客
		if($('.singleselect').is(':checked')){
			var passgername = [];
			$('input[name="passgername[]"]').each(function(index,elements){
				if($(this).hasClass('selecting')){
					passgername.push(elements.value);
				}
				
			});
			
			var ticketype = [];
			$('input[name="ticketype[]"]').each(function(index,elements){
				if($(this).hasClass('selecting')){
					ticketype.push(elements.value);
				}
				
			});
			
			var identitytype = [];
			$('input[name="identitytype[]"]').each(function(index,elements){
				if($(this).hasClass('selecting')){
					identitytype.push(elements.value);
				}
			});
			
			var passagerid = [];
			$('input[name="passagerid[]"]').each(function(index,elements){
				if($(this).hasClass('selecting')){
					passagerid.push(elements.value);
				}
			});
			
			var seatype = [];
			$('input[name="seatype[]"]').each(function(index,elements){
				if($(this).hasClass('selecting')){
					seatype.push(elements.value);
				}
			});
			
			var coach = [];
			$('input[name="coach[]"]').each(function(index,elements){
				if($(this).hasClass('selecting')){
					coach.push(elements.value);
				}
			});
			
			var seat = [];
			$('input[name="seat[]"]').each(function(index,elements){
				if($(this).hasClass('selecting')){
					seat.push(elements.value);
				}
			});
			
			//发起异步提交
			$.ajax({
				url:'/info.php/apps/trainsystem/reschedule/ctripModel',
				type:"POST",
				data:{
					orderNumber:ordernumber,
					DepartStationName:departcity,
					ArriveStationName:arrivecity,
					RescheduleDepartTime:departime,
					RescheduleArriveTime:arrivetime,
					RescheduleTrainNumber:checi,
					RescheduleTicketPrice:price,
					PassagerName:passgername,
					Ticketype:ticketype,
					IdentityType:identitytype,
					PassagerId:passagerid,
					RescheduleSeatName:seatype,
					Coach:coach,
					Seat:seat	
				},
				beforeSend:function(){
					$('#reschedule_select').html('改签请求已发送...');
					$('#reschedule_select').addClass('disabled');
				},
				success:function(json,status){
					var data = $.parseJSON(json);
					alert(data.Discription);
					$('#reschedule_select').html('单个改签');
					$('#reschedule_select').removeClass('disabled');
				}
			});
		}else{
			alert('请勾选乘客！');
		}
		
	});
	
	//选择功能
	$('.singleselect').click(function(){
		var selectpassager = $(this).parent().parent().parent();
		if($(selectpassager).find('input').hasClass('selecting')){
			$(selectpassager).find('input').removeClass('selecting');
		}else{
			$(selectpassager).find('input').addClass('selecting');
		}
	});
	
});
</script>
