const wx2my = require('../../wx2my');
const Behavior = require('../../Behavior');
// component/personCenter/personCenter.js
var app = getApp();

const wxService = require('../../utils/wxService');

const envInfo = require('../../config/index').envInfo;

Component({
  props: {
    personData: {},
    integralNum: 0,
    baseUserInfo: {},
    couponNum: 0,
    token: null
  },

  /**
   * 页面的初始数据
   */
  data: {
    personCenter: {},
    memberCardNo: "",
    memberActivateStatus: false,
    integralNum: 0,
    couponNum: 0,
    // baseUrl: '/assets/imgs/060610.png',
    baseUrl: '#02bb70',
    isAuthorization: false,
    _token: '',
    currentMobile: '',
    baseImgUrl: '',
    accreditUserInfo: wx2my.getStorageSync('_accreditUserInfo').data,
    avatar: '',
    nickName: ''
  },
  observers: {
    '**': function (e) {// 每次 setData 都触发
    }
  },
  didMount() {},
  didUpdate(prevProps, prevData) {
    const {code, mobile} = prevProps && prevProps.baseUserInfo && prevProps.baseUserInfo.member
    const {avatar, nickName} = prevData && prevData.accreditUserInfo
    this.setData({
      avatar,
      nickName,
      memberCardNo: code || '',
      currentMobile: mobile ||'',
      personCenter: prevProps && prevProps.personData,
      baseImgUrl: app.globalData.imageUrl
    })
  },
  methods: {
    handleToMemberOfOwn() {
      wxService.router(`/pages/memberOfOwn/memberOfOwn`);
    },

    toBonusDetails() {
      wxService.router(`/pages/integralWater/integralWater`);
    },

    toCouponList() {
      wxService.router(`/pages/coupons/coupons`);
    },

    handleTtoActiveMemebr() {
      if (wx2my.getStorageSync('_baseUserInfo')) {
        wxService.openCard();
      } else {
        this.setData({
          isAuthorization: true
        });
      }
    },

    handleGoWxCard() {
      wxService.openCard();
    }

  },
  detached() {}

});