// pages/microShop_shareList/microShop_shareList.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    first_content: [],
    second_content: [],
    third_content: [],
    fourth_content: [],
    activeName: 'first',
    show: true,
    orderData: [],
    time_type: "",
    active: 0,
    is_first_content: false,
    is_second_content: false,
    is_third_content: false,
    is_fourth_content: false,
    currentTabIndex: "0"
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    if (options.date) {
      this.setData({
        time_type: options.date
      });
      this.setDataByTabIndex();
    }
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
  },
  toInfo(e){
    console.log(e);
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageC/microshop/shareDetail/shareDetail?id='+id,
    });
  },
  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },
  //设置选择后的数据
  setDataByTabIndex() {
    if (this.data.currentTabIndex == "0" && !this.data.is_first_content) {
      this.setData({
        is_first_content: true
      });
      this.getData("");
    } else if (this.data.currentTabIndex == "1" && !this.data.is_second_content) {
      this.setData({
        is_second_content: true
      });
      this.getData("0");
    } else if (this.data.currentTabIndex == "2" && !this.data.is_third_content) {
      this.setData({
        is_third_content: true
      });
      this.getData("1");
    } else if (this.data.currentTabIndex == "3" && !this.data.is_fourth_content) {
      this.setData({
        is_fourth_content: true
      });
      this.getData("-1");
    }
  },
  //获取数据
  getData(_apply_status) {
    let that = this;
    let urlStr = app.getNetAddresss('plugin.micro.frontend.controllers.MicroShopBonusLog.list.apply');
    urlStr += '&apply_status=' + _apply_status;
    urlStr += '&time_type=' + this.data.time_type;
    app._getNetWork({
      url: urlStr,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          if (that.data.currentTabIndex == "0") {
            that.setData({
              first_content: res.data.list.data
            });
          } else if (that.data.currentTabIndex == "1") {
            that.setData({
              second_content: res.data.list.data
            });
          } else if (that.data.currentTabIndex == "2") {
            that.setData({
              third_content: res.data.list.data
            });
          } else if (that.data.currentTabIndex == "3") {
            that.setData({
              fourth_content: res.data.list.data
            });
          }
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  //tab 点击
  handleClick(e) {
    let tab = e.detail.index;
    if (this.data.currentTabIndex == tab) {
      return;
    } else {
      this.setData({
        currentTabIndex: tab
      });
    }
    this.setDataByTabIndex();
  },
});
