refactor event
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<div v-can="gaoPermissionCodes.registrationEventRecord.create" class="quick-sign-in-page">
|
||||
<button class="registration-event-select" type="button" @click="registrationEventSelectorVisible = true">
|
||||
<div v-can="permissionCodes.eventRecord.create" class="quick-sign-in-page">
|
||||
<button class="registration-event-select" type="button" @click="eventSelectorVisible = true">
|
||||
<span class="required-label">登记事件</span>
|
||||
<strong v-text="selectedRegistrationEventName" />
|
||||
<strong v-text="selectedEventName" />
|
||||
<t-icon name="chevron-right" />
|
||||
</button>
|
||||
<code-scanner
|
||||
@@ -25,7 +25,7 @@
|
||||
<t-cell
|
||||
v-for="item in recentRecordList"
|
||||
:key="item.id"
|
||||
:title="getRecordRegistrationEventName(item)"
|
||||
:title="getRecordEventName(item)"
|
||||
:description="formatTime(item.registeredAt)"
|
||||
:note="item.remark || '无备注'"
|
||||
arrow
|
||||
@@ -36,7 +36,7 @@
|
||||
<t-image
|
||||
v-if="getRecordPhotoURL(item)"
|
||||
:src="getRecordPhotoURL(item)"
|
||||
:alt="getRecordRegistrationEventName(item)"
|
||||
:alt="getRecordEventName(item)"
|
||||
fit="cover"
|
||||
class="record-photo"
|
||||
/>
|
||||
@@ -51,16 +51,16 @@
|
||||
@click="submitRegister"
|
||||
>登记</t-button>
|
||||
</div>
|
||||
<t-popup v-model="registrationEventSelectorVisible" placement="bottom">
|
||||
<t-popup v-model="eventSelectorVisible" placement="bottom">
|
||||
<div class="registration-event-panel">
|
||||
<div class="title">登记事件</div>
|
||||
<t-cell-group v-if="registrationEventList.length" theme="card">
|
||||
<t-cell-group v-if="eventList.length" theme="card">
|
||||
<t-cell
|
||||
v-for="item in registrationEventList"
|
||||
v-for="item in eventList"
|
||||
:key="item.id"
|
||||
:title="item.name"
|
||||
:note="item.id === selectedRegistrationEventId ? '当前使用' : ''"
|
||||
@click="selectRegistrationEvent(item.id || '')"
|
||||
:note="item.id === selectedEventId ? '当前使用' : ''"
|
||||
@click="selectEvent(item.id || '')"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<div v-else class="empty-block">暂无可用登记事件</div>
|
||||
@@ -71,16 +71,16 @@
|
||||
<script setup lang="ts">
|
||||
import { Toast } from "tdesign-mobile-vue";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import RegistrationEventAPI from "@/api/RegistrationEventAPI";
|
||||
import RegistrationEventRecordAPI from "@/api/RegistrationEventRecordAPI";
|
||||
import EventAPI from "@/api/EventAPI";
|
||||
import EventRecordAPI from "@/api/EventRecordAPI";
|
||||
import CodeScanner from "@/components/CodeScanner.vue";
|
||||
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
|
||||
import { useSettingStore } from "@/store/settingStore";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { RegistrationEvent } from "@/types/RegistrationEvent";
|
||||
import type { RegistrationEventRecord } from "@/types/RegistrationEventRecord";
|
||||
import { gaoPermissionCodes } from "@/utils/gaoPermission";
|
||||
import { getRegistrationEventRecordPhotoURL } from "@/utils/registrationEventRecord";
|
||||
import type { EventItem } from "@/types/EventItem";
|
||||
import type { EventRecord } from "@/types/EventRecord";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getEventRecordPhotoURL } from "@/utils/eventRecord";
|
||||
import { Time } from "timi-web";
|
||||
|
||||
defineOptions({
|
||||
@@ -88,21 +88,21 @@ defineOptions({
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const registrationEventStorageKey = "quick-scan-registration-event-id";
|
||||
const EventItemStorageKey = "quick-scan-registration-event-id";
|
||||
const settingStore = useSettingStore();
|
||||
const scanCode = ref("");
|
||||
const scanStatus = ref("正在启动扫码预览。");
|
||||
const scannerSessionKey = ref(0);
|
||||
const matchedCustomer = ref<Customer>();
|
||||
const recentRecordList = ref<RegistrationEventRecord[]>([]);
|
||||
const registrationEventList = ref<RegistrationEvent[]>([]);
|
||||
const selectedRegistrationEventId = ref("");
|
||||
const registrationEventSelectorVisible = ref(false);
|
||||
const recentRecordList = ref<EventRecord[]>([]);
|
||||
const eventList = ref<EventItem[]>([]);
|
||||
const selectedEventId = ref("");
|
||||
const eventSelectorVisible = ref(false);
|
||||
const submitting = ref(false);
|
||||
let latestDecodedText = "";
|
||||
|
||||
const selectedRegistrationEventName = computed(() => registrationEventList.value.find(item => item.id === selectedRegistrationEventId.value)?.name || "请选择登记事件");
|
||||
const canSubmitRegister = computed(() => !!matchedCustomer.value && !!selectedRegistrationEventId.value);
|
||||
const selectedEventName = computed(() => eventList.value.find(item => item.id === selectedEventId.value)?.name || "请选择登记事件");
|
||||
const canSubmitRegister = computed(() => !!matchedCustomer.value && !!selectedEventId.value);
|
||||
|
||||
// ---------- 扫码 ----------
|
||||
|
||||
@@ -144,7 +144,7 @@ async function submitRegister(): Promise<void> {
|
||||
try {
|
||||
await CustomerAPI.quickRegister({
|
||||
customerCode: customer.code || scanCode.value,
|
||||
registrationEventId: selectedRegistrationEventId.value,
|
||||
eventId: selectedEventId.value,
|
||||
remark: "客户快速扫码登记"
|
||||
});
|
||||
scanStatus.value = `登记成功:${customer.name || customer.code || scanCode.value}。`;
|
||||
@@ -160,7 +160,7 @@ async function submitRegister(): Promise<void> {
|
||||
}
|
||||
|
||||
function validateForm(): boolean {
|
||||
if (!selectedRegistrationEventId.value) {
|
||||
if (!selectedEventId.value) {
|
||||
showToast("请先选择登记事件", "warning");
|
||||
return false;
|
||||
}
|
||||
@@ -192,10 +192,10 @@ async function loadRecentRecordList(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
recentRecordList.value = (await RegistrationEventRecordAPI.rangeList({
|
||||
recentRecordList.value = (await EventRecordAPI.rangeList({
|
||||
customerId,
|
||||
beginRegisteredAt: 0,
|
||||
endRegisteredAt: Time.toTimestamp(new Date())
|
||||
beginAt: 0,
|
||||
endAt: Time.toTimestamp(new Date())
|
||||
}))
|
||||
.sort((left, right) => (right.registeredAt || 0) - (left.registeredAt || 0))
|
||||
.slice(0, 5);
|
||||
@@ -208,12 +208,12 @@ async function goRecordDetail(id: string): Promise<void> {
|
||||
await router.push(`/management/registration-event-records/${id}`);
|
||||
}
|
||||
|
||||
function getRecordRegistrationEventName(record: RegistrationEventRecord): string {
|
||||
return record.registrationEvent?.name || "未知事件";
|
||||
function getRecordEventName(record: EventRecord): string {
|
||||
return record.event?.name || "未知事件";
|
||||
}
|
||||
|
||||
function getRecordPhotoURL(record: RegistrationEventRecord): string {
|
||||
return getRegistrationEventRecordPhotoURL(record);
|
||||
function getRecordPhotoURL(record: EventRecord): string {
|
||||
return getEventRecordPhotoURL(record);
|
||||
}
|
||||
|
||||
function formatTime(value?: number): string {
|
||||
@@ -231,43 +231,43 @@ function formatTime(value?: number): string {
|
||||
// ---------- 登记事件 ----------
|
||||
|
||||
async function loadActions(): Promise<void> {
|
||||
registrationEventList.value = await RegistrationEventAPI.enabledList();
|
||||
const storedRegistrationEventId = loadStoredRegistrationEventId();
|
||||
const storedAction = registrationEventList.value.find(item => item.id === storedRegistrationEventId);
|
||||
selectedRegistrationEventId.value = storedAction?.id || registrationEventList.value[0]?.id || "";
|
||||
saveStoredRegistrationEventId(selectedRegistrationEventId.value);
|
||||
eventList.value = await EventAPI.enabledList();
|
||||
const storedEventId = loadStoredEventId();
|
||||
const storedAction = eventList.value.find(item => item.id === storedEventId);
|
||||
selectedEventId.value = storedAction?.id || eventList.value[0]?.id || "";
|
||||
saveStoredEventId(selectedEventId.value);
|
||||
}
|
||||
|
||||
function selectRegistrationEvent(registrationEventId: string | number | Array<string | number>): void {
|
||||
if (Array.isArray(registrationEventId)) {
|
||||
function selectEvent(eventId: string | number | Array<string | number>): void {
|
||||
if (Array.isArray(eventId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextRegistrationEventId = String(registrationEventId);
|
||||
if (!nextRegistrationEventId) {
|
||||
const nextEventId = String(eventId);
|
||||
if (!nextEventId) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectedRegistrationEventId.value = nextRegistrationEventId;
|
||||
saveStoredRegistrationEventId(nextRegistrationEventId);
|
||||
registrationEventSelectorVisible.value = false;
|
||||
selectedEventId.value = nextEventId;
|
||||
saveStoredEventId(nextEventId);
|
||||
eventSelectorVisible.value = false;
|
||||
showToast("登记事件已切换");
|
||||
}
|
||||
|
||||
function loadStoredRegistrationEventId(): string {
|
||||
function loadStoredEventId(): string {
|
||||
if (typeof window === "undefined") {
|
||||
return "";
|
||||
}
|
||||
|
||||
return window.localStorage.getItem(registrationEventStorageKey) || "";
|
||||
return window.localStorage.getItem(EventItemStorageKey) || "";
|
||||
}
|
||||
|
||||
function saveStoredRegistrationEventId(registrationEventId: string): void {
|
||||
if (typeof window === "undefined" || !registrationEventId) {
|
||||
function saveStoredEventId(eventId: string): void {
|
||||
if (typeof window === "undefined" || !eventId) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.localStorage.setItem(registrationEventStorageKey, registrationEventId);
|
||||
window.localStorage.setItem(EventItemStorageKey, eventId);
|
||||
}
|
||||
|
||||
function showToast(message: string, theme: "success" | "warning" = "success"): void {
|
||||
@@ -439,3 +439,4 @@ onMounted(loadActions);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user