customers.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const initialState = {
  2. customers: [],
  3. filterCustomers: [],
  4. selectedCustomer: null,
  5. loadingCustomers: false,
  6. }
  7. const state = {
  8. customers: initialState.customers,
  9. loadingCustomers: !initialState.loadingCustomers,
  10. selectedCustomer: initialState.selectedCustomer,
  11. filterCustomers: initialState.filterCustomers
  12. }
  13. const getters = {
  14. /**
  15. * [customers description]
  16. */
  17. customers(state) {
  18. return state.customers
  19. },
  20. /**
  21. * [loadingcustomers description]
  22. */
  23. loadingCustomers(state) {
  24. return state.loadingCustomers
  25. },
  26. /**
  27. * [selectedCustomer description]
  28. */
  29. selectedCustomer(state) {
  30. return state.selectedCustomer
  31. },
  32. /**
  33. * [customerVisible description]
  34. */
  35. customerVisible (state) {
  36. return state.filterCustomers.length === 0 ? state.customers : state.filterCustomers
  37. }
  38. }
  39. const mutations = {
  40. /**
  41. * [actions description]
  42. */
  43. setCustomers (state, payload) {
  44. state.customers = payload
  45. },
  46. /**
  47. * [loadingcustomers description]
  48. */
  49. setLoadingCutomers (state, payload) {
  50. state.loadingCustomers = !payload
  51. },
  52. /**
  53. * [selectedCustomer description]
  54. */
  55. setSelectedCustomer (state, payload) {
  56. state.selectedCustomer = payload
  57. },
  58. /**
  59. * [filterCustomers description]
  60. */
  61. setFilterPaymentsCustomers (state, payload) {
  62. state.filterCustomers = payload
  63. }
  64. }
  65. const actions = {
  66. /**
  67. * [INIT_PAYMENTS_CUSTOMERS]
  68. */
  69. initPaymentsCustomers({commit}, payload) {
  70. commit('setCustomers', payload)
  71. commit('setLoadingCutomers', payload)
  72. },
  73. /**
  74. * [SELECT_PAYMENTS_CUSTOMER]
  75. */
  76. selectPaymentsCustomer ({ commit, dispatch }, payload ) {
  77. commit('setSelectedCustomer', payload)
  78. dispatch('selectCustomerInvoices', payload.invoices)
  79. },
  80. /**
  81. * [FILTER_PAYMENTS_CUSTOMERS]
  82. */
  83. filterPaymentsCustomers ({ commit }, payload) {
  84. commit('setFilterPaymentsCustomers', payload)
  85. },
  86. /**
  87. * [RESET_CUSTOMERS]
  88. */
  89. resetCustomers ({ commit }) {
  90. commit('setCustomers', [])
  91. commit('setSelectedCustomer', null)
  92. commit('setFilterPaymentsCustomers', [])
  93. commit('setLoadingCutomers', true)
  94. }
  95. }
  96. export default {
  97. state,
  98. getters,
  99. mutations,
  100. actions
  101. }