homecart.js 947 B

1234567891011121314151617181920212223242526272829303132
  1. import PersistedState from '../PersistedState'
  2. // initial state
  3. const state = {
  4. total_amount:PersistedState.getStorage('homecart','total_amount', 0), // 总量
  5. total_price:PersistedState.getStorage('homecart','total_price', 0.00), // 总价
  6. cartGoods: PersistedState.getStorage('homecart','cartGoods', []) // 购物车中选中的商品
  7. }
  8. // mutations
  9. const mutations = {
  10. // 计算购物车总量和总价
  11. calculationAmount (state, amount) {
  12. state.total_amount = amount
  13. PersistedState.setStorage('homecart',state)
  14. },
  15. calculationPrice (state, price) {
  16. state.total_price = price
  17. PersistedState.setStorage('homecart',state)
  18. },
  19. saveSelectedCartGoods (state, payload) {
  20. state.cartGoods = payload.cartGoods
  21. PersistedState.setStorage('homecart',state)
  22. },
  23. clearSelectedCartGoods (state) {
  24. state.cartGoods = []
  25. PersistedState.setStorage('homecart',state)
  26. }
  27. }
  28. export default {
  29. state,
  30. mutations
  31. }