customers.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import {
  2. INIT_PAYMENTS_CUSTOMERS,
  3. SELECT_PAYMENTS_CUSTOMER,
  4. SELECT_CUSTOMER_INVOICES,
  5. FILTER_PAYMENTS_CUSTOMERS,
  6. RESET_CUSTOMERS
  7. } from '@/constants/actionTypes'
  8. import {
  9. SET_CUSTOMERS,
  10. SET_LOADING_CUSTOMERS,
  11. SET_SELECTED_CUSTOMER,
  12. SET_FILTER_PAYMENTS_CUSTOMERS
  13. } from '@/constants/mutationTypes'
  14. const initialState = {
  15. customers: [],
  16. filterCustomers: [],
  17. selectedCustomer: null,
  18. loadingCustomers: false,
  19. }
  20. const state = {
  21. customers: initialState.customers,
  22. loadingCustomers: !initialState.loadingCustomers,
  23. selectedCustomer: initialState.selectedCustomer,
  24. filterCustomers: initialState.filterCustomers
  25. }
  26. const getters = {
  27. /**
  28. * [customers description]
  29. * @param {[type]} state [description]
  30. * @return {[type]} [description]
  31. */
  32. customers(state) {
  33. return state.customers
  34. },
  35. /**
  36. * [loadingcustomers description]
  37. * @param {[type]} state [description]
  38. * @return {[type]} [description]
  39. */
  40. loadingCustomers(state) {
  41. return state.loadingCustomers
  42. },
  43. /**
  44. * [selectedCustomer description]
  45. * @param {[type]} state [description]
  46. * @return {[type]} [description]
  47. */
  48. selectedCustomer(state) {
  49. return state.selectedCustomer
  50. },
  51. customerVisible (state) {
  52. return state.filterCustomers.length === 0 ? state.customers : state.filterCustomers
  53. }
  54. }
  55. const mutations = {
  56. /**
  57. * [actions description]
  58. * @param {[type]} state [description]
  59. * @param {[type]} payload [description]
  60. */
  61. [SET_CUSTOMERS] (state, payload) {
  62. state.customers = payload
  63. },
  64. /**
  65. * [loadingcustomers description]
  66. * @param {[type]} state [description]
  67. * @param {[type]} payload [description]
  68. */
  69. [SET_LOADING_CUSTOMERS] (state, payload) {
  70. state.loadingCustomers = !payload
  71. },
  72. /**
  73. * [selectedCustomer description]
  74. * @param {[type]} state [description]
  75. * @param {[type]} payload [description]
  76. */
  77. [SET_SELECTED_CUSTOMER] (state, payload) {
  78. state.selectedCustomer = payload
  79. },
  80. [SET_FILTER_PAYMENTS_CUSTOMERS] (state, payload) {
  81. state.filterCustomers = payload
  82. }
  83. }
  84. const actions = {
  85. /**
  86. *
  87. * @param {*} param0
  88. * @param {*} payload
  89. */
  90. [INIT_PAYMENTS_CUSTOMERS] ({commit}, payload) {
  91. commit(SET_CUSTOMERS, payload)
  92. commit(SET_LOADING_CUSTOMERS, payload)
  93. },
  94. /**
  95. * @param {*} param0
  96. * @param {*} payload
  97. */
  98. [SELECT_PAYMENTS_CUSTOMER] ({ commit, dispatch }, payload ) {
  99. commit(SET_SELECTED_CUSTOMER, payload)
  100. dispatch(SELECT_CUSTOMER_INVOICES, payload.invoices)
  101. },
  102. /**
  103. * @param {*} param0
  104. * @param {*} payload
  105. *
  106. */
  107. [FILTER_PAYMENTS_CUSTOMERS] ({ commit }, payload) {
  108. commit(SET_FILTER_PAYMENTS_CUSTOMERS, payload)
  109. },
  110. /**
  111. * [RESET_CUSTOMERS]
  112. * @param {*} param0
  113. */
  114. [RESET_CUSTOMERS] ({ commit }) {
  115. commit(SET_CUSTOMERS, [])
  116. commit(SET_SELECTED_CUSTOMER, null)
  117. commit(SET_FILTER_PAYMENTS_CUSTOMERS, [])
  118. commit(SET_LOADING_CUSTOMERS, true)
  119. }
  120. }
  121. export default {
  122. state,
  123. getters,
  124. mutations,
  125. actions
  126. }