// pages/my/my.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tabcurrent: {tab: 4,bubble:''},
    releasepopup: false,
    avatar: '',
    user_nickname: '',
    bubble: ''
  },

  //个人中心
  personInfo() {
    let url = '/home/me/index'
    let header = {
      "XX-Token": wx.getStorageSync('token')
    }
    let params = {}
    app.post(url, params, header).then((res) => {
      // console.log(res)
      this.setData({
        avatar: res.avatar,
        user_nickname: res.user_nickname,
        bubble: res.bubble,
        [`tabcurrent.bubble`]: res.bubble
      });
    })
  },

  //跳转我的主页
  myIndex() {

    wx.navigateTo({
      url: '../my/myindex/myindex'
    })
  },
  //我的收藏
  myCollect() {
    wx.navigateTo({
      url: '../my/mycollect/mycollect',
    })
  },
  //消息通知
  messageList() {
    var bubble = this.data.bubble
    wx.navigateTo({
      url: '../my/alerts/alerts?bubble=' + bubble,
    })
  },
  //联系我们
  contactUs() {
    wx.navigateTo({
      url: '../my/contactUs/contactUs',
    })
  },
  //关于我们
  aboutUs() {
    wx.navigateTo({
      url: '../my/abouttUs/abouttUs',
    })
  },
  //导航点击
  chargeTab(e) {
    var index = e.currentTarget.dataset.index
    var current = this.data.current
    if (current == index) {
      return false
    } else {
      this.setData({
        current: index
      })
    }
  },

  //服务-导航
  service(e) {
    var tindex = e.currentTarget.dataset.tindex;
    var tabcurrent = this.data.tabcurrent;
    if (tabcurrent == tindex) {
      return false
    } else {
      this.setData({
        tabcurrent: tindex
      })
        // wx.showToast({
        //     title: '该功能正在开发中',
        //     icon: 'none'
        // })
        this.personInfo()
      wx.redirectTo({
        url: '/pages/service/service',
      })
    }
  },

  //资讯-导航
  consult(e) {
    var tindex = e.currentTarget.dataset.tindex
    var tabcurrent = this.data.tabcurrent
    if (tabcurrent == tindex) {
      return false
    } else {
      this.setData({
        tabcurrent: tindex
      })
        // wx.showToast({
        //     title: '该功能正在开发中',
        //     icon: 'none'
        // })
        this.personInfo()
        wx.redirectTo({
        url: '/pages/consult/consult',
      })
    }
  },

  //发布按钮
  release(e) {
    let that = this;
    that.setData({
      releasepopup: true
    })
  },

  //取消弹窗
  cancelPopup() {
    let that = this;
    that.setData({
      releasepopup: false
    })
  },

  //发布服务跳转
  releaseService() {
    // wx.showToast({
    //     title: '该功能正在开发中',
    //     icon: 'none'
    // });
    wx.navigateTo({
      url: '/pages/service/release/release',
    });
    this.setData({
        releasepopup: false
    })
  },
  //发布资讯跳转
  releaseMessage() {
    // wx.showToast({
    //   title: '该功能正在开发中',
    //   icon: 'none'
    // });
    this.setData({
        releasepopup: false
    })
    wx.navigateTo({
        url: '/pages/consult/release_consult/release_consult',
    })
  },
  //发布心愿跳转
  releaseWish() {
    // wx.showToast({
    //   title: '该功能正在开发中',
    //   icon: 'none'
    // });
    this.setData({
        releasepopup: false
    })
    wx.navigateTo({
        url: '/pages/wish/release/release',
    })
  },

  //心愿-导航
  wish(e) {
    var tindex = e.currentTarget.dataset.tindex
    var tabcurrent = this.data.tabcurrent
    if (tabcurrent == tindex) {
      return false
    } else {
      this.setData({
        tabcurrent: tindex
      })
        // wx.showToast({
        //     title: '该功能正在开发中',
        //     icon: 'none'
        // })
      wx.redirectTo({
        url: '/pages/wish/wish',
      })
    }
  },

  //我的-导航
  my(e) {
    var tindex = e.currentTarget.dataset.tindex
    var tabcurrent = this.data.tabcurrent
    if (tabcurrent == tindex) {
      return false
    } else {
      this.setData({
        tabcurrent: tindex
      })
      wx.redirectTo({
        url: '/pages/my/my',
      })
    }
  },


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

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

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

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

  },

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

  },

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

  },

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

  },

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

  }
})