app.js
5.37 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import baseApiInterface from '@/api/base'
const state = {
accountList: [],
accountVal: null,
mallList: [],
mallVal: null,
multiMallVal: [],
floorList: [],
floorVal: null,
multiFloorVal: [],
zoneList: [],
zoneVal: null,
multiZoneVal: [],
gateList: [],
gateVal: null,
multiGateVal: [],
cacheConditions: {}
}
// account
function getAccountList(query) {
return new Promise((resolve, reject) => {
baseApiInterface.account(query)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
})
}
// mall
function getMallList(query) {
return new Promise((resolve, reject) => {
baseApiInterface.mall(query)
.then(res => {
resolve(res)
})
.catch(error => {
reject(error)
})
})
}
// floor
function getFloorList(query) {
return new Promise((resolve, reject) => {
baseApiInterface.floor(query)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
})
}
// zone
function getZoneList(query) {
return new Promise((resolve, reject) => {
baseApiInterface.zone(query)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
})
}
// gate
function getGateList(query) {
return new Promise((resolve, reject) => {
baseApiInterface.gate(query)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
})
}
const mutations = {
SET_ACCOUNT_LIST: (state, accountList) => {
state.accountList = accountList
},
SET_ACCOUNT_VAL: (state, accountVal) => {
state.accountVal = accountVal
},
SET_MALL_LIST: (state, mallList) => {
state.mallList = mallList
},
SET_MALL_VAL: (state, mallVal) => {
state.mallVal = mallVal
},
SET_MULTI_MALL_VAL: (state, multiMallVal) => {
state.multiMallVal = multiMallVal
},
SET_FLOOR_LIST: (state, floorList) => {
state.floorList = floorList
},
SET_FLOOR_VAL: (state, floorVal) => {
state.floorVal = floorVal
},
SET_MULTI_FLOOR_VAL: (state, multiFloorVal) => {
state.multiFloorVal = multiFloorVal
},
SET_ZONE_LIST: (state, zoneList) => {
state.zoneList = zoneList
},
SET_ZONE_VAL: (state, zoneVal) => {
state.zoneVal = zoneVal
},
SET_MULTI_ZONE_VAL: (state, multiZoneVal) => {
state.multiZoneVal = multiZoneVal
},
SET_GATE_LIST: (state, gateList) => {
state.gateList = gateList
},
SET_GATE_VAL: (state, gateVal) => {
state.gateVal = gateVal
},
SET_MULTI_GATE_VAL: (state, multiGateVal) => {
state.multiGateVal = multiGateVal
},
SET_CACHE_VAL: (state, { key, val }) => {
state.cacheConditions[key] = val
}
}
const actions = {
async getAccounts({ commit }, userType, blocQuery) {
const { data } = await getAccountList(blocQuery)
console.log('account data', data)
commit('SET_ACCOUNT_LIST', data.data)
if (data.data.length) {
let singleBloc = null
data.data.forEach((item, index) => {
if (index === 0) {
singleBloc = item
}
})
commit('SET_ACCOUNT_VAL', singleBloc)
return Promise.resolve(singleBloc)
} else {
if (userType === 'super') {
commit('SET_ACCOUNT_VAL', { id: 0, name: 'none' })
} else {
console.error('Bloc list is empty!!')
}
}
},
async getMalls({ commit }, mallQuery, needAll) {
const { data } = await getMallList(mallQuery)
commit('SET_MALL_LIST', data.data)
let singleMall = null
let multiMall = []
let temp_multiMall = []
let temp_mall = null
multiMall = data.data.map((item, index) => {
if (index === 0) {
singleMall = item
}
return item
})
console.log('<===========================split line===========================>')
temp_multiMall = multiMall.length ? multiMall.map(item => item.id) : []
temp_mall = null || singleMall && singleMall.id
console.log('multiMall=====>', multiMall.map(item => item.id), temp_multiMall)
console.log('<===========================split line end===========================>')
commit('SET_MULTI_MALL_VAL', temp_multiMall)
commit('SET_MALL_VAL', temp_mall)
},
async getFloors({ commit }, floorQuery) {
const { data } = await getFloorList(floorQuery)
commit('SET_FLOOR_LIST', data.data)
let singleFloor = null
let multiFloor = []
let temp_multiFloor = []
let temp_floor = null
multiFloor = data.data.map((item, index) => {
if (index === 0) {
singleFloor = item
}
return item
})
temp_multiFloor = multiFloor.length ? multiFloor.map(item => item.id) : []
temp_floor = null || singleFloor && singleFloor.id
commit('SET_MULTI_FLOOR_VAL', temp_multiFloor)
commit('SET_FLOOR_VAL', temp_floor)
},
async getZones({ commit }, zoneQuery) {
const { data } = await getZoneList(zoneQuery)
commit('SET_ZONE_LIST', data.data)
let singleZone = null
let multiZone = []
let temp_multiZone = []
let temp_zone = null
multiZone = data.data.map((item, index) => {
if (index === 0) {
singleZone = item
}
return item
})
temp_multiZone = multiZone.length ? multiZone.map(item => item.id) : []
temp_zone = null || singleZone && singleZone.id
commit('SET_MULTI_ZONE_VAL', temp_multiZone)
commit('SET_ZONE_VAL', temp_zone)
},
}
export default {
namespaced: true,
state,
mutations,
actions
}