import common from '../../utils/util';
import main from '../../utils/main';

const app = getApp();
var AllList = [],List1=[];

Page({
  data: {
  },
  onLoad: function (options) {
    
    //app.globalData.userInfo.UserID=9;
    
    var pageType = 0;
    if (options.PageType == 1) {
      pageType = 1;
      wx.setNavigationBarTitle({
        title: "奖励名单"
      });
    }
    this.setData({
      Containnerheight: main.getWindowHeight(),
      ArrMenu: [
        { Name: "报名了", Selected: 1 },
        { Name: "续费了", Selected: 0 }
      ],
      ArrAward: [
        { Name: "等待出账", Remark: "等待用户渡过7天退款期的名单",List:[] },
        { Name: "出账", Remark: "已符合奖励条件的名单", List: [] },
        { Name: "结算完成", Remark: "已发放奖励的名单", List: [] },
      ],
      PageType: pageType,
    });

    if (app.globalData.userInfo.Subscribe == 1) {
      this.init();
    }
    else{
      wx.redirectTo({
        url: '../../pages/other/userbook',
      });
    }
    
  },
  init: function () {
    var that = this;
    main.getData('GetIntroducerUserList?UserID=' + app.globalData.userInfo.UserID, function (data) {
      wx.hideLoading();
      if (data) {
        List1=data.List1;
        AllList = data.List2;
        if (that.data.PageType == 0) {
          that.setData({
            List: data.List1,
          });
        }
        else {
          var sevenday = common.formatTime(common.addDate("d",-7,new Date()));
          //console.log(sevenday);
          for (var i = 0; i < AllList.length; i++) {
            if (AllList[i].IsPay == 1 && AllList[i].IsMember == 1){
              var payTime = AllList[i].PayTime;
              if (payTime != "1900-01-01 00:00:00"){
                if (sevenday < payTime) {
                  that.data.ArrAward[0].List.push(AllList[i]);
                }
                else {
                  if (AllList[i].IsRebate == 0) {
                    that.data.ArrAward[1].List.push(AllList[i]);
                  }
                  else {
                    that.data.ArrAward[2].List.push(AllList[i]);
                  }
                }
              }
            }
          }
          that.setData({
            ArrAward: that.data.ArrAward,
          });
        }
      }
    });
  },
  changeMenu: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var list = [];
    if (id == 0) {
      that.data.ArrMenu[0].Selected = 1;
      that.data.ArrMenu[1].Selected = 0;
      list = List1;
    }  
    else {
      that.data.ArrMenu[0].Selected = 0;
      that.data.ArrMenu[1].Selected = 1;
      list = AllList;
    }

    that.setData({
      ArrMenu: that.data.ArrMenu,
      List: list,
    });

    wx.pageScrollTo({
      scrollTop: 0,
    });
  },
  gogoShareUser: function () {
    wx.navigateTo({
      url: './shareuser',
    });
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?type=marketing&UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.uploadImageUrl+"web/program_screenshot_promotion.png",
    }
  },
});