// pages/member/MemberGradeList/MemberGradeList.js
var app = getApp();
// var WxParse = require('../../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    language: '',
    customer_open: true,
    show1: false,
    service_QRcode: '',
    service_mobile: '',
    level_type: "",
    levelList: [],
    //会员信息
    memberInfo: {},
    right: {},
    shopDesc: "",
    name: "",
    balance_recharge:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.init();
    this._getLevelUpData();
    let basicinfo = wx.getStorageSync('yz_basic_info');
    let that = this;
    wx.getSystemInfo({
      success:function(res){
        if(res.platform == "ios"){
          // IOS
          // 后台ios虚拟支付一键关闭前端苹果隐藏充值按钮
          if( basicinfo.globalParameter.ios_virtual_pay == 0){
            that.setData({
              is_ios:true
            });
          }else if( basicinfo.globalParameter.ios_virtual_pay == 1){
            that.setData({
              is_ios:false
            });
          }
        }else{
          that.setData({
            is_ios:true
          });
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  init(){
    this.setData({
      customer_open: true,
      show1: false,
      service_QRcode: '',
      service_mobile: '',
    });
  },
  callPhone() {
    wx.makePhoneCall({
      phoneNumber: this.data.service_mobile,

    });
  },
  closePop() {
    this.setData({
      show1: false
    });
  },
  showPop() {
    if (this.data.customer_open) {
      this.setData({
        show1: true
      });
    }
  
  },
  //获取升级等级数据
  _getLevelUpData() {
    let that = this;
    let urlStr = app.getNetAddresss("member.member-level.index");
    app._getNetWork({
      url: urlStr,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let level_message = res.data.data.map(function(item, index, key) {
            if (!app._isTextEmpty(item.description)) {
              item.description = item.description.replace(/(\r\n|\n|\r)/gm, "<br />");
              return item;
            } else {
              item.description = '';
              return item;
            }
          });
          that.setData({
            level_type: res.data.level_type,
            levelList: level_message,
            memberInfo: res.data.member_data,
            right: res.data.member_data.rights ? res.data.member_data.rights : '',
            shopDesc: res.data.shop_description,
            name: (res.data.shop_set?res.data.shop_set.name:''),
            balance_recharge:res.data.balance_recharge, //购买是否开启
          });
          if(res.data.shop_set && res.data.shop_set!=null){
            that.setData({
              customer_open: res.data.shop_set.customer_open == '1' ? true : false,
              service_QRcode: res.data.shop_set.service_QRcode,
              service_mobile: res.data.shop_set.service_mobile
            });
          }
          // let article = that.data.shopDesc;
          /**
           * WxParse.wxParse(bindName , type, data, target,imagePadding)
           * 1.bindName绑定的数据名(必填)
           * 2.type可以为html或者md(必填)
           * 3.data为传入的具体数据(必填)
           * 4.target为Page对象,一般为this(必填)
           * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
           */
          // WxParse.wxParse('article', 'html', article, that);
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  buy(e) {
    let goodid = e.currentTarget.dataset.goodid;
    wx.navigateTo({
      url: '/packageA/detail_v2/detail_v2?id=' + goodid
    });
  },
  gotoRightGood(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageB/member/RightGood/RightGood?level_id=' + id
    });
  },
  goChongzhi(e){
    let money = e.currentTarget.dataset.money;
    wx.navigateTo({
      url: '/packageA/member/balance/balance_recharge/balance_recharge?balance=' + money
    });
  }
});