accountItems.js
12.9 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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
// pages/accountItems/accountItems.js
import api from '~/api/api'
const app = getApp()
import { getYQorderInfo, get4SStoreList } from '~/store/index'
import { getShopSceneConfig } from '~/store/index'
import { setUserInfo } from '~/utils/cache/storageApi'
Page({
/**
* 页面的初始数据
*/
data: {
/**accountLevel 1工厂。2省 ,3市。4门店 */
searchValue: '',
edit: false,
copyLoginUserInfoList: [],
loginRole: {
1: '超管',
2: '商户号',
3: '区域运营',
4: '驻店负责人',
5: '销售',
},
selectedUuid: '',
requestFlag: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options, 'options');
let id = decodeURIComponent(options.scene).split('=')[1]
console.log(id, 'id');
id ? this.qrCodeScene(id) : this.getListSelectAccount()
},
async getSceneArr(yqMerchantId, loginUserObj) {
if (!loginUserObj?.isSuper && loginUserObj?.loginRole != 3) {
let checkAgree = await this.checkAgree(loginUserObj)
// if (!checkAgree) return wx.$router.go('pages.accountItems')
if (!checkAgree) return false
}
// let checkAgree = await this.checkAgree()
// if (!checkAgree) return false
// 超管开通全部场景
if (loginUserObj?.isSuper || loginUserObj?.loginRole == 3 || loginUserObj.loginRole == 5) return
// 获取4s店关联场景数据
getShopSceneConfig({ yqMerchantId }).then(result => {
if (!result?.length) return wx.$util.showToast('暂无开通业务,请联系总部管理员')
this.get4SStoreList(loginUserObj)
})
},
open() {
this.setData({
edit: true,
inputFocus: true
})
},
setValue(value) {
if (this.properties.filterEmoji) {
if (wx.$util.haveEmoji(value)) value = wx.$util.replaceEmoji(value)
}
this.setData({
searchValue: value
})
},
input(e) {
let {
value
} = e.detail
this.setValue(value)
},
inputBlur(e) {
this.emit(e)
},
inputConfifm(e) {
this.emit(e)
},
emit(e) {
let {
detail: {
value
}
} = e
this.setData({
edit: false,
searchValue: value
})
this.setValue(value)
this.searchEvent()
},
// 搜索过滤
searchEvent() {
let { searchValue, copyLoginUserInfoList, selectedUuid } = this.data
copyLoginUserInfoList.map(val => {
val.active = false
if (val.uuid == selectedUuid) val.active = true
return val
})
let filterArr = copyLoginUserInfoList.filter(val => val.merchantName.includes(searchValue) || val.merchantId == searchValue) || []
this.setData({
loginUserInfoList: filterArr
})
if (!searchValue) {
this.setData({
loginUserInfoList: copyLoginUserInfoList
})
}
},
// 免登录逻辑
qrCodeScene(id) {
api
.getSceneById({
id,
channelType: 1
})
.then(res => {
// debugger
// res => {
let { code, data } = res
let op = {}
if (code == '0') {
if (data) {
data.split('&').map(item => {
const [key, val] = item.split('=')
op[key] = val
})
if (op.noLogin) {
wx.$SCENE = {
...op
}
}
this.setData(
{
...op
},
() => {
this.noLoginFn()
}
)
}
}
// }
})
.catch(err => { })
},
noLoginFn() {
let that = this
let { noLogin } = this.data
wx.$util.showLoading()
api
.noLogin({
mobile: noLogin
})
.then(result => {
wx.$util.showLoading()
if (result.code == 0) {
let { loginUserInfoList, sessionId } = result.data
if (loginUserInfoList.length > 0) {
wx.$util.setSessionId(sessionId)
// loginUserInfoList.map
loginUserInfoList.map(item => {
if (item.userType == 2) {
item.active = true
}
return item
})
that.setData(
{
loginUserInfoList,
copyLoginUserInfoList: loginUserInfoList
},
() => {
that.choiceAccountLogin()
}
)
// else {
// wx.$router.reLaunch('pages.nothing')
// }
} else {
wx.hideLoading()
wx.showModal({
title: '温馨提示',
content: result.message,
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF'
})
}
}
})
.catch(err => {
wx.hideLoading()
})
},
getListSelectAccount() {
wx.$util.showLoading('加载中...')
api.getListSelectAccount().then(res => {
wx.$util.hideLoading()
let { code, data, message } = res
if (code == 0) {
let { loginUserInfoList, sessionId } = data
wx.$util.setSessionId(sessionId)
this.setData({
loginUserInfoList,
copyLoginUserInfoList: loginUserInfoList
})
} else {
wx.$util.showToast(message)
}
this.setData({
flag: true
})
})
},
chooseAccount(e) {
let { item } = e.currentTarget.dataset
let { loginUserInfoList } = this.data
loginUserInfoList.map(i => {
i.active = false
if (i.uuid == item?.uuid) {
i.active = true
}
return i
})
this.setData({
loginUserInfoList,
selectedUuid: item.uuid
})
this.choiceAccountLogin()
},
sceneHandle() {
const SCENE = wx.$SCENE
let { path, query } = SCENE
let { target, name } = wx.$util.getSceneId(path)
wx.$router.reLaunch(`${target}.${name}`, query)
wx.$SCENE = null
// debugger 兼容扫码优惠券进来和免登录逻辑冲突问题
// if (SCENE && SCENE.path != 'pages/accountItems/accountItems') {
},
// 检测一下是否能微信端小程序登录
checkAgree() {
return new Promise((resolve, reject) => {
let sysInfo = wx.getSystemInfoSync()
// let { environment } = sysInfo
// 1企业微信 0微信
let envName = sysInfo.environment ? 1 : 0
let { merchantId: yqMerchantId } = wx.$util.getUserInfo()
api.getYqStoreConfig({ yqMerchantId }).then(res => {
let {
code,
data
} = res
let loginControlList = data?.loginControlList || []
if (code == '0') {
// const loginControlList = []
// const loginControlList = [0, 1]
if (loginControlList == null || loginControlList.includes(envName) || loginControlList.length == 0) {
resolve(true)
} else {
wx.hideLoading()
wx.showModal({
title: '温馨提示',
content: `请在${envName == 0 ? '企业微信' : '微信'}中打开`,
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF'
})
resolve(false)
}
}
})
})
},
// 获取园区店下4s店数据
get4SStoreList(loginUserObj) {
let { merchantId, isSuper, uuid, loginRole } = loginUserObj
// 超管跳过选择4s店页面
if (isSuper || loginRole == 3 || loginRole == 5) {
// this.setShopMerchantObj(obj)
wx.$router.go('pages.sceneIndex')
return
}
get4SStoreList({ merchantId: isSuper || loginRole == 3 || loginRole == 5 ? undefined : merchantId, staffUUID: uuid }, isSuper || loginRole == 3 || loginRole == 5, true).then(result => {
let obj = (result && result[0]) || {}
// 仅一家4s店
if (result?.length == 1) {
this.setShopMerchantObj(obj)
wx.$router.go('pages.sceneIndex')
} else if (!result?.length) {
return wx.$util.showToast('园区店关联的4s店商户账号无效,请联系总部管理员')
} else {
wx.$router.go('pages.merchantList')
}
})
},
setShopMerchantObj(data) {
let { merchantName: shopMerchantName, merchantId: shopMerchantId } = data
wx.$util.setUserInfo({
...wx.$util.getUserInfo(),
shopMerchantName: shopMerchantName,
shopMerchantId: shopMerchantId,
default4SStoreInfo: {
merchantId: shopMerchantId,
merchantName: shopMerchantName
},
default4SStoreInfo_crowdFunding: {
merchantId: shopMerchantId,
merchantName: shopMerchantName
},
default4SStoreInfo_newCarConversion: {
merchantId: shopMerchantId,
merchantName: shopMerchantName
}
})
},
async choiceAccountLogin() {
let { loginUserInfoList } = this.data
let id = null
let yqMerchantId = null
let isSuper = null
loginUserInfoList.map(e => {
if (e.active) {
yqMerchantId = e.merchantId
id = e.uuid
isSuper = e.isSuper || e.loginRole == 3 || e.loginRole == 5
}
})
if (!id) {
wx.$util.showToast('请选择账号')
return
}
// 清空4s店数据
app.globalData.storeListRange = []
this.selectAccountLogin(id, yqMerchantId)
},
selectAccountLogin(id, yqMerchantId) {
if (this.data.requestFlag) return
this.setData({ requestFlag: true })
wx.$util.showLoading()
api
.selectAccountLogin({
id
})
.then(res => {
wx.$util.hideLoading()
this.setData({ requestFlag: false })
let { data, message } = res
// debugger
if (data) {
// app.globalData.YQorderSetting = null
app.globalData.yqdInfo.merchantRange = null
app.globalData.YQorderSetting = null
app.globalData.serviceFilmRollSetting = null
app.globalData.businessSchoolScene = null
wx.$util.hideLoading()
wx.$util.setUserInfo(data.loginUserInfoList[0])
app.gobalCheckYqdSuper(data.loginUserInfoList[0])
console.log(data.loginUserInfoList, 'loginUserInfoList');
// 获取园区店下单字段配置信息
getYQorderInfo()
// 超管跳过选择4s店
// console.log(wx.$SCENE != 'tabWorkOrder/staffDaily');
if (data.loginUserInfoList[0] && data.loginUserInfoList[0].isSuper && (wx.$SCENE?.path != 'tabWorkOrder/staffDaily' || wx.$SCENE?.path != 'tabWorkOrder/upgradeStaffDaily')) {
this.get4SStoreList(data.loginUserInfoList[0])
return
}
if (data.loginUserInfoList[0] && (data.loginUserInfoList[0]?.loginRole == 3 || data.loginUserInfoList[0]?.loginRole == 5) && (wx.$SCENE?.path != 'tabWorkOrder/staffDaily' || wx.$SCENE?.path != 'tabWorkOrder/upgradeStaffDaily')) {
this.get4SStoreList(data.loginUserInfoList[0])
return
}
const SCENE = wx.$SCENE
console.log(wx.$SCENE, ' wx.$SCENE');
// 展会用逻辑
if (SCENE && SCENE.path == 'packageEquity/clueList') {
// query
wx.$SCENE.query = {
activeIndex: 1
}
api.selectAccountLogin({ id: 'd45b7f0a3ed94ca6a16340937ccc1c1d' }).then((result) => {
// setUserInfo
wx.$util.setUserInfo({
...wx.$util.getUserInfo(),
sceneType: 1,
shopMerchantName: '杰西集团的门店',
shopMerchantId: 44205761,
})
api.selectMerchantScene({
sceneType: 1,
shopMerchantName: '杰西集团的门店',
shopMerchantId: 44205761,
}).then((result) => {
this.sceneHandle()
})
}).catch((err) => {
});
} else {
// 有场景信息就跳转对应页面 没有就登录场景
SCENE && SCENE.path != 'pages/accountItems/accountItems' ? this.sceneHandle() : this.getSceneArr(yqMerchantId, data.loginUserInfoList[0])
}
// debugger
// SCENE && SCENE.path != 'pages/accountItems/accountItems' ? this.sceneHandle() : this.getSceneArr(yqMerchantId, data.loginUserInfoList[0])
} else {
wx.$util.showToast(message)
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () { },
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
wx.hideHomeButton()
this.setData({
requestFlag: false
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () { },
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () { },
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () { },
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () { },
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () { }
})