<style scoped>
    ._vad_top{padding: 20px 0}
    ._vad_top>span._num{height:30px;background:#E3E3E3;border-radius:4px;display: inline-block;padding: 5px 10px;font-size: 14px;font-weight: bold}
    .wrapper .singeRowTable tr{border-bottom: 1px solid  #E3E3E3;margin-bottom: 10px;box-shadow: 0px 1px 0px rgba(227,227,227,1);margin-bottom: 20px;}
    .wrapper .singeRowTable tr th:hover,.wrapper .singeRowTable tr td:hover{background-color: #FFFFFF}
    .wrapper .singeRowTable tr th,.wrapper .singeRowTable tr td{background-color: #FFFFFF;text-align: center}
    .wrapper .singeRowTable .text_left{text-align: left;padding-left: 25px}
    .wrapper ._head_img{width: 24px;height: 24px;border-radius: 50%;}
    .wrapper .singeRowTable td img{vertical-align:middle;}
    .wrapper .singeRowTable .iconfont,.iconfont.icon-iconfontremind{color: #E95252}
    .iconfont.icon-iconfontremind{font-size: 24px;cursor: pointer;}
    .wrapper ._radius {display: inline-block;width: 24px;height: 24px;background-color: #FF793E;color: #fff;border-radius: 50%;text-align: center;line-height: 22px;font-size: 12px;margin-right: 10px;}
    .wrapper ._radius._tuan{background-color: #3EABFF}
    .wrapper .icon-img_delete_small{cursor: pointer;}
    .updatestatus{
      position: absolute;
      right:10px;
    }
   
</style>
<template>
  <div class="wrapper">
      <div class="_vad_top clearfix">
        <span class="_num PingFangSC">{{$t('visa.v_tuan')}}：{{num}}</span>
        <div class="fr">
          <button @click="DeleteMore" class="normalBtn">批量删除</button>

          <el-dropdown split-button type="primary" trigger="click" @command="bindVisa">
            {{$t('visa.v_tvisa')}}
            <el-dropdown-menu slot="dropdown" >
              <el-dropdown-item v-for="item in VisaManagementList" :key='item.Id' v-if="item.IsGroupSigned==1"  :command='{id:item.Id,type:2}'>{{item.Name}}</el-dropdown-item>
              <el-dropdown-item v-if="LineID!=14" :command='{id:-1,type:2}'>{{$t('visaT.v_Othervisas')}}</el-dropdown-item>    
            </el-dropdown-menu>
          </el-dropdown>
          <el-dropdown split-button type="primary" trigger="click"  @command="bindVisa">
            {{$t('visa.v_gvisa')}}
            <el-dropdown-menu slot="dropdown" >
              <el-dropdown-item v-for="(item,index) in VisaManagementList" :key='index+50000' v-if="item.IsOrderSigned==1" :command='{id:item.Id,type:1}'>{{item.Name}}</el-dropdown-item>
              <el-dropdown-item v-if="LineID!=14" :command='{id:-1,type:1}'>{{$t('visaT.v_Othervisas')}}</el-dropdown-item>
           </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
      <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0" style=" border-spacing:0 10px;" v-loading="loading">
        <tr>
          <th width=150 class="text_left"> <input type="checkbox" @change="checkAll" v-model="checkd" > {{$t('visa.v_suoshudingdan')}}</th>
          <th>{{$t('visa.v_youkeName')}}</th>
          <th>{{$t('visa.v_guanlianyewu')}}</th>
          <th>{{$t('visa.v_ziliaowanshan')}}</th>
          <th>{{$t('visa.v_visaType')}}</th>
          <th>{{$t('visa.v_qianzhengst')}}</th>
          <th>{{$t('admin.admin_czPerson')}}</th>
          <th> <input type="checkbox" @change="checkAll2" v-model="checkd2" >{{$t('hotel.table_operat')}}</th>
        </tr>
        <tr v-for="(item,index) in dataList">
          <td width=150 class="text_left"> 
            <input v-if="LineID==14" type="checkbox" :disabled="item.ApplyStatus!=-1" v-model="checkList" :value="item.Id" @change="checkThis">
            <input v-else type="checkbox" :disabled="item.VisaManageStatus>1" v-model="checkList" :value="item.Id" @change="checkThis">
             {{item.OrderId}}</td>
          <td>{{item.GuestName}}</td>
          <td><img class="_head_img" :src="item.SalesManPhoto" alt=""> {{item.SalesMan}}</td>
          <td>
            <span v-if="item.IsDataFull==2">{{$t('visa.v_yiwanshan')}}</span>
            <span v-if="item.IsDataFull==1">{{$t('visa.v_weiwanshan')}}</span>
            <span v-if="item.IsDataFull==0">{{$t('visa.v_weibangding')}}</span>
            <i v-if="item.IsDataFull==1||item.IsDataFull==0" class="iconfont icon-iconfontremind" @click="UrgeGuestInfo(item.Id,item.EmployeeId)" style="vertical-align:middle;"></i>
          </td>
          <td>
            <span v-if="LineID==14">
              {{item.VisaName}} 
                <span v-if="item.SignStatus==1" class="_radius" >{{$t('visa.v_dan')}}</span>
                <span v-if="item.SignStatus==2" class="_radius _tuan">{{$t('visa.v_tuan')}}</span>
            </span>
            <span v-else>
                <span v-if="item.VisaCountryType==1">{{$t('visa.v_Japanese')}}</span> 
                <span v-if="item.VisaCountryType==-1">{{$t('active.cl_qita')}}</span> 
                <span v-if="item.VisaType==1" class="_radius" >{{$t('visa.v_dan')}}</span>
                <span v-if="item.VisaType==2" class="_radius _tuan">{{$t('visa.v_tuan')}}</span>
            </span>
            
          </td>
          <td>
            <span v-if="LineID==14">
              <span v-if="item.ApplyStatus==0">{{$t('visa.v_chulizhong')}}</span> 
              <img v-if="item.ApplyStatus==1" src="../../assets/img/pass@2x.png" alt=""> 
             <img v-if="item.ApplyStatus==2" src="../../assets/img/fail@2x.png" alt="">
            </span>
             <span v-else>
               <span v-if="item.VisaCountryType!=0">
                 <span v-if="item.VisaManageStatus==1">{{$t('visa.v_weibanli')}}</span> 
                <span v-if="item.VisaManageStatus==2">{{$t('visa.v_banlizhong')}}</span> 
                <span v-if="item.VisaManageStatus==3">{{$t('visaT.Completionover')}}</span> 
                <!--   -->
                <span @click="goUrl('财务单据','FinancialDocumentsDetail',item.OrderId)" v-if="item.FinanceId>0" style="cursor:pointer" class="_radius _tuan">财</span>
               </span>
              
            </span>
            
          </td>
          <td>{{item.UpdateName}} <img class="_head_img" :src="item.UpdatePhoto" alt=""></td>
          <td style="position:relative;width:200px"> 
            <input v-if="item.VisaType==2 || item.SignStatus==2" type="checkbox"  v-model="checkList2" :value="item.Id" @change="checkThis2">
            <el-button @click="deletelist(item.Id)" type="danger" style="padding:5px" icon="el-icon-delete" circle></el-button>
            <!-- <i @click="deletelist(item.Id)" class="iconfont icon-img_delete_small"></i> -->
          <span v-if="LineID!=14">
            <!-- <button v-if="item.VisaManageStatus==1" @click="UpdateGuestStatus(item,2)" style='background:#3EABFF;padding:4px 6px;color:#fff;cursor:pointer'>办理</button> -->
             <el-tooltip class="item" effect="dark" content="办理完成" placement="top-start">
                <el-button @click="UpdateGuestStatus(item,3)"  style="padding:5px" type="success" v-if="item.VisaManageStatus==2" icon="el-icon-check" circle></el-button>
                <!-- <i  class="iconfont icon-yiqueren" style="color:rgb(75, 202, 129);cursor:pointer;font-size:18px" ></i> -->
              </el-tooltip>
            </span>
          </td>
        </tr>
      </table>
  </div>
</template>

<script>
export default {
  components:{},
  props:{},
  data(){
    return {
        id:0,
        num:0,
        VisaManagementList:[],
        dataList:[],
        checkList:[],
        checkListAll:[],
        loading:false,
        checkd:false,
        checkd2:false,
        checkList2:[],
        checkListAll2:[],
        deleteStatus:false,
        lastlen:false,
        StatusList:[
          {
            Id:'-1',
            Name:this.$t('pub.unlimitedSel')  
          },{
            Id:'0',
            Name:this.$t('Airticket.Air_toProcessed') 
          },
          {
            Id:'1',
            Name:  this.$t('visa.v_tongguo')
          },{
            Id:'2',
            Name:this.$t('visa.v_jujue')
          },
      ],
      LineID:14,
    }
  },
  watch:{},
  computed:{},
  methods:{
    goUrl: function (name, path, id ) {
      this.$router.push({ name: path, query: { id: id, blank: 'y', tab: name} });
    },
    UpdateGuestStatus(item,num){
      let msg={
        guestId:item.Id,
        visaManageStatus:num
      };
      this.apipost('dmc_post_UpdateGuestVisaManageStatus',msg,res=>{
        if(res.data.resultCode==1){
          this.$message.success(res.data.message)
          this.getData()
        }
        else{
            this.$message.error(res.data.message)
        }
      })
    },
    UrgeGuestInfo(id,EmployeeId){  //催客人完善资料
      let msg = {
        GuestId:id,
        EmployeeId:EmployeeId,
      }
      this.apipost('dmc_post_UrgeGuestInfo',msg,res=>{
        if(res.data.resultCode==1){
            this.$message.success(res.data.message)
            this.getData()
        }else{
            this.$message.error(res.data.message)
        }
      },err=>{})
    },
    deletelist(id){//删除提示
      this.$confirm(this.$t('visaT.sfshanchubd'), this.$t('tips.tips'), {
              confirmButtonText: this.$t('pub.sureBtn'),
              cancelButtonText: this.$t('pub.cancelBtn'),
              type: 'warning'
          }).then(() => {  
            this.deleteStatus=false;               
              this.deleteTshi(id)
          }).catch(() => {
          this.$message({
              type: 'info',
              message: this.$t('tips.cancleDelete')
        });
      });
    },  
    deleteTshi(id){  // 删除操作
      this.apipost('dmc_post_DelVisaPeople',{GuestId:id},res=>{
        if(res.data.resultCode==1){
          if(this.deleteStatus){
            if(this.lastlen){
              this.getData()
              this.$message.success(res.data.message)

            }
          }else{
            this.$message.success(res.data.message)
            this.getData()
          }
            
        }else{
            this.$message.error(res.data.message)
        }
      },err=>{})
    },
    bindVisa(command){ //绑定签证类型
      if(command.id>0&&this.LineID!=14){
        this.$message.error(this.$t('visaT.qxzzzdqzlx'))
        return;
      }
      if(this.checkList.length==0){
        this.$message.error(this.$t('visaT.qxzxybddry'))
        return
      }
      let msg = {
        TCID:this.id,
        VisaType:command.type,
        GuestArr:this.checkList,
        VisaId:command.id,
      }
      this.apipost('dmc_post_AddVisaPlan',msg,res=>{
        if(res.data.resultCode==1){
            this.$message.success(res.data.message)
            this.getData()
            this.checkList=[]
        }else{
            this.$message.error(res.data.message)
        }
      },err=>{})
    },
    DeleteMore(){
      let len=this.checkList2.length;
      if(len==0){
        this.Error("至少选择一条！");
        return;
      }
      this.deleteStatus=true; 
      this.lastlen=false;               
      
      this.$confirm(this.$t('visaT.sfshanchubd'), this.$t('tips.tips'), {
              confirmButtonText: this.$t('pub.sureBtn'),
              cancelButtonText: this.$t('pub.cancelBtn'),
              type: 'warning'
          }).then(() => {  
            for(let i=0;i<this.checkList2.length;i++){
        
              if(i+1==len){
                this.lastlen=true;
              }
              this.deleteTshi(this.checkList2[i])
            }
          }).catch(() => {
          this.$message({
              type: 'info',
              message: this.$t('tips.cancleDelete')
        });
      });
      
    
    },
    checkThis2(){ // 单选
      if(this.checkList2.length==this.checkListAll2.length){
        this.checkd2 = true
        return
      }
      this.checkd2 = false
    },
    checkAll2(){ //全选
      if(this.checkList2.length==this.checkListAll2.length){
          this.checkList2=[]
          return
      }
      this.checkList2 = this.checkListAll2
    },
    checkThis(){ // 单选
      if(this.checkList.length==this.checkListAll.length){
        this.checkd = true
        return
      }
      this.checkd = false
    },
    checkAll(){ //全选
      if(this.checkList.length==this.checkListAll.length){
          this.checkList=[]
          return
      }
      this.checkList = this.checkListAll
    },
    
    getVisaManagementList(){  //  获取签证管理
        this.apipost('dmc_get_visa_GetVisaManagementList',{Status:0,BranchId:-1,SignStatus:0},res=>{
            if(res.data.resultCode==1){
                this.VisaManagementList = res.data.data
            }else{
                this.$message.error(res.data.message)
            }
        },err=>{})
    },
    getData(){ //获取数据
      this.loading = true
      this.checkListAll=[];
      this.apipost('dmc_get_GetTCGuestList',{TCID:this.id},res=>{
            if(res.data.resultCode==1){
                this.dataList = res.data.data;
                this.dataList.forEach(x=>{
                  if(x.VisaType==2 || x.SignStatus==2){
                    this.checkListAll2.push(x.Id)
                  }
                })
                if(this.LineID==14){
                  this.dataList.forEach(x=>{
                  if(x.ApplyStatus==-1){
                    this.checkListAll.push(x.Id)
                  }
                })
                }else{
                  this.dataList.forEach(x=>{
                    if(x.VisaManageStatus==1 || x.VisaManageStatus==0){
                      this.checkListAll.push(x.Id)
                    }
                  })
                  
                }
                
            }else{
                this.$message.error(res.data.message)
            }
            this.loading = false
      },err=>{})
    }
  },
  created(){},
  mounted(){
        this.id =  this.$route.query.id
        this.num =  this.$route.query.num;
        this.LineID=this.$route.query.LineID?this.$route.query.LineID:this.LineID;
        this.getVisaManagementList()
        this.getData()
  }
}
</script>
