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

const app = getApp();
const ActivityArr = [
  {},
  {
    ActivityName: "newuserhelp",
    ImageArr: [
      { src: "salesactivity_a01_manual_01.png", h: 453 },
      { src: "salesactivity_a01_manual_02.png", h: 989 },
    ]
  },
  {
    ActivityName: "earlybird",
    ImageArr: [
      { src: "salesactivity_a02_manual_01.png", h: 397 },
      { src: "salesactivity_a02_manual_02.png", h: 715 },
    ]
  },
  {
    ActivityName: "end",
    ImageArr: [
      { src: "salesactivity_a03_manual_01.png", h: 397 },
      { src: "salesactivity_a03_manual_02.png", h: 715 },
    ]
  }];

Page({
  data: {
    ImagePath: app.globalData.uploadImageUrl,
    BtnShow: 0,
    ShowNone: false,
  },
  onLoad: function (options) {
    var that = this;
    var activityID = "1";
    if (options && options.ActivityID) {
      activityID = options.ActivityID;
    }

    var EndTime = "";
    if (options && options.EndTime) {
      EndTime = options.EndTime;
    }

    var EarlyBirdTimeStart = "", EarlyBirdTimeEnd = "";
    if (options && options.EarlyBirdTimeStart) {
      EarlyBirdTimeStart = options.EarlyBirdTimeStart;
      EarlyBirdTimeEnd = options.EarlyBirdTimeEnd;
    }

    if (activityID == 2) {
      var EarlyBirdTimeEnd1 = common.formatDateENG(EarlyBirdTimeEnd,"/");
      EarlyBirdTimeEnd1 = new Date(EarlyBirdTimeEnd1 + " 00:00:00");

      console.log("EarlyBirdTimeEnd1:" + EarlyBirdTimeEnd1);
      console.log("Today:" +new Date(common.formatTime(new Date(), "/", true) + " 00:00:00"));
      var dayNumber = common.diffDate("d", new Date(common.formatTime(new Date(), "/", true) + " 00:00:00"), EarlyBirdTimeEnd1);
      console.log(dayNumber);
      if (dayNumber < 0) {
        that.setData({
          ShowNone: true,
        });
      }
      else {
        if (dayNumber == 0)
          dayNumber = "今";
        that.setData({
          DayNumber: dayNumber,
        });
      }
    }

    that.setData({
      Containnerheight: main.getWindowHeight(),
      Activity: ActivityArr[activityID],
      ActivityID: activityID,
      EndTime: EndTime,
      EarlyBirdTimeStart: EarlyBirdTimeStart,
      EarlyBirdTimeEnd: EarlyBirdTimeEnd,
    });

    that.init();
  },
  init: function () {
    var that = this;
    var CouponType = 132;
    if (that.data.ActivityID == 3)
      CouponType = 133;
    main.getData("GetMiaoguoCoupon?UserID=" + app.globalData.userInfo.UserID + "&CouponType=" + CouponType, function (data) {
      if (data && data.length>0) {
        that.setData({
          BtnShow: 1,
        });
      }
    });
  },
  gotoPay: function (e) {
    var PayType = e.currentTarget.dataset.paytype;
    var EndDate = e.currentTarget.dataset.enddate;

    wx.navigateTo({
      url: '../other/pay?PayType=' + PayType + '&EndDate=' + EndDate,
    });
  },
  getCoupon: function (e) {
    var coupontype = e.currentTarget.dataset.coupontype;
    var limittime = e.currentTarget.dataset.limittime;

    var that = this;
    main.getData("SendMiaoguoCoupon?UserID=" + app.globalData.userInfo.UserID + "&CouponType=" + coupontype + "&LimitTime=" + limittime, function (data) {
      wx.showToast({
        title: '领券成功！',
      });
      that.setData({
        BtnShow: 1,
      });
    });

  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?LessonID=all&UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.ShareImage,
    }
  },
})
