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

var app = getApp();

Page({
  data: {
    PanelShow: 0,
    ImagePath: app.globalData.uploadImageUrl,
  },
  onLoad: function (options) {
    var that = this;
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo'] || app.globalData.userInfo.IsShow == 0) {
          that.setData({
            Containnerheight: main.getWindowHeight(),
          });
      
          that.init();
          wx.setNavigationBarColor({
            frontColor: "#ffffff",
            backgroundColor: "#9BD41C",
          });
        }
        else {
          wx.navigateTo({
            url: '../index/accredit',
          });
        }
      }
    });
  },
  init: function () {
    var that = this;
    main.getData("GetClassList?Flag=0", function (data) {
      if (data && data.length>0) {
        that.setData({
          StartDate: common.formatDateCHS(data[0].StartDate),
        })
      }
    });
  },
  payMoney: function () {
    var that = this;
    var money = 1;
    var detail = {};
    detail.UserID = app.globalData.userInfo.UserID;
    detail.Introducer = app.globalData.userInfo.Introducer;
    detail.PayType=9;
    detail = JSON.stringify(detail);
    //console.log(detail);
    //console.log(money);
    var remark = null;
    main.payMoney(9, remark, money, detail, function () {
      that.setData({
        PanelShow:1,
      });
      wx.setNavigationBarColor({
        frontColor: "#000000",
        backgroundColor: "#ffffff",
      });
    });
  },
  copyManager: function () {
    wx.setClipboardData({
      data: "秒过学习法",
      success(res) {
        wx.showModal({
          title: '已复制',
          showCancel: false,
          content: "请在微信添加公众号中长按粘贴。",
          confirmText: "知道了",
        });
      }
    });
  },
  gotoIndex: function () {
    wx.reLaunch({
      url: '../index/index',
    })
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.ShareImage,
    }
  },
})