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.

84 lines
2.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import MemberService from '@/services/member.service'
  2. export const state = () => ({
  3. items: [],
  4. selected: [],
  5. loading: false
  6. })
  7. export const getters = {
  8. isMemberSelected(state) {
  9. return state.selected.length > 0
  10. }
  11. }
  12. export const mutations = {
  13. setMemberList(state, payload) {
  14. state.items = payload
  15. },
  16. addMember(state, member) {
  17. state.items.unshift(member)
  18. },
  19. deleteMember(state, userId) {
  20. state.items = state.items.filter(item => item.id !== userId)
  21. },
  22. updateSelected(state, selected) {
  23. state.selected = selected
  24. },
  25. updateMember(state, member) {
  26. const item = state.items.find(item => item.id === member.id)
  27. Object.assign(item, member)
  28. },
  29. resetSelected(state) {
  30. state.selected = []
  31. },
  32. setLoading(state, payload) {
  33. state.loading = payload
  34. }
  35. }
  36. export const actions = {
  37. getMemberList({ commit }, payload) {
  38. commit('setLoading', true)
  39. return MemberService.getMemberList(payload.projectId)
  40. .then((response) => {
  41. commit('setMemberList', response.data)
  42. })
  43. .catch((error) => {
  44. alert(error)
  45. })
  46. .finally(() => {
  47. commit('setLoading', false)
  48. })
  49. },
  50. addMember({ commit }, data) {
  51. MemberService.addMember(data.projectId, data.userId, data.role)
  52. .then((response) => {
  53. commit('addMember', response.data)
  54. })
  55. .catch((error) => {
  56. alert(error)
  57. })
  58. },
  59. updateMemberRole({ commit }, member) {
  60. MemberService.updateMemberRole(member.projectId, member.id, member.role)
  61. .then((response) => {
  62. commit('updateMember', response.data)
  63. })
  64. .catch((error) => {
  65. alert(error)
  66. })
  67. },
  68. removeMember({ commit, state }, projectId) {
  69. for (const member of state.selected) {
  70. MemberService.deleteMember(projectId, member.id)
  71. .then((response) => {
  72. commit('deleteMember', member.id)
  73. })
  74. .catch((error) => {
  75. alert(error)
  76. })
  77. }
  78. commit('resetSelected')
  79. }
  80. }