accountSwitchingPop.js
2.6 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
// pages/tab/output/components/accountSwitchingPop/accountSwitchingPop.js
import { IMG_URL } from '~/utils/constantData.js'
import USERAPI from '~/api/usersApi/index'
import { setUserInfo } from '~/utils/cache/storageApi'
Component({
options: {
addGlobalClass: true
},
/**
* 组件的属性列表
*/
properties: {
popShow: {
type: Boolean,
value: false
},
merchantRange: Object
},
/**
* 组件的初始数据
*/
data: {
IMG_URL,
merchantList: []
},
observers: {
merchantRange: function (e) {
// console.log(e)
this.setData({
merchantList: e
})
}
},
/**
* 组件的方法列表
*/
methods: {
hidePopup() {
console.log(222)
this.triggerEvent('hidePopup')
},
confirm() {
console.log(111)
let { merchantRange, subIndex } = this.data
let actObj = merchantRange.find((item, index) => {
if (item.act) {
subIndex = index
}
return item.act
})
// console.log(actObj)
// this.setData({
// subIndex
// })
if (!actObj) {
return wx.$api.showToast({
title: '请选择服务商',
icon: 'error'
})
} else {
this.changePicker(actObj)
}
},
changePicker(actObj) {
// 修改对应下标显示
console.log('changePicker')
// let { value } = e.detail
// app.globalData.yqdInfo.subIndex = value
// let { merchantId } = this.data.merchantRange[value]
// let obj = {}
// if (merchantId) obj.merchantId = actObj
let { merchantId } = actObj
wx.$api.showLoading('加载中...')
USERAPI.switchSubLoginInfo({ merchantId }).then(res => {
console.log(res)
setUserInfo(res)
this.hidePopup()
this.triggerEvent('changeAccount', 'refresh')
// }
wx.$api.hideLoading()
})
// this.tapPicker()
},
select(e) {
// console.log(e)
let { index } = e.currentTarget.dataset
console.log(index)
let { merchantRange } = this.data
merchantRange.forEach((item, ind) => {
if (index == ind) {
item.act = true
} else {
item.act = false
}
this.setData({
merchantRange
})
})
},
input(e) {
console.log(e)
let { merchantRange } = this.data
let { value } = e.detail
merchantRange.forEach(item => {
item.act = false
item.show = item.merchantName.includes(value)
// = show
})
this.setData({
merchantRange
})
}
}
})