<template>
	<div>
		<div class="query-box" style="border-bottom: none;">
		<ul>
				<li><span><em>{{$t('advmanager.v_xilie')}}</em>
						<el-select  v-model="msg.LineteamId" filterable :placeholder="$t('pub.pleaseSel')">
			            <el-option :label="$t('pub.unlimitedSel')" value='-1'></el-option>
			            <el-option
			                v-for="item in LineTeamList"
			                :label='item.LtName'
			                :value='item.LtID'
			                :key='item.LtID'>
			            </el-option>
			        </el-select>
				</span>
				</li>
				<li>
					<span>
						<em>{{$t('visa.v_tuanhao')}}</em><el-input v-model='msg.TCNUM'  ></el-input>
					</span>
				</li>	
				<li><span><em>{{$t('sm.Date')}}</em><el-date-picker v-model='msg.StartDate' class='w135' @default-value="msg.StartDate" value-format="yyyy-MM-dd" type="date"></el-date-picker>
										-
		                            <el-date-picker v-model='msg.EndDate'  class='w135' @default-value="msg.EndDate" value-format="yyyy-MM-dd" type="date"></el-date-picker>
		            </span>
				</li>		
				<li>
					<input type="button" class="normalBtn" :value="$t('pub.searchBtn')"  @click="getList();resetPageIndex()"/>
				</li>
					<li>
					<input type="button" class="normalBtn" :value="$t('adm.adm_download')"  @click="DownLoadFile()"/>
				</li>
		</ul>				
	</div>
	
	<div style="width: 100%;  overflow-x: auto;padding-bottom: 10px; margin-top: 10px; " class="ownScrollbarStyle">
		<table  style="width: 100%;" border="0" cellspacing="1" cellpadding="0" class="busStatisticsTalbe"  v-loading='loading'>
			<tr>
				<th width="5%">{{$t('active.ad_xuhao')}}</th>
				<th width="5%">{{$t('sm.chufadi')}}</th>
				<th width="10%">{{$t('visa.v_tuanhao')}}</th>
				<th width="10%">{{$t('fnc.tuanqi')}}</th>
				<th width="10%">{{$t('Airticket.Air_Trip')}}</th>
				<th width="10%">{{$t('Operation.Op_ArriveTime')}}</th>
				<th width="10%">{{$t('ground.pctianshu')}}</th>
				<th width="10%">{{$t('ground.usebusTime')}}</th>
				<th width="5%">{{$t('admin.admin_personNumber')}}</th>
				<th width="5%">{{$t('Operation.Op_carType')}}</th>
				<th width="10%">{{$t('Airticket.Air_Trip')}}</th>
				<th width="10%">{{$t('leader.leader_Leader')}}+{{$t('leader.leader_Guide')}}</th>
			</tr>
			<tbody v-for="(outItem,outindex) in list">
			<template v-for="(item,index) in outItem.StaticsReportList">
			<tr>
				<td :rowspan="2*outItem.StaticsReportList.length" v-if='index==0'>
					<div >{{outindex+1}}</div>
					<!-- <div v-if='outItem.StaticsReportList.length>1' class="w100">合团号:{{outItem.NewCombinationNum}}</div> -->
				</td>
					<td><div >
						{{item.StartCityNames}}
						</div>
					</td>
					<td><div >
						{{outItem.NewCombinationNum}}
						</div>
					</td><td><div >
						{{item.StartDateStr}}{{item.AlCode}}
						</div>
					</td>
					<td><div >
					{{item.InOut}}
					</div></td>
					<td><div>{{GetFlight(item.FlightList)}}</div></td>
					<td><div >{{GetPeiChe(item.CommonReport.BusList)}}</div></td>
					<td><div >{{GetPeiCheDay(item.CommonReport.BusList)}}</div></td>
					<td><div >
						{{item.CommonReport.HouseStatistics.RealityNum}}
					</div></td>
					<td><div >{{GetPeiCheType(item.CommonReport.BusList)}}</div></td>
						<td><div >{{item.LineteamIdNames}}</div></td>
					<td><div >{{item.LeaderName}} {{item.LeaderName&&item.GuideName?"+":""}} {{item.GuideName}}</div></td>
				</tr>
			
				</template>
			</tbody>			
		</table>
	</div>
	<el-pagination  background @current-change="handleCurrentChange" :current-page.sync="currentPage" layout="total,prev, pager, next, jumper" :page-size=msg.pageSize :total=total></el-pagination>
		</div>
</template>

<script>
export default {
    data () {
        return {
        	loading:false,
        	currentPage:1,
        	total:0,
        	msg:{
        		pageIndex:1,
        		pageSize:15,
        		SelectType:4,
				LineId: 14,
				StartDate:"",
				EndDate:"",
		        LineteamId: "-1",           		
        	},
		    LineList: [],
		    LineTeamList: [],        	
        	thLengthTitle:[],
        	list:[],
        	colspanTotal:0,
        	
        }
 	},
    methods: {
	DownLoadFile(item) {
      this.GetLocalFile("dmcstatistics_post_GetBusExport", this.msg,  "车月统计信息.xls");
    },   
    getLineList() {
      this.apipost("line_post_GetAllList", {}, res => {
        if (res.data.resultCode == 1) {
          this.LineList = res.data.data;
        } else {
          this.$message.error(res.data.message);
        }
      });
	},   
	GetTotalPrice(obj){//车费总价
	let totalPrice=0;
				obj.forEach(busInfo => {
					if(busInfo.CostPrice!=undefined){
						totalPrice+=parseFloat(busInfo.CostPrice);
					}	
					});
					return totalPrice;
	},
	GetPeiChe(obj){//配车信息
	let jieji="";
		let songji="";
			let DayNum=0;
				obj.forEach((busInfo,index) => {
					if(busInfo.AirportPickUp==1&&index==0){
							jieji+="接机";
					}	
					else 	if(busInfo.AirportPickUp==2&&index==obj.length-1){
							songji+="送机";
					}	
						if(busInfo.AirportPickUp==0){
						if(busInfo.OrderState>-1){
							DayNum+=1;
						}
					}	
					});
					if(parseInt(DayNum)>0){
						if(jieji.length>0){
	jieji += "+"+DayNum+"天"
						}else{
								jieji +=DayNum+"天"
						}
					
					}
					if(songji.length>0){
						if(jieji.length>0){
							jieji += "+"+songji
						}
						else{
							jieji += songji
						}
					}
					return jieji;
	},
	GetPeiCheDay(obj){//配车天数信息
	let jieji="";
		let songji="";
			let DayNum=0;
				obj.forEach((busInfo,index) => {
					if(busInfo.AirportPickUp==0){
						if(busInfo.OrderState>-1){
							if(parseInt(DayNum)==0){
							jieji = new Date(busInfo.PlanDate).Format('MM/dd')	
							}
							else{
								songji= new Date(busInfo.PlanDate).Format('MM/dd')		
							}
							DayNum+=1;
						}
					}	
					});
					
					if(songji.length>0){
							jieji += "-"+songji
					}
					return jieji;
	},
	GetFlight(obj){//抵离时间
	let jieji="";
		let songji="";
			let DayNum=0;
				obj.forEach((FlightList,index) => {
							if(parseInt(DayNum)==0){
							jieji = new Date(FlightList.FlightDate).Format('MM/dd')	
							}
							else if(index==parseInt(DayNum)) {
								songji= new Date(FlightList.FlightDate).Format('MM/dd')	
								
							}
							DayNum+=1;
							
					});
					
					if(songji.length>0){
							jieji += "-"+songji
					}
					return jieji;
	},
	GetPeiCheType(obj){//配车型
	let jieji="";
		let songji="";
			let DayNum=0;
				obj.forEach((busInfo,index) => {
					if(busInfo.AirportPickUp==0){
						if(busInfo.OrderState>-1){
							if(parseInt(DayNum)==0){
							jieji = busInfo.BusTypeStr
							}
							DayNum+=1;
						}
					}	
					});
					return jieji;
	},
	
  	getCurrentMonthFirst(){
            var date=new Date();
			date.setDate(1);
			this.msg.StartDate=date;
            // return date;
        },
        // 获取当前月的最后一天
    getCurrentMonthLast(){
            var date=new Date();
            var currentMonth=date.getMonth();
            var nextMonth=++currentMonth;
            var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
			var oneDay=1000*60*60*24;
			this.msg.EndDate=new Date(nextMonthFirstDay-oneDay);
            // return new Date(nextMonthFirstDay-oneDay);
        },

   //获取系列列表
    getLineTeamList(lineId) {
      this.LineTeamList = [];
      this.apipost(
        "team_post_GetList",
        {
          lineID: 14,
          isTOOP: 1
        },
        res => {
          if (res.data.resultCode == 1) {
            this.msg.LineteamId = "-1";
            this.LineTeamList = res.data.data;
          }
        }
      );
    },    
   		 goUrlX(path,obj,title){
	 	   this.$router.push({ name:path,query:{"TCID":obj.TCIDS,StartDate:obj.StartDateStr,DayNum:obj.DayNum,TotalNumber:obj.TotalSeat,blank:'y',tab:title}}) 
		},	
  		goUrlR(path,obj,title){
	 	   this.$router.push({ name:path,query:{"ID":obj,blank:'y',tab:title}}) 
		},	
    	 goUrlT(path,obj,title){
	 	   this.$router.push({ name:path,query:{"id":obj,blank:'y',tab:title}}) 
		},	
		 goUrl(path,obj,title){
	 	   this.$router.push({ name:path,query:{"id":obj.TCIDS,'TCNUM':obj.TCNUMS,'flightTotal':obj.TotalSeat,'GuestNum':obj.CommonReport.HouseStatistics.RealityNum,'NewCombinationNum':obj.NewCombinationNum,blank:'y',tab:title}}) 
		},	
		handleCurrentChange(val) {
			this.msg.pageIndex = val;
			this.getList();
		},   
	    resetPageIndex() {
	      this.msg.pageIndex = 1;
	      this.currentPage = 1;
	    },		
    	getList(){
    		this.loading=true
    		this.apipost('dmcstatistics_post_GetUniteCombinationNumService',this.msg,res=>{
    			if(res.data.resultCode==1){
    				this.loading=false
    				this.total=res.data.data.count
    				this.list=res.data.data.pageData.data
    		 
    			}else{
    				this.loading=false
    				this.$message.error(res.data.message)
    			}
    		},err=>{})
    	},
    },
    mounted() {
		this.getCurrentMonthFirst();
		this.getCurrentMonthLast();
       this.getList()
//     this.getLineList()
       this.getLineTeamList()
    },    
}
</script>

<style>
.busIconStyle>span{margin-right: 20px; font-weight: bold;}
.busStatisticsTalbe{ background: #ccc;}
.busStatisticsTalbe tr th{background: #E6E6E6;height:40px; font-size: 12px; color: #333;}
.busStatisticsTalbe tr{background: #fff;text-align: center; height: 40px;}
.busStatisticsTalbe tr:nth-child(2n+1){background:#fafafa; }
.busStatisticsTalbe tr td{font-size: 12px;}
.busStatisticsTalbe tr td .pDateStyle{border-bottom: 1px solid #ccc; min-height: 24px;  line-height: 24px; margin-top: 0; box-sizing: content-box; padding: 0 10px;}
.busStatisticsTalbe tr td .pDateStyle:last-child{border-bottom: none;}
.busStatisticsTalbe tr td .link p:hover{text-decoration: underline; cursor: pointer;}
.busStatisticsTalbe tr td .link span:hover{text-decoration: underline; cursor: pointer;}
.busStatistics_tripDetails {padding: 0; box-shadow: 0px 1px 3px 0px #dedede; max-height: 400px;overflow-y: auto;}
.busStatistics_tripDetails .popper__arrow::after {border-bottom-color: #ededed !important;}
.busStatistics_tripDetails table { padding: 10px 0 0 20px; background-color: #ededed; border-collapse: collapse; border: 1px solid #d2d2d2; font-size: 12px;}
.busStatistics_tripDetails table th { background-color: #ededed; padding: 5px;}
.busStatistics_tripDetails table td { background-color: #ffffff; padding: 9px 15px;color: #333333;border: 1px solid #d2d2d2;}
.busStatistics_tripDetails table td._d_name {background-color: #ededed;}
.busStatistics_tripDetails table ._color_666 {color: #666666;}
.busStatistics_tripDetails table tr._color_666 th { padding: 9px 15px;}
</style>