// pages/Home/home.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    homeTravelSpecialSale:[],
    specialAirTicketItem:[],
    isLogin:0,
    ScrollView: '',
    Scrollindex:0,
    site: {
      companyId: app.state.companyId,
      cityId: app.state.cityId,
      siteName: app.state.siteName,
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.GetInitData();
    this.GetCZTM();
    this.GetAllTicket();
    this.setData({
      isLogin: app.isLogin,
    })
    let City = this.selectComponent('#CityComp');
    City.getCityList();
  },
  ChangeSite(val){
    console.log(val.detail);
    this.setData({
      site: val.detail
    })
    this.onLoad();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },
  Scroll(e){
    this.setData({
      ScrollView: e.target.dataset.id,
      Scrollindex: e.target.dataset.index,
    })
    console.log(this.data.ScrollView)
  },
  // 跟团游
  GetGroup() {
    let Msg = {
      airTicketType: 0,
      pageIndex: 1,
      pageSize: 2,
    };
    let that = this;
    app.$apiJavaNew('/api/b2b/home/getHomeSpecialAirTicketList', Msg).then(res => {

      that.setData({
        specialAirTicketItem: res.pageData
      })

    }).catch(err => {
      wx.showToast({
        title: err.message,
        icon: 'none',
        duration: 1000
      })
    })
  },
  // 超值特卖
  GetCZTM() {
    let that=this;
    let Msg = {
      companyId: that.data.site.companyId,
      cityId: that.data.site.cityId,
      pageIndex: 1,
      pageSize: 5,
    };
    app.$apiJavaNew('/api/b2b/home/getHomeTravelSpecialSale', Msg).then(res => {
      that.setData({
        homeTravelSpecialSale: res.pageData
      })

    }).catch(err => {
      wx.showToast({
        title: err.message,
        icon: 'none',
        duration: 1000
      })
    })
  },
  // 特价机票
  GetAllTicket() {
    let Msg = {
      airTicketType: 0,
      pageIndex: 1,
      pageSize: 2,
    };
    let that = this;
    app.$apiJavaNew('/api/b2b/home/getHomeSpecialAirTicketList', Msg).then(res => {
      
      that.setData({
        specialAirTicketItem: res.pageData
      })

    }).catch(err => {
      wx.showToast({
        title: err.message,
        icon: 'none',
        duration: 1000
      })
    })
  },
  GetInitData(){
    let that=this;
    app.$apiJavaNew('/api/b2b/home/getHomeInitData', {}).then(res => {
      console.log("首页数据",res);
      that.setData({
        homeTravelSpecialSale: res.homeTravelSpecialSale,
        specialAirTicketItem: res.specialAirTicketItem,
      })
      
    }).catch(err => {
      wx.showToast({
        title: err.message,
        icon: 'none',
        duration: 1000
      })
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})