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

const app = getApp();


Page({
  data: {
    ImagePath: app.globalData.uploadImageUrl,
  },
  onLoad: function (options) {
    var that = this;
    
    that.setData({
      Containnerheight: main.getWindowHeight(),
    });

    wx.showLoading({
      title: '请稍候',
    });
    var userid=app.globalData.userInfo.UserID;
    main.getData("GetAnnualReport?UserID=" + userid, function (data) {
      wx.hideLoading();
      if (data){
        that.setData({
          Data:data,
        });
      }
    });


    var imageQRCode = app.globalData.serverUrl;
    imageQRCode += common.Encrypt("BuildWXServiceQRCode?QRCodeType=0&UserID=" + app.globalData.userInfo.UserID + "&SourceID=" + app.globalData.ProgramID);
    console.log(imageQRCode);
    var that = this;
    var downloadTask = wx.downloadFile({
      url: imageQRCode,
      success(res) {
        if (res.statusCode === 200) {
          that.setData({
            QRCode:res.tempFilePath,
          });
        }
      },
      fail: function (err) {
        console.log("err:"+err);
      }
    });

    downloadTask.onProgressUpdate((res) => {
      console.log('下载进度', res.progress)
      console.log('已经下载的数据长度', res.totalBytesWritten)
      console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
    })
  },
  goto: function (e) {
    var url = e.currentTarget.dataset.url;
    
    wx.navigateTo({
      url: url,
    });
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?LessonID=all&UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.ShareImage,
    }
  },
})
