// pages/freeTravel/free.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    commonmsg: {
      companyId: app.state.companyId,
      freeRecommendType: 1,
      pageIndex: 1,
      pageSize: 4,
    },
    commonmsg2: {
      companyId: app.state.companyId,
      freeRecommendType: 2,
      pageIndex: 1,
      pageSize: 3,
    },
    isLogin: app.isLogin,
    TreatmentList:[],
    HotCrashList:[],
    CustomDesignerList:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.Treatment();
    this.HotCrash();
    this.CustomDesigner();
  },
  goUrl(){

  },
  goMore(e){
    console.log(e)
    let url=e.target.dataset.url;
    wx.navigateTo({
      url: url,
    })
  },
  Treatment(){
    let that=this;
    app.$api('b2b_get_GetB2BFreeRecommendPageList', that.data.commonmsg).then(res => {
     
      let TreatmentList = res.data.data.pageData;
      TreatmentList.forEach(item => {
        item.imgCover = JSON.parse(item.imgCover)
      })
      that.setData({
        TreatmentList: TreatmentList
      })
      
    }).catch(err => { })
  },
  HotCrash() {
    let that = this;
    app.$api('b2b_get_GetB2BFreeRecommendPageList', that.data.commonmsg2).then(res => {
      
      let HotCrashList = res.data.data.pageData;
      HotCrashList.forEach(item => {
        item.imgCover = JSON.parse(item.imgCover)
      })
      that.setData({
        HotCrashList: HotCrashList
      })

    }).catch(err => { })
  },
  CustomDesigner() {
    let that = this;
    app.$apiJavaNew('/api/b2b/free/getTripCustomList', {}).then(res => { 
      let CustomDesignerList = res.pageData;
      CustomDesignerList.forEach(item=>{
        item.emBirthday = that.Year(item.emBirthday);
      })
      that.setData({
        CustomDesignerList: res.pageData
      })
      
    }).catch(err => {
      wx.showToast({
        title: err.message,
        icon: 'none',
        duration: 1000
      })
    })
  },
  Year(val){
    let str = "";
    if (val) {
      str = val.substr(2, 1) + "0后"
    }
    return str;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})