user.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {
  2. CHNAGE_PRICE_PLATFORM_INFO,
  3. CHNAGE_SHOP_CAR_NUMBER,
  4. CHNAGE_LEVEL_TYPE
  5. } from './type'
  6. import { getStorageKeyToken } from '../../utils'
  7. import { getPricePlatformAllApi, getCartListApi, getSelectLevelPlatformRelationApi } from '../../api/anotherTFInterface'
  8. export default {
  9. namespaced: true,
  10. state() {
  11. return {
  12. pricePlatformInfo: {},
  13. shopCarNumber: 0,
  14. levelType: 0
  15. }
  16. },
  17. mutations: {
  18. [CHNAGE_PRICE_PLATFORM_INFO](state, pricePlatformInfo) {
  19. state.pricePlatformInfo = pricePlatformInfo
  20. },
  21. [CHNAGE_SHOP_CAR_NUMBER](state, shopCarNumber) {
  22. state.shopCarNumber = shopCarNumber
  23. },
  24. [CHNAGE_LEVEL_TYPE](state, levelType) {
  25. state.levelType = levelType
  26. }
  27. },
  28. actions: {
  29. count({ commit }) {
  30. if (!getStorageKeyToken()) return
  31. getPricePlatformAllApi({})
  32. .then((res) => {
  33. commit(CHNAGE_PRICE_PLATFORM_INFO, res.data)
  34. })
  35. getCartListApi({}).then((res) => {
  36. this.allCartNum = res.data.reduce((total, value) => total + value.skus.reduce((t, v) => t + (v.shelveState ? v.number : 0), 0), 0)
  37. })
  38. getSelectLevelPlatformRelationApi({})
  39. .then((res) => {
  40. commit(CHNAGE_LEVEL_TYPE, res.data.levelType)
  41. })
  42. }
  43. }
  44. }