<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('sm.Date')}}</em>
            <el-date-picker v-model='msg.StartDate' class='w135' value-format="yyyy-MM-dd" type="date"></el-date-picker>
            -
            <el-date-picker v-model='msg.EndDate' class='w135' value-format="yyyy-MM-dd" type="date"></el-date-picker>
          </span>
        </li>
        <li><span><em>{{$t('commonPickUp.Pick_resName')}}</em>
            <el-select v-model="msg.QDiningID" filterable :placeholder="$t('pub.pleaseSel')">
              <el-option :label="$t('pub.unlimitedSel')" :value='0'></el-option>
              <el-option v-for="item in DiningList" :label='item.Name' :value='item.ID' :key='item.ID'>
              </el-option>
            </el-select>
          </span>
        </li>
        <li>
          <input type="button" class="normalBtn" :value="$t('pub.searchBtn')" @click="getList();resetPageIndex()" />
          <button class="normalBtn" type="button" @click="DownLoadDinner()">{{$t('adm.adm_download')}}</button>
        </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="bookDinnerStatisticsTalbe" v-loading='loading'>
        <tr>
          <th width="110">{{$t('active.ad_xuhao')}}</th>
          <th width="100">{{$t('sm.chufadi')}}</th>
          <th width="120">{{$t('ground.hbsj')}}</th>
          <th width="180">{{$t('ground.gongsituanhao')}}</th>
          <th width="120">{{$t('ground.jiweishokzs')}}</th>
          <th width="120">{{$t('adm.adm_time')}}</th>
          <th width="300">{{$t('restaurant.res_resName')}}</th>
          <th width="100">{{$t('ground.yongcanleixing')}}</th>
          <th width="80">{{$t('admin.admin_status')}}</th>
          <th width="100">{{$t('ground.da')}}</th>
          <th width="100">{{$t('ground.zhong')}}</th>
          <th width="100">{{$t('ground.xiao')}}</th>
          <th width="100">{{$t('system.table_operation')}}</th>
        </tr>
        <template v-for="(outItem,outindex) in DataList">
          <tbody :class="{bookDinnerStatisticsSplitTrCss:outindex%2!=0}" :key="`d_s_`+outindex">
            <template v-for="(item,index) in outItem.StaticsReportList">
              <template v-for="(subItem,subIndex) in item.CommonReport.DiningList">
                <template v-for="(thirdItem,thirdIndex) in subItem.DiningSummaryList">
                  <tr :key="`d_s_d_`+outindex+index+subIndex+thirdIndex">
                    <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'>
                      {{item.FlightDate}}
                      <el-popover popper-class="bookDinnerStatistics_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="150">{{$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>
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      <div class="w150 link">
                        <p @click="goUrlT('productQuery',item.TCNUMS,'产品查询')">{{item.TCNUMS}}({{item.TCID}})</p>
                      </div>
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      <div class="w120 link">
                        <p @click="goUrlT('RegistrationList',item.TCIDS,'报名清单')">
                          {{item.TotalSeat}}/{{item.CommonReport.HouseStatistics.RealityYSeatNum}}/{{item.CommonReport.HouseStatistics.RealityESeatNum}}/{{item.CommonReport.HouseStatistics.RealityFSeatNum}}
                        </p>
                      </div>
                    </td>
                    <td :rowspan="subItem.DiningSummaryList.length" v-if='thirdIndex==0'>
                      {{subItem.UseTimeStr}}
                    </td>
                    <td style="text-align:left;padding-left:3px;">
                      {{thirdItem.DiningName}}
                      <br />
                      真实名称:<font style="color:red;">{{thirdItem.DiningRealName}}</font>
                    </td>
                    <td>
                      {{thirdItem.UseDinnerTypeStr}}
                    </td>
                    <td>
                      <template v-if="thirdItem.OrderState==-1">
                        <span style="color:red">未操作</span>
                      </template>
                      <template v-else-if="thirdItem.OrderState==1">
                        <span style="color:green">确定</span>
                      </template>
                      <template v-else>
                        <span style="color:red">暂定</span>
                      </template>
                    </td>
                    <td>
                      <!--大人-->
                      <template v-for="lastItem in thirdItem.DiningPriceList"
                        v-if="lastItem.PeopleType==1">{{lastItem.PeoplePrice}}</template>
                    </td>
                    <td>
                      <!--中学生-->
                      <template v-for="lastItem in thirdItem.DiningPriceList"
                        v-if="lastItem.PeopleType==2">{{lastItem.PeoplePrice}}</template>
                    </td>
                    <td>
                      <!--小学生-->
                      <template v-for="lastItem in thirdItem.DiningPriceList"
                        v-if="lastItem.PeopleType==3">{{lastItem.PeoplePrice}}</template>
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      <div class="w80 link">
                        <p @click="goDinnerDetails(item,outItem,'订餐详情')">{{$t('fnc.xiangqing')}}</p>
                      </div>
                    </td>
                  </tr>
                  <tr
                    v-if="subIndex== item.CommonReport.DiningList.length-1 && thirdIndex==subItem.DiningSummaryList.length-1">
                    <td :colspan="12" style="text-align: left!important;padding-left: 20px;">
                      <div class="link">
                        <p @click="goUrlT('productQuery',item.TCNUMS,'产品查询')">{{item.Titles}}</p>
                        <div v-show="outItem.StaticsReportList[0].DMCRemark!=''" class="colorE95252">
                          {{$t('Operation.Op_dijieRemark')}}:{{outItem.StaticsReportList[0].DMCRemark}}</div>
                      </div>
                    </td>
                  </tr>
                </template>
              </template>
            </template>
          </tbody>

        </template>
      </table>
    </div>
    <el-pagination background @current-change="handleCurrentChange" :current-page.sync="msg.currentPage"
      layout="total,prev, pager, next, jumper" :page-size="msg.pageSize" :total="msg.total"></el-pagination>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        userInfo: {}, //用户信息
        loading: false,
        msg: {
          pageIndex: 1,
          pageSize: 5,
          SelectType: 2,
          LineId: 0,
          PlaceID: 0,
          LineteamId: 0,
          StartDate: '',
          EndDate: '',
          currentPage: 1,
          total: 0,
          QDiningID: 0, //餐厅编号
        },
        //餐厅列表
        DiningList: [],
        queryCommonData: {
          PlaceList: [],
          LineList: [],
          LineTeamList: [],
        },
        DataList: [],
        boxHeight: 0,
      }
    },
    methods: {
      stringToArr(str) {
        return str.split(',')
      },
      PeopleTypeToWord(str) {
        if (str == 1)
          return this.$t('salesModule.Adult') + ':'
        if (str == 2)
          return this.$t('ground.xiaohai') + ':'
        if (str == 3)
          return this.$t('Operation.Op_baby') + ':'
      },
      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
          }
        })
      },
      goUrlR(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            "ID": obj,
            blank: 'y',
            tab: title
          }
        })
      },
      goUrlT(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            "id": obj,
            blank: 'y',
            tab: title
          }
        })
      },
      goDinnerDetails(obj, outItem, title) {
        var path = "bookDinnerStatisticsDetails";
        if (this.userInfo.RB_Group_id == 91) {
          path = "bookDinnerStatisticsDetails_SWT";
        }
        this.$router.push({
          name: path,
          query: {
            "id": obj.TCIDS,
            'TCNUM': obj.TCNUMS,
            'flightTotal': obj.TotalSeat,
            'GuestNum': obj.CommonReport.HouseStatistics.RealityNum,
            'NewCombinationNum': outItem.NewCombinationNum,
            blank: 'y',
            tab: title
          }
        })
      },
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      resetPageIndex() {
        this.msg.pageIndex = 1;
        this.msg.currentPage = 1;
      },
      getList() {
        this.loading = true
        this.apipost('dmcstatistics_post_GetUniteCombinationNumService', this.msg, res => {
          this.loading = false
          if (res.data.resultCode == 1) {
            this.msg.total = res.data.data.count;
            var sourceData = res.data.data.pageData.data;
            sourceData.forEach(outItem => {
              var rootRowspan = 0; //合团跨行
              outItem.StaticsReportList.forEach(item => {
                var itemRowSpan = 0; //餐厅跨行
                item.CommonReport.DiningList.forEach(thirdItem => {
                  thirdItem.DiningSummaryList.forEach(lastItem => {
                    rootRowspan++;
                    itemRowSpan++;
                  });
                });
                item.itemRowSpan = itemRowSpan;
              });
              rootRowspan += outItem.StaticsReportList.length;
              outItem.rootRowspan = rootRowspan;
            });
            this.DataList = sourceData;
            this.$forceUpdate()
          } else {
            this.$message.error(res.data.message);
          }
        }, err => {})
      },
      //获取餐厅列表
      GetDinnerList() {
        this.DiningList = [];
        this.apipost(
          "dining_post_GetList", {
            QCountrys: "651"
          },
          res => {
            if (res.data.resultCode == 1) {
              this.DiningList = res.data.data;
            }
          }
        );
      },
      //餐厅下载
      DownLoadDinner() {
        this.loading = true;
        let qMsg = {
          queryMsg: this.msg,
          uid: this.userInfo.EmployeeId
        };
        let fileName = this.$t('ground.cantxiazai') + this.$commonUtils.getCurrentDate() + ".xls";
        this.GetLocalFile("dinner_get_downloadDinner", qMsg, fileName,
          res => {
            this.loading = false;
          });
      }
    },
    mounted() {
      this.userInfo = this.getLocalStorage();
      if (this.userInfo.RB_Group_id == 2) {
        this.msg.LineId = 14;
      }
      let myDate = new Date();
      let nowDate =
        myDate.getFullYear() +
        "-" +
        parseInt(myDate.getMonth() + 1) +
        "-" +
        myDate.getDate();
      this.msg.StartDate = nowDate;
      let width = window.innerWidth - 50;
      let height = window.innerHeight - 65 - 164;
      this.boxHeight = height;
      this.offsetwidth = width;
      this.getLineList();
      this.GetDinnerList();
      this.getList();
    },
  }

</script>

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

  .bookDinnerStatisticsTalbe {
    background: #ccc;
  }

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

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

  /*.bookDinnerStatisticsTalbe tr:nth-child(2n+1){background:#f2f2f2; }*/
  .bookDinnerStatisticsTalbe tr td {
    font-size: 12px;
  }

  .bookDinnerStatisticsTalbe tr td .pHouseStyle {
    border-bottom: 1px solid #ccc;
    height: 20px;
    line-height: 20px;
  }

  .bookDinnerStatisticsTalbe tr td .pHouseStyle:last-child {
    border-bottom: none;
  }

  .bookDinnerStatisticsTalbe tr td .pDateStyle {
    border-bottom: 1px solid #ccc;
    height: 20px;
    line-height: 20px;
    margin-top: 0;
  }

  .bookDinnerStatisticsTalbe tr td .pMsgStyle {
    ;
    padding: 0 10px;
    line-height: 20px;
  }

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

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

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

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

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

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

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

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

  .bookDinnerStatistics_tripDetails>table ._color_666 {
    color: #666666;
  }

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

  .DiningTable {
    background: #fff;
  }

  .DiningTable tr {
    height: 20px;
  }

  .DiningTable tr th {
    height: 20px;
    font-size: 12px;
    background: #fafafa !important;
    border-bottom: 1px solid #ccc;
    border-right: 1px solid #ccc;
  }

  .DiningTable tr th:last-child {
    border-right: none;
  }

  .DiningTable tr td {
    height: 34px;
    border-bottom: 1px solid #ccc;
    border-right: 1px solid #ccc;
  }

  /* .bookDinnerStatisticsTalbe tr td .DiningTable tr:last-child >td{
    border-bottom:0;
  } */
  .DiningTable tr td:last-child {
    border-right: none;
  }

</style>
