<style>
  .HotelWorkP{
    display: inline-block;
    text-decoration: underline;
    cursor: pointer;
  }
</style>

<template>
  <div class="PriceHotelWorkList">
    <div class="query-box" style="border-bottom: none;">
      <ul>
        <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>系列</em>
            <el-select v-model="msg.LineteamId" filterable :placeholder="$t('pub.pleaseSel')">
              <el-option label="不限" :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>团号</em>
            <el-input v-model='msg.TCNUM'></el-input>
          </span>
        </li>
        <li><span><em>日期</em>
            <el-date-picker v-model='msg.StartGroupDate' class='w135' value-format="yyyy-MM-dd" type="date"
              :picker-options="pickerBeginDateBefore"></el-date-picker>
            -
            <el-date-picker v-model='msg.EndGroupDate' class='w135' value-format="yyyy-MM-dd" type="date"
              :picker-options="pickerBeginDateAfter"></el-date-picker>
          </span>
        </li>
        <li style="display:none;"><span>
            <em>状态</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>航空公司</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 style="display:none;">
          <span>
            <em>地接团号</em>
            <el-input v-model='msg.CombinationNum'></el-input>
          </span>
        </li>
        <li>
          <span>
            <em>出团公司</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>酒店状态</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="全部OK" :value='100'></el-option>
              <el-option label="暂定一晚" :value='1'></el-option>
              <el-option label="暂定两晚" :value='2'></el-option>
              <el-option label="暂定三晚" :value='3'></el-option>
              <el-option label="暂定四晚" :value='4'></el-option>
              <el-option label="暂定五晚" :value='5'></el-option>
              <el-option label="暂定六晚" :value='6'></el-option>
              <el-option label="暂定七晚以上" :value='7'></el-option>
            </el-select>
          </span>
        </li>
        <li>
          <input type="button" class="normalBtn" value="查询" @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" v-loading='loading'
        style="width:100%;">
        <tr>
          <th width="120">系列</th>
          <th width="120">团号</th>
          <th width="80">地接团号</th>
          <th width="90">机位数</th>
          <th width="90">操作人</th>
          <th width="110">时间</th>
          <th width="120">酒店名称</th>
          <th width="120">更换酒店</th>
          <th width="100">OP状态</th>
          <th width="100">地接状态</th>
          <th width="150">操作</th>
        </tr>
        <template v-for="(item,index) in DataList">
          <tbody>
            <template v-for="(subItem,subIndex) in item.HotelOrderListReports">
              <template v-for="(childItem,childIndex) in subItem.SubList">
                <tr>
                  <td :rowspan="item.rootRowspan" v-if='subIndex==0&&childIndex==0'>
                    <div>出团公司:{{item.OutBranchName}}</div>
                    <div>{{item.LtName}}</div>
                  </td>
                  <td :rowspan="item.rootRowspan" v-if='subIndex==0&&childIndex==0'>
                    <p class="HotelWorkP" @click="goUrlT('TravelControlList',item.TCNUM,'团控列表')">{{item.TCNUM}}({{item.TCID}})</p>
                  </td>
                  <td :rowspan="item.rootRowspan" v-if='subIndex==0&&childIndex==0'>{{item.DMCNum}} </td>
                  <td :rowspan="item.rootRowspan" v-if='subIndex==0&&childIndex==0'
                    style="text-align:left; padding-left:5px;">
                    {{$t('Airticket.Air_firstClass')}}:{{item.FSeat}} <br />
                    {{$t('Airticket.Air_businessClass')}}:{{item.CSeat}} <br />
                    {{$t('Airticket.Air_EconomyClass')}}:{{item.YSeat}}
                  </td>
                  <td :rowspan="item.rootRowspan" v-if='subIndex==0&&childIndex==0'>{{item.OPName}} </td>
                  <td :rowspan="subItem.SubList.length" v-if='childIndex==0'>
                    {{childItem.JourneyDate}}
                  </td>
                  <td>
                    <template v-if="childItem.HotelName!=childItem.NewHotelName && childItem.NewHotelName!=''">
                      <span style="text-decoration:line-through;"> {{childItem.HotelName}}</span>
                    </template>
                    <template v-else>
                      {{childItem.HotelName}}
                    </template>
                  </td>
                  <td>
                    <template v-if="childItem.HotelName!=childItem.NewHotelName">
                      <span style="color:red;">{{childItem.NewHotelName}}</span>
                    </template>
                  </td>
                  <td>
                    <template v-if="childItem.OPState==1">
                      <span style="color: green;">OP-指定</span>
                    </template>
                    <template v-else-if="childItem.OPState==2">
                      <span style="color:red;">OP-暂定</span>
                    </template>
                  </td>
                  <td>
                    <template v-if="childItem.DMCState==1">
                      <span style="color: green;">地接-OK</span>
                    </template>
                    <template v-else-if="childItem.DMCState==2">
                      <span style="color:red;">地接-暂定</span>
                    </template>
                    <template v-else-if="childItem.DMCState==0">
                      <span style="color:red;">地接-未操作</span>
                    </template>
                  </td>
                  <td :rowspan="subItem.SubList.length" v-if='childIndex==0'>
                    <el-popover placement="right" width="540" trigger="click" v-model="subItem.isShowPop">
                      <commonPriceHotelWork :ref="'commonPriceHotelWork_'+index+'_'+subIndex+'_'+childIndex+''"
                        :DateStr="childItem.JourneyDate" :TCID="item.TCID" :DayNum="subItem.DayNum" :TCNUM="item.TCNUM"
                        v-on:childPriceHotel="priceHotelList">
                      </commonPriceHotelWork>
                      <el-button size="small" type="danger"
                        :data-index="'commonPriceHotelWork_'+index+'_'+subIndex+'_'+childIndex+''" slot="reference"
                        style="cursor:pointer;"
                        @click="getPriceHotel(index,subIndex,childIndex),subItem.isShowPop=true">
                        更换酒店
                      </el-button>
                    </el-popover>
                  </td>
                </tr>
              </template>
            </template>
            <tr>
              <td :colspan="11" style="text-align:left;padding-left:5px;">
                {{item.Title}}
              </td>
            </tr>
          </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 commonPriceHotelWork from "../../commonPage/commonPriceHotelWork.vue";
  export default {
    data() {
      return {
        loading: false,
        currentPage: 1,
        total: 0,
        msg: {
          //出团公司集合
          OutBranchIds: [],
          pageIndex: 1,
          pageSize: 10,
          LineId: 0,
          PlaceID: 0,
          LineIdList: [14],
          LineteamId: 0,
          TCNUM: '',
          StartGroupDate: '',
          EndGroupDate: '',
          OutBranchId: -1,
          AirTicketId: 0,
          TeamMinNum: -1,
          TeamMaxNum: -1,
          CreateBy: 0,
          ApplyMinNum: -1,
          ApplyMaxNum: -1,
          DayNum: -1,
          OnlyShowOverTeam: false,
          TCState: [3], //去掉默认显示
          GroupState: [],
          SalePlat: [],
          UnionCityId: 0,
          SaleBranchId: [],
          total: 0,
          //是否有数据
          noData: false,
          currentPage: 1,
          //航班配置
          FlightState: 0,
          //预警团
          IsWarning: false,
          WarningQuery: '-1',
          RateOnDay: '-1',
          RateOn: '-1',
          TeamType: 0, //一般常规团
          IsShowUnion: -1,
          TCID: 0,
          HotelId: 0, //酒店编号
          HotelUseTime: "", //酒店使用时间
        },
        DataList: [], //数据列表
        boxHeight: 0,
        queryCommonData: {
          //公司数据
          BranchList: [],
          //国家
          PlaceList: [],
          LineList: [],
          LineTeamList: [],
          AirlineList: [],
          EmployeeList: [],
        },
        findex: 0,
        childIndex: 0,
        pickerBeginDateBefore: {
          disabledDate: time => {
            if (this.msg.EndGroupDate == null) {
              return false;
            } else {
              let endTime = new Date(this.msg.EndGroupDate)
              return endTime.getTime() < time.getTime()
            }
          }
        },
        pickerBeginDateAfter: {
          disabledDate: time => {
            let startTime = new Date(this.msg.StartGroupDate)
            return startTime.getTime() >= time.getTime()
          }
        }
      }
    },
    components: {
      commonPriceHotelWork
    },
    methods: {
      //点击酒店
      getPriceHotel(index, subIndex, childIndex) {
        let str = `commonPriceHotelWork_${index}_${subIndex}_${childIndex}`;
        this.$refs[str][0].getPriceHotelCheck();
      },
      //父页面方法
      priceHotelList(obj) {
        this.DataList.forEach(x => {
          x.HotelOrderListReports.forEach(y => {
            y.isShowPop = false;
          })
        });
        var nMsg = {
          TCID: obj.TCID,
          DayNum: obj.DayNum,
          HotelId: obj.ID
        };
        this.loading=true;
        this.apipost("travel_post_SavePriceHotelService", nMsg, res => {
          this.loading=false;
          if (res.data.resultCode == 1) {
            this.Success(res.data.message);
            this.getList();
          } else {
            this.Error(res.data.message);
          }
        });
      },
      goUrlT(path, TCNUMS, title) {
        this.$router.push({
          name: path,
          query: {
            tcmun: TCNUMS,
            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('travel_get_GetPriceHotelListService', this.msg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            var sourceData = res.data.data.pageData;
            if (sourceData) {
              sourceData.forEach(rootItem => {
                var rootRowspan = 0; //合团跨行
                rootItem.HotelOrderListReports.forEach(subItem => {
                  var itemRowSpan = 0; //酒店跨行
                  subItem.SubList.forEach(thirdItem => {
                    rootRowspan++;
                    itemRowSpan++;
                  });
                  subItem.itemRowSpan = itemRowSpan;
                });
                rootItem.rootRowspan = rootRowspan;
              });
            }
            this.DataList = sourceData;
            this.$forceUpdate()
          } else {
            this.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: 14,
        }
        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: 14,
          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 userInfo = this.getLocalStorage()
        let msg = {
          GroupId: 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() {
        let userInfo = this.getLocalStorage()
        var RB_Group_id = 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 => {}
        )
      },
    },
    mounted() {
      let myDate = new Date();
      let nowDate =
        myDate.getFullYear() +
        "-" +
        parseInt(myDate.getMonth() + 1) +
        "-" +
        myDate.getDate();
      this.msg.StartGroupDate = nowDate;
      //this.msg.StartGroupDate='2019-12-05';
      let width = window.innerWidth - 50;
      let height = window.innerHeight - 65 - 164;
      this.boxHeight = height;
      this.offsetwidth = width;
      this.getLinePlaceList();
      this.getAirlineList();
      this.getEmployeeList();
      this.getCompanyList();
      this.getList();
    },
  }

</script>

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

  .PriceHotelWorkList .roomReservationsTalbe {
    background: #ccc;
  }

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

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

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

  .PriceHotelWorkList .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;
  }

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

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

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

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

  .PriceHotelWorkList .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>