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

const app = getApp();

Page({
  data: {
    IsSelect: true,
  },
  onLoad: function (options) {
    var that = this;
    that.setData({
      Containnerheight: main.getWindowHeight(),
      ShowType:options.type,
    });

    var words=[];
    var unitsName="";
    var fieldName="";
    var arr =[];
    if (options.type=="CHN"){
      arr= wx.getStorageSync("HanziAll");
      fieldName="字";
    }
    else{
      var bookid=Number(options.bookid);
      fieldName="单词";
      if (bookid>100 && bookid<110){
        arr= wx.getStorageSync("PhoneticEngList");
        fieldName="音标";
      }
      else if (bookid>110 && bookid<120)
        arr= wx.getStorageSync("EnglishAll");
      else if (bookid>120 && bookid<130)
        arr= wx.getStorageSync("NewConceptEngList");
      else if (bookid>=130 && bookid<140)
        arr= wx.getStorageSync("CambridgeEngList");
    }
    arr = JSON.parse(arr);
    var unitsid = Number(options.unitsid);
    var id = options.id;
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].ID == unitsid) {
        var list = arr[i].Units;
        for (var j = 0; j < list.length; j++) {
          if (list[j].ID.toString()==id.toString()){
            unitsName = list[j].Name;
            words = list[j].Words;
          }
        }
        that.setData({
          UnitsName: unitsName,
          Words: words,
          FieldName:fieldName,
        });
      }
    }
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.ShareImage,
    }
  },
})
