MallSelect.nvue
4.43 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
<template>
<view class="mall-select-group">
<view class="group home-group" style="display: flex;flex-direction: row;justify-content: center;align-items: center;" v-if="isHome">
<slot name="leftIcon"></slot>
<uv-text @tap="handleTapToChoose" :text="displayVal.displayValue" lines="1" style="max-width: 640rpx;" :size="fontSize + 'rpx'" :bold="true" color="#fff"></uv-text>
<image @tap="handleTapToChoose" src="/static/tabbar/arrow-down-w.png" class="dot-img" style="width: 20rpx;min-width: 20rpx;" mode="widthFix"></image>
<slot @tap="handleTapToChoose" name="rightIcon"></slot>
</view>
<view v-else @tap="handleTapToChoose" class="page-group group"
style="display: flex;flex-direction: row;justify-content: center;align-items: center;">
<slot name="leftIcon"></slot>
<text class="group_text" style="font-size: 28rpx;">{{displayVal.displayValue}}</text>
<image src="/static/tabbar/arrow-down-w.png" class="dot-img" style="width: 20rpx;min-width: 20rpx;" mode="widthFix"></image>
<slot name="rightIcon"></slot>
</view>
</view>
</template>
<script setup>
import {
onLoad
} from '@dcloudio/uni-app'
import {
getStageObj
} from '@/utils'
import {
onMounted,
ref
} from 'vue'
const emit = defineEmits(['change'])
const props = defineProps({
currentStore: {
type: Object,
default: () => {
return {}
}
},
chooseGroup: {
type: String,
default: '0'
},
hasStore: {
type: String,
default: '1'
},
isHome: {
type: Boolean,
default: false
},
fontSize: {
type: Number,
default: 32
}
})
const displayVal = ref({
accountId: '',
groupId: '',
displayValue: '',
storeId: ''
})
// 获取当前选择的集团
onLoad(() => {
// 当前集团
const account = getStageObj('account')
// 如果有传递的门店数据,优先展示门店数据
if (props.currentStore.id) {
const {
accountId,
id,
groupId,
name
} = props.currentStore
displayVal.value = {
accountId,
groupId,
displayValue: name,
storeId: id
}
} else if (account.id) {
displayVal.value = {
accountId: account?.id,
displayValue: account?.name
}
}
emit('change', displayVal.value, 'init')
// 选中门店 执行渲染门店相关数据
uni.$on('mallSelect', e => {
let params = {}
switch (e.type) {
case 'account': {
params = {
accountId: account?.id,
groupId: '',
storeId: ''
}
break
}
case 'group': {
params = {
accountId: account?.id,
groupId: e.id,
storeId: ''
}
break
}
case 'store': {
params = {
accountId: account?.id,
groupId: e.groupId,
storeId: e.id
}
uni.setStorageSync('store', JSON.stringify(e))
emit('storeChange', e)
break
}
}
params.displayValue = e.name
displayVal.value = params
emit('change', displayVal.value, 'change')
})
})
/********** 搜索相关 ************/
const searchVal = ref('')
/********** popup相关 ************/
const accountShopRef = ref(null)
onMounted(() => {
// accountShopRef.value?.open('bottom')
})
const handleTapToChoose = () => {
uni.navigateTo({
url: `/subPackages/accountGroup/pages/mall-group/index?chooseGroup=${props.chooseGroup}&hasStore=${props.hasStore}`
})
// accountShopRef.value?.open('bottom')
}
const handleCloseChoose = () => {
accountShopRef.value?.close()
}
</script>
<style lang="scss" scoped>
@import '@/styles/normal.scss';
.group {
flex-direction: row;
align-items: center;
/* #ifdef APP */
lines: 1;
/* #endif */
&_text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #FFFFFF;
font-weight: 700;
font-size: 44rpx;
}
}
.mall-select-group {
flex: 1;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
.group{
&_text {
font-size: 32rpx;
// font-family: PingFang_Medium;
}
}
.dot-img{
margin-left: 10rpx;
}
}
.page-group{
width: 680rpx;
}
</style>