add event option

This commit is contained in:
Timi
2026-08-30 23:36:59 +08:00
parent 82e2359857
commit f65c88920a
17 changed files with 1620 additions and 398 deletions
+111 -2
View File
@@ -46,6 +46,13 @@
<t-cell title="需要拍照" :note="event.requirePhoto ? '是' : '否'" />
<t-cell title="需要核销" :note="event.requireVerification ? '是' : '否'" />
<t-cell title="次数约束" :note="getLimitText(event)" />
<t-cell
title="登记可选项"
:note="`${(event?.optionGroupList || []).length} 个选项组`"
:arrow="hasOptionGroup"
:hover="hasOptionGroup"
@click="openOptionPopup"
/>
</t-cell-group>
<t-cell-group v-entrance-transition="210" v-if="event" title="生效时间" theme="card">
<t-cell title="起始时间" :note="formatDate(event.beginAt)" />
@@ -53,17 +60,48 @@
<t-cell title="创建时间" :note="formatDate(event.createdAt, '未知时间')" />
<t-cell title="更新时间" :note="formatDate(event.updatedAt, '未知时间')" />
</t-cell-group>
<t-empty v-else :description="isLoading ? '正在加载登记事件' : '登记事件不存在'" />
<t-button
v-if="event && canDeleteEvent"
v-can="permissionCodes.event.delete"
class="cell-button"
theme="danger"
:loading="isRemoving"
:disabled="isRemoving"
@click="confirmRemoveEvent"
v-entrance-transition="280"
content="删除事件"
/>
<t-empty v-if="!event" :description="isLoading ? '正在加载登记事件' : '登记事件不存在'" />
</div>
<bottom-popup
v-model="optionPopupVisible"
title="登记可选项"
height="min(88vh, 48rem)"
left-button-text="关闭"
right-button-text=""
@left-button-click="closeOptionPopup"
>
<div v-if="event && hasOptionGroup" class="option-popup">
<event-option-selector
v-model="optionSelectionMap"
:event-list="[event]"
:selected-event-id-list="selectedEventIdList"
readonly
/>
</div>
</bottom-popup>
</template>
<script setup lang="ts">
import { DialogPlugin } from "tdesign-mobile-vue";
import { BottomPopup } from "timi-tdesign-mobile";
import { Time, Text } from "timi-web";
import { type ModuleCode, type Role, RoleAPI, useUserStore } from "timi-web-api";
import EventAPI from "@/api/EventAPI";
import EventOptionSelector from "@/components/EventOptionSelector.vue";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { useNavBarStore } from "@/store/navBarStore";
import type { EventItem, EventLimitType, EventStatus, EventValueType, EventValueUnit } from "@/types/EventItem";
import type { EventItem, EventLimitType, EventOptionSelectionMap, EventStatus, EventValueType, EventValueUnit } from "@/types/EventItem";
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
import { Message } from "@/utils/message";
@@ -82,6 +120,7 @@ const defaultColor = "#2f88ff";
// ---------- 权限与门店 ----------
const canUpdate = computed(() => userStore.hasPermissions(permissionCodes.event.update));
const canDeleteEvent = computed(() => userStore.hasPermissions(permissionCodes.event.delete));
const isGlobalManager = computed(() => userStore.hasRoles(gaoRoleCodes.globalManager));
const storeName = computed(() => {
const storeId = event.value?.storeId;
@@ -98,6 +137,15 @@ const storeName = computed(() => {
const event = ref<EventItem>();
const roleOptions = ref<Role[]>([]);
const isLoading = ref(false);
const isRemoving = ref(false);
const optionPopupVisible = ref(false);
const optionSelectionMap = reactive<EventOptionSelectionMap>({});
const hasOptionGroup = computed(() => !!event.value?.optionGroupList?.some(group => group.optionList?.length));
const selectedEventIdList = computed(() => {
const eventId = event.value?.id;
return eventId === undefined || eventId === null ? [] : [String(eventId)];
});
async function loadStoreScope(): Promise<void> {
if (isGlobalManager.value) {
@@ -193,6 +241,58 @@ function formatDate(timestamp?: number, emptyText = "不限"): string {
return timestamp === undefined || timestamp === null ? emptyText : Time.toDateTime(timestamp);
}
function openOptionPopup(): void {
if (!hasOptionGroup.value) {
return;
}
optionPopupVisible.value = true;
}
function closeOptionPopup(): void {
optionPopupVisible.value = false;
}
// ---------- 删除 ----------
async function confirmRemoveEvent(): Promise<void> {
const eventId = String(route.params.id || "");
if (!eventId || !canDeleteEvent.value || isRemoving.value) {
return;
}
const eventName = event.value?.name || "未命名事件";
const dialog = DialogPlugin.confirm({
title: "删除登记事件",
content: `确定删除登记事件 ${eventName} 吗?删除后无法恢复。`,
cancelBtn: "取消",
confirmBtn: "删除",
onCancel() {
dialog.destroy();
},
async onConfirm() {
dialog.destroy();
await removeEvent(eventId);
}
});
}
async function removeEvent(eventId: string): Promise<void> {
if (isRemoving.value) {
return;
}
isRemoving.value = true;
try {
await EventAPI.remove(eventId);
Message.success("登记事件已删除");
await router.replace("/management/registration-events");
} catch {
Message.error("登记事件删除失败");
} finally {
isRemoving.value = false;
}
}
// ---------- 导航 ----------
async function toEdit(): Promise<void> {
@@ -286,5 +386,14 @@ onUnmounted(() => {
height: 1rem;
border-radius: 50%;
}
.delete-button {
width: calc(100% - 2rem);
margin: 0 1rem;
}
}
.option-popup {
padding: 1rem;
}
</style>