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

const app = getApp();

Page({
  data: {},
  onLoad: function (options) {
    var that = this;
    that.setData({
      CheckListUserID: app.globalData.userInfo.UserID,
      Containnerheight: main.getWindowHeight(),
      UserID: app.globalData.userInfo.UserID,
      ListType: options.listtype,
    });

    var userid = app.globalData.userInfo.UserID;
    main.getData("GetMiaoguoLesson2?UserID=" + userid, function (data) {
      if (data) {

        var arr = [];
        if (that.data.ListType == "simple") {
          arr.push(data[0]);
          arr.push(data[1]);

          arr[0].Text = "前言";
          arr[1].Text = "基本操作";
          arr[1].Time = "时长约10分钟";


          arr[1].List[5] = data[2].List[4];
          arr[1].List[4] = data[1].List[2];
          arr[1].List[3] = data[1].List[1];
          arr[1].List[2] = data[1].List[0];
          arr[1].List[0] = data[2].List[0];
          arr[1].List[1] = data[2].List[1];

          arr[1].List.splice(6, 1);


          arr[1].List[4].Title = "通过【检验】生成字词、古诗词、英语题卡";
          arr[1].List[3].Title = "通过【加资料】制作字词、古诗词、英语题卡";
          arr[1].List[2].Title = "制作任何知识点的普通题卡";


          wx.setNavigationBarTitle({
            title: '简要版',
          });
        } else {
          wx.setNavigationBarTitle({
            title: '完整版',
          });
          for (var i = 0; i < 4; i++)
            arr.push(data[i]);
        }

        that.setData({
          List: arr,
        });

        wx.setStorageSync("LessonList", data);
      }
    });
  },
  gotoLesson: function (e) {
    var id = e.currentTarget.dataset.id;
    var idchild = "";
    if (e.currentTarget.dataset.idchild && id > 1)
      idchild = '&LessonPage=' + e.currentTarget.dataset.idchild;

    if (e.currentTarget.dataset.url) {
      if (this.data.ListType == "simple") {
        switch (e.currentTarget.dataset.idchild) {
          case 1:
            id = 3;
            idchild = "&LessonPage=1";
            break;
          case 2:
            id = 3;
            idchild = "&LessonPage=2";
            break;
          case 3:
            id = 2;
            idchild = "&LessonPage=1";
            break;
          case 4:
            id = 2;
            idchild = "&LessonPage=2";
            break;
          case 5:
            id = 2;
            idchild = "&LessonPage=3";
            break;
          case 6:
            id = 3;
            idchild = "&LessonPage=5";
            break;

        }
      }
      wx.navigateTo({
        url: '../other/video?LessonID=' + id + idchild +"&title=" + e.currentTarget.dataset.title+ "&imageurl=" + e.currentTarget.dataset.imageurl + "&url=" + e.currentTarget.dataset.url,
      });
    } else {
      if (id != 2 && id != 3) {
        wx.navigateTo({
          url: '../other/lesson?LessonID=' + id + idchild,
        });
      }
    }
  },
  onShareAppMessage: function () {
    var title = "完整版教学课程";
    if (this.data.ListType == "simple") {
      title = "简要版教学课程";
    }
    var url = app.globalData.SharePath + '?type=lesson&LessonID=all&ListType=' + this.data.ListType + '&UserID=' + app.globalData.userInfo.UserID;
    console.log(url);
    return {
      title: title,
      path: url,
      imageUrl: app.globalData.uploadImageUrl + "web/program_screenshot_lesson_a00.png",
    }
  },
})