addressData.js 1.16 KB
/*
 * Created by shipfi on 2016/5/31.
 */
import {
    MY_ADDRESS_LIST,
    MY_ADDRESS_LIST_ClEAR,
    SET_DEFAULT_ADDRESS,
    SELECT_ADDRESS




} from '../mutationTypes';


const state = {
    myAddressList:[],
    myAddressCount:0,
    selectAddress:{}


};

const mutations = {
    [MY_ADDRESS_LIST](state,action){//获取我的地址列表
        state.myAddressList = state.myAddressList.concat(action.myAddressList.list);
        state.myAddressCount = action.myAddressList.count;
    },
    [MY_ADDRESS_LIST_ClEAR](state,action){//清除我的地址列表
        state.myAddressList = [];
        state.myAddressCount ='';

    },
    [SET_DEFAULT_ADDRESS](state,action){//设置默认地址
        let index = state.myAddressList.findIndex(function(element) {
            return element.buyerAddressId==action.buyerAddressId;
        });
        state.myAddressList.forEach(function(element){
            element.isDefault=0;

        });
        state.myAddressList[index].isDefault=1;

    },
    [SELECT_ADDRESS](state,action){//获取指定地址信息
        state.selectAddress = action.selectAddress;

    },

};

export default {
    state,
    mutations
};