import { purchaseCartList } from '@/api/purchaseCart'
export default {
  state: {
    cartCount: 0,
  },
  getters: {
    cartCount: state => {
      return () => state.cartCount
    },
  },
  mutations: {
    setCartCount (state, count) {
      state.cartCount = count
    },
  },
  actions: {
    // 获取购物车列表
    getCartList ({ state, commit }) {
      purchaseCartList({pageNo:1,pageSize:1}).then(res => {
        commit('setCartCount', res.data ? res.data.count : 0)
      })
    },
    // 更新购物车数量
    updateCartCount ({ state, commit }, count) {
      commit('setCartCount', count)
    }
  }
}
