const rq = require("../../utils/request.js");
const ut = require("../../utils/util.js");
const {barcode,qrcode} = require("../../utils/index.js");
var s = getApp().globalData.setting;
var r=s;
Component({
  properties: {
    object: {
       type: Object,
       value: null
    },
    qy_data:{
       type: Object,
       value: null
    },
    pulscardname:{
        type:String,
        value:"--"
    },
    rfmName:{
        type:String,
        value:"--"
    },
    yuer:{
        type:Number,
        value:0
    },
    byquan:{
          type:Number,
          value:0
    },
    udata:{
        type: Object,
        value: null
    },

  },
  data: {
    // 这里是一些组件内部数据
    iurl: s.imghost,
    defaultAvatar: s.imghost + "/miniapp/images/no-head.jpg",
    userInfo:null,

    sys_switch:null,
    tc_hide:true,  //会员卡的弹出层隐藏
    brcode:'',
    showvipcode:false,

  },

  ready: function() {
       var th=this;
       if(getApp().globalData.userInfo){
            this.setData({userInfo:getApp().globalData.userInfo});
       }
       /*-------系统是否开通等级卡，会员是等级卡-----*/
       getApp().getConfig2(function (e) {
           var t_swi = e.switch_list;
           if (t_swi) t_swi = JSON.parse(t_swi)
           if (t_swi) {
               th.setData({sys_switch: t_swi});
           }
           var getuserqy_color=e.userqy_color;
           if (getuserqy_color) getuserqy_color = JSON.parse(getuserqy_color)
           if(getuserqy_color){
               th.setData({userqy_color:getuserqy_color})
           }
       })

  },

  pageLifetimes: {
    //要处理一下，游客登录后的界面的变化,主要还该是改变会员
    show: function () {
         if(!this.data.userInfo && getApp().globalData.userInfo){
              this.setData({userInfo:getApp().globalData.userInfo});
         }
    }
  },

  methods: {
      //登陆会员
      login_user(){
          getApp().goto('/packageE/pages/togoin/togoin');
      },
      //------卡片的显示和关闭--------
      show_tc: function () {
          var that=this;
          if (!this.data.userInfo) return false;
          var getnowtime;
          getApp().request.get("/api/weshop/users/getServerTime", {
              success: function (res) {
                  if (res.data.code == 0)
                  {
                      getnowtime=res.data.data;
                      if (!getnowtime)
                      {
                          ut.m_toast("获取服务时间失败");
                          return;
                      }
                      //base64_encode($user.mobile.'|'.date('Y-m-d H:i:s')
                      var val = that.data.userInfo.mobile + "|" +getnowtime+"|"+that.data.getusercode_vailtime;
                      val = "^" + ut.base64_encode(val);

                      qrcode('qrcode', val, 350, 350, that);
                      let userInfo = getApp().globalData.userInfo;
                      barcode('barcode', userInfo.userQrcode, 480,140,that);
                      that.setData({
                          tc_hide: false,
                          brcode:userInfo.userQrcode
                      });
                  }
              }
          })
      },
      showtext:function(){
        this.setData({
          showvipcode:true
        })
      },
      //隐藏会员卡
      hide_tc: function () {
          this.setData({
              tc_hide: true,
          });
      },

      //--跳转到预存款页面--
      deposit: function () {
          if (!this.data.userInfo)
          {
              this.login_user();
              return false;
          }
          wx.navigateTo({
              url: '/packageD/pages/user/deposit/deposit',
          })
      },
      //--跳转到余额页面--
      balance: function () {
          if (!this.data.userInfo)
          {
              this.login_user();
              return false;
          };
          wx.navigateTo({
              url: '/packageD/pages/user/member/menber',
          })
      },
      //--跳转到优惠券--
      coupon: function () {
          var th = this;
          if (!this.data.userInfo)
          {
              this.login_user();
              return false;
          };
          //  th.sendsm();
          wx.navigateTo({
              url: '/packageD/pages/user/coupons/coupons',
          })
      },
      //--跳转到积分--
      integral: function () {
          if (!this.data.userInfo)
          {
              this.login_user();
              return false;
          }
          wx.navigateTo({
              url: '/packageD/pages/user/integral/integral',
          })
      },

      jump: function () {
          let isRfm = wx.getStorageSync('isRfm')
          //升级为RFM就不跳转成长值详情
          if (!isRfm) {
              getApp().goto("/packageE/pages/user/grow_value/grow_value")
          }
      },

      //跳转到链接
      goto: function (e) {
          console.log(e);
          console.log('跳转');
          var url = e.currentTarget.dataset.url;
          wx.navigateTo({ url: url })

      },

      go_info:function (){
          getApp().goto("/packageG/pages/user/userinfo/userinfo");
      }


  }
})