RecentReceptionList.uvue 5.78 KB
<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>