malls.js
11.1 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import dateArr from '../dateData.js';
import { MALLS } from '../mutation-types.js'
// initial state
const state = {
list: [], // 门店列表
checkedMallId: null, // 单选门店
multiCheckedMallId: [], // 多选门店
gateList: [], // 出入口列表
checkedGateId: null, // 单选出入口
multiCheckedGateId: [], // 多选出入口
customTimeData: [], // 自定义时间数据
selectedCustomStartDate: '', // 自定义开始时间字符串
selectedCustomEndDate: '', // 自定义结束时间字符串
pickerCustomStartDate: [], // 自定义开始时间picker下标
pickerCustomEndDate: [], // 自定义结束时间picker下标
dayDateData: [], // 天级时间数据
selectedDayTime: '', // 选中时间字符串
pickerDayDate: [] ,// 选中天时间picker下标,
startDayTime: '', // 开始日期
endDayTime: '', // 结束日期
pickerStartDayDate: [], // 结束日期
pickerEndDayDate: [], // 结束日期
}
// getter
const getter = {}
// actions
const actions = {
getMallList({ commit }, { data, header, isMultiple = false }) {
uni.request({
url: window.url + "/malls",
data: data,
header: header,
method: 'GET',
success: (res) => {
console.log('store res', res)
let result = res.data;
let buildData = result.data.map(item => {
item._selected = false;
return item;
})
// 默认选中一个/多个
let mallId = null
, multiMallId = [];
multiMallId = buildData.map((item, index) => {
if(index == 0) {
mallId = {
id: item.id,
name: item.name
};
}
return {
id: item.id,
name: item.name
};
});
// console.log('store actions', isMultiple, mallId, multiMallId)
commit(MALLS.CHECKED_MALL_ID, mallId)
if(isMultiple) {
commit(MALLS.CHECKED_MULTI_MALL_ID, multiMallId)
}
commit(MALLS.SET_MALLS, buildData)
}
})
},
getGateList({ commit }, { data, header, isMultiple = false }) {
uni.request({
url: window.url + "/gates",
data: data,
header: header,
method: 'GET',
success: (res) => {
console.log('store gates res', res)
let result = res.data;
let buildGateData = result.data.map(item => {
item._selected = false;
return item;
})
// 默认选中一个/多个
let gateId = null
, multiGateId = [];
multiGateId = buildGateData.map((item, index) => {
if(index == 0) {
gateId = {
id: item.id,
name: item.name
};
}
return {
id: item.id,
name: item.name
};
});
// console.log('store gate actions', isMultiple, gateId, multiGateId)
commit(MALLS.CHECKED_GATE_ID, gateId)
if(isMultiple) {
commit(MALLS.CHECKED_MULTI_GATE_ID, multiGateId)
}
commit(MALLS.SET_GATES, buildGateData)
}
})
},
getDateData({ commit }, frontDay) {
dateArr.getCustomTime(customTimeData => {
let startDate = null
, endDate = null
, startTime = {}
, endTime = {}
, times = []
, customStartTimes = {}
, customEndTimes = {}
, customPickerStartIdx = []
, customPickerEndIdx = [];
endDate = new Date();
startDate = frontTime(endDate, frontDay);
endTime = formatterCustomTime(endDate, true);
startTime = formatterCustomTime(startDate, true);
customPickerStartIdx = computedPickerIdx(startTime);
customPickerEndIdx = computedPickerIdx(endTime);
customStartTimes = `${startTime['Y']}-${startTime['M']}-${startTime['D']} ${startTime['h']}:${startTime['m']}:${startTime['s']}`;
customEndTimes = `${endTime['Y']}-${endTime['M']}-${endTime['D']} ${endTime['h']}:${endTime['m']}:${endTime['s']}`;
// console.log('customTimeData', customTimeData)
// console.log('store times', customStartTimes, customEndTimes, customTimeData, customPickerStartIdx, customPickerEndIdx);
commit(MALLS.SET_TIMEDATA, customTimeData); // 自定义时间数据
// commit(MALLS.SET_SELECTED_CUSTOM_START_TIME, customStartTimes); // 自定义开始时间
// commit(MALLS.SET_SELECTED_CUSTOM_END_TIME, customEndTimes); // 自定义结束时间
// commit(MALLS.SET_PICKER_CUSTOM_START_IDX, customPickerStartIdx); // 自定义时间组件下标
// commit(MALLS.SET_PICKER_CUSTOM_END_IDX, customPickerEndIdx); // 自定义时间组件下标
})
// 日级
dateArr.getDayTime(dayData => {
let dayTime = {}
, dayTimesText = ''
, pickerIdx = []
dayTime = formatterDayTime(new Date());
pickerIdx = computedPickerIdx(dayTime);
dayTimesText = `${dayTime['Y']}-${dayTime['M']}-${dayTime['D']}`;
commit(MALLS.SET_DAY_DATA, dayData); // 日级时间数据
commit(MALLS.SET_SELECTED_DAY_TIME, dayTimesText); // 日级时间文本
commit(MALLS.SET_PICKER_DAY_IDX, pickerIdx) // 日级时间组件下标
// pickerStartDayDate pickerEndDayDate
})
// 开始结束日期
dateArr.getStartEndTime(dayData => {
let startDate = null
, endDate = null
, startTime = ''
, endTime = ''
, st = ''
, et = ''
, pickerSt = []
, pickerEt = [];
endDate = new Date();
startDate = frontTime(endDate, 7);
endTime = formatterDayTime(endDate);
startTime = formatterDayTime(startDate);
pickerSt = computedPickerIdx(startTime);
pickerEt = computedPickerIdx(endTime);
console.log('开始结束日期:', pickerSt, pickerEt)
st = `${startTime['Y']}-${startTime['M']}-${startTime['D']}`;
et = `${endTime['Y']}-${endTime['M']}-${endTime['D']}`;
commit(MALLS.SET_SELECTED_CUSTOM_START_TIME, st); // 自定义开始时间文本
commit(MALLS.SET_SELECTED_CUSTOM_END_TIME, et);
commit(MALLS.SET_PICKER_START_IDX, pickerSt);
commit(MALLS.SET_PICKER_END_IDX, pickerEt)
})
},
// 存储新值
updateDayDate({ commit }, { dayTimeText, dayPickerIdx }) {
commit(MALLS.SET_SELECTED_DAY_TIME, dayTimeText); // 日级时间文本
commit(MALLS.SET_PICKER_DAY_IDX, dayPickerIdx) // 日级时间组件下标
},
updateCustomDate({ commit }, { customTimeStartText, customTimeEndText, customPickerStartIdx, customPickerEndIdx }) {
customTimeStartText && commit(MALLS.SET_SELECTED_CUSTOM_START_TIME, customTimeStartText); // 自定义开始时间文本
customTimeEndText && commit(MALLS.SET_SELECTED_CUSTOM_END_TIME, customTimeEndText); // 自定义结束时间文本
customPickerStartIdx && commit(MALLS.SET_PICKER_CUSTOM_START_IDX, customPickerStartIdx) // 自定义开始时间组件下标
customPickerEndIdx && commit(MALLS.SET_PICKER_CUSTOM_END_IDX, customPickerEndIdx) // 自定义结束时间组件下标
},
updateCheckedMall({ commit }, mallId) {
commit(MALLS.CHECKED_MALL_ID, mallId)
},
updateMultiCheckedMall({ commit }, multiMallId) {
commit(MALLS.CHECKED_MULTI_MALL_ID, multiMallId)
},
updateCheckedGate({ commit }, gateId) {
commit(MALLS.CHECKED_GATE_ID, gateId)
},
updateMultiCheckedGate({ commit }, multiGateId) {
commit(MALLS.CHECKED_MULTI_GATE_ID, multiMallId)
},
updateStartEndDate({ commit }, { startDate, endDate, startPickerIdx, endPickerIdx }) {
startDate && commit(MALLS.SET_START_DATE, startDate)
endDate && commit(MALLS.SET_END_DATE, endDate)
startPickerIdx && commit(MALLS.SET_PICKER_START_IDX, startPickerIdx)
endPickerIdx && commit(MALLS.SET_PICKER_END_IDX, endPickerIdx)
}
}
// 默认15天
function frontTime(currentTime, frontDay = 15) {
return new Date(currentTime.getTime() - frontDay * 24 * 60 * 60 * 1000);
}
// 格式化日期
function formatterCustomTime(date) {
let baseFormatter = {
Y: date.getFullYear(),
M: date.getMonth() + 1,
D: date.getDate(),
h: date.getHours(),
m: date.getMinutes(),
s: date.getSeconds()
}
let resFormatterTime = {};
Object.keys(baseFormatter).forEach(k => {
if(baseFormatter[k]) {
resFormatterTime[k] = (baseFormatter[k] + '').replace(/(?=\b\d\b)/g, '0')
}
})
return resFormatterTime;
}
function formatterDayTime(date) {
let baseFormatter = {
Y: date.getFullYear(),
M: date.getMonth() + 1,
D: date.getDate()
}
let resFormatterTime = {};
Object.keys(baseFormatter).forEach(k => {
resFormatterTime[k] = (baseFormatter[k] + '').replace(/(?=\b\d\b)/g, '0')
})
return resFormatterTime;
}
// 处理日期组件保存的下标值 2019-04-04 10:10:20 格式
function dealTimeIdx(timeStr) {
return timeStr.replace(/\-|\s|\:/g, ',').split(',')
}
// 计算 awesome-picker 下标
function computedPickerIdx(dateObject) {
let temp = [];
Object.keys(dateObject).forEach(key => {
switch(key) {
case 'Y':
temp.push({
index: dateObject[key] - 1999,
value: dateObject[key] + '年' // 拼接年月日时分秒
})
break;
// case ''
default:
temp.push({
index: dateObject[key] - 1,
value: dateObject[key] + (key === 'M' ? '月' : key === 'D' ? '日' : '' )
})
break;
}
})
return temp;
}
function getGate(data, header, isMultiple) {
uni.request({
url: window.url + "/gates",
data: data,
header: header,
method: 'GET',
success: (res) => {
console.log('store gates res', res)
let result = res.data;
// 默认选中一个/多个
let gateId = null
, multiGateId = [];
multiGateId = result.data.map((item, index) => {
if(index == 0) {
gateId = {
id: item.id,
name: item.name
};
}
return item.id;
});
console.log('store actions', isMultiple, gateId, multiGateId)
commit(MALLS.CHECKED_GATE_ID, { gateId })
if(isMultiple) {
commit(MALLS.CHECKED_MULTI_GATE_ID, multiMallId)
}
commit(MALLS.SET_GATES, result.data)
}
})
}
// mutations
const mutations = {
// 门店
[MALLS.SET_MALLS](state, malls) {
state.list = malls
},
[MALLS.CHECKED_MALL_ID] (state, mallId) {
state.checkedMallId = mallId;
},
[MALLS.CHECKED_MULTI_MALL_ID] (state, multiMallId) {
state.multiCheckedMallId = multiMallId;
},
// 出入口
[MALLS.SET_GATES](state, gates) {
state.gateList = gates
},
[MALLS.CHECKED_GATE_ID] (state, gateId) {
state.checkedGateId = gateId;
},
[MALLS.CHECKED_MULTI_GATE_ID] (state, multiGateId) {
state.multiCheckedGateId = multiGateId;
},
// 日期
[MALLS.SET_TIMEDATA] (state, timeData) {
state.customTimeData = timeData;
},
[MALLS.SET_SELECTED_CUSTOM_START_TIME] (state, time) {
// state.selectedCustomStartDate = time
state.startDayTime = time
},
[MALLS.SET_SELECTED_CUSTOM_END_TIME] (state, time) {
// state.selectedCustomEndDate = time
state.endDayTime = time
},
[MALLS.SET_PICKER_CUSTOM_START_IDX] (state, pickerCustomStartIdx) {
state.pickerCustomStartDate = pickerCustomStartIdx
},
[MALLS.SET_PICKER_CUSTOM_END_IDX] (state, pickerCustomEndIdx) {
state.pickerCustomEndDate = pickerCustomEndIdx
},
[MALLS.SET_SELECTED_DAY_TIME] (state, dayTime) {
state.selectedDayTime = dayTime
},
[MALLS.SET_PICKER_DAY_IDX] (state, pickerIdx) {
state.pickerDayDate = pickerIdx
},
[MALLS.SET_DAY_DATA] (state, dayData) {
state.dayDateData = dayData
},
// 开始结束日期
[MALLS.SET_START_DATE] (state, startDate) {
state.startDayTime = startDate
},
[MALLS.SET_END_DATE] (state, endDate) {
state.endDayTime = endDate
},
[MALLS.SET_PICKER_START_IDX] (state, pickerStartIdx) {
state.pickerStartDayDate = pickerStartIdx
},
[MALLS.SET_PICKER_END_IDX] (state, pickerEndIdx) {
state.pickerEndDayDate = pickerEndIdx
}
}
export default {
namespaced: true,
state,
getter,
actions,
mutations
}