<template>
  <div class="passengerSaleList">
    <div class="passengerSaleList_topBtn">
       <template v-if="isOrder==0">
        <span style="color:red;">OP已关闭订单操作,如需修改,请联系OP开启。</span>
       </template>
       <template  v-if="isOrder==1 && !isDis" > <div   v-show="tableList.length<guestNum&&IsLeaderOrder>0"  @click="showSetLeader=true;getBranchList()">选择领队/导游</div>
        <div  v-show="tableList.length<guestNum"  @click="goUrlA(0)">新增</div>
      </template>
     
      <div v-if="isOrder==1 && isOneDay !== 1 && !isDis" @click="goUrlP()">分房</div>
    </div>
    <div class="passengerSaleList_tableBox">
      <table class="passengerSaleList_table" border="0" cellspacing="0" cellpadding="0" :loading="loading">
        <thead>
          <tr>
            <th width="2%">ID</th>
            <th width="2%">分房</th>
            <th width="5%">酒店及房型</th>
            <th width="5%">旅客姓名</th>
            <th width="5%">英文姓</th>
            <th width="5%">英文名</th>
            <th width="3%">性别</th>
            <th width="7%">出生日期</th>
            <th width="4%">年龄类型</th>
            <th width="6%">出生地</th>
            <th width="6%">护照号</th>
            <th width="6%">签发地</th>
            <th width="7%">签发日期</th>
            <th width="7%">护照有效期</th>
            <th width="6%">客户手机</th>
            <th width="9%">身份证</th>
            <th width="5%">签证状态</th>
            <th width="5%">是否学生</th>
            <th width="8%">{{$t('hotel.table_operat')}}</th>
          </tr>
        </thead>
        <tbody v-show="tableList.length>0">
          <tr v-for="(item,index) in tableList" :key="index" :class="{'redTr':item.VisaState==1}">
            <td>{{item.Sort}}</td>
            <td>{{item.HoustNo}}</td>
            <td>{{item.HouseType}}</td>
            <td>{{item.Name}}</td>
            <td>{{item.ESurName}}</td>
            <td>{{item.EName}}</td>
            <td>{{item.Sex}}</td>
            <td>{{item.Birthday}}</td>
            <td>{{item.PeopleType}}</td>
            <td>{{item.BirthdayAddress}}</td>
            <td>{{item.PassportNo}}</td>
            <td>{{item.PassportAddress}}</td>
            <td>{{item.PassportIssued}}</td>
            <td>{{item.PassportExpiry}}</td>
            <td>{{item.MobilePhone}}</td>
            <td>{{item.IdCard}}</td>
            <td>{{item.VisaState==1?'拒签':"正常"}}</td>
            <td style="color:red;">{{item.IsHightSchool==1?'学生':""}}</td>
            <td>
              <el-button-group>
                <el-tooltip v-if="isOrder==1 && !isDis" class="item" effect="dark" :content="$t('pub.updateMsg')" placement="top-start">
                  <el-button type="primary" style='background:#00C6FF; border-color:#00C6FF'
                    icon="iconfont icon-bianji-smal" @click="goUrlA(item.Id)"></el-button>
                </el-tooltip>
                <el-tooltip v-if="isOrder==1 && !isDis" class="item" effect="dark" :content="$t('system.table_delete')" placement="top-start">
                  <el-button type="primary" style='background:#e95252; border-color:#e95252'
                    icon="iconfont icon-shanchu" @click="pal_del(item)"></el-button>
                </el-tooltip>
                <el-tooltip v-if="isOrder==1 && !isDis" class="item" effect="dark" content="下载申请表" placement="top-start">
                  <el-button type="primary" style='background:#9E8DE3; border-color:#9E8DE3'
                    icon="iconfont icon-img_download" @click="goUrlB(item.Id)"></el-button>
                </el-tooltip>
              </el-button-group>
            </td>
          </tr>
        </tbody>
        <tbody v-show="tableList.length===0" class="passengerSaleList_table_noInfo">
          <tr>
            <td colspan="19" class="">{{$t('system.content_noData')}}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <div class="combottomDiv" v-if="showSetLeader" v-loading="loadingSet">
      <div class="combottomTitle">{{ $t("ground.szlindui") }}</div>
      <div class="clearfix">
        <el-form label-width="100px">
          <el-col :span="4">
            <el-form-item :label="$t('fnc.ssuogongsi')">
              <el-select v-model="leaderQueryMsg.RB_Branch_id" filterable :placeholder="$t('pub.pleaseSel')">
                <el-option v-for="item in BranchList" :key="item.Id" :label="item.BName" :value="item.Id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('system.query_workType')">
              <el-select v-model="leaderQueryMsg.LeaderType" :placeholder="$t('pub.pleaseSel')">
                <el-option v-for="item in leaderTypeArray" :key="item.Id" :label="item.Text" :value="item.Id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('system.query_name')" prop="lineCode">
              <el-input v-model="leaderQueryMsg.LeaderName" @keyup.enter.native="getLeaderList"  :placeholder="$t('tips.srgjzjxguolv')"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <input type="button" class="normalBtn Rs_leaderSearch" @click="getLeaderList"
              :value="$t('pub.searchBtn')" />
            <input type="button" class="normalBtn Rs_leaderSearch" @click="showSetLeader = false"
              :value="$t('pub.closeSel')" />
          </el-col>
        </el-form>
      </div>
      <div class="clearfix RL_bottomDiv">
        <div style="width:100%;">
          <div class="RL_LeaderListDiv" style="float: left;width: 30%;">
            <div class="RL_LeaderTitle">
              {{ $t("ground.dxmindan") }}
              <span v-if="isLeaderType">(<span>{{ isLeaderType }}</span>)</span>
            </div>
            <div class="RL_ListDiv">
              <div class="LeaderSpan" :class="{ ckedClass: ckedIndex == index }" v-for="(item, index) in leaderListArr"
              :key="item.subCode" @click="getLeaderInfo(index, item.LeaderId)" style="margin:5px 0px 0px 5px;" >
                <span class="RL_LeaderName">{{ item.LeaderName }}:{{item.IdCard }}/ {{item.Passport }} /{{item.MobilePhone }}【{{
                    getLeaderTypeStr(item.Type, item.LeaderGuidClass)
                  }}】</span>
              </div>

             
            </div>
          </div>
          <div class="clearfix " style="float: left;width: 5%;">
      <div >
          <input type="button" class="normalBtn"  @click="setTheLeader"
            :value="$t('pub.sureBtn')" />
        </div>
      </div>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        loading: false,
        msg: {
          id: '0',
          tcid: '0',
          tcnum: '0'
        },
        setMsg:{
          OrderId:0,
          TCID:0,
          NewGuestId:0,
        },
        guestNum: 0,
        isOrder: 0,
        tableList: [],
        isOneDay: 0,
        LineId: 0,
        EndDateStr: "",
        isDis: false,
        IsLeaderOrder:0,
        leaderQueryMsg: {
          QTCID: 0,
          CountryID: 0,
          LeaderType: 0,
          RB_Branch_id: 0,
          LeaderName: "",
        },
         //验证重复提交
         isSubmit: true,
        ckedIndex:-1,
          //领队或者领兼地
       isLeaderType: "",
        leaderTypeArray: [{
            Id: 0,
            Text: "请选择",
          },{
            Id: 2,
            Text: "领队兼导游",
          },
          {
            Id: 1,
            Text: "领队",
          },
          {
            Id: 3,
            Text: "导游",
          },
        ],
         //分公司列表
         BranchList: [],
         showSetLeader:false,
         loadingSet:false,
         leaderListArr: [],
      };
    },
    methods: {

            //确定设置领队
        setTheLeader() {
        if (this.isSubmit) {
          this.isSubmit = false;
          this.apipost(
            "sellorder_post_SetLeaderOrGuide",
            this.setMsg,
            (res) => {
              this.isSubmit = true;
              if (res.data.resultCode == 1) {
                this.Success(res.data.message);
                this.getData();
                this.showSetLeader = false;
                this.leaderListArr = [];
                this.ScheduleArray = [];
              } else {
                this.Error(res.data.message);
              }
            },
            (err) => {}
          );
        }
      },
          //点击选中名单
          getLeaderInfo(index,LeaderId) {
        this.ckedIndex = index;
        this.setMsg.NewGuestId=LeaderId
          },
      getLeaderTypeStr: function (type, clas) {
        if (type == 2) {
          return "领兼地";
        } else  if (type ==3) {
          return "导游";
        } 
        else if (type == 1 && clas == 0) {
          return "领队";
        } else if (type == 1 && clas == 1) {
          return "同行领队";
        } else if (type == 1 && clas == 2) {
          return "临时领队";
        }
      },
       //获取公司列表
       getBranchList() {
        let msg = {
          Status: "0",
          is_show: "",
          RB_Group_Id: "",
        };
        this.apipost(
          "admin_get_BranchGetList",
          msg,
          (res) => {
            this.BranchList = res.data.data;
          },
          (err) => {}
        );
      },
      //查询领队
      getLeaderList() {
        this.loadingSet = true;
        this.leaderListArr == [];
        this.apipost(
          "LeaderSchedule_get_GetByKeyCanUseLeader",
          this.leaderQueryMsg,
          (res) => {
            this.loadingSet = false;
            if (res.data.resultCode == 1) {
              this.leaderListArr = res.data.data.LeaderData;
              this.ScheduleArray = res.data.data.ScheduleData;
              if (this.leaderQueryMsg.LeaderType == 1) {//1领队2领队兼导游3导游
                this.isLeaderType = "领队";
              } else  if (this.leaderQueryMsg.LeaderType == 2){
                this.isLeaderType = "领兼地";
              }else if (this.leaderQueryMsg.LeaderType == 3){
                this.isLeaderType = "导游";
              }
            }
          },
          (err) => {}
        );
      },
      getData: function () {
        this.loading = true
        this.apipost("sellorder_get_GetTravelGuestList", {
          OrderId: this.msg.id
        }, res => {
          if (res.data.resultCode == 1) {
            this.guestNum = res.data.data.GuestNum;
            this.tableList = res.data.data.list;
            this.isOneDay = res.data.data.IsOneDay;
            this.LineId = res.data.data.LineId;
            this.EndDateStr = res.data.data.EndDateStr;
            this.IsLeaderOrder= res.data.data.IsLeaderOrder;
            this.leaderQueryMsg.QTCID=   res.data.data.TCID;
          } else {
            this.$message.error(res.data.message)
          }
          this.loading = false
        });
      },
      pal_del: function (item) {
        this.$confirm('是否删除该旅客?', this.$t('tips.tips'), {
          confirmButtonText: this.$t('pub.sureBtn'),
          cancelButtonText: this.$t('pub.cancelBtn'),
          type: 'warning'
        }).then(() => {
          this.apipost('sellorder_post_DelTravelGuestInfo', {
            GuestId: item.Id
          }, res => {
            if (res.data.resultCode == 1) {
              this.$message.success('删除成功!')
              this.getData()
            } else {
              this.$message.error(res.data.message)
            }
          }, err => {})
        })
      },
      goUrlA: function (guestId) {
        this.$router.push({
          name: 'addPassenger',
          query: {
            "TCID": this.msg.tcid,
            "orderId": this.msg.id,
            'guestId': guestId,
            'isOneDay': this.isOneDay,
            'LineId': this.LineId,
            "EndDateStr": this.EndDateStr
          }
        });
      },
      goUrlB: function (guestId) {
        let routeData = this.$router.resolve({
          name: 'VisaPersonalFormSell',
          query: {
            data: guestId
          }
        });
        window.open(routeData.href, '_blank');
      },
      goUrlP: function () {
        this.$router.push({
          name: 'passengerListSale',
          query: {
            id: this.msg.id,
            tcnum: this.msg.tcnum,
            blank: 'y',
            tab: '旅客分房'
          }
        });
      },
    },
    mounted: function () {
      this.msg.id = this.$route.query.id === undefined ? "0" : this.$route.query.id
      this.msg.tcid = this.$route.query.tcid === undefined ? "0" : this.$route.query.tcid
      this.msg.tcnum = this.$route.query.tcnum === undefined ? "0" : this.$route.query.tcnum
      this.isOrder = this.$route.query.isOrder === undefined ? 0 : this.$route.query.isOrder
      this.isDis = this.$route.query.isDis ? true : false;
      this.setMsg.OrderId = this.$route.query.id === undefined ? "0" : this.$route.query.id
      this.setMsg.TCID = this.$route.query.tcid === undefined ? "0" : this.$route.query.tcid
      this.getData()
    }
  };

</script>

<style>
  .ckedClass {
    background-color: #e95252 !important;
    color: #fff;
  }
  .RL_ListDiv {
    width: 100%;
    height: 174px;
    overflow: auto;
  }
  .RL_LeaderListDiv {
    width: 200px;
    height: 206px;
    margin-left: 30px;
    border: 1px solid #d1d1d1;
  }
  .RL_infoDiv {
    width: 260px;
    height: 140px;
    border: 1px solid #d1d1d1;
    padding: 10px;
    font-size: 14px;
  }
  .RL_LeaderTitle {
    width: 100%;
    height: 30px;
    text-align: center;
    color: #fff;
    background-color: #e95252;
    line-height: 30px;
    font-size: 14px;
  }
  .RL_LeaderName {
    display: inline-block;
    min-width: 50px;
    font-size: 14px;
  }

  .RL_bottomDiv>div {
    float: left;
    margin-right: 20px;
  }
  .passengerSaleList {
    width: 100%;
  }

  .passengerSaleList_topBtn {
    padding: 20px 0 0 0;
    text-align: right;
  }

  .passengerSaleList_topBtn>div {
    display: inline-block;
    margin: 0 0 0 10px;
    padding: 0 15px;
    height: 30px;
    line-height: 30px;
    font-size: 14px;
    color: #E95252;
    border: 1px solid #E95252;
    border-radius: 15px;
    background: #FFFFFF;
    cursor: pointer;
  }

  .passengerSaleList_tableBox {
    padding: 20px 0 0 0;
    width: 100%;
  }

  .passengerSaleList_table {
    width: 100%;
    color: #333;
    border-bottom: 1px solid #cccccc;
    border-right: 1px solid #cccccc;
  }

  .passengerSaleList_table tr {
    background: #fff;
  }

  .passengerSaleList_table tr th {
    background: #e6e6e6;
    height: 30px;
    font-size: 12px;
    text-align: center;
    border-top: 1px solid #cccccc;
    border-left: 1px solid #cccccc;
  }
 

  .passengerSaleList_table tr td {
    padding: 10px;
    font-size: 12px;
    text-align: center;
    border-top: 1px solid #cccccc;
    border-left: 1px solid #cccccc;
  }

  .passengerSaleList_table_noInfo tr td {
    height: 30px;
    text-align: center;
    font-size: 12px;
    color: #999999;
  }

  /*拒签人员*/
  .passengerSaleList_table .redTr td{
    color: #E95252;
  }

</style>