<template>
  <div>
    <div class="query-box" style="border-bottom: none;">
      <ul>
        <li>
          <span>
            <em>{{$t('advmanager.v_line')}}</em>
            <el-select v-model="msg.LineId" filterable :placeholder="$t('pub.pleaseSel')" @change="getLinePlaceList()">
              <el-option :label="$t('pub.unlimitedSel')" :value='0'></el-option>
              <el-option v-for="item in queryCommonData.LineList" :label='item.LineName' :value='item.LineID'
                :key='item.LineID'>
              </el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span>
            <em>{{$t('Operation.Op_Country')}}/{{$t('system.query_dest')}}</em>
            <el-select v-model="msg.PlaceID" filterable :placeholder="$t('pub.pleaseSel')" @change="getLineTeamList()">
              <el-option :label="$t('pub.unlimitedSel')" :value="0"></el-option>
              <el-option v-for="item in queryCommonData.PlaceList" :label="item.PlaceName" :value="item.PlaceID"
                :key="item.LtID"></el-option>
            </el-select>
          </span>
        </li>
        <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='0'></el-option>
              <el-option v-for="item in queryCommonData.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('pub.date')}}</em>
            <!-- <el-date-picker v-model='msg.StartDate' class='w135' value-format="yyyy-MM-dd" type="date"
              :picker-options="pickerBeginDateBefore"></el-date-picker> -->
              <DateLimit :clearable="false" :StartGroupDate="msg.StartDate" :EndGroupDate="msg.EndDate" @change="(date)=> msg.StartDate = date"></DateLimit>
            -
            <el-date-picker v-model='msg.EndDate' class='w135' value-format="yyyy-MM-dd" type="date"
              :picker-options="pickerBeginDateAfter"></el-date-picker>
          </span>
        </li>
        <li><span>
            <em>{{$t('admin.admin_status')}}</em>
            <el-select v-model='msg.PriceStatus'>
              <el-option :label="$t('pub.unlimitedSel')" :value="0"></el-option>
              <el-option v-for="team in $tripUtils.TeamStatesList.TeamStates" :label="team.Name" :key="team.Id"
                :value="team.Id" v-if="team.Id==1 || team.Id==3"></el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span>
            <em>{{$t('Airticket.Air_Airlines')}}</em>
            <el-select v-model="msg.AirLineId" filterable :placeholder="$t('system.ph_buxian')">
              <el-option :label="$t('system.ph_buxian')" :value="0">
              </el-option>
              <el-option v-for="item in queryCommonData.AirlineList" :key="item.AirLineId" :label="item.AlName"
                :value="item.AirLineId"></el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span>
            <em>OP</em>
            <el-select v-model="msg.CreateBy" filterable :placeholder="$t('pub.pleaseSel')">
              <el-option :label="$t('pub.unlimitedSel')" :value="0">
              </el-option>
              <el-option v-for="item in queryCommonData.EmployeeList" :label="item.EmName" :value="item.EmployeeId"
                :key="item.EmployeeId"></el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span>
            <em>{{$t('ground.dijietuanhao')}}</em>
            <el-input v-model='msg.CombinationNum'></el-input>
          </span>
        </li>
        <li>
          <span>
            <em>{{$t('scen.sc_cp')}}</em>
            <el-select v-model="msg.OutBranchIds" filterable multiple class="multiple_input"
              :placeholder="$t('pub.pleaseSel')">
              <el-option v-for="item in queryCommonData.BranchList" :label='item.BName' :value='item.Id' :key='item.Id'>
              </el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span>
            <em>{{$t('ground.jiudianzhuangtai')}}</em>
            <el-select v-model="msg.HotelStatus" :placeholder="$t('pub.pleaseSel')" filterable>
              <el-option :label="$t('pub.unlimitedSel')" :value='0'></el-option>
              <el-option :label="$t('ground.jiudianztS[0]')" :value='100'></el-option>
              <el-option :label="$t('ground.jiudianztS[1]')" :value='1'></el-option>
              <el-option :label="$t('ground.jiudianztS[2]')" :value='2'></el-option>
              <el-option :label="$t('ground.jiudianztS[3]')" :value='3'></el-option>
              <el-option :label="$t('ground.jiudianztS[4]')" :value='4'></el-option>
              <el-option :label="$t('ground.jiudianztS[5]')" :value='5'></el-option>
              <el-option :label="$t('ground.jiudianztS[6]')" :value='6'></el-option>
              <el-option :label="$t('ground.jiudianztS[7]')" :value='7'></el-option>
            </el-select>
          </span>
        </li>
        <li>
          <input type="button" class="normalBtn" :value="$t('pub.searchBtn')" @click="getList();resetPageIndex()" />
        </li>
      </ul>
    </div>
    <div style="width: 100%;  overflow-x: auto;padding-bottom: 10px; " class="ownScrollbarStyle"
      :style="{height: boxHeight + 'px'}">
      <table border="0" cellspacing="1" cellpadding="0" class="roomReservationsTalbe" style="width:100%"
        v-loading='loading'>
        <tr>
          <th width="120">{{$t('active.ad_xuhao')}}</th>
          <th width="80">{{$t('ground.chufadi')}}</th>
          <th width="90">{{$t('ground.hbsj')}}</th>
          <th width="145">{{$t('ground.gongsituanhao')}}</th>
          <th width="100">{{$t('ground.jiweishu')}}<br />(Y/E/F)</th>
          <th width="80">{{$t('ground.zhanchuang')}}<br />{{$t('ground.bzhanchuang')}}</th>
          <th width="80">{{$t('ground.shijiyfs')}}</th>
          <th width="100">{{$t('system.table_operation')}}</th>
          <th width="110">{{$t('adm.adm_time')}}</th>
          <th width="120">{{$t('hotel.hotel_name')}}</th>
          <th width="120">{{$t('ground.genghuanjiudian')}}</th>
          <th width="100">OP{{$t('hotel.hotel_status')}}</th>
          <th width="100">{{$t('ground.dijiezhuangtai')}}</th>
          <th width="150">{{$t('ground.fangjianyds')}}<br />
            SGL/TWN/DBL/TRP/{{$t('objFill.shidao')}}S
          </th>
        </tr>
        <tr v-if="DataList.length==0">
          <td colspan="14">{{$t('system.content_noData')}}</td>
        </tr>
        <template v-for="(outItem,outindex) in DataList">
          <tbody :class="{roomReservationsSplitTrCss:outindex%2!=0}">
            <template v-for="(item,index) in outItem.StaticsReportList">
              <template v-for="(subItem,subIndex) in item.CommonReport.HotelOrderListReport"
                v-if="subItem.HotelOrderList.length>0">
                <template v-for="(thirdItem,thirdIndex) in subItem.HotelOrderList">
                  <tr>
                    <td :rowspan="outItem.rootRowspan" v-if='index==0&&subIndex==0&&thirdIndex==0'>
                      {{outItem.NewCombinationNum}}
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      {{item.StartCityNames}}
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      <div class="w150">
                        {{item.FlightDate}}
                        <el-popover popper-class="roomReservations_tripDetails" width="550" trigger="click">
                          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr class="_color_666" style="text-align:center;">
                              <th width="60">{{$t('Airticket.Air_segment')}}</th>
                              <th width="80">{{$t('system.query_flightNum')}}</th>
                              <th width="150">{{$t('system.ph_flightTime')}}</th>
                              <th width="80">{{$t('system.query_arrivalTime')}}</th>
                              <th width="100">{{$t('system.query_stopCity')}}</th>
                            </tr>
                            <tr v-for="(ds,din) in item.FlightList" :key="din" style="text-align:center;">
                              <td class="_d_name _color_666">
                                <span v-if="din==0">{{$t('Airticket.Air_go')}}</span>
                                <span
                                  v-else-if="din==item.FlightList.length-1">{{$t('Airticket.Air_returnTrip')}}</span>
                                <span
                                  v-else-if="din>0 && din!=item.FlightList.length-1">{{$t('Airticket.Air_transit')}}</span>
                              </td>
                              <td>
                                <div>{{ds.Flight_number}}</div>
                                <div style="margin-top:5px;">{{ds.AlName}}</div>
                              </td>
                              <td>
                                <div>{{ds.FlightDate}} {{ds.Departure_time}}</div>
                                <div style="margin-top:5px;">{{ds.dName}}</div>
                              </td>
                              <td>
                                <div>{{ds.FlightArrivalTime}} {{ds.Arrival_time}}</div>
                                <div style="margin-top:5px;">{{ds.aName}}</div>
                              </td>
                              <td>{{ds.StopoverName}}</td>
                            </tr>
                          </table>
                          <el-button slot="reference" class="normalBtn mt5"
                            style='height:24px; padding: 0 10px; background: #2AAEF2; border-color: #2AAEF2;'>
                            {{$t('fnc.xiangqing')}}
                          </el-button>
                        </el-popover>
                      </div>
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      <p @click="goToTravelList(item)" style="cursor:pointer;text-decoration:underline;">
                        {{item.TCNUMS}}({{item.TCIDS}})
                      </p>
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      <p @click="goUrlT('RegistrationList',item.TCIDS,'报名清单')"
                        style="cursor:pointer;text-decoration:underline;">
                        {{item.TotalSeat}}/{{item.CommonReport.HouseStatistics.RealityYSeatNum}}/{{item.CommonReport.HouseStatistics.RealityESeatNum}}/{{item.CommonReport.HouseStatistics.RealityFSeatNum}}
                      </p>
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      <p @click="goUrlT('passengerHouse',item.TCIDS,'房间分配')"
                        style="cursor:pointer;text-decoration:underline;">
                        {{item.CommonReport.HouseStatistics.NeedBed}}/{{item.CommonReport.HouseStatistics.NoNeedBed}}
                      </p>
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      {{item.CommonReport.HouseStatistics.RealityRoomNum}}
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      <p :title="$t('objFill.v101.hote.dianjtzdjdczym')" @click="goRoomDetails(item,outItem,'订房详情')"
                        style="cursor:pointer;text-decoration:underline;color:red;font-weight:bold;">
                        {{$t('fnc.xiangqing')}}</p>
                    </td>
                    <td :rowspan="subItem.HotelOrderList.length" v-if='thirdIndex==0'>
                      {{subItem.UseTimeStr}}
                    </td>
                    <td style="text-align:left;padding-left:2px;">
                      <template v-if="thirdItem.HotelName!=thirdItem.NewHotelName && thirdItem.NewHotelName!=''">
                        <span style="text-decoration:line-through"> {{thirdItem.HotelName}}</span>
                      </template>
                      <template v-else>
                        {{thirdItem.HotelName}}
                      </template>
                    </td>
                    <td style="text-align:left;padding-left:2px;">
                      <template v-if="thirdItem.HotelName!=thirdItem.NewHotelName">
                        <span style="color:red;">{{thirdItem.NewHotelName}}</span>
                      </template>
                    </td>
                    <td>
                      <template v-if="thirdItem.OPState==1">
                        <span style="color: green;">OP-{{$t('ground.zhiding')}}</span>
                      </template>
                      <template v-else-if="thirdItem.OPState==2">
                        <span style="color:red;">OP-{{$t('visa.v_zanding')}}</span>
                      </template>
                    </td>
                    <td>
                      <template v-if="thirdItem.DMCState==1">
                        <span style="color: green;">{{$t('ground.dijie')}}-OK</span>
                      </template>
                      <template v-else-if="thirdItem.DMCState==2">
                        <span style="color:red;">{{$t('ground.dijie')}}-{{$t('visa.v_zanding')}}</span>
                      </template>
                      <template v-else-if="thirdItem.DMCState==0">
                        <span style="color:red;">{{$t('ground.dijie')}}-{{$t('ground.wicaozuo')}}</span>
                      </template>
                    </td>
                    <td>
                      <span v-for="(lastItem,lastIndex) in thirdItem.OrderDetailsList">
                        {{lastItem.HouseTypeCount}}
                        <template v-if="lastIndex!=thirdItem.OrderDetailsList.length-1">
                          /
                        </template>
                      </span>
                    </td>
                  </tr>
                </template>
              </template>
            </template>
          </tbody>
        </template>
      </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>
  import DateLimit from '../public/DateLimit.vue';
  export default {
    components: {DateLimit},
    data() {
      return {
        userInfo: {}, //当前登录用户信息
        loading: false,
        currentPage: 1,
        total: 0,
        msg: {
          pageIndex: 1,
          pageSize: 5,
          SelectType: 1,
          StartDate: '',
          EndDate: '',
          //酒店编号
          HotelId: 0,
          //日期
          DateStr: "",
          //出团公司
          OutBranchIds: [],
          LineId: 0,
          PlaceID: 0,
          LineteamId: 0,
          //航空公司
          AirLineId: 0,
          CreateBy: 0,
          TCNUM: '',
          PriceStatus: 0,
          CombinationNum: '',
          HotelStatus: 0
        },
        DataList: [], //数据列表
        boxHeight: 0,
        queryCommonData: {
          //公司数据
          BranchList: [],
          //国家
          PlaceList: [],
          LineList: [],
          LineTeamList: [],
          AirlineList: [],
          EmployeeList: [],
        },
        pickerBeginDateBefore: {
          disabledDate: time => {
            if (this.msg.EndDate == null) {
              return false;
            } else {
              let endTime = new Date(this.msg.EndDate)
              return endTime.getTime() < time.getTime()
            }
          }
        },
        pickerBeginDateAfter: {
          disabledDate: time => {
            let startTime = new Date(this.msg.StartDate)
            return startTime.getTime() >= time.getTime()
          }
        }
      }
    },
    methods: {
      goUrlR(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            "ID": obj,
            blank: 'y',
            tab: title
          }
        })
      },
      //跳转到团控列表
      goToTravelList(item) {
        var qMsg = {
          TCID: item.TCID,
          tcmun: item.TCNUMS,
          blank: 'y',
          tab: "团控列表"
        };
        var path = "TravelControlList";
        if (item.TeamType == 1) {
          path = "TravelControlListSale";
          qMsg.tab = "小包团列表";
        }
        if (item.TeamType == 2) {
          path = "oneDayTrip";
          qMsg.tab = "当地游列表";
        }
        this.$router.push({
          name: path,
          query: qMsg
        })
      },
      goUrlT(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            "id": obj,
            blank: 'y',
            tab: title
          }
        })
      },
      goRoomDetails(obj, outItem, title) {
        var path = "roomReservationsDetails";
        if (this.userInfo.RB_Group_id == 91) {
          path = "roomReservationsDetails_swt";
        }
        this.$router.push({
          name: path,
          query: {
            "id": obj.TCIDS,
            'TCNUM': obj.TCNUMS,
            'flightTotal': obj.TotalSeat,
            'GuestNum': obj.CommonReport.HouseStatistics.RealityNum,
            'NewCombinationNum': outItem.NewCombinationNum,
            'LeaderName': obj.LeaderName,
            'GuideName': obj.GuideName,
            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 => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            var sourceData = res.data.data.pageData.data;
            if (sourceData) {
              sourceData.forEach(rootItem => {
                var rootRowspan = 0; //合团跨行
                rootItem.StaticsReportList.forEach(subItem => {
                  var itemRowSpan = 0; //酒店跨行
                  subItem.CommonReport.HotelOrderListReport.forEach(thirdItem => {
                    thirdItem.HotelOrderList.forEach(lastItem => {
                      rootRowspan++;
                      itemRowSpan++;
                    });
                  });
                  subItem.itemRowSpan = itemRowSpan;
                });
                rootItem.rootRowspan = rootRowspan;
              });
            }
            this.DataList = sourceData;
            this.$forceUpdate()
          } else {
            this.$message.error(res.data.message)
          }
        }, err => {})
      },
      getLineList() {
        this.apipost("line_post_GetAllList", {}, res => {
          if (res.data.resultCode == 1) {
            this.queryCommonData.LineList = res.data.data;
            this.queryCommonData.PlaceList = []
            this.queryCommonData.LineTeamList = []
          } else {
            this.Error(res.data.message);
          }
        });
      },
      //获取目的地列表
      getLinePlaceList() {
        this.msg.PlaceID = 0;
        this.msg.LineteamId = 0;
        let msg = {
          lineID: this.msg.LineId,
        }
        this.apipost('team_post_GetLinePlace', msg, res => {
          if (res.data.resultCode == 1) {
            this.queryCommonData.PlaceList = res.data.data
            this.queryCommonData.LineTeamList = []
          }
        })
      },
      //获取系列列表
      getLineTeamList() {
        this.msg.LineteamId = 0
        let msg = {
          lineID: this.msg.LineId,
          placeID: this.msg.PlaceID,
          isTOOP: 1
        }
        this.apipost('team_post_GetList', msg, res => {
          if (res.data.resultCode == 1) {
            this.queryCommonData.LineTeamList = res.data.data
          }
        })
      },
      //获取航空公司
      getAirlineList() {
        this.apipost(
          'airline_post_GetList', {},
          res => {
            if (res.data.resultCode == 1) {
              this.queryCommonData.AirlineList = res.data.data
            }
          },
          err => {}
        )
      },
      //根据当前员工所在部门获取该部门及子部门员工信息
      getEmployeeList() {
        let msg = {
          GroupId: this.userInfo.RB_Group_id,
          BranchId: '-1',
          DepartmentId: '-1',
          PostId: '-1',
          IsLeave: '0'
        }
        this.apipost(
          'admin_get_EmployeeGetList', {},
          res => {
            if (res.data.resultCode == 1) {
              this.queryCommonData.EmployeeList = res.data.data
            }
          },
          err => {}
        )
      },
      //初始化公司
      getCompanyList() {
        var RB_Group_id = this.userInfo.RB_Group_id
        let msg = {
          Status: 0,
          is_show: 0,
          RB_Group_Id: RB_Group_id
        }
        this.apipost(
          'admin_get_BranchGetList',
          msg,
          res => {
            if (res.data.resultCode == 1) {
              this.queryCommonData.BranchList = res.data.data;
            }
          },
          err => {}
        )
      },
      getLineList() {
        this.apipost("line_post_GetAllList", {}, res => {
          if (res.data.resultCode == 1) {
            this.queryCommonData.LineList = res.data.data;
            this.queryCommonData.PlaceList = []
            this.queryCommonData.LineTeamList = []
          } else {
            this.Error(res.data.message);
          }
        });
      },
    },
    mounted() {
      this.userInfo = this.getLocalStorage();
      let myDate = new Date();
      let nowDate =
        myDate.getFullYear() +
        "-" +
        parseInt(myDate.getMonth() + 1) +
        "-" +
        myDate.getDate();

      if (this.$route.query.hotelId) {
        this.msg.HotelId = this.$route.query.hotelId;
      }
      if (this.$route.query.dateStr) {
        this.msg.DateStr = this.$route.query.dateStr;
      }
      if (this.$route.query.hotelId || this.$route.query.dateStr) {
        this.msg.StartDate = "";
      } else {
        this.msg.StartDate = nowDate;
      }
      let width = window.innerWidth - 50;
      let height = window.innerHeight - 65 - 164;
      this.boxHeight = height;
      this.offsetwidth = width;
      if (this.userInfo.RB_Group_id == 2) {
        this.msg.LineId = 14;
      }
      this.getLineList();
      this.getAirlineList();
      this.getEmployeeList();
      this.getCompanyList();
      this.getList();
    },
  }

</script>

<style>
  .roomReservationsSplitTrCss td {
    background: #eee !important;
  }

  .roomReservationsTalbe {
    background: #ccc;
  }

  .roomReservationsTalbe tr th {
    background: #E6E6E6;
    height: 40px;
    font-size: 12px;
    color: #333;
  }

  .roomReservationsTalbe tr {
    background: #fff;
    text-align: center;
    height: 40px;
  }

  .roomReservationsTalbe tr td {
    font-size: 12px;
  }

  .roomReservationsTalbe tr td .pDateStyle {
    border-bottom: 1px solid #ccc;
    min-height: 24px;
    line-height: 24px;
    margin-top: 0;
    box-sizing: content-box;
    padding: 0 10px;
  }

  .roomReservationsTalbe tr td .pDateStyle:last-child {
    border-bottom: none;
  }

  .roomReservationsTalbe tr td .pDateStyle>span:after {
    content: '/';
  }

  .roomReservationsTalbe tr td .pDateStyle>span:last-child:after {
    content: ''
  }

  .roomReservationsTalbe tr td .link p:hover {
    text-decoration: underline;
    cursor: pointer;
  }

  .roomReservationsTalbe tr td .phoverStype:hover {
    text-decoration: underline;
    cursor: pointer;
  }

  .roomReservations_tripDetails {
    padding: 0;
    box-shadow: 0px 1px 3px 0px #dedede;
    max-height: 400px;
    overflow-y: auto;
  }

  .roomReservations_tripDetails .popper__arrow::after {
    border-bottom-color: #ededed !important;
  }

  .roomReservations_tripDetails table {
    padding: 10px 0 0 20px;
    background-color: #ededed;
    border-collapse: collapse;
    border: 1px solid #d2d2d2;
    font-size: 12px;
  }

  .roomReservations_tripDetails table th {
    background-color: #ededed;
    padding: 5px;
  }

  .roomReservations_tripDetails table td {
    background-color: #ffffff;
    padding: 9px 15px;
    color: #333333;
    border: 1px solid #d2d2d2;
  }

  .roomReservations_tripDetails table td._d_name {
    background-color: #ededed;
  }

  .roomReservations_tripDetails table ._color_666 {
    color: #666666;
  }

  .roomReservations_tripDetails table tr._color_666 th {
    padding: 9px 15px;
  }

</style>