var app = getApp()
const util = require('../../utils/utils.js');
Page({
  data: {
    list: [],
    yaoqing: false,
    user_list: [],
    condition: '',
    invite_new_users_configs_id: ''
  },
  onLoad: function (options) { 
    app.request('/pages/inviteNewusersConfigs', '', 'GET').then(res => {
      console.log(res)
      if (res.statusCode == 200) {
        this.setData({
          list: res.data.dynamic_item,
          condition: res.data.condition,
          invite_new_users_configs_id: res.data.id
        })
      }
    })
    app.request('/user/getInviteUsers', '', 'GET').then(res => {
      console.log(res)
      if (res.statusCode == 200) {
        this.setData({
          user_list: res.data.data
        })
      }
    })
  },
  get: util.throttle(function (e) {
    console.log(e)
    var gift_num = e.currentTarget.dataset.gift_num,
      gift_id = e.currentTarget.dataset.gift_id,
      gift_type = e.currentTarget.dataset.give_type,
      num = e.currentTarget.dataset.num,
      invite_new_users_configs_id = this.data.invite_new_users_configs_id;
      console.log(gift_type)
    var data = {
      'invite_new_users_configs_id': invite_new_users_configs_id,
      'num': num,
      'gift_type': gift_type,
      'gift_id': gift_id,
      'gift_num': gift_num
    }
    app.request('/user/getInviteNewUsersReward', data, 'POST').then(res => {
      console.log(res)
      if (res.statusCode == 200) {
        // this.setData({user_list:res.data.data})
        wx.showToast({
          title: '领取成功',
          icon: 'none'
        })
      }
    })
  }, 2000),
  yaoqing: function () {
    this.setData({
      yaoqing: true
    })
  },
  cancel: function () {
    this.setData({
      yaoqing: false
    })
  },
  poster: function () {
    this.setData({
      yaoqing: false
    })
    wx.navigateTo({
      url: '/pages/poster/poster',
    })
  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function (options) {
    var that = this;
    // 设置菜单中的转发按钮触发转发事件时的转发内容
    return{
      title: "我分享了一个大礼包，快来领取吧~", // 默认是小程序的名称(可以写slogan等)
      path: '/pages/index/index?scene='+wx.getStorageSync('user_ID'), // 默认是当前页面，必须是以‘/’开头的完整路径
      imageUrl: 'http://resource.bike.hanyiyun.com/weapp/yaoqing.png', //自定义图片路径，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
    }
  }
})