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: '',
    storgeUserInfo: wx2my.getStorageSync('_baseUserInfo')
  },
  observers: {
    '**': function (e) {// 每次 setData 都触发
    }
  },
  didMount() {
    this.setData({
      personCenter: this.props.personData,
      baseImgUrl: app.globalData.imageUrl
    });
  },

  methods: {
    _userInfoChange(newVal, oldVal) {
      console.log('newVal, oldVal', newVal, oldVal)
      if (newVal !== oldVal) {
        this.setData({
          memberActivateStatus: newVal && newVal.memberActivateStatus || false,
          memberCardNo: newVal && newVal.memberCardNo || '',
          currentMobile: newVal && newVal.member && newVal.member.mobile || ''
        });
      }
    },

    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() {
    this._userInfoChange = null;
  }

});