selectMerchantPopup.js
3.19 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
// pages/tab/output/components/accountSwitchingPop/accountSwitchingPop.js
import { IMG_URL } from '~/utils/constantData.js'
Component({
options: {
addGlobalClass: true
},
/**
* 组件的属性列表
*/
properties: {
popShow: {
type: Boolean,
value: false,
observer: function (n) {
if (n) {
let { merchantRange, selectInfo } = this.data
// let activeIndex = merchantRange.findIndex(v => v.merchantId == selectInfo.shopMerchantIds[0])
if (merchantRange.length) merchantRange.unshift({ merchantId: '', merchantName: '全部' })
merchantRange.forEach((item, ind) => {
item.show = true
item.act = selectInfo.shopMerchantIds.includes(item.merchantId)
})
this.setData({
searchKeyword: '',
merchantRange,
selectedMerchantIds: Array.isArray(selectInfo?.shopMerchantIds) ? selectInfo?.shopMerchantIds.map(item => item.merchantId) : ''
})
}
}
},
merchantRange: Object,
selectInfo: Object,
isMerchant: Boolean
},
/**
* 组件的初始数据
*/
data: {
IMG_URL,
serviceList: [],
searchKeyword: ''
},
observers: {
merchantRange: function (e) {
this.setData({
serviceList: e || []
})
}
},
/**
* 组件的方法列表
*/
methods: {
hidePopup() {
this.triggerEvent('hidePopup')
},
confirm() {
let { merchantRange, subIndex } = this.data
let actObj = merchantRange.filter((item, index) => {
return item.act
})
if (!actObj || (actObj && !actObj.length)) {
return wx.$api.showToast({
title: '请选择门店',
icon: 'error'
})
} else {
if (actObj.merchantId == '' && actObj.merchantName == '全部') {
actObj.merchantName = '所有门店'
}
this.changePicker(actObj)
}
},
changePicker(actObj) {
this.triggerEvent('merchantConfirm', { merchantList: actObj })
this.hidePopup()
},
select(e) {
let { index, target } = e.currentTarget.dataset
let { merchantRange } = this.data
let ids = []
merchantRange.forEach((item, ind) => {
if (index == ind) {
item.act = !item.act
}
// 选全部,门店置空;选中门店,全部置空
if ((index == 0 && ind != 0) || (index != 0 && ind == 0)) {
item.act = false
}
if(item.act) {
ids.push(item.merchantId)
}
})
this.setData({
merchantRange,
selectedMerchantIds: ids
})
},
search(e) {
let { merchantRange, selectedMerchantIds } = this.data
let { value } = e.currentTarget.dataset && Object.keys(e.currentTarget.dataset).length ? e.currentTarget.dataset : e.detail
merchantRange.forEach(item => {
item.act = false
item.show = item.merchantName?.includes(value)
if (selectedMerchantIds.includes(item.merchantId)) item.act = true
})
this.setData({
merchantRange
})
},
input(e) {
let { value } = e.detail
this.setData({
searchKeyword: value
})
}
}
})