Employee.uvue
7.89 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<template>
<view>
<un-popup :show="visible"
mode="bottom"
:round="20"
:z-index="dynamicZIndex"
@close="handlePopupClose">
<view class="popup-wrapper" :style="{ height: windowHeight * 0.6 + 'px' }">
<view class="popup-header">
<view class="icon-close-box" @click="handleHide">
<uni-icons color="#1A1A1A" :size="18" type="closeempty"></uni-icons>
</view>
<text class="popup-title">请选择{{ title }}</text>
</view>
<scroll-view class="select-box"
direction="vertical"
:show-scrollbar="false"
:bounces="false"
:scroll-with-animation="false"
scroll-y>
<view v-if="employeeList.length == 0" style="padding: 40px 20px; text-align: center;">
<text style="color: #999; font-size: 14px;">暂无销售人员数据</text>
</view>
<view class="view-content">
<template v-for="(item, index) in employeeList" :key="index">
<view class="select-item"
:class="[{ 'is-active': (salesUuid as string) == (item as UTSJSONObject).uuid }]"
@click="handleSelect(item)">
<text class="select-item-text" :class="[{ 'is-active-text': (salesUuid as string) == (item as UTSJSONObject).uuid }]">{{ (item as UTSJSONObject).staffName }}</text>
</view>
</template>
</view>
</scroll-view>
</view>
</un-popup>
</view>
</template>
<script setup lang="uts">
import { ComponentPublicInstance, computed, onUnmounted, ref, watch } from "vue";
import { getEmployeeListApi } from "@/api/common-api.uts";
// import { resolutionState } from "@/services/adapter/index.uts";
import { dispatch, state } from "@/store/index.uts";
import { storage } from "@/utils/storage.uts";
import { useWindowHeight } from "@/services/adapter/hooks/index.uts";
// 使用统一的 windowHeight hook
const windowHeight = useWindowHeight();
type Props = {
salesPropsUuid?: string
title?: string
}
type UserInfo = UTSJSONObject
const props = withDefaults(defineProps<Props>(), {
title: "销售",
salesPropsUuid: ""
});
const emit = defineEmits(["close", "select"]);
let componentDisposed = false;
onUnmounted((): void => {
componentDisposed = true;
});
const visible = ref<boolean>(false);
const watchStatus = computed<boolean>(() => {
const status = state.user?.historyStatus;
if (status == null) {
return false;
} else if (status == 1) {
return true;
} else {
return false;
}
});
const updateView = ref<number>(Date.now());
const salesUuid = computed<string>(() => {
const val1 = state.user.customerInfo.salesUuid;
const val2 = props.salesPropsUuid;
return val1 !== null && val1 !== "" ? (val1 as string) : val2;
});
// 动态计算 z-index,确保始终在最上层(高于 ToolBox 的 10073)
const dynamicZIndex = computed<number>(() => {
return 10090;
});
// const windowHeight = computed<number>(() => {
// const height = resolutionState.windowHeight;
// return height > 0 ? height : uni.getWindowInfo().windowHeight;
// });
const employeeList = ref<Array<any>>([]);
/** 使用 `string` 字面量键;`String` 类型在桥接时可能异常;缓存可能是 JSON 字符串或数组 */
const STORAGE_KEY_EMPLOYEE_LIST = "employeeList";
function readEmployeeListFromStorage(): Array<any> {
const raw = storage.get(STORAGE_KEY_EMPLOYEE_LIST) as any | null;
if (raw == null) {
return [] as any[];
}
if (Array.isArray(raw)) {
return raw as Array<any>;
}
if (typeof raw === "string") {
const s = (raw as string).trim();
if (s === "") {
return [] as any[];
}
try {
const parsed = JSON.parse(s) as any;
return Array.isArray(parsed) ? (parsed as Array<any>) : ([] as any[]);
} catch (_e) {
return [] as any[];
}
}
return [] as any[];
}
watch(updateView, () => {
console.log("updateView triggered, reading from storage");
const list = readEmployeeListFromStorage();
console.log("storage employeeList length:", list.length);
employeeList.value = list;
console.log("employeeList.value updated, length:", employeeList.value.length);
}, { immediate: true });
function close(): void {
visible.value = false;
}
watch(watchStatus, () => {
close();
}, { immediate: true });
function handleClose(): void {
emit("close");
}
function handlePopupClose(): void {
visible.value = false;
emit("close");
}
function handleHide(): void {
visible.value = false;
}
function open(): void {
visible.value = true;
const userInfo = storage.getParse("userInfo") as UserInfo;
const shopMerchantIdRaw = userInfo["shopMerchantId"] as string | null;
const shopMerchantId = shopMerchantIdRaw != null ? shopMerchantIdRaw : "";
if (shopMerchantId === "") {
return;
}
// 获取销售人员列表
getEmployeeListApi({ merchantId: shopMerchantId }).then((res: any) => {
if (componentDisposed) {
return;
}
console.log("getEmployeeListApi response:", res);
const list = res as Array<any>;
console.log("list length:", list != null ? list.length : 0);
dispatch("setEmployeeList", list);
const listToStore = list != null ? list : [];
console.log("Saving to storage, length:", listToStore.length);
storage.set(STORAGE_KEY_EMPLOYEE_LIST, listToStore, 0);
console.log("Triggering updateView");
updateView.value = Date.now();
console.log("updateView triggered with:", updateView.value);
});
}
function handleSelect(item: any): void {
close();
emit("select", item);
}
defineExpose({ open, close });
</script>
<style scoped lang="scss">
.popup-wrapper {
background: #ffffff;
border-radius: 20px 20px 0 0;
display: flex;
flex-direction: column;
overflow: hidden;
}
.popup-header {
position: relative;
display: flex;
align-items: center;
justify-content: center;
height: 56px;
flex-shrink: 0;
border-bottom: 1px solid #f0f0f0;
}
.popup-title {
font-size: 18px;
font-weight: 600;
color: #292d33;
}
.icon-close-box {
position: absolute;
right: 16px;
top: 50%;
transform: translateY(-50%);
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
}
.select-box {
flex: 1;
min-height: 0;
position: relative;
display: flex;
flex-direction: column;
}
.view-content {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
padding: 16px 24px 24px;
box-sizing: border-box;
// ✅ UVUE 不支持 min-height: 100%,移除后由 flex 布局自适应
}
.select-item {
width: 48%; /* 预留间距,避免49%引起的意外换行 */
margin-bottom: 12px;
height: 44px; /* 加高触控面积,显得更大气 */
background-color: #f8f9fa; /* 低调的浅灰背景 */
border-radius: 8px; /* 圆角增加现代感 */
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
border: 1px solid transparent;
transition: background-color 0.2s ease, border-color 0.2s ease;
}
/* 悬浮反馈 */
.select-item:active {
background-color: #f1f3f5;
}
/* 选中状态 */
.is-active {
background-color: rgba(22, 119, 255, 0.05); /* 淡淡的主题色背景 */
border: 1px solid rgba(22, 119, 255, 0.3); /* 主题色描边 */
}
.select-item-text {
text-align: center;
color: #495057; /* 稳重的深灰色 */
font-size: 15px;
line-height: 20px;
font-weight: 500;
}
.is-active-text {
color: #1677FF; /* 选中时的文字色与边框呼应 */
font-weight: 600;
}
</style>