<template>
  <div
    class="items-start travel-list"
    :class="$q.platform.is.desktop ? 'row q-mt-lg' : 'colmuns'"
  >
  <!-- 移动端 -->
  <div v-if="$q.platform.is.mobile">
    
    <div class="flex">
       <div @click="showAddress = true" class="nav-item">目的地<i class="iconfont iconarrowdown text-grey-6" style="margin-top: 3px; margin-left:4px"></i></div>
       <div @click="showCategory = true" class="nav-item">商品類別<i class="iconfont iconarrowdown text-grey-6" style="margin-top: 3px; margin-left:4px"></i></div>
       <div @click="showDate = true" class="nav-item">旅程時間<i class="iconfont iconarrowdown text-grey-6" style="margin-top: 3px; margin-left:4px"></i></div>
       <div @click="showPrice = true" class="nav-item">價錢/时间<i class="iconfont iconarrowdown text-grey-6" style="margin-top: 3px; margin-left:4px"></i></div>
    </div>
      <popup mode="top" v-model="showAddress">
      <q-card flat class="rounded-borders q-py-md">
        <div class="text-subtitle1 text-weight-bold q-mx-md">篩選目的地</div>
        <q-input
          v-model="searchAdd.name"
          type="text"
          standout
          placeholder="蒐索關鍵字"
          class="q-ma-md"
          @input="changeAddrSearchHandler"
        />
      </q-card>
      </popup>
      
      <popup mode="top" v-model="showCategory">
        <q-card flat class="rounded-borders q-py-md q-mt-lg">
        <div class="text-subtitle1 text-weight-bold q-mx-md">行程類型</div>
        <q-radio v-model="msg.TicketType" val="1" label="往返" />
        <q-radio v-model="msg.TicketType" val="2" label="单程" />
      </q-card> 

      <q-card flat class="rounded-borders q-py-md q-mt-lg">
        <div class="text-subtitle1 text-weight-bold q-mx-md">出發城市</div>
        <q-select filled 
        v-model="msg.DepartCityId" 
        :options="goodsType" 
        emit-value map-options 
        option-label="Name" 
        o-value="ID" label="請選擇出發地">
                    </q-select>
      </q-card> 
    </popup>
      <popup mode="top" v-model="showDate">
      <q-card flat class="rounded-borders q-mt-lg overflow-hidden">
        <div class="q-my-sm q-mx-lg f20 bold">旅程時間</div>
          <div
            class="addr-list q-px-md q-py-sm row items-center"
            v-for="(y, yi) in dayArray"
            :key="yi"
          >
            <q-checkbox
              v-model="y.checked"
              size="xs"
              @input="changeTripDayHandler"
            />
            <span
              class="col text-grey-8 text-subtitle2 text-regular q-mt-xs"
              style="font-weight: 400"
            >
              {{ y.text }}
            </span>
          </div>
      </q-card>
      </popup>
      <popup mode="top" v-model="showPrice">

      <q-card flat class="rounded-borders q-pa-md q-mt-lg">
        <div class="text-subtitle1 text-weight-bold">價錢篩選（CNY）</div>
        <div class="q-mt-md text-grey-6 text-subtitle2 text-regular">
          {{ msg.priceRange.min }} - {{ msg.priceRange.max }}
        </div>
        <q-range
          v-model="msg.priceRange"
          :min="priceModel.min"
          :max="priceModel.max"
          :step="1"
          @change="testHandler"
          color="primary"
          class="q-mt-md"
        />
      </q-card><q-card flat class="rounded-borders q-mt-lg row no-padding q-mb-lg">
        <div
          class="q-px-md q-py-sm "
          style="border-right: 1px solid #eee; border-radius: 0 !important"
        >
          <q-icon name="iconfont iconigw-l-date-trade" size="24px" />
        </div>
        <div class="row items-center justify-center col">
          <span class="text-grey-8">
            {{
              msg.StartDate
                ? `${msg.StartDate} - ${msg.EndDate}`
                : "篩選出發日期"
            }}
          </span>
          <q-popup-proxy :offset="[0, 0]" ref="qDateProxy">
            <div>
              <q-date
                v-model="dateRange"
                :options="optionsFn"
                range
                @range-end="dateRangeHandler"
                mask="YYYY-MM-DD"
              ></q-date>
            </div>
          </q-popup-proxy>
        </div>
      </q-card></popup>
  </div>
    <div v-else class="col-3" :class="$q.platform.is.desktop ? 'q-mr-lg' : 'q-ma-md'">
      <q-card flat class="rounded-borders q-py-md">
        <div class="text-subtitle1 text-weight-bold q-mx-md">篩選目的地</div>
        <q-input
          v-model="searchAdd.name"
          type="text"
          standout
          placeholder="蒐索關鍵字"
          class="q-ma-md"
          @input="changeAddrSearchHandler"
        />
      
      </q-card>
      <q-card flat class="rounded-borders q-py-md q-mt-lg">
        <div class="text-subtitle1 text-weight-bold q-mx-md">行程類型</div>
        <div class="q-gutter-sm" style=" display: inline-flex;  justify-content: space-around;">
          <q-radio @input="handleTicked" v-model="msg.TicketType" val="1" label="往返" :dense="true"  style="margin-left:1.5rem;"/>
          <q-radio  @input="handleTicked" v-model="msg.TicketType" val="2" label="单程"  :dense="true" style="margin-left:2rem;"/>
        </div>
      </q-card> 

      <q-card flat class="rounded-borders q-py-md q-mt-lg">
        <div class="text-subtitle1 text-weight-bold q-mx-md">出發地</div>
        <!-- ref="category" -->
        <!-- <q-tree
            v-model:ticked="ticked"
            :nodes="goodsType"
            no-connectors
            node-key="ID"
            label-key="Name"
            tickable="true"
            tick-strategy="leaf"
            @update:ticked="handleTicked"
            :ticked="ticked"
          />  -->
        <q-select filled v-model="msg.DepartCityId" :options="goodsType" @input="handleTicked" emit-value map-options option-label="Name" option-value="ID" label="請選擇出發地">
                    </q-select>
      </q-card>
      <q-card flat class="rounded-borders q-py-md q-mt-lg">
        <div class="text-subtitle1 text-weight-bold q-mx-md">目的地</div>
        <q-select filled v-model="msg.ArriveCityId" :options="ArriveCityList" @input="handleTicked" emit-value map-options option-label="Name" option-value="ID" label="請選擇目的地">
                    </q-select>
      </q-card>
      <q-card flat class="rounded-borders q-mt-lg row no-padding">
        <div
          class="q-px-md q-py-sm"
          style="border-right: 1px solid #eee; border-radius: 0 !important"
        >
          <q-icon name="iconfont iconigw-l-date-trade" size="24px" />
        </div>
        <div class="row items-center justify-center col">
          <span class="text-grey-8">
            {{
              msg.StartDate
                ? `${msg.StartDate} - ${msg.EndDate}`
                : "篩選出發日期"
            }}
          </span>
          <q-popup-proxy :offset="[0, 0]" ref="qDateProxy">
            <div>
              <q-date
                v-model="dateRange"
                :options="optionsFn"
                range
                @range-end="dateRangeHandler"
                mask="YYYY/MM/DD"
              ></q-date>
            </div>
          </q-popup-proxy>
        </div>
      </q-card>

      <q-card flat class="rounded-borders q-pa-md q-mt-lg">
        <div class="text-subtitle1 text-weight-bold">價錢篩選（CNY）</div>
        <div class="q-mt-md text-grey-6 text-subtitle2 text-regular">
          {{ msg.priceRange.min }} - {{ msg.priceRange.max }}
        </div>
        <q-range
          v-model="msg.priceRange"
          :min="priceModel.min"
          :max="priceModel.max"
          :step="1"
          @change="testHandler"
          color="primary"
          class="q-mt-md"
        />
      </q-card>
      <q-card flat class="rounded-borders q-mt-lg overflow-hidden">
        <q-expansion-item
          expand-separator
          label="旅程時間"
          class="text-subtitle1 text-weight-bold rounded-borders"
        >
          <div
            class="addr-list q-px-md q-py-sm row items-center"
            v-for="(y, yi) in dayArray"
            :key="yi"
          >
            <q-checkbox
              v-model="y.checked"
              size="xs"
              @input="changeTripDayHandler"
            />
            <span
              class="col text-grey-8 text-subtitle2 text-regular q-mt-xs"
              style="font-weight: 400"
            >
              {{ y.text }}
            </span>
          </div>
        </q-expansion-item>
      </q-card>
    </div>
    <div class="col q-mt-sm">
      <div class="rounded-borders bg-white q-col-gutter-sm">
        <div class="row q-col-gutter-sm items-center q-pa-md">
          <div class="text-subtitle2 q-mr-md">
            <span class="text-weight-bold text-primary q-mr-sm">
              {{ TotalCount }}
            </span>
            <span>項體驗行程</span>
          </div>
          <q-chip
            v-for="(x, i) in chosenAddress"
            size="13px"
            :key="i"
            removable
            outline
            color="grey"
            :label="x.Name"
          />
        </div>
        <div
          class="q-pa-md row items-center"
          style="border-top: 1px solid #eee"
        >
          <span class="f12">排序：</span>
          <q-chip
            square
            :icon="x.icon"
            class="cursor-pointer"
            clickable
            :text-color="msg.orderBy != x.value ? 'dark' : 'white'"
            :class="{
              'bg-grey-3': msg.orderBy != x.value,
              'bg-primary': msg.orderBy == x.value,
            }"
            v-for="(x, i) in sortArray"
            :key="i"
            @click="chosenSortHandler(x)"
            >{{ x.label }}</q-chip
          >
        </div>
      </div>
      <div class="q-mt-lg" v-if="!$q.loading.isActive &&DataList&& DataList.length > 0">
        <div
          class="rounded-borders cursor-pointer overflow-hidden bg-white"
          :class="$q.platform.is.desktop ? 'row q-mb-md' : 'colmuns q-ma-md'"
          v-for="(x, i) in DataList"  :key="i"  >

        <!-- <template v-if="x.AirlineUrl&&x.AirlineUrl.length>0">
          <q-img
            :src="x.AirlineUrl"
            :ratio="1"
            spinner-color="grey"
            spinner-size="20px"
            :width="$q.platform.is.desktop ? '272px' : ''"
            :height="$q.platform.is.desktop ? '' : '200px'"
            class="bg-grey-3"
          />
        </template>
          <template v-else>
            <q-img
            :ratio="1"
            spinner-color="grey"
            spinner-size="20px"
            :width="$q.platform.is.desktop ? '272px' : ''"
            :height="$q.platform.is.desktop ? '' : '200px'"
            class="bg-grey-3"   />
          </template> -->
          <div class="q-pa-md col column" @click="GotoDetails(x)">

            <!-- 启程 -->       
              <div class="col"  v-for="(item, index) in x.FlightList" :style="(x.StartTripNum-1)==index?'margin-bottom:15px':''">
                  <div class="row items-center f12 text-grey-6 q-mt-md" >
                    <q-chip dense color="orange" text-color="white"  style="height:40px;font-size:12px;">
                      <div style=" writing-mode: vertical-lr; transform: rotate(0deg);">{{item.FlightSubType==1?'去&nbsp;程':'回&nbsp;程'}}</div> </q-chip>
                      <div outline color="secondary" >
                        <div style="display: flex;">
                          <div style="margin-right:20px;margin-left:5px;">
                            {{item.dName}}
                            <q-space />
                           <div style="color:#333;"> {{item.FlightDate}} {{item.Departure_time}}</div>
                          </div>
                          <div style="margin-right:20px;min-width:100px;width:auto;">
                            <div style="text-align:center;">
                             {{item.Flight_number}} 
                             <!-- +{{item.Span_days}} -->
                            </div>
                            
                            <q-separator color="orange" inset style="margin-left:0px !important; margin-right:0px !important;" />
                            <q-space />
                            <div >
                            <div style="margin-left: 5px;float: left;">  {{item.DepartureName}}</div>
                            <!-- <div style="text-align:center;margin:0px 5px;">
                              <template v-if="item.FlightSubType==1&&x.DepartureTime">
                              <template v-if="x.DepartureTime.Days>0"><span>{{x.DepartureTime.Days}}h&nbsp;</span></template>
                              <template v-if="x.DepartureTime.Hours>0"><span> {{x.DepartureTime.Hours}}m&nbsp;</span></template>
                                <template v-if="x.DepartureTime.Minutes>0"> <span> {{x.DepartureTime.Minutes}}s&nbsp;</span></template>
                                <template v-if="item.StopType==2">经停</template>
                             </template>
                              <template v-else-if="item.FlightSubType==3&&x.ArrivalTime">
                                <template v-if="x.ArrivalTime.Days>0"><span>{{x.ArrivalTime.Days}}h&nbsp;</span></template>
                                <template v-if="x.ArrivalTime.Hours>0"><span> {{x.ArrivalTime.Hours}}m&nbsp;</span></template>
                                <template v-if="x.ArrivalTime.Minutes>0"> <span> {{x.ArrivalTime.Minutes}}s&nbsp;</span></template>
                              </template> 
                            </div> -->
                            <div style="margin-right: 5px;float: right;">{{item.ArrivalCityName}}</div>
                            </div>
                          </div>
                          
                          <div style="margin-left:10px;">
                             {{item.aName}}
                            <q-space />
                            {{item.Arrival_time}}
                          </div>

                        </div>
                    
                      </div> 
                  </div>
                  <q-space />
                 
              </div>

            <div class="row items-end"  >
              <div class="col f12">
                <!-- <span>起飞时间：</span>
                <span class="text-primary text-weight-bold q-pr-sm q-mr-sm" style="border-right: 1px solid #efefef"  >{{ x.FlightDate }} {{x.WeekDayStr}}</span> -->
                <span class="text-primary text-weight-bold q-pr-sm q-mr-sm" style="border-right: 1px solid #efefef"  >
                  
                  <template v-if="x.AirlineUrl&&x.AirlineUrl.length>0">
          <q-img
          rounded 
            :src="x.AirlineUrl"
            :ratio="1"
            spinner-color="grey"
            spinner-size="20px"
            :width="$q.platform.is.desktop ? '27px' : ''"
            :height="$q.platform.is.desktop ? '' : '20px'"
            class="bg-grey-3"
            style="border-radius:50%;"
          />
        </template>
          <template v-else>
            <q-img
            rounded 
            :ratio="1"
            spinner-color="grey"
            spinner-size="20px"
            :width="$q.platform.is.desktop ? '27px' : ''"
            :height="$q.platform.is.desktop ? '' : '20px'"
            class="bg-grey-3"   style="border-radius:50%;" />
          </template> 
                  {{ x.AirLineName }} </span>
                <span>剩餘空位：</span>
                <span class="text-secondary text-weight-bold"  >{{ x.B2BSellNum }}</span>
              </div>
              <div class="text-h6 product-price">
                CNY：{{ x.B2CPrice }}<span class="price-stuff">元</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div  v-else-if="!$q.loading.isActive &&DataList&& DataList.length == 0"
        class="text-center q-mt-xl"
      >
        <div class="text-center inline-block">
          <p>
            <img src="~assets/sad.svg" style="width: 30vw; max-width: 150px" />
          </p>
          <p class="text-faded">
            我们找不到有关
            <span v-if="msg.searchKey">\"{{ msg.searchKey }}\"</span>
            的旅游体验，输入其他字眼重试或探索以下人气体验
          </p>
        </div>
      </div>
      <div class="row justify-end">
        <q-pagination
          v-if="PageCount > 1"
          v-model="msg.pageIndex"
          :max="PageCount"
          @input="goSearchHandler"
          :direction-links="true"
          color="white"
          text-color="dark"
          active-color="primary"
          active-text-color="white"
          active-design="unelevated"
          unelevated
          glossy
          ellipses
          :max-pages="6"
          boundary-numbers
          size="13px"
          padding="sm md"
        ></q-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import popup from "../props/index";
import { date } from "quasar";
export default {
  props: ["qMsg"],
  components: {popup},
  data() {
    return {
      showAddress: false,
      showCategory: false,
      showDate: false,
      showPrice: false,
      areaTicked: [],
      ticked: [],
      selected: [],
      searchAdd: {
        name: "",
        value: 0,
      },
      areaList: [],
      chosenAddress: [],
      goodsType: [],
      ArriveCityList:[],
      dateRange: null,
      msg: null,
      dayArray: [
        {
          id: 1,
          min: 1,
          max: 1,
          text: "1天",
        },
        {
          id: 2,
          min: 2,
          max: 2,
          text: "2天",
        },
        {
          id: 3,
          min: 3,
          max: 3,
          text: "3天",
        },
        {
          id: 4,
          min: 4,
          max: 4,
          text: "4天",
        },
        {
          id: 5,
          min: 5,
          max: 5,
          text: "5天",
        },
        {
          id: 6,
          min: 6,
          max: 6,
          text: "6天",
        },
        {
          id: 7,
          min: 7,
          max: 8,
          text: "7-8天",
        },
        {
          id: 8,
          min: 9,
          max: 10,
          text: "9-10天",
        },
        {
          id: 9,
          min: 10,
          max: 1000,
          text: "10天以上",
        },
      ],
      DataList: [],
      sortArray: [
        {
          label: "默认排序",
          value: 0,
          icon: "iconfont icongood",
        },
        {
          label: "價格：低到高",
          value: 1,
          icon: "iconfont iconmeiyuan",
        },
        {
          label: "價格：高到低",
          value: 2,
          icon: "iconfont iconmeiyuan",
        },
      ],
      TotalCount: 0,
      PageCount: 0,
      priceModel: {
        min: 1,
        max: 100000,
      },
    };
  },
  created() {
    this.msg = this.qMsg;
    this.initGoods();
    this.msg.priceRange = {
      min: 1,
      max: 100000,
    };
    this.msg.minPrice = 0;
    this.msg.maxPrice = 100000;
    this.dayArray.forEach((x) => {
      x.checked = false;
    });
    this.msg.StartDate = date.formatDate(new Date(this.qMsg.StartDate), "YYYY/MM/DD")
    this.msg.EndDate = date.formatDate(new Date(this.qMsg.EndDate), "YYYY/MM/DD")
    this.dateRange = { from: this.msg.StartDate, to: this.msg.EndDate };
    
  },
  mounted() {
    
  },
  methods: {
    handleSelected(target) {
    },
    handleTicked() {
      this.msg.pageIndex = 1
      //this.ticked = target;
      // this.getChoseTicked();
      this.goSearchHandler();
    },
    handleAreaTicked(target) {
      this.msg.pageIndex = 1
      this.msg.placeIds = this.getChoseAddressCity().join(",");
      this.goSearchHandler();
    },
    getChoseTicked() {
      function treeToArray(tree) {
        return tree.reduce((res, item) => {
          const { children, ...i } = item;
          return res.concat(
            i,
            children && children.length ? treeToArray(children) : []
          );
        }, []);
      }
      const areaList = treeToArray(this.goodsType);
      areaList.forEach((item,index) => {
        if (this.ticked.includes(item.ID)) {
         this.msg.DepartCityId=item.StartId;
        }
      });
    },
    initAreaList() {
      let jObj = JSON.parse(window.localStorage.getItem("baseifo"));
      let arr = [];
      jObj.AreaList.forEach((x) => {
        x.children = x.SubList;
        x.children.forEach((y) => {
          y.checked = false;
          y.explsed = false;
          y.isShow = true;
          if (y.Id === this.msg.areaId) {
            arr.push(y.Id);
          }
          if (y.SubList) {
            y.children = y.SubList;
            y.children.forEach((z) => {
              z.checked = false;
              z.explsed = false;
              z.isShow = true;
              if (z.Id === this.msg.areaId) {
                arr.push(z.Id);
              }
              if (y.Id === this.msg.areaId) {
                arr.push(z.Id);
              }
            });
          }
        });
        this.areaList = jObj.AreaList;
        this.areaListJSON = JSON.parse(JSON.stringify(this.areaList));
      });

      if (this.msg.areaId) {
        this.$nextTick(() => {
          this.$refs.area?.setTicked([...new Set(arr)], true);
        });
      }
    },
    changeExplesdHandler(x) {
      x.explsed = !x.explsed;
      if (x.SubList) {
      }
    },
    
    chosenSortHandler(x) {
      this.msg.orderBy = x.value;
      this.msg.pageIndex = 1
      this.goSearchHandler();
    },
    getChoseAddressCity() {
      let result = [];
      function treeToArray(tree) {
        return tree.reduce((res, item) => {
          const { children, ...i } = item;
          return res.concat(
            i,
            children && children.length ? treeToArray(children) : []
          );
        }, []);
      }
      const areaList = treeToArray(this.areaList);
      areaList.forEach((item) => {
        if (this.areaTicked.includes(item.Id)) {
          let arr = item.DestinationList.map((item) => item.ID);
          result = result.concat(arr);
        }
      });
      return result;
    },
    changeTripDayHandler() {
      this.$forceUpdate();
      // this.msg.minTripDay = "0";
      // this.msg.maxTripDay = "0";
      // this.dayArray.forEach(x => {
      //   if (x.checked) {
      //     this.msg.minPrice =
      //       this.msg.minPrice > x.min ? x.min : this.msg.minPrice;
      //     this.msg.maxPrice =
      //       this.msg.maxPrice < x.max ? x.max : this.msg.maxPrice;
      //   }
      // });
      // this.msg.minTripDay =
      //   this.msg.minTripDay == "0" ? "" : this.msg.minTripDay;
      // this.msg.maxTripDay =
      //   this.msg.maxTripDay == "0" ? "" : this.msg.maxTripDay;
      let arr = [];
      this.dayArray.forEach((item) => {
        if (item.checked) {
          arr.push(item.id);
        }
      });
      this.msg.dayNumList = arr;
      this.msg.pageIndex = 1
      this.goSearchHandler();
    },
    optionsFn(cd) {
      return (
        cd >=
        date.formatDate(date.addToDate(new Date(), { days: 1 }), "YYYY/MM/DD")
      );
    },
    testHandler(e) {
      this.$forceUpdate();
      this.msg.minPrice = e.min;
      this.msg.maxPrice = e.max;
      this.msg.pageIndex = 1
      this.goSearchHandler();
    },
    dateRangeHandler(e) {
      this.msg.StartDate = `${e.from.year}/${e.from.month}/${e.from.day}`;
      this.msg.EndDate = `${e.to.year}/${e.to.month}/${e.to.day} `;
      this.$refs.qDateProxy.hide();
      this.msg.pageIndex = 1
      this.goSearchHandler();
    },
    initGoods() {
      this.ArriveCityList=[];
      this.goodsType=[];
      this.apipost(
        "AirTicket_get_GetTicketCity",
        this.msg,
        (res) => {
          if (res.data.resultCode == 1) {
            var jObj = res.data.data;
            jObj.forEach((x) => {
              x.checked = false;
              x.explsed = false;
              x.isShow = true;
              x.children = x.CityList;
              x.children.forEach((y) => {
                y.checked = false;
                y.explsed = false;
                y.isShow = true;
                let lineIdIndex =   this.ArriveCityList.findIndex((yId) => y.ID == yId.ID);
                if(lineIdIndex==-1){
                  this.ArriveCityList.push(y);
                }
              });
              this.goodsType.push(x);
            });
              this.goSearchHandler();
          } else this.goSearchHandler();
        },
        (err) => {}
      );

      //this.goodsTypeJSON = JSON.stringify(this.goodsType);
    },
    dfs(tree, ope, filter) {
      const walkAndCopy = (tree, depth = 1) => {
        if (filter(tree)) {
          const copy = { ...tree };
          ope(tree.Name, depth);
          if (tree.children) {
            copy.children = [];
            tree.children.forEach((node) => {
              const subTree = walkAndCopy(node, depth + 1);
              subTree && copy.children.push(subTree);
            });
          }
          return copy;
        } else if (tree && tree.children && tree.children.length) {
          const copy = { ...tree };
          ope(tree.Name, depth);
          copy.Name = tree.Name;
          if (tree.children) {
            copy.children = [];
            tree.children.forEach((node) => {
              const subTree = walkAndCopy(node, depth + 1);
              subTree && copy.children.push(subTree);
            });
          }
          return copy;
        }
      };
      return walkAndCopy(tree);
    },
    changeAddrSearchHandler(v) {
      this.areaListJSONTMP = JSON.parse(JSON.stringify(this.areaListJSON));
      let tree = this.dfs(
        { Name: "", children: this.areaListJSONTMP },
        (name, depth) => {},
        ({ Name }) => {
          return Name.indexOf(v) !== -1;
        }
      );
      tree = this.dfs(
        tree,
        (name, depth) => {},
        ({ Name }) => {
          return Name.indexOf(v) !== -1;
        }
      );
      tree = this.dfs(
        tree,
        (name, depth) => {},
        ({ Name }) => {
          return Name.indexOf(v) !== -1;
        }
      );
      this.areaList = tree.children;
      // this.areaList.forEach(x => {
      //   x.isShow = x.Name.indexOf(v) != -1;
      //   x.isShowChild = false;
      //   x.SubList.forEach(y => {
      //     y.isShow = y.Name.indexOf(v) != -1;
      //     if (y.isShow) {
      //       x.isShow = true;
      //       x.isShowChild = true;
      //     }
      //   });
      // });
    },
    goSearchHandler() {
      
      // this.msg.placeIds = this.areaTicked.join(",");
      this.$q.loading.show();
      this.DataList = [];
      let minTripDay = -1,
        maxTripDay = -1,
        minPrice = -1,
        maxPrice = -1;
      if (this.qMsg.minPrice != "") {
        minPrice = parseFloat(this.qMsg.minPrice);
      }
      if (this.qMsg.maxPrice != "") {
        maxPrice = parseFloat(this.qMsg.maxPrice);
        if (minPrice > maxPrice) {
          this.Error("价格区间的最低价格不能低于最大价格");
          return false;
        }
      }
      var companyId = -1;
      if (localStorage.groupinfo) {
        var groupinfo = JSON.parse(localStorage.groupinfo);
        companyId =
          groupinfo.siteList[0] && groupinfo.siteList[0].companyId
            ? groupinfo.siteList[0].companyId
            : -1;
      }
      if (localStorage.b2bUser) {
        var b2bUser = JSON.parse(window.localStorage.getItem("b2bUser"));
        if (b2bUser) {
          this.msg.priceOrderByField = 2;
        }
      }
      this.msg.webSiteCategoryIds = this.ticked.join(",");
      this.PageCount = 0;
      this.TotalCount = 0;
      this.apipost(
        "AirTicket_get_GetTicketProductPage",
        this.msg,
        (res) => {
          this.$q.loading.hide();

          if (res.data.resultCode == 1) {
            this.PageCount = res.data.data.pageCount;
            this.TotalCount = res.data.data.count;
            var tempArray = res.data.data.pageData;
            if (tempArray && tempArray.length > 0) {
              this.DataList = tempArray;
             // this.renderSearchInfo(res.data.data.pageData.condition);
              this.$forceUpdate();
            }
          }
        },
        (err) => {}
      );
    },
    renderSearchInfo(condition) {
      if (!condition.length) {
        return;
      }
      let areaInfo = condition.find((item) => item.type === 1).list;
      let dayInfo = condition.find((item) => item.type === 2).list;
      let priceInfo = condition.find((item) => item.type === 3);
      let categoryInfo = condition.find((item) => item.type === 4).list;
      // this.areaTicked = areaInfo;
      this.areaListJSONTMP = JSON.parse(JSON.stringify(this.areaListJSON));
      let tree = this.dfs(
        { Name: "", children: this.areaListJSONTMP },
        (name, depth) => {},
        ({ Id }) => {
          return areaInfo.includes(Id);
        }
      );
      tree = this.dfs(
        tree,
        (name, depth) => {},
        ({ Id }) => {
          return areaInfo.includes(Id);
        }
      );
      tree = this.dfs(
        tree,
        (name, depth) => {},
        ({ Id }) => {
          return areaInfo.includes(Id);
        }
      );
      this.areaList = tree.children;
      const categoryTmp = JSON.parse(this.goodsTypeJSON);
      let category = this.dfs(
        { Name: "", children: categoryTmp },
        (name, depth) => {},
        (item) => {
          return categoryInfo.includes(item.Id);
        }
      );
      category = this.dfs(
        category,
        (name, depth) => {},
        (item) => {
          return categoryInfo.includes(item.Id);
        }
      );
      category = this.dfs(
        category,
        (name, depth) => {},
        (item) => {
          return categoryInfo.includes(item.Id);
        }
      );
      this.goodsType = category.children;
      this.priceModel = { min: priceInfo.minPrice, max: priceInfo.maxPrice };
      let arr = [];
      dayInfo.forEach((item) => {
        if (item < 6) {
          arr.push(item);
        } else if (item === 7 || item === 8) {
          arr.push(7);
        } else if (item === 8 || item === 10) {
          arr.push(8);
        } else {
          arr.push(9);
        }
      });
      this.dayArray = this.dayArray.filter((item) => arr.includes(item.id));
    },

    GotoDetails(item) {
      this.CommonJump('/planeticketOrder/' + encodeURIComponent(item.TCID),{}, "blank");
    },
    SwitchTCID(obj,i,index) {
      if(this.DataList&&this.DataList.length>0){
        let nowobj=  JSON.parse(JSON.stringify(obj));
        this.DataList[i] = {
          ...nowobj.priceList[index]
        }
        this.DataList[i].index=index;
        this.DataList[i].startDateList=nowobj.startDateList;
        this.DataList[i].priceList=nowobj.priceList;
        this.$forceUpdate();
      }
    },
  },
};
</script>

<style>
.addr-list:hover {
  background: #E3F2FD;
}
</style>
<style lang="scss" scoped>
::v-deep .q-menu {
  width: 100% !important;
}
.price-stuff {
  font-size: 12px;
  margin-left: 4px;
}
.nav-item {
  width: 25%;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background: #fff;
  font-weight: bold;
}
.nav-item:hover {
  background: #f5f5f5;
} 
</style>
