refactor event
This commit is contained in:
+31
-30
@@ -14,12 +14,12 @@
|
||||
</template>
|
||||
</t-button>
|
||||
<t-button
|
||||
v-if="showRegistrationEventFilter"
|
||||
v-if="showEventFilter"
|
||||
class="filter-btn"
|
||||
theme="primary"
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
@click="registrationEventFilterVisible = true"
|
||||
@click="eventFilterVisible = true"
|
||||
content="登记事件"
|
||||
>
|
||||
<template #icon>
|
||||
@@ -60,7 +60,7 @@
|
||||
<t-cell
|
||||
v-for="item in selectedDayRecords"
|
||||
:key="item.id"
|
||||
:title="getRecordRegistrationEventName(item)"
|
||||
:title="getRecordEventName(item)"
|
||||
:description="getRecordCustomerName(item)"
|
||||
:note="`${formatRecordTime(item.registeredAt)}`"
|
||||
/>
|
||||
@@ -69,19 +69,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</t-popup>
|
||||
<t-popup v-model="registrationEventFilterVisible" placement="bottom">
|
||||
<t-popup v-model="eventFilterVisible" placement="bottom">
|
||||
<div class="filter-popup">
|
||||
<div class="popup-head">
|
||||
<div class="title">登记事件筛选</div>
|
||||
<t-button theme="default" variant="text" size="small" @click="registrationEventFilterVisible = false">
|
||||
<t-button theme="default" variant="text" size="small" @click="eventFilterVisible = false">
|
||||
关闭
|
||||
</t-button>
|
||||
</div>
|
||||
<div class="popup-body">
|
||||
<t-checkbox-group v-model="selectedRegistrationEventIdListProxy" class="items">
|
||||
<t-checkbox-group v-model="selectedEventIdListProxy" class="items">
|
||||
<t-checkbox
|
||||
class="item"
|
||||
v-for="item in registrationEventList"
|
||||
v-for="item in eventList"
|
||||
:key="item.id"
|
||||
:value="item.id"
|
||||
:label="item.name"
|
||||
@@ -96,8 +96,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type {RegistrationEvent} from "@/types/RegistrationEvent";
|
||||
import type {RegistrationEventRecord} from "@/types/RegistrationEventRecord";
|
||||
import type {EventItem} from "@/types/EventItem";
|
||||
import type {EventRecord} from "@/types/EventRecord";
|
||||
import {Time} from "timi-web";
|
||||
|
||||
interface CalendarDay {
|
||||
@@ -106,56 +106,56 @@ interface CalendarDay {
|
||||
dateText: string;
|
||||
inMonth: boolean;
|
||||
isToday: boolean;
|
||||
records: RegistrationEventRecord[];
|
||||
records: EventRecord[];
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
registrationEventList: RegistrationEvent[];
|
||||
eventList: EventItem[];
|
||||
customerName?: string;
|
||||
emptyText?: string;
|
||||
loading?: boolean;
|
||||
modelValue: Date;
|
||||
records: RegistrationEventRecord[];
|
||||
selectedRegistrationEventIdList: string[];
|
||||
showRegistrationEventFilter?: boolean;
|
||||
records: EventRecord[];
|
||||
selectedEventIdList: string[];
|
||||
showEventFilter?: boolean;
|
||||
}>(), {
|
||||
customerName: "",
|
||||
emptyText: "当前月份暂无匹配登记",
|
||||
loading: false,
|
||||
showRegistrationEventFilter: true
|
||||
showEventFilter: true
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [value: Date];
|
||||
"update:selectedRegistrationEventIdList": [value: string[]];
|
||||
"update:selectedEventIdList": [value: string[]];
|
||||
}>();
|
||||
|
||||
const weekNameList = ["日", "一", "二", "三", "四", "五", "六"];
|
||||
const dayRecordVisible = ref(false);
|
||||
const registrationEventFilterVisible = ref(false);
|
||||
const eventFilterVisible = ref(false);
|
||||
const selectedDayTitle = ref("");
|
||||
const selectedDayRecords = ref<RegistrationEventRecord[]>([]);
|
||||
const selectedDayRecords = ref<EventRecord[]>([]);
|
||||
|
||||
const selectedRegistrationEventIdListProxy = computed({
|
||||
get: () => props.selectedRegistrationEventIdList,
|
||||
set: value => emit("update:selectedRegistrationEventIdList", value)
|
||||
const selectedEventIdListProxy = computed({
|
||||
get: () => props.selectedEventIdList,
|
||||
set: value => emit("update:selectedEventIdList", value)
|
||||
});
|
||||
const registrationEventNameMap = computed(() => {
|
||||
const eventNameMap = computed(() => {
|
||||
const map = new Map<string, string>();
|
||||
for (const item of props.registrationEventList) {
|
||||
for (const item of props.eventList) {
|
||||
if (item.id) {
|
||||
map.set(item.id, item.name || "未命名事件");
|
||||
}
|
||||
}
|
||||
return map;
|
||||
});
|
||||
const selectedRegistrationEventIdSet = computed(() => new Set(props.selectedRegistrationEventIdList));
|
||||
const selectedEventIdSet = computed(() => new Set(props.selectedEventIdList));
|
||||
const filteredRecords = computed(() => {
|
||||
if (!props.showRegistrationEventFilter || !props.selectedRegistrationEventIdList.length) {
|
||||
if (!props.showEventFilter || !props.selectedEventIdList.length) {
|
||||
return props.records;
|
||||
}
|
||||
|
||||
return props.records.filter(item => item.registrationEventId && selectedRegistrationEventIdSet.value.has(item.registrationEventId));
|
||||
return props.records.filter(item => item.eventId && selectedEventIdSet.value.has(item.eventId));
|
||||
});
|
||||
const currentMonthFilteredRecords = computed(() => filteredRecords.value.filter(item => isInCurrentMonth(item.registeredAt)));
|
||||
const monthTitle = computed(() => `${props.modelValue.getFullYear()} 年 ${props.modelValue.getMonth() + 1} 月`);
|
||||
@@ -192,15 +192,15 @@ function openDayRecords(day: CalendarDay): void {
|
||||
dayRecordVisible.value = true;
|
||||
}
|
||||
|
||||
function getRecordRegistrationEventName(record?: RegistrationEventRecord): string {
|
||||
function getRecordEventName(record?: EventRecord): string {
|
||||
if (!record) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return record.registrationEvent?.name || (record.registrationEventId ? registrationEventNameMap.value.get(record.registrationEventId) : "") || "未知事件";
|
||||
return record.event?.name || (record.eventId ? eventNameMap.value.get(record.eventId) : "") || "未知事件";
|
||||
}
|
||||
|
||||
function getRecordCustomerName(record: RegistrationEventRecord): string {
|
||||
function getRecordCustomerName(record: EventRecord): string {
|
||||
return record.customer?.name || props.customerName || record.customerId || "未知客户";
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ function formatRecordTime(value?: number): string {
|
||||
return Time.formatDateTime(date);
|
||||
}
|
||||
|
||||
function getRecordDateText(record: RegistrationEventRecord): string {
|
||||
function getRecordDateText(record: EventRecord): string {
|
||||
const date = Time.toDateObject(record.registeredAt);
|
||||
return date ? Time.formatDate(date) : "";
|
||||
}
|
||||
@@ -456,3 +456,4 @@ function addMonths(date: Date, months: number): Date {
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<p v-if="label" class="t-form__label" :class="{required: requiredMark}" v-text="label" />
|
||||
<t-checkbox-group v-model="modelValue" class="group">
|
||||
<t-checkbox
|
||||
v-for="item in registrationEventList"
|
||||
v-for="item in eventList"
|
||||
:key="item.id"
|
||||
:value="item.id"
|
||||
class="item"
|
||||
@@ -12,15 +12,15 @@
|
||||
<span v-text="item.name" />
|
||||
</t-checkbox>
|
||||
</t-checkbox-group>
|
||||
<div v-if="!registrationEventList.length" class="empty-block">暂无可用登记事件</div>
|
||||
<div v-if="!eventList.length" class="empty-block">暂无可用登记事件</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { RegistrationEvent } from "@/types/RegistrationEvent";
|
||||
import type { EventItem } from "@/types/EventItem";
|
||||
|
||||
interface Props {
|
||||
registrationEventList: RegistrationEvent[];
|
||||
eventList: EventItem[];
|
||||
label?: string;
|
||||
requiredMark?: boolean;
|
||||
}
|
||||
@@ -87,3 +87,4 @@ const modelValue = defineModel<string[]>({ required: true });
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user