friend.js
3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import _ from 'loadsh'
import Helper from '../../utils/helper'
const friendModules = {
state: {
friendList: [],
search: '',
user: {
loading: false,
list: [],
paginate: {
page: 1, size: 20, total: 0
}
},
admin: {
loading: false,
list: [],
paginate: {
page: 1, size: 20, total: 0
}
},
scheme: {
loading: false,
list: [],
paginate: {
page: 1, size: 20, total: 0
}
},
createGroupModelVisible: false,
},
getters: {},
mutations: {
updateFriendList(state, friendList) {
state.friendList = friendList
},
updateFriendSearch(state, search) {
state.search = search
},
updateLoading(state, {type, loading}) {
state[type].loading = loading
},
updateList(state, {type, resource}) {
state[type].list = resource.data
state[type].paginate = resource.meta
},
appendList(state, {type, resource}) {
state[type].list = state[type].list.concat(resource.data)
state[type].paginate = resource.meta
},
reset(state) {
Object.assign(state, {
friendList: [],
search: '',
user: {
loading: false,
list: [],
paginate: {
page: 1, size: 20, total: 0
}
},
admin: {
loading: false,
list: [],
paginate: {
page: 1, size: 20, total: 0
}
},
scheme: {
loading: false,
list: [],
paginate: {
page: 1, size: 20, total: 0
}
},
createGroupModelVisible: false,
})
}
},
actions: {
getAllFriendList({dispatch}, payload) {
dispatch('getFriendList', {type: 'user', ...payload})
dispatch('getFriendList', {type: 'scheme', ...payload})
dispatch('getFriendList', {type: 'admin', ...payload})
},
getFriendList({state, commit}, payload) {
const type = _.get(payload, 'type', '')
const page = _.get(payload, 'page', _.get(state, `${type}.paginate.page`, 1))
const size = _.get(payload, 'size', _.get(state, `${type}.paginate.size`, 20))
const search = state.search
const method = _.get(payload, 'method', 'update')
commit('updateLoading', {type, loading: true})
Helper.contactList({method: 'forPaginate', search, type, page, size}).then(resource => commit(method + 'List', {type, resource})).finally(() => commit('updateLoading', {type, loading: false}))
},
}
}
export default friendModules