import {PaymentState} from '@/types/views/payment.interface';
import {GetterTree, MutationTree, ActionTree} from 'vuex';

const state: PaymentState = {
    author: '三毛'
};

// 强制使用getter获取state
const getters: GetterTree<PaymentState, any> = {
    author: (state: PaymentState) => state.author
};

// 更改state
const mutations: MutationTree<PaymentState> = {
    // 更新state都用该方法
    UPDATE_STATE(state: PaymentState, data: PaymentState) {
        for (const key in data) {
            if (!data.hasOwnProperty(key)) {
                return;
            }
            // @ts-ignore
            state[key] = data[key];
        }
    }
};

const actions: ActionTree<PaymentState, any> = {
    UPDATE_STATE_ASYN({commit, state: PaymentState}, data: PaymentState) {
        commit('UPDATE_STATE', data);
    },
    // GET_DATA_ASYN({ commit, state: LoginState }) {
    //   Payment.getData()
    // }
};

export default {
    state,
    getters,
    mutations,
    actions
};

