Employee.vue
4.05 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
<template>
<MessageBox ref="employeeBoxVisible" position="bottom" :isFooter="false" :title="`请选择${title}`" :maxHeight="1000" @close="$emit('close')">
<view class="select-box">
<view class="select-item" :class="{ checked: selectedId == item[valueKey] }" @click="handleSelect(item)" v-for="(item, index) in displayList" :key="index">
{{ item[labelKey] }}
</view>
</view>
</MessageBox>
</template>
<script type="text/ecmascript-6">
export default {
name: 'Employee',
props: {
title: {
type: String,
default: '销售'
},
salesPropsUuid: {
type: String,
default: ''
},
list: {
type: Array,
default: null
},
labelKey: {
type: String,
default: 'staffName'
},
valueKey: {
type: String,
default: 'uuid'
},
// default: 销售顾问;seller: 转化人员/驻店零售
employeeType: {
type: String,
default: 'default'
}
},
data () {
return {
sellerEmployeeList: [],
defaultEmployeeList: []
}
},
watch: {
watchStatus: {
immediate: true,
handler (newval) {
this.close()
}
},
},
computed: {
watchStatus () {
return this.$store.state.user.historyStatus
},
selectedId () {
if (Array.isArray(this.list) || this.employeeType === 'seller' || this.employeeType === 'default') {
return this.salesPropsUuid
}
return this.$store.state.user.customerInfo.salesUuid || this.salesPropsUuid
},
displayList () {
if (Array.isArray(this.list)) {
return this.list
}
if (this.employeeType === 'seller') {
return this.sellerEmployeeList
}
if (this.employeeType === 'default') {
return this.defaultEmployeeList
}
return this.$store.state.user.employeeList
}
},
mounted () {
},
methods: {
async open () {
if (Array.isArray(this.list)) {
this.$refs.employeeBoxVisible.open()
return
}
uni.showLoading({
title: '加载中',
mask: true
})
await this.ensureEmployeeList()
uni.hideLoading()
this.$refs.employeeBoxVisible.open()
},
async ensureEmployeeList () {
const userInfo = uni.$storage.get('userInfo') || {}
if (this.employeeType === 'seller') {
if (this.sellerEmployeeList.length) return
const { merchantId } = userInfo
const res = await uni.$api.popupApi.getEmployeeList({
merchantId,
sceneList: ''
})
this.sellerEmployeeList = res || []
return
}
if (this.employeeType === 'default') {
if (this.defaultEmployeeList.length) return
const { shopMerchantId, sceneType } = userInfo
const apiTargetName = sceneType == 1 ? 'getEmployeeList' : 'getOrderScreenEmployeeList'
const res = await uni.$api.popupApi[apiTargetName]({
merchantId: shopMerchantId,
sceneList: [sceneType]
})
this.defaultEmployeeList = res || []
return
}
const employeeList = this.$store.state.user.employeeList
if (employeeList && employeeList.length) return
const { shopMerchantId } = userInfo
const res = await uni.$api.commonApi.getEmployeeList({
merchantId: shopMerchantId
})
this.$store.dispatch('setEmployeeList', res)
uni.$storage.set('employeeList', res || [])
},
handleSelect (item) {
this.close();
this.$emit('select', item)
},
close () {
this.$refs?.employeeBoxVisible?.close()
}
}
}
</script>
<style scoped lang="scss">
.select-box {
margin: toRpx(40) 0;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: toRpx(32);
overflow-y: scroll;
max-height: 50vh;
padding-bottom: toRpx(60);
.select-item {
text-align: center;
height: toRpx(68);
line-height: toRpx(44);
opacity: 1;
border: toRpx(2) solid #dce0e6;
color: #333;
font-size: toRpx(32);
border-radius: toRpx(8);
&.checked {
border: toRpx(2) solid #292d33;
}
}
}
</style>