// pages/dan/tuaninfo.js
var util = require('../../utils/util.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_info: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.setNavigationBarTitle({
      title: '超级团长'
    });
    var token = wx.getStorageSync('token');

    app.util.request({
      'url': 'entry/wxapp/user',
      'data': {
        controller: 'user.groupleaderindex',
        'token': token
      },
      dataType: 'json',
      success: function (res) {
        if (res.data.code == 0) {
          that.setData({
            user_info: res.data.data
          });
        }
      }
    })

  },
  go_wingoods: function () {
    var link = '/Snailfish_shop/pages/dan/tuan_wingoods';
    var pages_all = getCurrentPages();
    if (pages_all.length > 3) {
      wx.redirectTo({
        url: link
      })
    } else {
      wx.navigateTo({
        url: link
      })
    }
  },
  gotuanyuan: function (event) {

    var type = event.currentTarget.dataset.type;
    //tuanyuan
    var link = '/Snailfish_shop/pages/dan/tuan_tuanyuan?type=' + type;
    var pages_all = getCurrentPages();
    if (pages_all.length > 3) {
      wx.redirectTo({
        url: link
      })
    } else {
      wx.navigateTo({
        url: link
      })
    }
  },
  goqrcode: function () {
    var token = wx.getStorageSync('token');
    wx.showLoading({
      title: '获取中',
    })

    app.util.request({
      'url': 'entry/wxapp/user',
      'data': {
        controller: 'user.load_user_qrcode',
        'token': token
      },
      dataType: 'json',
      success: function (res) {

        if (res.data.code == 0) {
          setTimeout(function () {
            wx.hideLoading()
          }, 2000)
          var image_path = res.data.image_path;
          wx.getImageInfo({
            src: image_path,
            success: function (res) {
              var real_path = res.path;
              wx.saveImageToPhotosAlbum({
                filePath: real_path,
                success(res) {
                  wx.showToast({
                    title: '图片保存成功，可以分享给好友',
                    icon: 'none',
                    duration: 2000
                  })
                }
              })
            }
          })
        }

      }
    })

    
  },
  goindex: function () {
    var link = '/Snailfish_shop/pages/dan/groupleaderindex';
    var pages_all = getCurrentPages();
    if (pages_all.length > 3) {
      wx.redirectTo({
        url: link
      })
    } else {
      wx.navigateTo({
        url: link
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})