kind.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. export const state = () => ({
  2. kinds: {
  3. fetching: false,
  4. data: []
  5. },
  6. kindsParentWithBother: {
  7. fetching: false,
  8. data: []
  9. },
  10. children: {
  11. fetching: false,
  12. data: []
  13. },
  14. kindProperty: {
  15. fetching: false,
  16. data: []
  17. },
  18. brands: {
  19. fetching: false,
  20. data: []
  21. },
  22. firstChildren: {
  23. fetching: false,
  24. data: []
  25. }
  26. })
  27. export const mutations = {
  28. REQUEST_KIND (state, action) {
  29. if (!action.id) {
  30. state.kinds.fetching = true
  31. } else {
  32. const kind = state.kinds.data.find(kind => Object.is(kind.id, action.id))
  33. if (kind) {
  34. kind.fetching = true
  35. }
  36. }
  37. },
  38. GET_KIND_FAILURE (state, action) {
  39. if (!action.id) {
  40. state.kinds.fetching = false
  41. } else {
  42. const kind = state.kinds.data.find(kind => Object.is(kind.id, action.id))
  43. if (kind) {
  44. kind.fetching = false
  45. }
  46. }
  47. },
  48. GET_KIND_SUCCESS (state, action) {
  49. if (!action.id) {
  50. state.kinds.fetching = false
  51. action.result.forEach(kind => {
  52. kind.fetching = false
  53. })
  54. state.kinds.data = action.result
  55. } else {
  56. const kind = state.kinds.data.find(kind => Object.is(kind.id, action.id))
  57. if (kind) {
  58. kind.fetching = false
  59. kind.children = action.result
  60. }
  61. }
  62. },
  63. REQUEST_KINDPARENTSWITHBOTHERS (state) {
  64. state.kindsParentWithBother.fetching = true
  65. },
  66. GET_KINDPARENTSWITHBOTHERS_SUCCESS (state, result) {
  67. state.kindsParentWithBother.fetching = false
  68. state.kindsParentWithBother.data = result
  69. },
  70. GET_KINDPARENTSWITHBOTHERS_FAILURE (state) {
  71. state.kindsParentWithBother.fetching = false
  72. },
  73. REQUEST_CHILDREN (state) {
  74. state.children.fetching = true
  75. },
  76. GET_CHILDREN_SUCCESS (state, result) {
  77. state.children.fetching = false
  78. state.children.data = result
  79. },
  80. GET_CHILDREN_FAILURE (state) {
  81. state.children.fetching = false
  82. },
  83. REQUEST_KINDPROPERTY (state) {
  84. state.kindProperty.fetching = true
  85. },
  86. GET_KINDPROPERTY_SUCCESS (state, result) {
  87. state.kindProperty.fetching = false
  88. state.kindProperty.data = result
  89. },
  90. GET_KINDPROPERTY_FAILURE (state) {
  91. state.kindProperty.fetching = false
  92. },
  93. REQUEST_KINDBRANDS (state) {
  94. state.brands.fetching = true
  95. },
  96. GET_KINDBRANDS_SUCCESS (state, result) {
  97. state.brands.fetching = false
  98. state.brands.data = result
  99. },
  100. GET_KINDBRANDS_FAILURE (state) {
  101. state.brands.fetching = false
  102. },
  103. REQUEST_KINDFIRSTCHILD (state) {
  104. state.firstChildren.fetching = true
  105. },
  106. GET_KINDFIRSTCHILD_SUCCESS (state, result) {
  107. state.firstChildren.fetching = false
  108. state.firstChildren.data = result
  109. },
  110. GET_KINDFIRSTCHILD_FAILURE (state) {
  111. state.firstChildren.fetching = false
  112. }
  113. }