375 lines
9.7 KiB
Vue
375 lines
9.7 KiB
Vue
<template>
|
|
<section class="register-record-calendar">
|
|
<month-calendar v-model="monthProxy" :days="calendarDayList" @day-click="openDayRecords">
|
|
<template #actions>
|
|
<t-button
|
|
v-if="showEventFilter"
|
|
class="filter-btn"
|
|
theme="primary"
|
|
size="extra-small"
|
|
variant="outline"
|
|
@click="eventFilterVisible = true"
|
|
content="登记事件"
|
|
>
|
|
<template #icon><t-icon name="filter" /></template>
|
|
</t-button>
|
|
</template>
|
|
<template #day="{ day }">
|
|
<span v-if="getDayRecords(day.dateText).length" class="count" v-text="`${getDayRecords(day.dateText).length} 条`" />
|
|
</template>
|
|
</month-calendar>
|
|
<center-tips v-if="loading">正在加载登记日历</center-tips>
|
|
<center-tips v-else-if="!currentMonthFilteredRecords.length" :content="emptyText" />
|
|
<t-cell title="登记事件记录列表" arrow @click="openRecordList">
|
|
<template #left-icon>
|
|
<t-icon name="catalog" />
|
|
</template>
|
|
</t-cell>
|
|
<t-popup v-model="dayRecordVisible" placement="bottom" destroy-on-close>
|
|
<div class="day-record-panel">
|
|
<div class="popup-head">
|
|
<h3 v-text="selectedDayTitle" />
|
|
<t-button theme="default" variant="text" size="small" @click="dayRecordVisible = false">
|
|
关闭
|
|
</t-button>
|
|
</div>
|
|
<div class="popup-body">
|
|
<t-cell-group v-if="selectedDayRecords.length" theme="card">
|
|
<t-cell
|
|
v-for="item in selectedDayRecords"
|
|
:key="item.id"
|
|
:title="getRecordEventName(item)"
|
|
:description="getRecordCustomerName(item)"
|
|
:note="`${formatRecordTime(item.registeredAt)}`"
|
|
arrow
|
|
hover
|
|
@click="toRecordDetail(item)"
|
|
/>
|
|
</t-cell-group>
|
|
<center-tips v-else>该日暂无登记事件记录</center-tips>
|
|
</div>
|
|
</div>
|
|
</t-popup>
|
|
<t-popup v-model="eventFilterVisible" placement="bottom" destroy-on-close>
|
|
<div class="filter-popup">
|
|
<div class="popup-head">
|
|
<div class="title">登记事件筛选</div>
|
|
<t-button theme="default" variant="text" size="small" @click="eventFilterVisible = false">
|
|
关闭
|
|
</t-button>
|
|
</div>
|
|
<div class="popup-body">
|
|
<event-selector
|
|
v-model="selectedEventIdListProxy"
|
|
:event-list="eventList"
|
|
label=""
|
|
/>
|
|
</div>
|
|
</div>
|
|
</t-popup>
|
|
</section>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import StoreAPI from "@/api/StoreAPI";
|
|
import EventSelector from "@/components/EventSelector.vue";
|
|
import MonthCalendar from "@/components/monthCalendar/MonthCalendar.vue";
|
|
import { buildMonthCalendarDays, type MonthCalendarDay } from "@/components/monthCalendar/monthCalendar";
|
|
import type {EventItem} from "@/types/EventItem";
|
|
import type {EventRecord} from "@/types/EventRecord";
|
|
import type {StoreBusinessDay} from "@/types/Store";
|
|
import {getCurrentStoreId} from "@/utils/store";
|
|
import {Time} from "timi-web";
|
|
|
|
interface CalendarDay extends MonthCalendarDay {
|
|
records: EventRecord[];
|
|
}
|
|
|
|
export interface EventRecordCalendarListPayload {
|
|
monthCursor: Date;
|
|
selectedEventIdList: string[];
|
|
}
|
|
|
|
const props = withDefaults(defineProps<{
|
|
eventList: EventItem[];
|
|
customerName?: string;
|
|
emptyText?: string;
|
|
loading?: boolean;
|
|
modelValue: Date;
|
|
records: EventRecord[];
|
|
selectedEventIdList: string[];
|
|
showEventFilter?: boolean;
|
|
storeId?: string;
|
|
}>(), {
|
|
customerName: "",
|
|
emptyText: "当前月份暂无匹配登记",
|
|
loading: false,
|
|
showEventFilter: true,
|
|
storeId: ""
|
|
});
|
|
|
|
const emit = defineEmits<{
|
|
"update:modelValue": [value: Date];
|
|
"update:selectedEventIdList": [value: string[]];
|
|
list: [value: EventRecordCalendarListPayload];
|
|
}>();
|
|
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
const monthProxy = computed({
|
|
get: () => props.modelValue,
|
|
set: value => emit("update:modelValue", value)
|
|
});
|
|
const dayRecordVisible = ref(false);
|
|
const eventFilterVisible = ref(false);
|
|
const selectedDayTitle = ref("");
|
|
const selectedDayRecords = ref<EventRecord[]>([]);
|
|
const businessDayList = ref<StoreBusinessDay[]>([]);
|
|
let businessDayRequestId = 0;
|
|
|
|
const selectedEventIdListProxy = computed({
|
|
get: () => props.selectedEventIdList,
|
|
set: value => emit("update:selectedEventIdList", value)
|
|
});
|
|
const eventNameMap = computed(() => {
|
|
const map = new Map<string, string>();
|
|
for (const item of props.eventList) {
|
|
if (item.id) {
|
|
map.set(item.id, item.name || "未命名事件");
|
|
}
|
|
}
|
|
return map;
|
|
});
|
|
const selectedEventIdSet = computed(() => new Set(props.selectedEventIdList));
|
|
const resolvedStoreId = computed(() => props.storeId || getCurrentStoreId());
|
|
const restDaySet = computed(() => new Set(
|
|
businessDayList.value
|
|
.filter(item => item.status === "CLOSED" && item.dateValue)
|
|
.map(item => item.dateValue as number)
|
|
));
|
|
const filteredRecords = computed(() => {
|
|
if (!props.showEventFilter || !props.selectedEventIdList.length) {
|
|
return props.records;
|
|
}
|
|
|
|
return props.records.filter(item => item.eventId && selectedEventIdSet.value.has(item.eventId));
|
|
});
|
|
const currentMonthFilteredRecords = computed(() => filteredRecords.value.filter(item => isInCurrentMonth(item.registeredAt)));
|
|
const calendarDayList = computed<CalendarDay[]>(() => buildMonthCalendarDays(props.modelValue).map(day => {
|
|
const records = getDayRecords(day.dateText);
|
|
return {
|
|
...day,
|
|
isRestDay: restDaySet.value.has(Number(day.dateText.replaceAll("-", ""))),
|
|
records,
|
|
marked: 0 < records.length,
|
|
disabled: !records.length
|
|
};
|
|
}));
|
|
|
|
watch([() => props.modelValue, resolvedStoreId], async () => {
|
|
await loadBusinessDays();
|
|
}, {
|
|
deep: true,
|
|
immediate: true
|
|
});
|
|
|
|
async function loadBusinessDays(): Promise<void> {
|
|
const storeId = resolvedStoreId.value;
|
|
if (!storeId) {
|
|
businessDayList.value = [];
|
|
return;
|
|
}
|
|
|
|
const requestId = ++businessDayRequestId;
|
|
const beginDate = getCalendarBeginDate(props.modelValue);
|
|
const endDate = addDays(beginDate, 41);
|
|
try {
|
|
const result = await StoreAPI.businessDayCalendar(storeId, toDateValue(beginDate), toDateValue(endDate));
|
|
if (requestId === businessDayRequestId) {
|
|
businessDayList.value = result || [];
|
|
}
|
|
} catch {
|
|
if (requestId === businessDayRequestId) {
|
|
businessDayList.value = [];
|
|
}
|
|
}
|
|
}
|
|
|
|
function getDayRecords(dateText: string): EventRecord[] {
|
|
return filteredRecords.value.filter(item => getRecordDateText(item) === dateText);
|
|
}
|
|
|
|
function openDayRecords(day: MonthCalendarDay): void {
|
|
const records = getDayRecords(day.dateText);
|
|
if (!records.length) {
|
|
return;
|
|
}
|
|
|
|
selectedDayTitle.value = `${day.dateText} 登记事件记录`;
|
|
selectedDayRecords.value = [...records].sort((left, right) => (right.registeredAt || 0) - (left.registeredAt || 0));
|
|
dayRecordVisible.value = true;
|
|
}
|
|
|
|
function openRecordList(): void {
|
|
emit("list", {
|
|
monthCursor: props.modelValue,
|
|
selectedEventIdList: props.selectedEventIdList
|
|
});
|
|
}
|
|
|
|
async function toRecordDetail(record: EventRecord): Promise<void> {
|
|
if (!record.id) {
|
|
return;
|
|
}
|
|
|
|
dayRecordVisible.value = false;
|
|
await router.push({
|
|
path: `/management/registration-event-records/${record.id}`,
|
|
query: {
|
|
transitionDepth: String(getCurrentRouteDepth() + 1)
|
|
}
|
|
});
|
|
}
|
|
|
|
function getRecordEventName(record?: EventRecord): string {
|
|
if (!record) {
|
|
return "";
|
|
}
|
|
|
|
return record.event?.name || (record.eventId ? eventNameMap.value.get(record.eventId) : "") || "未知事件";
|
|
}
|
|
|
|
function getRecordCustomerName(record: EventRecord): string {
|
|
return record.customer?.name || props.customerName || record.customerId || "未知客户";
|
|
}
|
|
|
|
function formatRecordTime(value?: number): string {
|
|
if (!value) {
|
|
return "-";
|
|
}
|
|
|
|
const date = Time.toDateObject(value);
|
|
if (!date) {
|
|
return "-";
|
|
}
|
|
return Time.toDateTime(date);
|
|
}
|
|
|
|
function getRecordDateText(record: EventRecord): string {
|
|
const date = Time.toDateObject(record.registeredAt);
|
|
return date ? Time.toDate(date) : "";
|
|
}
|
|
|
|
function isInCurrentMonth(value?: number): boolean {
|
|
const date = Time.toDateObject(value);
|
|
return !!date && date.getFullYear() === props.modelValue.getFullYear() && date.getMonth() === props.modelValue.getMonth();
|
|
}
|
|
|
|
function getCurrentRouteDepth(): number {
|
|
return Number(route.meta.depth ?? 0);
|
|
}
|
|
|
|
function getMonthStart(date: Date): Date {
|
|
return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);
|
|
}
|
|
|
|
function getCalendarBeginDate(date: Date): Date {
|
|
const monthStart = getMonthStart(date);
|
|
return addDays(monthStart, -monthStart.getDay());
|
|
}
|
|
|
|
function addDays(date: Date, days: number): Date {
|
|
const value = new Date(date);
|
|
value.setDate(value.getDate() + days);
|
|
return value;
|
|
}
|
|
|
|
function toDateValue(date: Date): number {
|
|
return Number(Time.toDate(date).replaceAll("-", ""));
|
|
}
|
|
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
.register-record-calendar {
|
|
display: flex;
|
|
overflow: hidden;
|
|
background: rgba(255, 255, 255, .92);
|
|
box-shadow: var(--td-shadow-1);
|
|
border-radius: .75rem;
|
|
flex-direction: column;
|
|
|
|
.count {
|
|
width: 100%;
|
|
color: var(--td-brand-color);
|
|
overflow: hidden;
|
|
font-size: .625rem;
|
|
font-weight: 700;
|
|
white-space: nowrap;
|
|
text-overflow: ellipsis;
|
|
}
|
|
}
|
|
|
|
.day-record-panel,
|
|
.filter-popup {
|
|
gap: .875rem;
|
|
padding: 1rem 0 calc(1rem + var(--tui-safe-bottom, 0px)) 0;
|
|
display: flex;
|
|
background: #f5f5f8;
|
|
border-radius: 1rem 1rem 0 0;
|
|
flex-direction: column;
|
|
max-height: min(80vh, 40rem);
|
|
|
|
h3,
|
|
.title {
|
|
margin: 0;
|
|
color: #0f172a;
|
|
font-size: 1rem;
|
|
text-align: center;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.popup-head {
|
|
gap: .5rem;
|
|
display: flex;
|
|
padding: 0 1rem;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.popup-body {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
}
|
|
}
|
|
|
|
.filter-popup {
|
|
padding: 1rem 1rem calc(1rem + var(--tui-safe-bottom, 0px)) 1rem;
|
|
|
|
.popup-head,
|
|
.popup-body {
|
|
padding: 0;
|
|
}
|
|
}
|
|
|
|
:global(html.theme-dark) {
|
|
.register-record-calendar {
|
|
background: rgba(15, 23, 42, .88);
|
|
box-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
|
|
|
|
.count { color: #60a5fa; }
|
|
}
|
|
|
|
.day-record-panel,
|
|
.filter-popup {
|
|
background: #10161f;
|
|
|
|
h3,
|
|
.title {
|
|
color: #e2e8f0;
|
|
}
|
|
}
|
|
}
|
|
</style>
|
|
|