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

const app = getApp();

Page({
  data: {
  },
  onReady() {
    this.videoContext = wx.createVideoContext('myVideo')
  },
  onLoad: function (options) {
    var that = this;
    var height = app.globalData.systemInfo.windowHeight;
    that.setData({
      Containnerheight:height,
    });
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: "#000000",
    });

    var LessonID = 2;
    var LessonPage = 1;
    if (options && options.LessonID) {
      LessonID = options.LessonID;
    } 
    if (options && options.LessonPage) {
      LessonPage = options.LessonPage;
    }
    else
      LessonPage=1;

    if (options.url){
      that.setData({
        LessonID: LessonID,
        LessonPage: LessonPage,
        VideoUrl:app.globalData.uploadImageUrl+"web/_lesson/"+options.url,
        ImageUrl:options.imageurl,
      });
      wx.setNavigationBarTitle({
        title: options.Title,
      });
    }
    else{
      var userid = app.globalData.userInfo.UserID;
      main.getData("GetMiaoguoLesson2?UserID=" + userid, function (data) {
        if (data) {          
          that.setData({
            LessonID: LessonID,
            LessonPage: LessonPage,
            VideoUrl:app.globalData.uploadImageUrl+"web/_lesson/"+data[LessonID-1].List[LessonPage-1].VideoUrl,
            ImageUrl:data[LessonID-1].List[LessonPage-1].ImageUrl,
          });
          wx.setNavigationBarTitle({
            title: data[LessonID-1].List[LessonPage-1].Title,
          });
        }
      });
    }

    

   
  },
  onUnload: function () {
    this.InsertMiaoguoUserLesson();
  },
  onHide: function () {
    this.InsertMiaoguoUserLesson();
  },
  InsertMiaoguoUserLesson: function () {
    
    var url = "InsertMiaoguoUserLesson?UserID=" + app.globalData.userInfo.UserID;
    url += "&LessonID=" + this.data.LessonID;
    url += "&Content=" + this.data.LessonPage;

    main.getData(url, function (data) {});
  },
  onShareAppMessage: function () {
    var title ="课程";
    var imageUrl = app.globalData.uploadImageUrl+"web/"+this.data.ImageUrl;
    return {
      title: title,
      path: app.globalData.SharePath + '?type=video&LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID,
      imageUrl: imageUrl,
    }
  },
})
