CustomerAutocomplete.uvue
4.72 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
<template>
<view :class="['customer-box',{'is-show':showCustomerBox}]">
<view class="customer-title">
客户档案的记录
</view>
<scroll-view
scroll-y
class="scroll-box"
:style="scrollBoxStyle"
>
<template v-if="loading">
<view class="loading flex">
<uni-icons
type="refreshempty"
:size="46"
color="#3773F8"
class="icon"
>
</uni-icons>
</view>
</template>
<template v-else>
<template v-if="searchList.length">
<template v-for="(i,index) in searchList" :key="index">
<view
class="item flex"
hover-class="active"
@click="chooseItem(i)"
>
{{ `${showType == 'tel'?i.ownerPhone:i.ownerName}`}}
</view>
</template>
</template>
<template v-else>
<view class="nothing flex">
<view class="icon">
</view>
未匹配到客户信息
</view>
</template>
</template>
</scroll-view>
</view>
</template>
<script setup lang="uts">
import { storage } from '@/utils/storage.uts'
import { state } from '@/store/index.uts'
import { getCustomerInfoListApi } from '@/api/customer-api.uts'
type CustomerInfo = UTSJSONObject
type UserInfo = UTSJSONObject
type SearchParams = {
merchantId: string
bussinessScene: number
ownerPhone?: string
ownerName?: string
}
const props = defineProps({
searchValue: String,
showType: String,
show: Boolean
})
const emit = defineEmits(['choose'])
const loading = ref<boolean>(true)
const searchList = ref<Array<CustomerInfo>>([])
const showCustomerBox = computed<boolean>(() => {
const searchValue = props.searchValue ?? ''
return props.show == true && (state.user?.haveCustomerAccess ?? false) && (searchValue !== '' && searchValue !== null)
})
// ✅ UVUE 不支持 calc(),动态计算 scroll-box 高度
const scrollBoxStyle = computed<UTSJSONObject>(() => {
// 原样式: height: calc(100% - 64rpx)
// 64rpx ≈ 32px (rpx 是响应式像素,通常 2rpx = 1px)
// 使用百分比近似:95%
return {
"height": "95%"
} as UTSJSONObject;
});
async function getCustomerInfoList(val: string, type: string): Promise<void> {
try {
loading.value = true
const userInfo: UserInfo | null = storage.get("userInfo") as UTSJSONObject | null
const userInfoObj = userInfo ?? { shopMerchantId: '', sceneType: 0 }
const shopMerchantId = userInfoObj.shopMerchantId
const params: SearchParams = {
merchantId: shopMerchantId as String,
bussinessScene: userInfoObj.sceneType == 0 ? 1 : 2
}
if (type == 'tel') {
params.ownerPhone= val
} else {
params.ownerName = val
}
const result = await getCustomerInfoListApi(params as UTSJSONObject)
searchList.value = result as UTSArray<UTSJSONObject>
loading.value = false
} catch (error) {
loading.value = false
}
}
watch(showCustomerBox.value , (newVal: boolean) => {
if (newVal == true) {
getCustomerInfoList(props.searchValue ?? '', props.showType ?? '')
}
}, { immediate: true })
function chooseItem(item: CustomerInfo): void {
emit('choose', item)
}
</script>
<style scoped lang='scss'>
.customer-box {
position: absolute;
left: 0;
top: 88rpx;
width: 100%;
height: 352rpx;
background: #ffffff;
border-radius: 16rpx;
z-index: -1;
opacity: 0;
.customer-title {
font-size: 24rpx;
color: #999999;
line-height: 40rpx;
padding: 16rpx 24rpx 8rpx;
}
.scroll-box {
// ✅ UVUE 不支持 calc(),高度由 JS 动态计算
height: 95%;
.loading {
width: 100%;
height: 100%;
justify-content: center;
.icon {
// ✅ UVUE 不支持 animation,已移除旋转动画
}
}
.nothing {
width: 100%;
height: 100%;
font-size: 24rpx;
color: #c7ccd7;
flex-direction: column;
.icon {
margin-top: 52rpx;
width: 96rpx;
height: 96rpx;
/* background-image: url('@/assets/images/common/nothing.webp'); */
background-size: 100%;
}
}
.item {
width: 100%;
height: 48rpx;
font-size: 28rpx;
color: #333333;
line-height: 40rpx;
padding-left: 24rpx;
margin-bottom: 8rpx;
}
.active {
background: #ecf1ff;
}
// ✅ UVUE 不支持 @keyframes,已移除 rotate-loading 动画
}
}
.is-show {
z-index: 1;
opacity: 1;
}
</style>