<style>
.TravelDaysTrip .el-form-item {
  display: inline-block;
}
</style>

<template>
  <div>
    <el-form :model="subConfig" :rules="Rules" ref="dayTripForm">
      <div class="TravelDaysTrip" :class="{'foldHeight':isFold==1}">
        <span class="TMTitle"><i></i>线路行程 </span>
        <!-- <span class="foldList" style="margin-left:20px" @click="goUrl('TravelPreview')">预览行程</span> -->
        <div class="DaysTripTop">
          <span class="TDTextspan">行程天数</span>
          <span class="TDInputspan">
            <el-form-item prop="DayNum">
              <el-input :disabled="isOpenGroup" class="w120 LowNum" v-model="subConfig.DayNum" @keyup.native="checkInteger(subConfig,'DayNum');createLineTrip()">
                <template slot="append">天</template>
              </el-input>
            </el-form-item>
          </span>
          <span class="TDInputspan">
            <el-form-item prop="NightNum">
              <el-input :disabled="isOpenGroup" class="w120 LowNum" v-model="subConfig.NightNum" @keyup.native="checkInteger(subConfig,'NightNum')">
                <template slot="append">晚</template>
              </el-input>
            </el-form-item>
          </span>
          <span class="TDTextspan">集合出发城市</span>
          <span>
            <el-form-item prop="StartCityId">
              <el-select :disabled="isOpenGroup" class='w200' :placeholder="$t('pub.pleaseSel')" v-model="subConfig.StartCityId"
                filterable>
                <el-option :label="$t('pub.unlimitedSel')" :value='SelectDefaultValue'></el-option>
                <el-option v-for="item in StartCity" :label='item.startCityName' :value='item.ID' :key='item.ID'>
                </el-option>
              </el-select>
            </el-form-item>
          </span>
          <span class="TDTextspan">返回抵达城市</span>
          <span>
            <el-form-item prop="ReturnArriveCityId">
              <el-select :disabled="isOpenGroup" class='w200' :placeholder="$t('pub.pleaseSel')" v-model="subConfig.ReturnArriveCityId"
                filterable>
                <el-option :label="$t('pub.unlimitedSel')" :value='SelectDefaultValue'></el-option>
                <el-option v-for="item in StartCity" :label='item.startCityName' :value='item.ID' :key='item.ID'>
                </el-option>
              </el-select>
            </el-form-item>
          </span>
        </div>
        <div class="TravelDayContent clearfix">
          <div class="vertical-line"></div>
          <div class="days-box" v-for="(item,index) in subConfig.DayList" :key="item.subCode">
            <div class="leftDayLine">
              <div class="dayCircle">D{{index+1}}</div>
            </div>
            <div class="rightDayContent">
              <div class="TD_Operation">
                <div class="TD_daysMove">
                    <el-tooltip class="item" effect="dark" content="上移行程" placement="top-start" v-if="index!=0">
                        <i class="iconfont icon-shangyi" @click="MoveDays(index,0)"></i>
                    </el-tooltip>
                    <el-tooltip class="item" effect="dark" content="下移行程" placement="top-start" v-if="index!=subConfig.DayList.length-1">
                      <i class="iconfont icon-xiayi1" @click="MoveDays(index,1)"></i>
                    </el-tooltip>
                    <el-tooltip class="item" effect="dark" content="删除" placement="top-start">
                      <i class="iconfont icon-xingzhuang" @click="removeDaysTrip(index)"></i>
                    </el-tooltip>
                    <!-- <el-tooltip class="item" effect="dark" content="编辑" placement="top-start">
                      <i class="iconfont icon-bianji" @click=""></i>
                    </el-tooltip> -->
                    <el-tooltip class="item" effect="dark" content="添加" placement="top-start">
                      <i class="iconfont icon-mui-icon-add" @click="addDaysTrip(index)"></i>
                    </el-tooltip>
                </div>
              </div>
              <div class="dayscontent hideToggle" v-show="item.isHide">
                <div class="toggle-box" @click="changeToggleBox(item)">
                  点击展开
                </div>
                <div class="daycnt">
                  <div class="d">第{{index+1}}天</div>
                  <div class="title-box">
                    <div class="t">
                        {{item.dayArray[0].childItem.Title}}                  
                    </div>
                  </div>
                </div>
              </div>
              <div class="dayscontent" v-show="!item.isHide">
                <div class="toggle-box" @click="changeToggleBox(item)">
                  点击折叠
                </div>
                <div class="daycnt">
                  <div class="d">第{{index+1}}天</div>
                  <div class="title-box">
                    <titleTrip :isOpenGroup="isOpenGroup"  v-bind:subItemObj="item.dayArray[0]" >
                    </titleTrip>
                  </div>
                </div>
                <div v-for="(subItem,subIndex) in item.dayArray" :key="subItem.subCode">
                  <div v-if="subItem.Type==$tripUtils.TypeKey.traffic">
                    <trifficTrip v-bind:subItemObj="subItem" v-bind:subIndex="subIndex" v-bind:index="index"
                      v-bind:QueryData="subArray" v-bind:DayList="subConfig.DayList" v-bind:DefaultList="trafficSameList"
                      :isOpenGroup="isOpenGroup" v-bind:subTotalIndex="item.dayArray.length" v-bind:AllCityList="AllCityList"
                      v-bind:UseTypeArray="UseTypeArray" v-bind:AirPickUp="AirPickUp" v-bind:AirSend="AirSend"
                      v-bind:StartCity="StartCity"></trifficTrip>
                  </div>
                  <div v-if="subItem.Type==$tripUtils.TypeKey.hotel">
                    <span v-if="IsDirect==1">
                      <hotelTrip v-bind:subItemObj="subItem" v-bind:DefaultList="hotelSameList" v-bind:subIndex="subIndex"
                        v-bind:DinnerList="DinnerList" v-bind:index="index" :isOpenGroup="isOpenGroup"
                        v-bind:subTotalIndex="item.dayArray.length"></hotelTrip>
                    </span>
                    <span v-else>
                      <hotelTripdisDirect v-bind:subItemObj="subItem" v-bind:DefaultList="hotelSameList"
                        v-bind:subIndex="subIndex" v-bind:DinnerList="DinnerList" v-bind:index="index" :isOpenGroup="isOpenGroup"
                        v-bind:subTotalIndex="item.dayArray.length"></hotelTripdisDirect>
                    </span>
                  </div>
                  <div v-if="subItem.Type==$tripUtils.TypeKey.scenic">
                    <span v-if="IsDirect==1">
                      <scienTrip v-bind:subItemObj="subItem" v-bind:DefaultList="scenicSameList" v-bind:subIndex="subIndex"
                        v-bind:index="index" :isOpenGroup="isOpenGroup" v-bind:subTotalIndex="item.dayArray.length"></scienTrip>
                    </span>
                    <span v-else>
                      <scienTripdisDirect v-bind:subItemObj="subItem" v-bind:DefaultList="scenicSameList"
                        v-bind:subIndex="subIndex" v-bind:index="index" :isOpenGroup="isOpenGroup" v-bind:subTotalIndex="item.dayArray.length"></scienTripdisDirect>
                    </span>
                  </div>
                  <div v-if="subItem.Type==$tripUtils.TypeKey.dinner">
                    <span v-if="IsDirect==1">
                      <dinnerTrip v-bind:subItemObj="subItem" v-bind:DefaultList="dinnerSameList" v-bind:subIndex="subIndex"
                        v-bind:HotelList="HotelList" v-bind:index="index" :isOpenGroup="isOpenGroup"
                        v-bind:subTotalIndex="item.dayArray.length"></dinnerTrip>
                    </span>
                    <span v-else>
                      <dinnerTripdisDirect v-bind:subItemObj="subItem" v-bind:DefaultList="dinnerSameList"
                        v-bind:subIndex="subIndex" v-bind:HotelList="HotelList" v-bind:index="index" :isOpenGroup="isOpenGroup"
                        v-bind:subTotalIndex="item.dayArray.length"></dinnerTripdisDirect>
                    </span>
                  </div>
                  <div v-if="subItem.Type==$tripUtils.TypeKey.freedom">
                    <freedomTrip v-bind:subItemObj="subItem" v-bind:DefaultList="freedomSameList" v-bind:subIndex="subIndex"
                      v-bind:index="index" :isOpenGroup="isOpenGroup" v-bind:subTotalIndex="item.dayArray.length"></freedomTrip>
                  </div>
                  <div v-if="subItem.Type==$tripUtils.TypeKey.warmtip">
                    <warmtipTrip v-bind:subItemObj="subItem" v-bind:DefaultList="warmtipSameList" v-bind:subIndex="subIndex"
                      :isOpenGroup="isOpenGroup" v-bind:subTotalIndex="item.dayArray.length"></warmtipTrip>
                  </div>
                </div>
                <div v-if="!isOpenGroup" class="tripListSpan">
                  <span class="tripList" @click="addChildItem(index,typeItem.Type)" v-for="(typeItem,typeIndex) in typeArrayListAll"
                    :key="typeIndex">{{typeItem.Name}}</span>
                </div>
                <div class="tripListSpan" v-else>
                  <span class="tripList" @click="addChildItem(index,typeItem.Type)" v-for="(typeItem,typeIndex) in typeArrayList"
                    :key="typeIndex">{{typeItem.Name}}</span>
                </div>
              </div>
            </div>
            <div class="lastHoverContent">
            </div>
          </div>
        </div>
      </div>
    </el-form>
  </div>
</template>
<script>
import trifficTrip from "../travelLineTrip/trifficTrip";


import scienTrip from "../travelLineTrip/scienTrip_Direct";
import scienTripdisDirect from "../travelLineTrip/scienTrip_disDirect";

import hotelTrip from "../travelLineTrip/hotelTrip_Direct";
import hotelTripdisDirect from "../travelLineTrip/hotelTrip_disDirect";

import dinnerTrip from "../travelLineTrip/dinnerTrip_Direct";
import dinnerTripdisDirect from "../travelLineTrip/dinnerTrip_disDirect";

import freedomTrip from "../travelLineTrip/freedomTrip";
import warmtipTrip from "../travelLineTrip/warmtipTrip";
import titleTrip from "../travelLineTrip/titleTrip";
import { callbackify } from "util";

export default {
  /*
  * subConfig.DayList:行程天数[循环生成数据使用]
  * AllCityList:所有的城市列表
  * StartCity:出发城市，集合城市
  * UseTypeArray:用车类型
  * AirPickUp:接机
  * AirSend:送机
  */
  props: [
    "subArray",
    "subConfig",
    "isOpenGroup",
    "IsDirect",
    "AllCityList",
    "StartCity",
    "UseTypeArray",
    "AirPickUp",
    "AirSend"
  ],
  data() {
    var SetOutCityIdValidate = (rule, value, callback) => {
      if (value === 0) {
        callback(new Error("请选择集合出发城市"));
      } else {
        return callback();
      }
    };
    var ReturnArriveCityIdValidate = (rule, value, callback) => {
      if (value === 0) {
        callback(new Error("请选择返回抵达城市"));
      } else {
        return callback();
      }
    };

    return {
      //类型数组
      typeArrayListAll: this.$tripUtils.TypeArray,
      typeArrayList:[],
      //酒店默认叙述
      hotelSameList: [],
      //餐厅默认叙述
      dinnerSameList: [],
      //景点默认叙述
      scenicSameList: [],
      //自由活动默认叙述
      freedomSameList: [],
      //交通默认叙述
      trafficSameList: [],
      //温馨提示默认叙述
      warmtipSameList: [],
      //标题提示默认叙述
      titleSameList: [],
      //下拉框默认值
      SelectDefaultValue: 0,
      tempDinnerType: [],
      //时间类型
      TimeTypeList: [],
      //折叠展开
      isFold: "",
      //验证
      Rules: {
        //集合出发城市
        StartCityId: [
          {
            validator: SetOutCityIdValidate,
            trigger: "change"
          }
        ],
        //返回抵达城市
        ReturnArriveCityId: [
          {
            validator: ReturnArriveCityIdValidate,
            trigger: "change"
          }
        ],
        //天
        DayNum: [
          {
            required: true,
            message: "请填写行程天数",
            trigger: "blur"
          }
        ],
        //晚
        NightNum: [
          {
            required: true,
            message: "请填写行程晚数",
            trigger: "blur"
          }
        ]
      },
      HotelList: [], //所有酒店
      DinnerList: [] //所有餐厅
    };
  },
  components: {
    trifficTrip: trifficTrip,

    scienTrip: scienTrip,
    scienTripdisDirect: scienTripdisDirect,

    hotelTrip: hotelTrip,
    hotelTripdisDirect: hotelTripdisDirect,

    dinnerTrip: dinnerTrip,
    dinnerTripdisDirect: dinnerTripdisDirect,

    freedomTrip: freedomTrip,
    warmtipTrip: warmtipTrip,
    titleTrip: titleTrip
  },
  methods: {
    changeToggleBox(item) {
      item.isHide = !item.isHide;
      this.$forceUpdate();
    },
    goUrl(url) {
      let id = this.$route.query.configId;
      this.$router.push({
        path: url,
        query: {
          id: id
        }
      });
    },
    //表单验证
    validateForm() {
      let flag = false;
      var that = this;
      that.$refs["dayTripForm"].validate(valid => {
        flag = valid;
      });
      return flag;
    },
    //生成行程天数
    createLineTrip() {
      if (this.subConfig.DayNum > this.subConfig.DayList.length) {
        for (
          var i = this.subConfig.DayList.length;
          i < this.subConfig.DayNum;
          i++
        ) {
          //去掉以前默认的交通
          var dayItem = this.$tripUtils.daysArrayObj();
          dayItem.isHide = false;
          dayItem.dayNum = i + 1;
          var titleItem = this.$tripUtils.titleObj();
          titleItem.DayNum = i + 1;
          var daysArrayItem = this.$tripUtils.daysArrayItemObj();
          daysArrayItem.Type = this.$tripUtils.TypeKey.title;
          daysArrayItem.childItem = titleItem;
          dayItem.dayArray.push(daysArrayItem);
          this.subConfig.DayList.push(dayItem);
        }
      } else {
        //删除多余的项
        for (
          var i = this.subConfig.DayNum;
          i < this.subConfig.DayList.length;
          i++
        ) {
          var dayObj = this.subConfig.DayList[i];
          dayObj.dayArray.forEach((subItem, subIndex) => {
            this.commonRemove(subItem.childItem.DayNum, subIndex);
          });
        }
        this.subConfig.DayList.length = this.subConfig.DayNum;
      }
    },

    //点击往后追加
    addChildItem(index, type) {
      switch (type.toString()) {
        //交通
        case this.$tripUtils.TypeKey.traffic:
          var trafficItem = this.$tripUtils.trafficObj();
          trafficItem.DayNum = index + 1;
          var subTrafficObj = this.$tripUtils.subTrafficObj();
          //默认下一天的出发城市
          var StartCityId = this.$tripUtils.GetCityId(
            this.subConfig.DayList,
            trafficItem.DayNum - 1,
            index,
            false
          );
          subTrafficObj.StartCityId = StartCityId;
          trafficItem.SubTraffic.push(subTrafficObj);
          var daysArrayItem = this.$tripUtils.daysArrayItemObj();
          daysArrayItem.Type = this.$tripUtils.TypeKey.traffic;
          daysArrayItem.childItem = trafficItem;
          this.subConfig.DayList[index].dayArray.push(daysArrayItem);
          break;
        //景点
        case this.$tripUtils.TypeKey.scenic:
          var scenicItem = this.$tripUtils.scenicObj();
          scenicItem.DayNum = index + 1;
          var daysArrayItem = this.$tripUtils.daysArrayItemObj();
          daysArrayItem.Type = this.$tripUtils.TypeKey.scenic;
          //获取城市编号
          var cityId = this.$tripUtils.GetCityId(
            this.subConfig.DayList,
            index,
            this.subConfig.DayList[index].dayArray.length,
            true
          );
          scenicItem.CityId = cityId;
          //查询数组
          var qArray = this.$tripUtils.GetCityIdArray(
            this.subConfig.DayList,
            index,
            this.subConfig.DayList[index].dayArray.length,
            true
          );
          scenicItem.QCity = qArray.join(",");
          daysArrayItem.childItem = scenicItem;
          this.subConfig.DayList[index].dayArray.push(daysArrayItem);
          break;
        //酒店
        case this.$tripUtils.TypeKey.hotel:
          var hotelItem = this.$tripUtils.hotelObj();
          hotelItem.DayNum = index + 1;
          var daysArrayItem = this.$tripUtils.daysArrayItemObj();
          daysArrayItem.Type = this.$tripUtils.TypeKey.hotel;

          //获取城市编号
          var cityId = this.$tripUtils.GetCityId(
            this.subConfig.DayList,
            index,
            this.subConfig.DayList[index].dayArray.length,
            true
          );

          //查询数组
          var qArray = this.$tripUtils.GetCityIdArray(
            this.subConfig.DayList,
            index,
            this.subConfig.DayList[index].dayArray.length,
            true
          );
          hotelItem.QCity = qArray.join(",");
          hotelItem.CityId = cityId;
          daysArrayItem.childItem = hotelItem;
          this.subConfig.DayList[index].dayArray.push(daysArrayItem);
          break;
        //餐厅
        case this.$tripUtils.TypeKey.dinner:
          var dinnerItem = this.$tripUtils.dinnerObj();
          dinnerItem.DayNum = index + 1;
          var daysArrayItem = this.$tripUtils.daysArrayItemObj();
          daysArrayItem.Type = this.$tripUtils.TypeKey.dinner;
          //获取城市编号
          var cityId = this.$tripUtils.GetCityId(
            this.subConfig.DayList,
            index,
            this.subConfig.DayList[index].dayArray.length,
            true
          );

          //查询数组
          var qArray = this.$tripUtils.GetCityIdArray(
            this.subConfig.DayList,
            index,
            this.subConfig.DayList[index].dayArray.length,
            true
          );
          dinnerItem.QCity = qArray.join(",");
          dinnerItem.CityId = cityId;

          daysArrayItem.childItem = dinnerItem;
          this.subConfig.DayList[index].dayArray.push(daysArrayItem);
          break;
        case this.$tripUtils.TypeKey.freedom:
          var freedomItem = this.$tripUtils.dinnerObj();
          freedomItem.DayNum = index + 1;
          var daysArrayItem = this.$tripUtils.daysArrayItemObj();
          daysArrayItem.Type = this.$tripUtils.TypeKey.freedom;
          //获取城市编号
          var cityId = this.$tripUtils.GetCityId(
            this.subConfig.DayList,
            index,
            this.subConfig.DayList[index].dayArray.length,
            true
          );
          freedomItem.CityId = cityId;
          daysArrayItem.childItem = freedomItem;
          this.subConfig.DayList[index].dayArray.push(daysArrayItem);
          break;
        //温馨提示
        case this.$tripUtils.TypeKey.warmtip:
          var warmtipItem = this.$tripUtils.warmtipObj();
          warmtipItem.DayNum = index + 1;
          var daysArrayItem = this.$tripUtils.daysArrayItemObj();
          daysArrayItem.Type = this.$tripUtils.TypeKey.warmtip;
          //获取城市编号
          var cityId = this.$tripUtils.GetCityId(
            this.subConfig.DayList,
            index,
            this.subConfig.DayList[index].dayArray.length,
            true
          );
          warmtipItem.CityId = cityId;
          daysArrayItem.childItem = warmtipItem;
          this.subConfig.DayList[index].dayArray.push(daysArrayItem);
          break;
        //标题
        case this.$tripUtils.TypeKey.title:
          var titleItem = this.$tripUtils.titleObj();
          titleItem.DayNum = index + 1;
          var daysArrayItem = this.$tripUtils.daysArrayItemObj();
          daysArrayItem.Type = this.$tripUtils.TypeKey.title;
          daysArrayItem.childItem = titleItem;
          this.subConfig.DayList[index].dayArray.push(daysArrayItem);
          break;
      }
    },

    //获取相似线路行程
    getSameJourney() {
      var msg = {
        ID: this.subArray.ConfigId,
        LineId: this.subArray.LineID,
        LineteamId: this.subArray.LineteamId
      };
      this.apipost(
        "travel_get_GetTopTenSameJourneyList",
        msg,
        res => {
          if (res.data.resultCode == 1) {
            this.hotelSameList = res.data.data.hotelSameList;
            this.dinnerSameList = res.data.data.dinnerSameList;
            this.scenicSameList = res.data.data.scenicSameList;
            this.freedomSameList = res.data.data.freedomSameList;
            this.trafficSameList = res.data.data.trafficSameList;
            this.warmtipSameList = res.data.data.warmtipSameList;
            this.titleSameList = [];
          }
        },
        err => {}
      );
    },
    //上移下移(IsUp:0上移，1下移)
    MoveItem(dayNum, subIndex, IsUp) {
      this.subConfig.DayList.forEach(dayItem => {
        if (dayItem.dayNum == dayNum) {
          var currentItem = dayItem.dayArray[subIndex];
          //上移
          if (IsUp == 0) {
            if (subIndex > 0) {
              var upItem = dayItem.dayArray[subIndex - 1];
              this.$set(dayItem.dayArray, subIndex - 1, currentItem);
              this.$set(dayItem.dayArray, subIndex, upItem);
            }
          } else {
            //下移
            if (subIndex != dayItem.dayArray.length - 1) {
              var downItem = dayItem.dayArray[subIndex + 1];
              this.$set(dayItem.dayArray, subIndex + 1, currentItem);
              this.$set(dayItem.dayArray, subIndex, downItem);
            }
          }
        }
      });
    },
    //天数上移下移
    MoveDays(index, IsUp) {
      var currentItem = this.subConfig.DayList[index];
      //上移
      if (IsUp == 0) {
        if (index > 0) {
          var upItem = this.subConfig.DayList[index - 1];
          currentItem.dayNum = currentItem.dayNum - 1;
          upItem.dayNum = upItem.dayNum + 1;
          if (currentItem.dayArray != null && currentItem.dayArray.length > 0) {
            currentItem.dayArray.forEach(cItem => {
              cItem.childItem.DayNum = currentItem.dayNum;
            });
          }
          if (upItem.dayArray != null && upItem.dayArray.length > 0) {
            upItem.dayArray.forEach(cItem => {
              cItem.childItem.DayNum = upItem.dayNum;
            });
          }
          this.$set(this.subConfig.DayList, index - 1, currentItem);
          this.$set(this.subConfig.DayList, index, upItem);
        }
      } else {
        //下移
        if (index != this.subConfig.DayList.length - 1) {
          var downItem = this.subConfig.DayList[index + 1];
          currentItem.dayNum = currentItem.dayNum + 1;
          downItem.dayNum = downItem.dayNum - 1;
          if (currentItem.dayArray != null && currentItem.dayArray.length > 0) {
            currentItem.dayArray.forEach(cItem => {
              cItem.childItem.DayNum = currentItem.dayNum;
            });
          }
          if (downItem.dayArray != null && downItem.dayArray.length > 0) {
            downItem.dayArray.forEach(cItem => {
              cItem.childItem.DayNum = downItem.dayNum;
            });
          }
          this.$set(this.subConfig.DayList, index + 1, currentItem);
          this.$set(this.subConfig.DayList, index, downItem);
        }
      }
    },
    //左右移动
    ExchangeImg(dayNum, subIndex, imgIndex, IsMove) {
      this.subConfig.DayList.forEach(dayItem => {
        if (dayItem.dayNum == dayNum) {
          dayItem.dayArray.forEach((arrItem, arrIndex) => {
            if (arrIndex == subIndex) {
              var imgItem = arrItem.childItem.ImaArray[imgIndex];
              //左移
              if (IsMove == 0) {
                var upItem = arrItem.childItem.ImaArray[imgIndex - 1];
                this.$set(arrItem.childItem.ImaArray, imgIndex - 1, imgItem);
                this.$set(arrItem.childItem.ImaArray, imgIndex, upItem);
              } else {
                //右移动
                var downItem = arrItem.childItem.ImaArray[imgIndex + 1];
                this.$set(arrItem.childItem.ImaArray, imgIndex + 1, imgItem);
                this.$set(arrItem.childItem.ImaArray, imgIndex, downItem);
              }
            }
          });
        }
      });
    },
    //公用删除
    commonRemove(dayNum, subIndex) {
      let RemoveInfo = [];
      this.subConfig.DayList.forEach(x => {
        if (x.dayNum == dayNum) {
          let info = {
            Key: 0,
            Value: 0
          };
          if (x.dayArray[subIndex].childItem.ID > 0) {
            info.Key = x.dayArray[subIndex].Type;
            //后台枚举类型为7前台的为9
            if (info.Key == 7) {
              info.Key = 9;
            }
            info.Value = x.dayArray[subIndex].childItem.ID;
            this.subConfig.RemoveChild.push(info);
          }
          x.dayArray.splice(subIndex, 1);
        }
      });
    },
    //删除某天行程
    removeDaysTrip(index) {
      var item = this.subConfig.DayList[index];
      item.dayArray.forEach((delItem, subIndex) => {
        this.commonRemove(item.dayNum, subIndex);
      });

      this.subConfig.DayList.splice(index, 1);
      this.subConfig.DayList.forEach((dayItem, dayIndex) => {
        if (dayIndex >= index) {
          dayItem.dayNum = dayIndex + 1;
          dayItem.dayArray.forEach(subItem => {
            subItem.childItem.DayNum = dayIndex + 1;
          });
        }
      });
      this.subConfig.DayNum = this.subConfig.DayList.length;
    },
    //在某天后添加一天行程
    addDaysTrip(addIndex) {
      var array = [];
      this.subConfig.DayList.forEach((item, index) => {
        if (index < addIndex) {
          array.push(item);
        } else if (addIndex == index) {
          array.push(item);
          //新加一天的行程
          var dayItem = this.$tripUtils.daysArrayObj();
          dayItem.isHide = false;
          dayItem.dayNum = item.dayNum + 1;
          var titleItem = this.$tripUtils.titleObj();
          titleItem.DayNum = item.dayNum + 1;
          var daysArrayItem = this.$tripUtils.daysArrayItemObj();
          daysArrayItem.Type = this.$tripUtils.TypeKey.title;
          daysArrayItem.childItem = titleItem;
          dayItem.dayArray.push(daysArrayItem);
          array.push(dayItem);
        } else {
          item.dayNum = item.dayNum + 1;
          array.push(item);
        }
      });
      this.subConfig.DayList = array;
      this.subConfig.DayNum = array.length;
    },
    //公用删除图片
    commonRemoveImg(index, subItemObj) {
      subItemObj.childItem.ImaArray.splice(index, 1);
    },
    //点击折叠
    fold() {
      if (this.isFold == "") {
        this.isFold = 1;
      } else {
        this.isFold = "";
      }
    },
    emitData() {
      var TrafficList = [];
      var ScenicList = [];
      var HotelList = [];
      var DinnerList = [];
      var FreedomList = [];
      var WarmTipList = [];
      var TitleList = [];
      this.subConfig.DayList.forEach((item, dayIndex) => {
        var rank = 1;
        if (item.dayArray != null && item.dayArray.length > 0) {
          item.dayArray.forEach(subItem => {
            subItem.childItem.Rank = rank;
            subItem.childItem.dayNum = item.dayNum;
            subItem.Type = subItem.Type.toString();
            switch (subItem.Type) {
              case this.$tripUtils.TypeKey.traffic:
                TrafficList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.scenic:
                ScenicList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.hotel:
                HotelList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.dinner:
                DinnerList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.freedom:
                FreedomList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.warmtip:
                WarmTipList.push(subItem.childItem);
                break;
              case this.$tripUtils.TypeKey.title:
                TitleList.push(subItem.childItem);
                break;
            }
            rank++;
          });
        }
      });
      var obj = {
        RemoveChild: this.subConfig.RemoveChild,
        RemoveImg: this.subConfig.RemoveImg,
        DayNum: this.subConfig.DayNum,
        NightNum: this.subConfig.NightNum,
        StartCityId: this.subConfig.StartCityId,
        ReturnArriveCityId: this.subConfig.ReturnArriveCityId,
        DinnerList: DinnerList,
        FreedomList: FreedomList,
        HotelList: HotelList,
        ScenicList: ScenicList,
        TrafficList: TrafficList,
        WarmTipList: WarmTipList,
        TitleList: TitleList
      };
      this.HotelList = HotelList;
      this.DinnerList = DinnerList;
      this.$emit("headCallBack", obj);
    }
  },
  mounted() {
    //防止首次初始化数据失败
    this.emitData();
    this.typeArrayList.push(this.$tripUtils.TypeArray[this.$tripUtils.TypeArray.length-1]);
    // this.getSameJourney();
  },
  created() {
    if (this.isOpenGroup == undefined) {
      this.isOpenGroup = false;
    }
  },
  computed: {
    //获取行程天数
    getDayNum() {
      return this.subConfig.DayNum;
    },
    //获取目的地
    getCountryId() {
      return this.subArray.CountryID;
    },
    getDayList() {
      return this.subConfig.DayList;
    }
  },
  watch: {
    //监听天数是否改变
    getDayNum(newValue, oldValue) {
      this.createLineTrip();
    },
    //监听目的地国家是否改变
    getCountryId(newValue, oldValue) {
      this.createLineTrip();
    },
    subConfig: {
      handler: function(newValue, oldValue) {
        this.emitData();
      },
      deep: true
    }
  }
};
</script>