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

const app = getApp();

Page({
  data: {
    ImageUrl:app.globalData.uploadImageUrl,
  },
  onLoad: function (options) {
    let that = this;
    that.setData({
      Containnerheight: main.getWindowHeight(),
    });
    
    wx.setNavigationBarTitle({
      title: options.title,
    });

    that.init(options);

    main.checkGenerating();
  },
  init:function(options){
    let that = this;
    let list=wx.getStorageSync('ChoicenessList');
    let arr=[];
    let levelArr=[];
    for(let i=0;i<list.length;i++){
      if ((options.level && options.level.indexOf(list[i].LevelStr)>=0) 
      || (options.articlestyle && options.articlestyle==list[i].ArticleStyle)){
        list[i].Words=list[i].Words.split(",").join("   ");
        list[i].IsShow=1;
        arr.push(list[i]);
        let b=false;
        //debugger;
        for(let j=0;j<levelArr.length;j++){
          if (levelArr[j].Name==list[i].LevelStr){
            b=true;
            break;
          }
        }
        if (!b){
          let obj={};
          obj.Name=list[i].LevelStr;
          obj.CSS="";
          levelArr.push(obj);
        }
      }
    }
    levelArr=common.sort(levelArr,"ASC","Name","String");
    levelArr.unshift({Name:"LATEST",CSS:"Selected",CSS2:"btn0"});
    //debugger;
    that.setData({
      List:arr,
      Level:levelArr,
    });
  },
  filter:function(e){
    let that = this;
    let level=e.currentTarget.dataset.name;
    let list=that.data.List;
    for(let i=0;i<list.length;i++){
      list[i].IsShow=0;
      if (level==list[i].LevelStr || level=="LATEST"){
        list[i].IsShow=1;
      }
    }
    let list2=that.data.Level;
    for(let i=0;i<list2.length;i++){
      list2[i].CSS="";
      if (level==list2[i].Name){
        list2[i].CSS="Selected";
      }
    }
    that.setData({
      List:list,
      Level:list2,
    });
  },
  goto: function (e) {
    let that=this;
    var url=e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url,
    });
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?goto=articlefine&UserID=' + app.globalData.userInfo.UserID,
    }
  },
})