You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

register.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import axios from 'axios';
  2. export default {
  3. namespaced: true,
  4. state: {
  5. individuals: [],
  6. agents: [],
  7. registerIndividual: {
  8. name: '',
  9. surname: '',
  10. email: '',
  11. cellNumber: '',
  12. username: '',
  13. password: '',
  14. },
  15. registerAgency: {
  16. name: '',
  17. eaabeffcNumber: '',
  18. companyRegNumber: '',
  19. user: {
  20. name: '',
  21. surname: '',
  22. email: '',
  23. cellNumber: '',
  24. username: '',
  25. password: '',
  26. role: '',
  27. },
  28. },
  29. },
  30. mutations: {
  31. setIndividual(state, type) {
  32. state.registerIndividual = type;
  33. },
  34. setIndividuals(state, type) {
  35. state.individuals = type;
  36. },
  37. setAgents(state, type) {
  38. state.agents = type;
  39. },
  40. setAgency(state, type) {
  41. state.registerAgency = type;
  42. },
  43. addIndividual(state, type) {
  44. state.registerIndividual = type;
  45. },
  46. addAgency(state, type) {
  47. state.registerAgency = type;
  48. },
  49. addAgent(state, type) {
  50. state.registerIndividual = type;
  51. },
  52. updateIndividual(state, type) {
  53. state.registerIndividual.find(item => item.id === type.id).username = type.username;
  54. state.registerIndividual.find(item => item.id === type.id).password = type.password;
  55. },
  56. updateAgency(state, type) {
  57. state.registerAgency.find(item => item.id === type.id).eaabeffcNumber = type.eaabeffcNumber;
  58. state.registerAgency.find(item => item.id === type.id).companyRegNumber = type.companyRegNumber;
  59. },
  60. clearIndividual(state) {
  61. state.registerIndividual = {
  62. name: '',
  63. surname: '',
  64. email: '',
  65. cellNumber: '',
  66. username: '',
  67. password: '',
  68. };
  69. },
  70. clearAgency(state) {
  71. state.registerAgency = {
  72. name: '',
  73. eaabeffcNumber: '',
  74. companyRegNumber: '',
  75. user: {
  76. name: '',
  77. surname: '',
  78. email: '',
  79. cellNumber: '',
  80. username: '',
  81. password: '',
  82. },
  83. };
  84. },
  85. removeIndividual(state, id) {
  86. state.registerIndividual.pop(state.registerIndividual.find(p => p.id === id));
  87. },
  88. removeAgency(state, id) {
  89. state.registerAgency.pop(state.registerAgency.find(a => a.id === id));
  90. },
  91. removeAgent(state, id) {
  92. state.registerAgency.pop(state.registerAgency.find(a => a.id === id));
  93. },
  94. },
  95. getters: {},
  96. actions: {
  97. getIndividuals({ commit }) {
  98. axios
  99. .get('/api/individual')
  100. .then(result => commit('setIndividuals', result.data))
  101. .catch(console.error);
  102. },
  103. getAgents({ commit }) {
  104. axios
  105. .get('/api/agent')
  106. .then(result => commit('setAgents', result.data))
  107. .catch(console.error);
  108. },
  109. // getAgency({
  110. // commit,
  111. // }, id) {
  112. // axios
  113. // .get(`/api/agency/${id}`)
  114. // .then(result => commit('setAgency', result.data))
  115. // .catch(console.error);
  116. // },
  117. saveIndividual({ commit }, item) {
  118. axios
  119. .post('/api/register/register', item)
  120. .then(result => commit('addIndividual', result.data))
  121. .catch(console.error);
  122. },
  123. saveAgency({ commit }, item) {
  124. axios
  125. .post('/api/register/registeragency', item)
  126. .then(result => commit('addAgency', result.data))
  127. .catch(console.error);
  128. },
  129. saveAgent({ commit }, item) {
  130. axios
  131. .post('/api/agent', item)
  132. .then(result => commit('addAgent', result.data))
  133. .catch(console.error);
  134. },
  135. // updateIndividual({
  136. // commit,
  137. // }, item) {
  138. // axios
  139. // .put('/api/individual', item)
  140. // .then(result => commit('updateIndividual', item))
  141. // .catch(console.error);
  142. // },
  143. // updateAgency({
  144. // commit,
  145. // }, item) {
  146. // axios
  147. // .put('/api/agency', item)
  148. // .then(result => commit('updateAgency', item))
  149. // .catch(console.error);
  150. // },
  151. // clearIndividual({
  152. // commit,
  153. // }) {
  154. // commit('clearIndividual');
  155. // },
  156. // clearAgency({
  157. // commit,
  158. // }) {
  159. // commit('clearAgency');
  160. // },
  161. deleteIndividual({ commit }, id) {
  162. axios
  163. .delete(`/api/individual/${id}`)
  164. .then(result => commit('removeIndividual', id))
  165. .catch(console.error);
  166. },
  167. deleteAgent({ commit }, id) {
  168. axios
  169. .delete(`/api/agent/${id}`)
  170. .then(result => commit('removeAgent', id))
  171. .catch(console.error);
  172. },
  173. // deleteAgency({
  174. // commit,
  175. // }, id) {
  176. // axios
  177. // .delete(`/api/agency/${id}`)
  178. // .then(result => commit('removeAgency', id))
  179. // .catch(console.error);
  180. // },
  181. },
  182. };