// pages/index/tripDay/tripDay.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    msg:{
      ConfigId:'4265',
      DayNum:'2',
      TCID:'7003',
    },
    dataInfo:{},
    dayInfo:{},
    isDirect:1,
    suffix:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("options",options)
    let that=this;
    let msg=that.data.msg;
    if (options.ConfigId){
      msg.ConfigId = options.ConfigId;
      msg.DayNum = options.DayNum;
      msg.TCID = options.TCID;
      that.setData({
        msg: msg
      })
    }
    that.getData()
  },
  getData(){
    let that=this;
    let msg=this.data.msg
    app.$api('b2b_get_GetMXYTravelJourneyInfo', msg ).then(res => {
      let dayInfo={
        titleList:[],
        scenList:[],
        warnList:[],
        mealList:[],
        hotelList:[],
      };
      res.dayArray.forEach(item=>{
        if (item.Type && item.Type==7){
          dayInfo.titleList.push(item);
        }
        if (item.Type && item.Type == 2) {
          dayInfo.scenList.push(item);
        }
        if (item.Type && item.Type == 6) {
          dayInfo.warnList.push(item);
        }
        if (item.Type && item.Type == 4) {
          dayInfo.mealList.push(item);
        }
        if (item.Type && item.Type == 3) {
          dayInfo.hotelList.push(item);

        }
      })
      this.setData({
        dataInfo:res,
        dayInfo: dayInfo,
        isDirect: res.isDirect
      })
      console.log("dataInfo", this.data.dataInfo)
      console.log("dayInfo", dayInfo)
      that.getHotelSuffix();
    }).catch(err => { })
  },
  getHotelSuffix() {
    let List = this.data.dayInfo.hotelList;
    let isDirect = this.data.isDirect;
    let suffix = "";
  
    if (List.length > 1) {
      if (isDirect === 1) {
        suffix = "或同級"
      }
    } else {
      
      if (List.length == 1 && List[0].childItem.HotelName != '温馨的家' && List[0].childItem.HotelName != '机场附近酒店') {
        
        if (List[0].childItem.Status == 1) {
          suffix = "【保证入住】"
          
        } else {
          if (isDirect === 1) {
            suffix = "或同級"
          }
        }
      }
    }
    this.setData({
      suffix: suffix,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})