<style>
    .AirClick{
        text-decoration: underline;
        cursor: pointer;
    }
</style>
<template>
    <div class="AirTicketApp" style="padding-bottom:20px">
         <div class="Header">
            <el-col :span="8"  style="margin:10px 0">
                 <el-date-picker
                    v-model="value1"
                    type="daterange"
                    value-format="yyyy-MM-dd"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                    </el-date-picker>
            </el-col>
          
          <button style="margin-top:15px" class="normalBtn" @click="getList">查询</button>
          <button style="margin-top:15px" class="hollowFixedBtn" @click="Export">导出</button>
       
           
      </div>
       <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0" v-loading="loading">
           <tr>
               <th v-if="index==0" v-for="(item,index) in ColNameList" :key="index">{{item}}</th>
               <th v-if="index!=0 && index!=ColNameList.length" colspan="2" v-for="(item,index) in ColNameList" :key="index">{{item}}</th>
               <th v-if="index==ColNameList.length" v-for="(item,index) in ColNameList" :key="index">{{item}}</th>
           </tr>
           <tr>
               <td></td>
               <td v-for="item in LossList" :class="{'AirClick':item.Value!='损失占比'}" @click="goToDetail(item)">{{item.Value}}</td>
               <td>{{SunMoney}}</td>
           </tr>
           <tr v-for="(item,index) in Rlist" :key="index">
               <td>{{item.BranchName}}</td>
               <td v-for="(cl,index) in item.LossTL" :key="index">{{cl}}</td>
               <td>{{item.TotalMoney}}</td>
           </tr>
       </table>

    </div>
</template>
<script>
export default {
    data(){
        return{
           loading:false,
           ColNameList:[],
           LossList:[],
           SunMoney:0,
           Rlist:[],
           value1:[],
           msg:{
               StartTime:"",
               EndTime:"",
           },
           userInfo:{},
        }
    },created(){
        this.userInfo = this.getLocalStorage();
    },methods:{
        Export(){

            let msg=this.msg;
            msg.EmployeeId = this.userInfo.EmployeeId;
            var fileName = "机票损失分摊.xls";
            this.GetLocalFile("financestatistics_post_OutToExcelGetCompamyAirTicketRatioList", msg, fileName);
        },
        getList(){
            if(this.value1){
                this.msg.StartTime=this.value1[0];
                this.msg.EndTime=this.value1[1];

            }else{
                this.msg.StartTime="";
                this.msg.EndTime="";

            }
            this.loading = true;
            this.apipost('financestatistics_post_GetCompamyAirTicketRatioList',this.msg, res => {                     
                    this.loading = false;

                    if(res.data.resultCode == 1) {
                        this.ColNameList=res.data.data.ColNameList;
                        this.Rlist=res.data.data.Rlist;
                        this.LossList=res.data.data.LossList[0].LossTL;
                        this.SunMoney = res.data.data.LossList[0].TotalMoney;
                    } else {
                        this.$message.error(res.data.message);                        
                    }
                    this.loading = false;
            }, err => {})
        },
        //跳转至详情
        goToDetail(item){
            if(item.Value!='损失占比'){
                if(item.IsTravel==1){
                    this.$router.push({
                    name: 'TeamRevenueReport',
                    query: {
                        StartTime:item.StartTime,
                        EndTime:item.EndTime,
                        LineId:item.LineId,
                        LtIdStr:item.LtIdStr,
                        IsSelectTravelLoss:1,
                        blank: "y",
                    }
                    });
                }
                else{
                    this.$router.push({
                    name: 'AirTicketLossDetail',
                    query: {
                        msg: JSON.stringify(item),
                        blank: "y",
                        }
                    });
                }
                
            }
        }
 
    },mounted(){
        //默认查询当月第一个到最后一天日期
        if(this.$route.query.startDate && this.$route.query.endDate){
            let startDate=this.$route.query.startDate;
            let endDate=this.$route.query.endDate;
            this.value1.push(startDate,endDate);
        }else{
            var now = new Date();
            var month = now.getMonth() + 1;//js获取到的是月份是 0-11 所以要加1
            var year = now.getFullYear();
            var nextMonthFirstDay = new Date([year,month + 1,1].join('-')).getTime();
            var oneDay = 1000 * 24 * 60 * 60;
            var monthLast = new Date(nextMonthFirstDay - oneDay).getDate()
            if(month<10){
                month='0'+month;
            }
            let startDate = [year,month,1].join('-');
            let endDate = [year,month,monthLast].join('-');
            this.value1.push(startDate,endDate);

        }
        
        this.getList();
    }
}
</script>