feat(event): customer photo for event record calendar
This commit is contained in:
@@ -40,11 +40,16 @@
|
||||
:key="item.id"
|
||||
:title="getRecordEventName(item)"
|
||||
:description="getRecordCustomerName(item)"
|
||||
:note="`${formatRecordTime(item.registeredAt)}`"
|
||||
:note="formatRecordTime(item.registeredAt)"
|
||||
arrow
|
||||
hover
|
||||
@click="toRecordDetail(item)"
|
||||
/>
|
||||
>
|
||||
<template #left-icon>
|
||||
<t-image v-if="getRecordPhotoURL(item)" :src="getRecordPhotoURL(item)" :alt="getRecordCustomerName(item)" fit="cover" class="avatar" />
|
||||
<div v-else class="avatar fallback" v-text="getRecordCustomerName(item).slice(0, 1)" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<center-tips v-else>该日暂无登记事件记录</center-tips>
|
||||
</div>
|
||||
@@ -72,6 +77,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import StoreAPI from "@/api/StoreAPI";
|
||||
import EventRecordAPI from "@/api/EventRecordAPI";
|
||||
import EventSelector from "@/components/EventSelector.vue";
|
||||
import MonthCalendar from "@/components/monthCalendar/MonthCalendar.vue";
|
||||
import { buildMonthCalendarDays, type MonthCalendarDay } from "@/components/monthCalendar/monthCalendar";
|
||||
@@ -79,6 +85,7 @@ import type {EventItem} from "@/types/EventItem";
|
||||
import type {EventRecord} from "@/types/EventRecord";
|
||||
import type {StoreBusinessDay} from "@/types/Store";
|
||||
import {getCurrentStoreId} from "@/utils/store";
|
||||
import {getCustomerPhotoURL} from "@/utils/customer";
|
||||
import {Time} from "timi-web";
|
||||
|
||||
interface CalendarDay extends MonthCalendarDay {
|
||||
@@ -126,6 +133,7 @@ const selectedDayTitle = ref("");
|
||||
const selectedDayRecords = ref<EventRecord[]>([]);
|
||||
const businessDayList = ref<StoreBusinessDay[]>([]);
|
||||
let businessDayRequestId = 0;
|
||||
let dayRecordRequestId = 0;
|
||||
|
||||
const selectedEventIdListProxy = computed({
|
||||
get: () => props.selectedEventIdList,
|
||||
@@ -199,7 +207,7 @@ function getDayRecords(dateText: string): EventRecord[] {
|
||||
return filteredRecords.value.filter(item => getRecordDateText(item) === dateText);
|
||||
}
|
||||
|
||||
function openDayRecords(day: MonthCalendarDay): void {
|
||||
async function openDayRecords(day: MonthCalendarDay): Promise<void> {
|
||||
const records = getDayRecords(day.dateText);
|
||||
if (!records.length) {
|
||||
return;
|
||||
@@ -208,6 +216,31 @@ function openDayRecords(day: MonthCalendarDay): void {
|
||||
selectedDayTitle.value = `${day.dateText} 登记事件记录`;
|
||||
selectedDayRecords.value = [...records].sort((left, right) => (right.registeredAt || 0) - (left.registeredAt || 0));
|
||||
dayRecordVisible.value = true;
|
||||
const requestId = ++dayRecordRequestId;
|
||||
const [year, month, date] = day.dateText.split("-").map(Number);
|
||||
const begin = new Date(year, month - 1, date);
|
||||
const end = new Date(year, month - 1, date, 23, 59, 59, 999);
|
||||
const customerIds = [...new Set(records.map(item => item.customerId).filter((id): id is string => Boolean(id)))];
|
||||
const eventIds = [...new Set(records.map(item => item.eventId).filter((id): id is string => Boolean(id)))];
|
||||
try {
|
||||
const result = await EventRecordAPI.list({
|
||||
index: 0,
|
||||
size: records.length,
|
||||
storeId: resolvedStoreId.value,
|
||||
customerId: customerIds.length === 1 ? customerIds[0] : undefined,
|
||||
eventIdList: eventIds,
|
||||
beginAt: Time.toTimestamp(begin),
|
||||
endAt: Time.toTimestamp(end)
|
||||
});
|
||||
if (requestId !== dayRecordRequestId) return;
|
||||
const customers = new Map((result.list || []).map(item => [item.id, item.customer]));
|
||||
selectedDayRecords.value = selectedDayRecords.value.map(item => ({
|
||||
...item,
|
||||
customer: customers.get(item.id) || item.customer
|
||||
}));
|
||||
} catch {
|
||||
// 记录资料不可用时保留姓名占位。
|
||||
}
|
||||
}
|
||||
|
||||
function openRecordList(): void {
|
||||
@@ -243,6 +276,10 @@ function getRecordCustomerName(record: EventRecord): string {
|
||||
return record.customer?.name || props.customerName || record.customerId || "未知客户";
|
||||
}
|
||||
|
||||
function getRecordPhotoURL(record: EventRecord): string {
|
||||
return getCustomerPhotoURL(record.customer, 64);
|
||||
}
|
||||
|
||||
function formatRecordTime(value?: number): string {
|
||||
if (!value) {
|
||||
return "-";
|
||||
@@ -252,7 +289,7 @@ function formatRecordTime(value?: number): string {
|
||||
if (!date) {
|
||||
return "-";
|
||||
}
|
||||
return Time.toDateTime(date);
|
||||
return Time.toTime(date);
|
||||
}
|
||||
|
||||
function getRecordDateText(record: EventRecord): string {
|
||||
@@ -341,6 +378,18 @@ function toDateValue(date: Date): number {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.fallback {
|
||||
display: flex;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.filter-popup {
|
||||
|
||||
Reference in New Issue
Block a user