526 lines
14 KiB
Vue
526 lines
14 KiB
Vue
<template>
|
||
<div class="tui-page-layout tui-navbar">
|
||
<t-navbar
|
||
fixed
|
||
:z-index="20"
|
||
title="登记事件详情"
|
||
left-arrow
|
||
@left-click="goBack"
|
||
>
|
||
<template #right>
|
||
<t-button
|
||
v-if="canUpdate"
|
||
@click="toEdit"
|
||
theme="primary"
|
||
variant="text"
|
||
size="small"
|
||
content="编辑"
|
||
/>
|
||
</template>
|
||
</t-navbar>
|
||
<main class="tui-page-content scroll column">
|
||
<div
|
||
v-can="permissionCodes.event.read"
|
||
class="registration-event-detail"
|
||
>
|
||
<div v-entrance-transition v-if="event" class="event-header">
|
||
<div class="color" :style="{ background: event.color || defaultColor }" />
|
||
<div class="header-content">
|
||
<div class="title-row">
|
||
<h2 v-text="event.name || '未命名事件'" />
|
||
<t-tag :theme="getStatusTheme(event.status)" variant="light-outline" :content="getStatusText(event.status)" />
|
||
</div>
|
||
<div class="description" v-text="Text.display(event.description)" />
|
||
</div>
|
||
</div>
|
||
<t-cell-group v-entrance-transition v-if="event" title="基本信息" theme="card">
|
||
<t-cell title="所属门店" :note="storeName" />
|
||
<t-cell title="业务类型" :note="getEventBizTypeText(event.bizType)" />
|
||
<t-cell v-if="isPackagePurchaseEvent(event)" title="绑定套餐">
|
||
<template #note>
|
||
<div class="package-note">
|
||
<strong v-text="event.packageConfig?.name || '未返回套餐配置'" />
|
||
<span v-if="event.packageConfig" v-text="`${formatPackageAmount(event.packageConfig.standardAmount)}|${getPackageConfigStatusText(event.packageConfig.status)}`" />
|
||
</div>
|
||
</template>
|
||
</t-cell>
|
||
<t-cell title="事件颜色">
|
||
<template #note>
|
||
<div class="color-note">
|
||
<span class="color-dot" :style="{ background: event.color || defaultColor }" />
|
||
<span v-text="(event.color || defaultColor).toLowerCase()" />
|
||
</div>
|
||
</template>
|
||
</t-cell>
|
||
<t-cell title="说明" :note="Text.display(event.description)" />
|
||
<t-cell title="可登记角色">
|
||
<template #note>
|
||
<div v-if="event.roleCodeList?.length" class="tag-list">
|
||
<t-tag
|
||
v-for="roleCode in event.roleCodeList"
|
||
:key="roleCode"
|
||
theme="primary"
|
||
variant="light-outline"
|
||
:content="getRoleName(roleCode)"
|
||
/>
|
||
</div>
|
||
<span v-else>未配置</span>
|
||
</template>
|
||
</t-cell>
|
||
<t-cell
|
||
v-if="canReadEventRecord && event.bizType !== 'PACKAGE_PURCHASE'"
|
||
title="登记记录"
|
||
note="查看该事件登记记录"
|
||
arrow
|
||
:hover="true"
|
||
@click="toEventRecordList"
|
||
/>
|
||
<t-cell
|
||
v-else-if="event.bizType === 'PACKAGE_PURCHASE'"
|
||
title="购买记录"
|
||
note="请在套餐订单列表或订单详情中查看"
|
||
/>
|
||
</t-cell-group>
|
||
<t-cell-group v-entrance-transition v-if="event" title="登记配置" theme="card">
|
||
<t-cell title="数值类型" :note="getValueTypeText(event.valueType)" />
|
||
<t-cell v-if="event.valueType === 'NUMBER'" title="数值单位" :note="getValueUnitText(event.valueUnit)" />
|
||
<t-cell v-if="event.valueType === 'NUMBER'" title="登记必填数值" :note="event.requireValue ? '是' : '否'" />
|
||
<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 v-if="event" title="生效时间" theme="card">
|
||
<t-cell title="起始时间" :note="formatDate(event.beginAt)" />
|
||
<t-cell title="终止时间" :note="formatDate(event.endAt)" />
|
||
<t-cell title="创建时间" :note="formatDate(event.createdAt, '未知时间')" />
|
||
<t-cell title="更新时间" :note="formatDate(event.updatedAt, '未知时间')" />
|
||
</t-cell-group>
|
||
<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
|
||
content="删除事件"
|
||
/>
|
||
<t-empty v-if="!event" :description="isLoading ? '正在加载登记事件' : '登记事件不存在'" />
|
||
</div>
|
||
</main>
|
||
<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>
|
||
<event-remove-dialog
|
||
v-model:visible="removeDialogVisible"
|
||
:event="removeTarget"
|
||
:loading="isRemoving"
|
||
@confirm="removeEvent"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { BottomPopup, useExpandToMaster, usePane } 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 EventRemoveDialog from "@/pages/event/component/EventRemoveDialog.vue";
|
||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||
import { getEventBizTypeText, isPackagePurchaseEvent } from "@/utils/event";
|
||
import { formatPackageAmount, getPackageConfigStatusText } from "@/utils/package";
|
||
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||
import { Message } from "@/utils/message";
|
||
|
||
|
||
|
||
|
||
|
||
import type { EventItem, EventLimitType, EventOptionSelectionMap, EventStatus, EventValueType, EventValueUnit } from "@/types/EventItem";
|
||
|
||
defineOptions({
|
||
name: "EventDetail"
|
||
});
|
||
|
||
const props = withDefaults(defineProps<{
|
||
/** 指定事件 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
|
||
eventId?: string;
|
||
}>(), {
|
||
eventId: ""
|
||
});
|
||
|
||
const emit = defineEmits<{
|
||
/** 内联在右栏时请求切换到编辑视图 */
|
||
edit: [];
|
||
}>();
|
||
|
||
const route = useRoute();
|
||
const router = useRouter();
|
||
const userStore = useUserStore();
|
||
const currentStoreStore = useCurrentStoreStore();
|
||
const moduleCode: ModuleCode = "GAO";
|
||
const defaultColor = "#2f88ff";
|
||
|
||
function resolveId(): string {
|
||
return props.eventId || String(route.params.id || "");
|
||
}
|
||
|
||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||
useExpandToMaster({
|
||
path: "/management/registration-events",
|
||
id: () => resolveId()
|
||
});
|
||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||
const pane = usePane();
|
||
|
||
// ---------- 权限与门店 ----------
|
||
|
||
const isDeletedEvent = computed(() => event.value?.status === "DELETED");
|
||
const canUpdate = computed(() => !isDeletedEvent.value && userStore.hasPermissions(permissionCodes.event.update));
|
||
const canDeleteEvent = computed(() => !isDeletedEvent.value && userStore.hasPermissions(permissionCodes.event.delete));
|
||
const canReadEventRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.read));
|
||
const isGlobalManager = computed(() => userStore.hasRoles(gaoRoleCodes.globalManager));
|
||
const storeName = computed(() => {
|
||
const storeId = event.value?.storeId;
|
||
if (!storeId) {
|
||
return "未绑定门店";
|
||
}
|
||
const store = currentStoreStore.storeList.find(item => item.id === storeId)
|
||
|| (currentStoreStore.loginStore?.id === storeId ? currentStoreStore.loginStore : undefined);
|
||
return store?.name || store?.code || storeId;
|
||
});
|
||
|
||
// ---------- 事件资料 ----------
|
||
|
||
const event = ref<EventItem>();
|
||
const roleOptions = ref<Role[]>([]);
|
||
const isLoading = ref(false);
|
||
const isRemoving = ref(false);
|
||
const removeDialogVisible = ref(false);
|
||
const removeTarget = ref<EventItem>();
|
||
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) {
|
||
await currentStoreStore.loadStoreList();
|
||
return;
|
||
}
|
||
await currentStoreStore.loadLoginStore();
|
||
}
|
||
|
||
async function loadRoleOptions(): Promise<void> {
|
||
try {
|
||
roleOptions.value = await RoleAPI.manageableList(moduleCode);
|
||
} catch (error) {
|
||
console.warn("登记事件角色加载失败", error);
|
||
roleOptions.value = [];
|
||
}
|
||
}
|
||
|
||
async function loadEvent(): Promise<void> {
|
||
const eventId = resolveId();
|
||
if (!eventId) {
|
||
event.value = undefined;
|
||
return;
|
||
}
|
||
|
||
event.value = undefined;
|
||
isLoading.value = true;
|
||
try {
|
||
await loadStoreScope();
|
||
const [eventResult] = await Promise.all([
|
||
EventAPI.detail(eventId),
|
||
loadRoleOptions()
|
||
]);
|
||
event.value = eventResult;
|
||
} catch (error) {
|
||
event.value = undefined;
|
||
console.warn("登记事件详情加载失败", error);
|
||
Message.error("登记事件加载失败");
|
||
} finally {
|
||
isLoading.value = false;
|
||
}
|
||
}
|
||
|
||
// ---------- 展示 ----------
|
||
|
||
function getStatusText(status?: EventStatus): string {
|
||
return ({
|
||
DRAFT: "草稿",
|
||
ACTIVE: "可登记",
|
||
INACTIVE: "不可登记",
|
||
DELETED: "已删除"
|
||
} as Record<string, string>)[status || "ACTIVE"] || "可登记";
|
||
}
|
||
|
||
function getStatusTheme(status?: EventStatus): "default" | "primary" | "danger" {
|
||
if (!status || status === "ACTIVE") {
|
||
return "primary";
|
||
}
|
||
if (status === "DELETED") {
|
||
return "danger";
|
||
}
|
||
return "default";
|
||
}
|
||
|
||
function getValueTypeText(valueType?: EventValueType): string {
|
||
return valueType === "NUMBER" ? "携带数值" : "不携带数值";
|
||
}
|
||
|
||
function getValueUnitText(valueUnit?: EventValueUnit | null): string {
|
||
return valueUnit === "CENT" ? "金额(元)" : valueUnit === "COUNT" ? "次数" : "未配置单位";
|
||
}
|
||
|
||
function getLimitText(value: EventItem): string {
|
||
const limitValue = value.limitValue && 0 < value.limitValue ? Math.floor(value.limitValue) : 1;
|
||
const textMap: Record<EventLimitType, string> = {
|
||
NONE: "不限",
|
||
DAILY_HALF_DAY: `上午和下午各 ${limitValue} 次`,
|
||
INTERVAL_HOUR: `每隔 ${limitValue} 小时`,
|
||
NATURAL_DAY: `每天 ${limitValue} 次`,
|
||
NATURAL_MONTH: `每月 ${limitValue} 次`,
|
||
TOTAL_LIMIT: `事件总计 ${limitValue} 次`,
|
||
CUSTOMER_TOTAL_LIMIT: `单客户总计 ${limitValue} 次`
|
||
};
|
||
return textMap[value.limitType || "NONE"];
|
||
}
|
||
|
||
function getRoleName(code: string): string {
|
||
const role = roleOptions.value.find(item => item.code === code);
|
||
return role?.name || code;
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
// ---------- 删除 ----------
|
||
|
||
function confirmRemoveEvent(): void {
|
||
const currentEvent = event.value;
|
||
if (!currentEvent?.id || !canDeleteEvent.value || isRemoving.value) {
|
||
return;
|
||
}
|
||
|
||
removeTarget.value = currentEvent;
|
||
removeDialogVisible.value = true;
|
||
}
|
||
|
||
async function removeEvent(eventItem: EventItem): Promise<void> {
|
||
const eventId = eventItem.id;
|
||
if (!eventId) {
|
||
return;
|
||
}
|
||
if (isRemoving.value) {
|
||
return;
|
||
}
|
||
|
||
isRemoving.value = true;
|
||
removeDialogVisible.value = false;
|
||
removeTarget.value = undefined;
|
||
try {
|
||
await EventAPI.remove(eventId);
|
||
Message.success("登记事件已删除");
|
||
await router.replace("/management/registration-events");
|
||
} catch {
|
||
Message.error("登记事件删除失败");
|
||
} finally {
|
||
isRemoving.value = false;
|
||
}
|
||
}
|
||
|
||
// ---------- 导航 ----------
|
||
|
||
async function toEventRecordList(): Promise<void> {
|
||
const eventId = event.value?.id || String(route.params.id || "");
|
||
if (!eventId || !canReadEventRecord.value || isPackagePurchaseEvent(event.value)) {
|
||
return;
|
||
}
|
||
await router.push({
|
||
name: "EventRecordList",
|
||
query: {
|
||
eventIds: eventId,
|
||
transitionDepth: String(getCurrentRouteDepth() + 1)
|
||
}
|
||
});
|
||
}
|
||
|
||
function getCurrentRouteDepth(): number {
|
||
const transitionDepth = Array.isArray(route.query.transitionDepth)
|
||
? route.query.transitionDepth[0]
|
||
: route.query.transitionDepth;
|
||
const depth = Number(transitionDepth);
|
||
if (transitionDepth && Number.isInteger(depth) && 0 <= depth && depth <= 20) {
|
||
return depth;
|
||
}
|
||
return Number(route.meta.depth ?? 0);
|
||
}
|
||
|
||
async function toEdit(): Promise<void> {
|
||
const eventId = resolveId();
|
||
if (!canUpdate.value || !eventId) {
|
||
return;
|
||
}
|
||
|
||
// 分栏时右栏直接切到编辑视图,不跳路由,列表上下文保留
|
||
if (pane) {
|
||
emit("edit");
|
||
return;
|
||
}
|
||
|
||
await router.push({
|
||
name: "EventEdit",
|
||
params: { id: eventId },
|
||
query: { transitionDepth: String(Number(route.meta.depth ?? 0) + 1) }
|
||
});
|
||
}
|
||
|
||
function goBack(): void {
|
||
if (pane) {
|
||
pane.close();
|
||
return;
|
||
}
|
||
|
||
void router.back();
|
||
}
|
||
|
||
watch(() => [props.eventId, route.params.id], async () => {
|
||
await loadEvent();
|
||
}, { immediate: true });
|
||
|
||
onMounted(() => {
|
||
if (canUpdate.value) {
|
||
}
|
||
});
|
||
|
||
|
||
</script>
|
||
|
||
<style scoped lang="less">
|
||
.registration-event-detail {
|
||
gap: 1rem;
|
||
min-height: 100vh;
|
||
padding: 0 0 1rem;
|
||
display: flex;
|
||
flex-direction: column;
|
||
|
||
.event-header {
|
||
gap: .75rem;
|
||
margin: 0 1rem;
|
||
padding: 1rem;
|
||
display: flex;
|
||
background: var(--td-bg-color-container);
|
||
box-shadow: var(--td-shadow-1);
|
||
border-radius: 1.4rem;
|
||
|
||
.color {
|
||
width: 3.5rem;
|
||
height: 3.5rem;
|
||
flex: 0 0 auto;
|
||
border-radius: .7rem;
|
||
}
|
||
|
||
.header-content {
|
||
min-width: 0;
|
||
flex: 1;
|
||
}
|
||
|
||
.title-row {
|
||
gap: .5rem;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
|
||
h2 {
|
||
margin: 0;
|
||
font-size: 1.125rem;
|
||
}
|
||
}
|
||
|
||
.description {
|
||
margin-top: .5rem;
|
||
color: var(--td-text-color-secondary);
|
||
line-height: 1.5;
|
||
word-break: break-all;
|
||
}
|
||
}
|
||
|
||
.color-note,
|
||
.tag-list,
|
||
.package-note {
|
||
gap: .4rem;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.package-note {
|
||
flex-direction: column;
|
||
align-items: flex-end;
|
||
|
||
span {
|
||
color: var(--td-text-color-secondary);
|
||
font-size: .8125rem;
|
||
}
|
||
}
|
||
|
||
.color-dot {
|
||
width: 1rem;
|
||
height: 1rem;
|
||
border-radius: 50%;
|
||
}
|
||
|
||
.delete-button {
|
||
width: calc(100% - 2rem);
|
||
margin: 0 1rem;
|
||
}
|
||
}
|
||
|
||
.option-popup {
|
||
padding: 1rem;
|
||
}
|
||
|
||
</style>
|