<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('advmanager.v_xilie')}}{{$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>
          <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">
      <table border="0" cellspacing="1" cellpadding="0" class="admissionStatisticsTalbe" v-loading='loading'>
        <tr>
          <th width="120">{{$t('active.ad_xuhao')}}</th>
          <th width="100">{{$t('sm.chufadi')}}</th>
          <th width="120">{{$t('ground.hbsj')}}</th>
          <th width="140">{{$t('salesModule.CompanyNum')}}</th>
          <th width="120">{{$t('visa.v_tuanhao')}}</th>
          <th width="120">{{$t('sm.Date')}}</th>
          <th width="250">{{$t('commonPickUp.Pick_attractions')}}</th>
          <th width="100">{{$t('system.table_operation')}}</th>
        </tr>
        <template v-for="(outItem,outindex) in DataList">
          <tbody :class="{admissionStatisticsSplitTrCss:outindex%2!=0}">
            <template v-for="(item,index) in outItem.StaticsReportList">
              <template v-for="(subItem,subIndex) in item.CommonReport.ScenicList">
                <template v-for="(thirdItem,thirdIndex) in subItem.ScenicStatisticsList">
                  <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'>
                      {{item.FlightDate}}
                      <el-popover popper-class="admissionStatistics_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="w150 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.ScenicStatisticsList.length" v-if='thirdIndex==0'>
                      {{thirdItem.UseTimeStr}}
                    </td>
                    <td style="text-align:left;padding-left:3px;">
                      {{thirdItem.ScenicName}} 【<span
                        style="color:red">{{getUseTypeStr(thirdItem.TicketPriceList)}}</span>】
                    </td>
                    <td :rowspan="item.itemRowSpan" v-if='subIndex==0&&thirdIndex==0'>
                      <div class="link">
                        <div class="w80">
                          <p @click="goTicketDetails(item,outItem,'门票详情')">{{$t('fnc.xiangqing')}}
                          </p>
                        </div>
                      </div>
                    </td>
                  </tr>
                  <tr
                    v-if="subIndex== item.CommonReport.ScenicList.length-1 && thirdIndex==subItem.ScenicStatisticsList.length-1">
                    <td colspan="7" style="text-align:left; padding-left:5px">
                      <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="currentPage"
      layout="total,prev, pager, next, jumper" :page-size=msg.pageSize :total=total></el-pagination>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        userInfo: {}, //用户信息
        loading: false,
        currentPage: 1,
        total: 0,
        msg: {
          pageIndex: 1,
          pageSize: 5,
          SelectType: 3,
          LineId: 0,
          PlaceID: 0,
          LineteamId: 0,
          StartDate: '',
          EndDate: ''
        },
        queryCommonData: {
          PlaceList: [],
          LineList: [],
          LineTeamList: [],
        },
        DataList: [],
      }
    },
    methods: {
      getUseTypeStr(item) {
        var str = '';
        if (item) {
          item.forEach(childItem => {
            var useStr = "";
            if (childItem.PeopleType == 1) {
              useStr = "成人"
            }
            if (childItem.PeopleType == 2) {
              useStr = "中人"
            }
            if (childItem.PeopleType == 3) {
              useStr = "小人"
            }
            str += useStr + ":" + childItem.UsePeopleNum + ",";
          });
        }
        return str.substring(0, str.lastIndexOf(','));
      },
      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
          }
        })
      },
      goUrlT(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            "id": obj,
            blank: 'y',
            tab: title
          }
        })
      },
      goTicketDetails(obj, outItem, title) {
        var path = "admissionStatisticsDetails";
        if (this.userInfo.RB_Group_id == 91) {
          path = "admissionStatisticsDetails_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.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 tempData = res.data.data.pageData.data;
            tempData.forEach(outItem => {
              var rootRowspan = 0; //合团跨行
              outItem.StaticsReportList.forEach(item => {
                var itemRowSpan = 0; //景点跨行
                item.CommonReport.ScenicList.forEach(thirdItem => {
                  thirdItem.ScenicStatisticsList.forEach(lastItem => {
                    rootRowspan++;
                    itemRowSpan++;
                  });
                });
                item.itemRowSpan = itemRowSpan;
              });
              rootRowspan += outItem.StaticsReportList.length;
              outItem.rootRowspan = rootRowspan;
            });
            this.DataList = tempData;
          } else {
            this.$message.error(res.data.message)
          }
        }, err => {})
      },
    },
    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;
      this.getLineList();
      this.getList()
    },
  }

</script>

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

  .admissionStatisticsTalbe {
    background: #ccc;
  }

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

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

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

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

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

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

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

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

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

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

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

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

</style>