RecentReceptionList.uvue
5.78 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
<template>
<view class="rrl-root">
<view class="rrl-header">
<text class="rrl-title">最近接待记录</text>
<text class="rrl-more" @click="onViewAll">查看全部</text>
</view>
<view class="rrl-content">
<view v-if="loading" class="rrl-loading">
<text class="rrl-loading-text">加载中...</text>
</view>
<view v-else-if="cardList.length == 0" class="rrl-empty">
<text class="rrl-empty-text">暂无接待记录</text>
</view>
<view v-else :class="['rrl-list', isPortrait ? 'rrl-list--portrait' : 'rrl-list--landscape']">
<view
v-for="(item, idx) in cardList"
:key="'rrl-' + idx"
class="rrl-card"
@click="onCardClick(item.rawData)"
>
<view class="rrl-card-top">
<text class="rrl-card-name">{{ item.customerName }}</text>
<text :class="['rrl-card-badge', item.badgeBgClass]">
{{ item.resultText }}
</text>
</view>
<view class="rrl-card-info">
<text class="rrl-card-label">{{ item.carTypeText }}</text>
<text class="rrl-card-time">{{ item.timeText }}</text>
</view>
</view>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { type Ref, computed, onMounted, ref } from "vue";
import { getReceptions } from "@/api/modules/receptions.uts";
import { useOrientation } from "@/services/adapter/hooks/index.uts";
import { getStr } from "@/pages/receptionCenter/types/reception-center-helpers.uts";
type ReceptionCardItem = {
customerName: string;
resultText: string;
badgeBgClass: string;
carTypeText: string;
timeText: string;
rawData: UTSJSONObject;
};
const props = withDefaults(defineProps<{
/** 最多展示条数 */
limit?: number
}>(), {
limit: 3
});
// 横竖屏检测
const orientationHook = useOrientation();
const isPortrait = computed((): boolean => {
return (orientationHook.isPortrait as Ref<boolean>).value;
});
const cardList = ref<ReceptionCardItem[]>([]);
const loading = ref(true);
function buildCardItem(row: UTSJSONObject): ReceptionCardItem {
const status = row["status"];
const statusName = getStr(row, 'result');
const resultText = statusName != '' ? statusName : '战败';
// 新接口:brand + carSeries 拼接
const brand = getStr(row, 'brand');
const series = getStr(row, 'carSeries');
let carTypeText = '';
if (brand != '') {
carTypeText = series != '' ? `${brand} ${series}` : brand;
} else {
carTypeText = '未填写车型';
}
return {
customerName: getStr(row, 'customerName'),
resultText: resultText,
badgeBgClass: status == 1 ? 'rrl-badge--active' : 'rrl-badge--done',
carTypeText: carTypeText,
timeText: getStr(row, 'startTime'),
rawData: row
} as ReceptionCardItem;
}
async function fetchRecentList(): Promise<void> {
loading.value = true;
try {
const params = {
pageNum: 1,
status: 1
} as UTSJSONObject;
const resp = await getReceptions(params);
// 新接口 request() 已提取 data 层,返回直接是数组
let data: any[] = [];
if (resp != null) {
if (Array.isArray(resp)) {
data = resp as any[];
} else {
// 兼容:如果返回的是对象,尝试取 list 字段
const obj = resp as UTSJSONObject;
const list = obj["list"];
if (list != null && Array.isArray(list)) {
data = list as any[];
}
}
}
const limit = props.limit;
const count = data.length < limit ? data.length : limit;
const items: ReceptionCardItem[] = [];
let i = 0;
while (i < count) {
items.push(buildCardItem(data[i] as UTSJSONObject));
i++;
}
cardList.value = items;
} catch (_e) {
cardList.value = [];
} finally {
loading.value = false;
}
}
function onCardClick(rawData: UTSJSONObject): void {
uni.navigateTo({
url: `/pages/receptionCenter/forms/FormDetail?record=${encodeURIComponent(JSON.stringify(rawData))}`
});
}
function onViewAll(): void {
uni.navigateTo({ url: "/pages/receptionCenter/center" });
}
onMounted(() => {
void fetchRecentList();
});
</script>
<style scoped lang="scss">
.rrl-root {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
min-height: 0;
overflow: hidden;
}
.rrl-header {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 6px 0 8px 0;
flex-shrink: 0;
}
.rrl-title {
font-size: 16px;
font-weight: 600;
color: #1e293b;
}
.rrl-more {
font-size: 13px;
color: #3773f8;
padding: 4px 0;
}
.rrl-content {
flex: 1;
min-height: 0;
overflow: hidden;
}
.rrl-loading,
.rrl-empty {
display: flex;
align-items: center;
justify-content: center;
padding: 24px 0;
}
.rrl-loading-text {
font-size: 14px;
color: #94a3b8;
}
.rrl-empty-text {
font-size: 14px;
color: #94a3b8;
}
.rrl-list {
display: flex;
}
/* 竖屏:纵向排列,纵向滚动 */
.rrl-list--portrait {
flex-direction: column;
}
.rrl-list--portrait .rrl-card {
width: 100%;
margin-bottom: 10px;
}
.rrl-list--portrait .rrl-card:last-child {
margin-bottom: 0;
}
/* 横屏:横向排列,占满一行 */
.rrl-list--landscape {
flex-direction: row;
flex-wrap: nowrap;
}
.rrl-list--landscape .rrl-card {
flex: 1;
margin-right: 10px;
min-width: 0;
}
.rrl-list--landscape .rrl-card:last-child {
margin-right: 0;
}
.rrl-card {
background: #ffffff;
border: 1px solid #f1f5f9;
border-radius: 12px;
padding: 12px 14px;
box-sizing: border-box;
flex-shrink: 0;
}
.rrl-card-top {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
margin-bottom: 6px;
}
.rrl-card-name {
font-size: 15px;
font-weight: 600;
color: #1e293b;
flex: 1;
margin-right: 8px;
}
.rrl-card-badge {
font-size: 11px;
padding: 2px 8px;
border-radius: 10px;
flex-shrink: 0;
}
.rrl-card-info {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.rrl-card-label {
font-size: 13px;
color: #64748b;
}
.rrl-card-time {
font-size: 12px;
color: #94a3b8;
}
</style>