import common from '../../utils/util';
import main from '../../utils/main';
import animation from '../../utils/animation';
import commonBehavior from '../behaviors/commonBehavior';

const app = getApp();

Page({
  behaviors: [commonBehavior],
  data: {
    IsShowRemind:false,
    remindAnimation: "",
    IsIPhoneX:app.globalData.IsIPhoneX,
  },
  onLoad: function (options) {
    let that = this;
    that.setData({
      Containnerheight: main.getWindowHeight(),
      Version:app.globalData.Version,
    });
    that.initMenu();

    // setTimeout(function(){
    //   if (!app.globalData.IsProduction){
    //     wx.navigateTo({
    //       url: 'articlefine',
    //     })
    //   }
    // },1000);

    if (app.globalData.goto){
      wx.navigateTo({
        url: app.globalData.goto,
      });
    }

    if (app.globalData.systemInfo.windowHeight>700){
      that.setData({
        CanScrollCSS: "panelTop1",
      });
    }

    that.getBaiduToken();
    
  },
  onShow:function(){
    
    this.getData();
    main.checkGenerating();

    if (wx.getStorageSync('IsShowGuideContainer')){
      this.initGuide();
    }
    else{
      this.setData({
        IsShowGuideContainer:false,
      })
    }

    if (app.globalData.goto){
      app.globalData.goto="";
    }
    else{
      app.globalData.OCRWords=[];
    }
  },
  goto: function (e) {
    let that=this;
    var url=e.currentTarget.dataset.url;
    if (url=="wordsinput"){
      if (that.data.TodayCount>that.data.MaxCount){
        animation.toggleRemindWithAnimation(that);
        return ;
      }
    }
    if (url=="articlefine"){
      wx.redirectTo({
        url: url,
      });
    }
    else{
      wx.navigateTo({
        url: url,
      });
    }
    that.setData({
      IsShowRemind:false,
    })
    
  },
  getData:function(){
    let that=this;
    main.getData('GetYJBDCArticleList?UserID=' + app.globalData.userInfo.UserID+'&IsTodayCount=1', function (data) {
      if (data) {
        that.setData({
          TodayCount:data.TodayCount,
          MaxCount:data.MaxCount,
          UnReadCount:data.UnReadCount,
        });
      }
    });
  },
  showRemind:function(){
    animation.toggleRemindWithAnimation(this);
  },
  initGuide:function(){
    let that=this;
    that.setData({
      IsShowGuideContainer:true,
    });
    main.showGuideContainer(that,"#txtWordsInput",-5,60,"pic_ha01",196,126);
    wx.setStorageSync('IsShowGuideContainer', true);
  },
  initMenu:function(){
    let that = this;
    main.getData('GetYJBDCGenerateConfig?UserID=' + app.globalData.userInfo.UserID, function (data) {
      app.globalData.GenerateConfig=data;
    });
  },
  catchTouchMove: main.catchTouchMove,
  getBaiduToken: function () {
    var that = this;
    wx.login({
      success: function (res0) {
        main.getData('GetBaiduToken?ProgramID=' + app.globalData.ProgramID+"&Code="+res0.code, function (data) {
          if (data) {
            app.globalData.BaiduToken=data;
            //console.log("BD:"+data);
          }
        });
      },
    });
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.ShareImage,
    }
  },
})