var app = getApp();
var $ = require('../../../../js/util.js');
Page({
  data: {
    info: [],
    aff_config:[],
    user:[],
    //公共提示
    hasMore: false,//无更多数据提示
    dataNull: true,//未获取到数据提示
    //分享
    is_share:0,
    web_name:'',
    wx_img:'',
    img_url:'',
    shire_img:'',
    hidden:false
  },
  onLoad: function (options) {//接收上个页面传的参数
    var self = this;
    // var user_info = app.globalData.userInfo;
    // if ($.isEmptyObject(user_info)){
    //   // app.HCerror('提示', "请先登录", true, function (ret) {
    //   //       app.HCswitchTab('../../index/index'); 
    //   //     });
    // }
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
    var self = this;
    app.getUserInfo(function (ret) {
      self.setData({
        info: ret,
      });
      self.getIndex();
    });


  },
  onShow: function () {
    // var self = this;
    // app.getUserInfo(function (ret) {
    //   self.setData({
    //     info: ret,
    //   });
    //   self.getIndex();
    // });

  },
  shareshow: function () {
    var self = this;
    var user=self.data.user;
    if(user.rank_id==1){
      app.HCnavigateTo('../../../../smallshop/pages/pro_level/pro_level/pro_level');
    }else{
      self.setData({
        is_share: 1,
      })
    }
  },
  sharehide: function () {
    var self = this;
    self.setData({
      is_share: 0,
    })
  },
  getIndex: function () {
    var self = this;
    var action = 'c=Extension&a=index';
   // app.showLoading('加载中...');
    app.ajaxRequest(action, 'GET', '', function (ret) {
      if (ret.status == 1) {
        self.setData({
          // template: ret.template.data,
          info: ret.data,
          aff_config: ret.data.affconfig,
          user:ret.data.user_info,
          web_name:ret.web_name,
          wx_img:ret.data.wx_img,
          img_url:ret.data.wx_img,
          shire_img:ret.data.shire_img,
          hidden: true
        })
      }
    }, true);
  },
  goToPoster: function (event) {
    var self = this;
    self.setData({
      tw_share: 1,
      is_share_show: 0,
      is_share:0,
    })
    
  },
  goToExtensionList: function (event) {
    app.HCnavigateTo('../invite_list/invite_list');
  },
  goToExtension: function (event) {
    app.HCnavigateTo('../list/list');
  },
   goToExtensionpoints: function (event) {
    app.HCnavigateTo('../points_list/points_list');
  },
  onShareAppMessage: function () {
    // console.log($.getCurrentPageUrl());return;
    return {
      title: this.data.web_name,
      path: '/pages/index/index?invite_key=' + app.globalData.init_invite_key,
      imageUrl:this.data.shire_img
    }
  },
  onshare: function () {
    wx.showShareMenu({
      withShareTicket: true
    })
  },
  onImgOK(e) {
    this.setData({ img_url: e.detail.path });
  },
  // 关闭遮罩
  close_mask:function(event){
    var self = this;
    self.setData({
      is_fuwu_show: 0,
      is_share_show: 0,
      showspec:false,
      tw_share:0,
    });
  },
  // 保存到本地
  saveimg: function () {
    var self = this;
    wx.getImageInfo({
      src: self.data.img_url,
      success: function (sres) {
        wx.saveImageToPhotosAlbum({
          filePath: sres.path,
          success: function (fres) {
            if (fres.errMsg == 'saveImageToPhotosAlbum:ok') {
              app.HCtoast('保存成功', 1000);
            } else {
              app.HCtoast('保存失败,请重新保存', 1000);
            }
          }
        })
      }
    })
  },
  goToIntegral: function (event) {
      app.HCnavigateTo('../../integral/list/list?invite_key=' + app.globalData.init_invite_key);
  
  },
})