bindAccount.js 1.26 KB
import { maskAccount } from '../../utils/mine-handler';
export default function() {
  return {
    namespaced: true,
    state: {
      alipayAccount: '',
      certName: '',
      nickName: '',
      validStatus: -1
    },
    mutations: {
      addUserAliPayAccount(state, data) {
        let {
          alipayAccount,
          certName,
          nickName,
          validStatus
        } = data;

        // state.alipayAccount = maskAccount(alipayAccount);
        state.alipayAccount = alipayAccount || '';
        state.nickName = nickName || '';
        state.certName = certName || '';
        state.validStatus = validStatus || 0;
      }
    },
    actions: {
      async fetchUserAliPayAccount({ commit }) {
        const result = await this.$api.get('/api/ufo/home/getUserAliPayAccount');

        if (result.code === 200) {
          commit('addUserAliPayAccount', result.data);
        } else {
          commit('addUserAliPayAccount', {});
        }
      },
      async bindAliPayAccount({ commit }, {account, name}) {
        const result = await this.$api.get('/api/ufo/home/bindAliPayAccount', {
          alipayAccount: account,
          certName: name
        });

        // commit('addUserAliPayAccount', result.data);
        return result;
      },
    },
  };
}