v1.6.0 #13
@@ -76,6 +76,17 @@ async function listLedger(page: PointLedgerPage, options?: ListOptions): Promise
|
||||
return await axios.post(`${BASE_URI}/ledger/list`, withCurrentStoreId(page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 按流水 ID 查询积分流水。
|
||||
*
|
||||
* 不传 storeId:服务端按当前登录人的门店范围解析,非全局管理员天然只能查本店。
|
||||
*/
|
||||
async function ledgerDetail(id: string): Promise<PointLedger> {
|
||||
return await axios.post(`${BASE_URI}/ledger/detail`, undefined, {
|
||||
params: { id }
|
||||
});
|
||||
}
|
||||
|
||||
/** 人工调整积分,后端使用 adjustRequestId 保证幂等。 */
|
||||
async function adjust(request: PointAdjustRequest): Promise<void> {
|
||||
await axios.post(`${BASE_URI}/adjust`, withCurrentStoreId(request));
|
||||
@@ -177,6 +188,7 @@ export default {
|
||||
detailByCustomerId,
|
||||
detail,
|
||||
listLedger,
|
||||
ledgerDetail,
|
||||
adjust,
|
||||
ruleList,
|
||||
ruleDetail,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
:z-index="20"
|
||||
title="积分流水详情"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
@left-click="goBack"
|
||||
/>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div v-if="customer" v-can="permissionCodes.point.ledgerRead" class="point-ledger-detail">
|
||||
@@ -83,7 +83,7 @@
|
||||
<center-tips v-else :content="getRuleEmptyText()" />
|
||||
</t-cell-group>
|
||||
</template>
|
||||
<t-empty v-else :description="isLoading ? '正在加载积分流水' : '积分流水快照不存在,请从积分流水列表进入'" />
|
||||
<t-empty v-else :description="isLoading ? '正在加载积分流水' : '积分流水不存在或无权查看'" />
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
@@ -92,11 +92,13 @@
|
||||
<script setup lang="ts">
|
||||
import { TimeLabel, Text } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import EventAPI from "@/api/EventAPI";
|
||||
import EventRecordAPI from "@/api/EventRecordAPI";
|
||||
import PointAPI from "@/api/PointAPI";
|
||||
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
|
||||
import { buildLedgerSubPane } from "@/pages/point/component/ledgerPane";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { EventItem } from "@/types/EventItem";
|
||||
import type { EventRecord } from "@/types/EventRecord";
|
||||
@@ -109,10 +111,48 @@ defineOptions({
|
||||
name: "PointLedgerDetail"
|
||||
});
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** 指定流水 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
|
||||
ledgerId?: string;
|
||||
}>(), {
|
||||
ledgerId: ""
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
|
||||
function resolveId(): string {
|
||||
return props.ledgerId || String(route.params.id || "");
|
||||
}
|
||||
|
||||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||||
useExpandToMaster({
|
||||
path: "/management/points/ledger",
|
||||
id: () => resolveId()
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
const pane = usePane();
|
||||
|
||||
/**
|
||||
* 尝试在右栏压入一层子页(分栏的第三层)。
|
||||
*
|
||||
* 接不住时有三种情况:整页打开详情、窄屏、宿主列表没声明子页槽,
|
||||
* 此时返回 false,调用方退回整页跳转。
|
||||
*/
|
||||
function openSub(view: string): boolean {
|
||||
return pane?.openSub(view) ?? false;
|
||||
}
|
||||
|
||||
function goBack(): void {
|
||||
if (pane) {
|
||||
pane.close();
|
||||
return;
|
||||
}
|
||||
|
||||
void router.back();
|
||||
}
|
||||
|
||||
// ---------- 权限 ----------
|
||||
|
||||
const canReadCustomer = computed(() => userStore.hasPermissions(permissionCodes.customer.read));
|
||||
@@ -139,32 +179,6 @@ function isDeletedEventRevokeLedger(value?: PointLedger): boolean {
|
||||
return value?.changeType === "REVOKE" && value?.triggerSourceType === "EVENT_RECORD" && !value.triggerSourceId;
|
||||
}
|
||||
|
||||
function getQueryText(key: string): string {
|
||||
const value = route.query[key];
|
||||
return Array.isArray(value) ? String(value[0] || "") : String(value || "");
|
||||
}
|
||||
|
||||
function parseLedgerSnapshot(): PointLedger | undefined {
|
||||
const snapshotText = getQueryText("snapshot");
|
||||
if (!snapshotText) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const snapshot = JSON.parse(snapshotText) as PointLedger;
|
||||
if (!snapshot || typeof snapshot !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
...snapshot,
|
||||
id: String(route.params.id || snapshot.id || "")
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn("积分流水快照解析失败", error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadOptional<T>(loader: () => Promise<T>, message: string): Promise<T | undefined> {
|
||||
try {
|
||||
return await loader();
|
||||
@@ -175,17 +189,24 @@ async function loadOptional<T>(loader: () => Promise<T>, message: string): Promi
|
||||
}
|
||||
|
||||
async function loadPageData(): Promise<void> {
|
||||
ledger.value = parseLedgerSnapshot();
|
||||
ledger.value = undefined;
|
||||
customer.value = undefined;
|
||||
triggerEvent.value = undefined;
|
||||
eventRecord.value = undefined;
|
||||
hitRule.value = undefined;
|
||||
if (!ledger.value) {
|
||||
const id = resolveId();
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
try {
|
||||
// 流水只追加不修改,缺字段的旧链接一律以服务端这条为准
|
||||
ledger.value = await PointAPI.ledgerDetail(id);
|
||||
if (!ledger.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ledger.value.triggerSourceType === "EVENT_RECORD" && ledger.value.triggerSourceId && canReadEventRecord.value && !isDeletedEventRevoke.value) {
|
||||
eventRecord.value = await loadOptional(() => EventRecordAPI.detail(ledger.value!.triggerSourceId!), "积分流水关联事件记录加载失败");
|
||||
}
|
||||
@@ -200,14 +221,20 @@ async function loadPageData(): Promise<void> {
|
||||
const ruleResult = ledger.value.ruleId && canReadRule.value
|
||||
? loadOptional(() => PointAPI.ruleDetail(ledger.value!.ruleId!), "积分流水命中规则加载失败")
|
||||
: Promise.resolve(undefined);
|
||||
const customerResult = !eventRecord.value?.customer && ledger.value.customerId && canReadCustomer.value
|
||||
? loadOptional(() => CustomerAPI.detail(ledger.value!.customerId!), "积分流水客户加载失败")
|
||||
: Promise.resolve(undefined);
|
||||
// 详情接口已经把客户资料带回来了,只有缺失时才单独补一次
|
||||
const customerResult = ledger.value.customer
|
||||
? Promise.resolve(ledger.value.customer)
|
||||
: !eventRecord.value?.customer && ledger.value.customerId && canReadCustomer.value
|
||||
? loadOptional(() => CustomerAPI.detail(ledger.value!.customerId!), "积分流水客户加载失败")
|
||||
: Promise.resolve(undefined);
|
||||
|
||||
[triggerEvent.value, hitRule.value, customer.value] = await Promise.all([eventResult, ruleResult, customerResult]);
|
||||
if (eventRecord.value?.customer) {
|
||||
customer.value = eventRecord.value.customer;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("积分流水加载失败", error);
|
||||
ledger.value = undefined;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
@@ -312,43 +339,54 @@ function getRuleEmptyText(): string {
|
||||
// ---------- 导航 ----------
|
||||
|
||||
async function toCustomerDetail(): Promise<void> {
|
||||
if (customer.value?.id) {
|
||||
await router.push(`/management/customers/${customer.value.id}`);
|
||||
const id = customer.value?.id;
|
||||
if (!id || openSub(buildLedgerSubPane("customer", id))) {
|
||||
return;
|
||||
}
|
||||
await router.push(`/management/customers/${id}`);
|
||||
}
|
||||
|
||||
async function toPointAccount(): Promise<void> {
|
||||
if (!canReadPointAccount.value || !ledger.value?.accountId) {
|
||||
const accountId = ledger.value?.accountId;
|
||||
if (!canReadPointAccount.value || !accountId) {
|
||||
return;
|
||||
}
|
||||
if (openSub(buildLedgerSubPane("account", accountId, ledger.value?.storeId || ""))) {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
name: "PointAccountDetail",
|
||||
params: { id: ledger.value.accountId },
|
||||
params: { id: accountId },
|
||||
query: {
|
||||
storeId: ledger.value.storeId || "",
|
||||
storeId: ledger.value?.storeId || "",
|
||||
transitionDepth: String(Number(route.meta.depth ?? 0) + 1)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function toEventDetail(): Promise<void> {
|
||||
if (!canReadEvent.value || !triggerEvent.value?.id) {
|
||||
const id = triggerEvent.value?.id;
|
||||
if (!canReadEvent.value || !id) {
|
||||
return;
|
||||
}
|
||||
if (openSub(buildLedgerSubPane("event", id))) {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
name: "EventDetail",
|
||||
params: { id: triggerEvent.value.id },
|
||||
params: { id },
|
||||
query: { transitionDepth: String(Number(route.meta.depth ?? 0) + 1) }
|
||||
});
|
||||
}
|
||||
|
||||
async function toEventRecordDetail(): Promise<void> {
|
||||
if (!eventRecord.value?.id) {
|
||||
const id = eventRecord.value?.id;
|
||||
if (!id || openSub(buildLedgerSubPane("event-record", id))) {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
name: "EventRecordDetail",
|
||||
params: { id: eventRecord.value.id },
|
||||
params: { id },
|
||||
query: {
|
||||
transitionDepth: String(Number(route.meta.depth ?? 0) + 1),
|
||||
changeType: ledger.value?.changeType
|
||||
@@ -357,17 +395,30 @@ async function toEventRecordDetail(): Promise<void> {
|
||||
}
|
||||
|
||||
async function toPointRuleDetail(): Promise<void> {
|
||||
if (!canReadRule.value || !hitRule.value?.id) {
|
||||
const id = hitRule.value?.id;
|
||||
if (!canReadRule.value || !id) {
|
||||
return;
|
||||
}
|
||||
if (openSub(buildLedgerSubPane("rule", id))) {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
name: "PointRuleDetail",
|
||||
params: { id: hitRule.value.id },
|
||||
params: { id },
|
||||
query: { transitionDepth: String(Number(route.meta.depth ?? 0) + 1) }
|
||||
});
|
||||
}
|
||||
|
||||
watch(() => [route.params.id, route.query.snapshot], async () => {
|
||||
/**
|
||||
* 重载判据:两个来源拼成一个字符串再 watch。
|
||||
*
|
||||
* 不能直接 watch `[props.ledgerId, route.params.id]`:读 `route.params.id` 会依赖
|
||||
* 整个 `params` 对象,分栏里改个 query(进子页、返回)也会被连带触发,
|
||||
* `loadPageData` 一进来就把 ledger 置空重拉,看起来就是详情页自己刷新了一遍。
|
||||
*/
|
||||
const reloadKey = computed(() => `${props.ledgerId}|${String(route.params.id || "")}`);
|
||||
|
||||
watch(reloadKey, async () => {
|
||||
await loadPageData();
|
||||
}, { immediate: true });
|
||||
</script>
|
||||
|
||||
+149
-135
@@ -7,117 +7,136 @@
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
/>
|
||||
<main v-can="permissionCodes.point.ledgerRead" class="tui-page-content scroll column list">
|
||||
<t-pull-down-refresh
|
||||
class="pull-refresh"
|
||||
v-model="isRefreshing"
|
||||
:refresh-timeout="30000"
|
||||
@refresh="reload"
|
||||
@scrolltolower="load"
|
||||
>
|
||||
<div class="filters glass">
|
||||
<t-input
|
||||
v-model="customerKeyword"
|
||||
class="customer"
|
||||
type="search"
|
||||
borderless
|
||||
placeholder="输入客户编码或姓名"
|
||||
@clear="searchCustomer"
|
||||
@enter="searchCustomer"
|
||||
@input="searchCustomer"
|
||||
>
|
||||
<template #suffix-icon>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
theme="primary"
|
||||
variant="outline"
|
||||
content="选择客户"
|
||||
@click.stop="selectorVisible = true"
|
||||
/>
|
||||
</template>
|
||||
</t-input>
|
||||
<t-dropdown-menu class="menus">
|
||||
<t-dropdown-item
|
||||
v-model="changeTypeFilter"
|
||||
label="流水类型"
|
||||
:options="changeTypeOptions"
|
||||
@change="selectChangeType"
|
||||
/>
|
||||
<t-dropdown-item
|
||||
v-model="dateFilter"
|
||||
:label="dateFilterLabel"
|
||||
:options="dateFilterOptions"
|
||||
@change="selectDateFilter"
|
||||
/>
|
||||
</t-dropdown-menu>
|
||||
</div>
|
||||
<div class="list-wrap">
|
||||
<card-container v-if="customer" class="customer">
|
||||
<customer-profile-card :customer="customer" />
|
||||
</card-container>
|
||||
<t-cell-group class="summary" theme="card">
|
||||
<t-cell
|
||||
title="开始时间"
|
||||
:note="dateRange[0] || '-'"
|
||||
arrow
|
||||
@click="openStartDate"
|
||||
/>
|
||||
<t-cell
|
||||
title="结束时间"
|
||||
:note="dateRange[1] || '-'"
|
||||
arrow
|
||||
@click="openEndDate"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="pageResult.list.length" class="list" theme="card">
|
||||
<t-cell
|
||||
v-entrance-transition="{ step: 30 }"
|
||||
v-for="item in pageResult.list"
|
||||
:key="item.id"
|
||||
class="item"
|
||||
:arrow="!!item.id"
|
||||
:hover="!!item.id"
|
||||
@click="toDetail(item)"
|
||||
<master-detail-page
|
||||
v-can="permissionCodes.point.ledgerRead"
|
||||
class="list"
|
||||
:split="isWide"
|
||||
:selected="!!selectedId"
|
||||
:direction="paneDirection"
|
||||
:sub="!!subView"
|
||||
>
|
||||
<template #master>
|
||||
<t-pull-down-refresh
|
||||
class="pull-refresh"
|
||||
v-model="isRefreshing"
|
||||
:refresh-timeout="30000"
|
||||
@refresh="reload"
|
||||
@scrolltolower="load"
|
||||
>
|
||||
<div class="filters glass">
|
||||
<t-input
|
||||
v-model="customerKeyword"
|
||||
class="customer"
|
||||
type="search"
|
||||
borderless
|
||||
placeholder="输入客户编码或姓名"
|
||||
@clear="searchCustomer"
|
||||
@enter="searchCustomer"
|
||||
@input="searchCustomer"
|
||||
>
|
||||
<template #leftIcon>
|
||||
<t-image
|
||||
v-if="getCustomerPhotoURL(item.customer!, 64)"
|
||||
:src="getCustomerPhotoURL(item.customer!, 64)"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
<template #suffix-icon>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
theme="primary"
|
||||
variant="outline"
|
||||
content="选择客户"
|
||||
@click.stop="selectorVisible = true"
|
||||
/>
|
||||
<div v-else class="avatar fallback" v-text="(item.customer?.name || item.customer?.code || '客').slice(0, 1)" />
|
||||
</template>
|
||||
<template #title>
|
||||
<div class="title">
|
||||
<t-tag
|
||||
class="type-icon"
|
||||
:theme="item.pointDelta && 0 < item.pointDelta ? 'success' : 'danger'"
|
||||
:content="getLedgerShortType(item)"
|
||||
variant="outline"
|
||||
</t-input>
|
||||
<t-dropdown-menu class="menus">
|
||||
<t-dropdown-item
|
||||
v-model="changeTypeFilter"
|
||||
label="流水类型"
|
||||
:options="changeTypeOptions"
|
||||
@change="selectChangeType"
|
||||
/>
|
||||
<t-dropdown-item
|
||||
v-model="dateFilter"
|
||||
:label="dateFilterLabel"
|
||||
:options="dateFilterOptions"
|
||||
@change="selectDateFilter"
|
||||
/>
|
||||
</t-dropdown-menu>
|
||||
</div>
|
||||
<div class="list-wrap">
|
||||
<card-container v-if="customer" class="customer">
|
||||
<customer-profile-card :customer="customer" />
|
||||
</card-container>
|
||||
<t-cell-group class="summary" theme="card">
|
||||
<t-cell
|
||||
title="开始时间"
|
||||
:note="dateRange[0] || '-'"
|
||||
arrow
|
||||
@click="openStartDate"
|
||||
/>
|
||||
<t-cell
|
||||
title="结束时间"
|
||||
:note="dateRange[1] || '-'"
|
||||
arrow
|
||||
@click="openEndDate"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="pageResult.list.length" class="list" theme="card">
|
||||
<t-cell
|
||||
v-entrance-transition="{ step: 30 }"
|
||||
v-for="item in pageResult.list"
|
||||
:key="item.id"
|
||||
class="item"
|
||||
:arrow="!!item.id"
|
||||
:hover="!!item.id"
|
||||
@click="toDetail(item)"
|
||||
>
|
||||
<template #leftIcon>
|
||||
<t-image
|
||||
v-if="getCustomerPhotoURL(item.customer!, 64)"
|
||||
:src="getCustomerPhotoURL(item.customer!, 64)"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div class="name" v-text="item.customer?.name" />
|
||||
</div>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<div>
|
||||
<span>时间:</span>
|
||||
<time-label :timestamp="item.occurredAt" underline />
|
||||
<div v-else class="avatar fallback" v-text="(item.customer?.name || item.customer?.code || '客').slice(0, 1)" />
|
||||
</template>
|
||||
<template #title>
|
||||
<div class="title">
|
||||
<t-tag
|
||||
class="type-icon"
|
||||
:theme="item.pointDelta && 0 < item.pointDelta ? 'success' : 'danger'"
|
||||
:content="getLedgerShortType(item)"
|
||||
variant="outline"
|
||||
/>
|
||||
<div class="name" v-text="item.customer?.name" />
|
||||
</div>
|
||||
<div v-text="`余额:${formatPointValue(item.balanceBefore)} → ${formatPointValue(item.balanceAfter)}`" />
|
||||
<div v-text="item.remark" />
|
||||
</div>
|
||||
</template>
|
||||
<template #note>
|
||||
<div class="delta keep-text" :class="getLedgerTheme(item)" v-text="getLedgerDelta(item)" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<center-tips :content="loadStateText" />
|
||||
</div>
|
||||
</t-pull-down-refresh>
|
||||
</main>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<div>
|
||||
<span>时间:</span>
|
||||
<time-label :timestamp="item.occurredAt" underline />
|
||||
</div>
|
||||
<div v-text="`余额:${formatPointValue(item.balanceBefore)} → ${formatPointValue(item.balanceAfter)}`" />
|
||||
<div v-text="item.remark" />
|
||||
</div>
|
||||
</template>
|
||||
<template #note>
|
||||
<div class="delta keep-text" :class="getLedgerTheme(item)" v-text="getLedgerDelta(item)" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<center-tips :content="loadStateText" />
|
||||
</div>
|
||||
</t-pull-down-refresh>
|
||||
</template>
|
||||
<template #detail>
|
||||
<point-ledger-detail :key="`detail-${selectedId}`" :ledger-id="selectedId" />
|
||||
</template>
|
||||
<!--
|
||||
第三层:详情点进子页(客户 / 积分账户 / 事件 / 事件记录 / 积分规则)时,
|
||||
列表整列滑出、详情退到主栏,右栏换成那个子页。
|
||||
-->
|
||||
<template #sub>
|
||||
<ledger-sub-view :key="subView" :view="subView" />
|
||||
</template>
|
||||
</master-detail-page>
|
||||
<customer-selector
|
||||
v-model="selectedCustomerId"
|
||||
v-model:visible="selectorVisible"
|
||||
@@ -152,11 +171,15 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { DropdownValue } from "tdesign-mobile-vue";
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import { TimeLabel, Toolkit } from "timi-web";
|
||||
import { type PageResult, useUserStore } from "timi-web-api";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import PointAPI from "@/api/PointAPI";
|
||||
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||
import PointLedgerDetail from "@/pages/point/PointLedgerDetail.vue";
|
||||
import LedgerSubView from "@/pages/point/component/LedgerSubView.vue";
|
||||
import { getLedgerSubRoute, parseLedgerSubPane } from "@/pages/point/component/ledgerPane";
|
||||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { PointLedger, PointLedgerChangeType, PointLedgerPage } from "@/types/Point";
|
||||
@@ -172,10 +195,27 @@ defineOptions({
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const currentStoreStore = useCurrentStoreStore();
|
||||
|
||||
// ---------- 分栏导航 ----------
|
||||
|
||||
// 选中项、切换方向、关闭逻辑、转屏、query 同步都在这里;积分流水没有内联编辑视图
|
||||
const { selectedId, subView, paneDirection, isWide, openDetail } = useMasterDetailPane({
|
||||
path: "/management/points/ledger",
|
||||
detail: detailRoute
|
||||
});
|
||||
|
||||
/**
|
||||
* 转屏变窄时右栏不再渲染,按右栏当前那一层落到整页路由。
|
||||
*
|
||||
* 子页落到各自模块的整页,详情落到流水自己的详情页。
|
||||
*/
|
||||
function detailRoute(id: string): string {
|
||||
const sub = parseLedgerSubPane(subView.value || "");
|
||||
return sub ? getLedgerSubRoute(sub) : `/management/points/ledger/${id}`;
|
||||
}
|
||||
|
||||
// ---------- 筛选 ----------
|
||||
|
||||
const isGlobalManager = computed(() => userStore.hasRoles(gaoRoleCodes.globalManager));
|
||||
@@ -410,38 +450,12 @@ function getLedgerTheme(item: PointLedger): string {
|
||||
return item.pointDelta && 0 < item.pointDelta ? "increase" : "decrease";
|
||||
}
|
||||
|
||||
async function toDetail(item: PointLedger): Promise<void> {
|
||||
function toDetail(item: PointLedger): void {
|
||||
if (!item.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const snapshot: PointLedger = {
|
||||
id: item.id,
|
||||
accountId: item.accountId,
|
||||
storeId: item.storeId,
|
||||
customerId: item.customerId,
|
||||
changeType: item.changeType,
|
||||
direction: item.direction,
|
||||
pointDelta: item.pointDelta,
|
||||
balanceBefore: item.balanceBefore,
|
||||
balanceAfter: item.balanceAfter,
|
||||
ruleId: item.ruleId,
|
||||
triggerSourceType: item.triggerSourceType,
|
||||
triggerSourceId: item.triggerSourceId,
|
||||
salesOrderId: item.salesOrderId,
|
||||
groovyScriptVersionId: item.groovyScriptVersionId,
|
||||
ruleSnapshot: item.ruleSnapshot,
|
||||
sourcePayload: item.sourcePayload,
|
||||
idempotencyKey: item.idempotencyKey,
|
||||
remark: item.remark,
|
||||
operatorUserId: item.operatorUserId,
|
||||
occurredAt: item.occurredAt
|
||||
};
|
||||
await router.push({
|
||||
name: "PointLedgerDetail",
|
||||
params: { id: item.id },
|
||||
query: { snapshot: JSON.stringify(snapshot) }
|
||||
});
|
||||
openDetail(item.id);
|
||||
}
|
||||
|
||||
function buildUnixRange(): [number, number] {
|
||||
|
||||
@@ -191,8 +191,11 @@ defineOptions({
|
||||
const props = withDefaults(defineProps<{
|
||||
/** 指定积分规则 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
|
||||
ruleId?: string;
|
||||
/** 在分栏中新增积分规则。 */
|
||||
create?: boolean;
|
||||
}>(), {
|
||||
ruleId: ""
|
||||
ruleId: "",
|
||||
create: false
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
@@ -200,6 +203,9 @@ const currentId = computed(() => props.ruleId || String(route.params.id || ""));
|
||||
|
||||
const routeNavBarTitle = computed(() => {
|
||||
// 内联时路由停在列表页,标题不能只看 route.name
|
||||
if (props.create) {
|
||||
return "新增积分规则";
|
||||
}
|
||||
if (props.ruleId) {
|
||||
return "编辑积分规则";
|
||||
}
|
||||
@@ -215,11 +221,10 @@ const routeNavBarTitle = computed(() => {
|
||||
const router = useRouter();
|
||||
|
||||
// 竖屏整页编辑转横屏:回到分栏,并用 view=edit 让列表页把右栏还原成编辑。
|
||||
// 新增(Create)返回空 id,不触发——右栏没有可依附的选中项
|
||||
useExpandToMaster({
|
||||
path: "/management/points/rules",
|
||||
id: () => (route.name === "PointRuleCreate" ? "" : currentId.value),
|
||||
query: { view: "edit" }
|
||||
id: () => (route.name === "PointRuleCreate" ? "__create__" : currentId.value),
|
||||
query: route.name === "PointRuleCreate" ? {} : { view: "edit" }
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
const pane = usePane();
|
||||
|
||||
@@ -86,7 +86,8 @@
|
||||
</t-pull-down-refresh>
|
||||
</template>
|
||||
<template #detail>
|
||||
<point-rule-edit v-if="editing" :key="`edit-${selectedId}`" :rule-id="selectedId" />
|
||||
<point-rule-edit v-if="selectedId === createPaneId" key="create" create />
|
||||
<point-rule-edit v-else-if="editing" :key="`edit-${selectedId}`" :rule-id="selectedId" />
|
||||
<point-rule-detail
|
||||
v-else
|
||||
:key="`detail-${selectedId}-${detailVersion}`"
|
||||
@@ -121,12 +122,13 @@ defineOptions({
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const createPaneId = "__create__";
|
||||
|
||||
// 选中项、切换方向、关闭逻辑、转屏、query 同步都在这里
|
||||
const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
|
||||
useMasterDetailPane({
|
||||
path: "/management/points/rules",
|
||||
detail: id => `/management/points/rules/${id}`,
|
||||
detail: id => id === createPaneId ? "/management/points/rules/create" : `/management/points/rules/${id}`,
|
||||
edit: id => `/management/points/rules/${id}/edit`
|
||||
});
|
||||
const userStore = useUserStore();
|
||||
@@ -279,6 +281,12 @@ watch(keyword, () => {
|
||||
reloadByKeyword();
|
||||
});
|
||||
|
||||
watch(selectedId, async (id, previousId) => {
|
||||
if (previousId === createPaneId && id !== createPaneId) {
|
||||
await reload();
|
||||
}
|
||||
});
|
||||
|
||||
// ---------- 事件名称 ----------
|
||||
|
||||
const eventList = ref<EventItem[]>([]);
|
||||
@@ -340,6 +348,10 @@ function getStatusTheme(status?: PointRuleStatus): "default" | "success" | "warn
|
||||
}
|
||||
|
||||
async function toCreate(): Promise<void> {
|
||||
if (isWide.value) {
|
||||
openDetail(createPaneId);
|
||||
return;
|
||||
}
|
||||
await router.push({ name: "PointRuleCreate" });
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<customer-detail
|
||||
v-if="kind === 'customer'"
|
||||
:customer-id="arg"
|
||||
/>
|
||||
<point-account-detail
|
||||
v-else-if="kind === 'account'"
|
||||
:account-id="arg"
|
||||
:store-id="extra"
|
||||
/>
|
||||
<event-detail
|
||||
v-else-if="kind === 'event'"
|
||||
:event-id="arg"
|
||||
/>
|
||||
<event-record-detail
|
||||
v-else-if="kind === 'event-record'"
|
||||
:record-id="arg"
|
||||
/>
|
||||
<point-rule-detail
|
||||
v-else-if="kind === 'rule'"
|
||||
:rule-id="arg"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import CustomerDetail from "@/pages/customer/CustomerDetail.vue";
|
||||
import EventDetail from "@/pages/event/EventDetail.vue";
|
||||
import EventRecordDetail from "@/pages/event/EventRecordDetail.vue";
|
||||
import PointAccountDetail from "@/pages/point/PointAccountDetail.vue";
|
||||
import PointRuleDetail from "@/pages/point/PointRuleDetail.vue";
|
||||
import { parseLedgerSubPane } from "@/pages/point/component/ledgerPane";
|
||||
|
||||
defineOptions({ name: "LedgerSubView" });
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** 子页标识,形如 `customer:698f`、`account:698f:12`。 */
|
||||
view?: string;
|
||||
}>(), {
|
||||
view: ""
|
||||
});
|
||||
|
||||
const pane = computed(() => parseLedgerSubPane(props.view));
|
||||
const kind = computed(() => pane.value?.kind || "");
|
||||
const arg = computed(() => pane.value?.arg || "");
|
||||
const extra = computed(() => pane.value?.extra || "");
|
||||
</script>
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* 积分流水详情在右栏压入子页时的标识约定:`<kind>[:<arg>[:<extra>]]`。
|
||||
*
|
||||
* 这些子页都属于别的模块,宿主(积分流水列表页)按标识直接渲染对应页面,
|
||||
* 与交易订单的 `orderPane` 是同一套思路,只是这里的上一级固定是当前流水。
|
||||
*/
|
||||
export type LedgerSubKind = "customer" | "account" | "event" | "event-record" | "rule";
|
||||
|
||||
export type LedgerSubPane = {
|
||||
kind: LedgerSubKind;
|
||||
/** 主参数:目标对象的 id。 */
|
||||
arg: string;
|
||||
/** 附加参数:目前只有积分账户详情需要带上门店 id。 */
|
||||
extra: string;
|
||||
};
|
||||
|
||||
const LEDGER_SUB_KINDS: LedgerSubKind[] = ["customer", "account", "event", "event-record", "rule"];
|
||||
|
||||
function isLedgerSubKind(value: string): value is LedgerSubKind {
|
||||
return LEDGER_SUB_KINDS.includes(value as LedgerSubKind);
|
||||
}
|
||||
|
||||
/** 拼接子页标识,调用方通常是流水详情里的跳转函数。 */
|
||||
export function buildLedgerSubPane(kind: LedgerSubKind, arg: string, extra = ""): string {
|
||||
return extra ? `${kind}:${arg}:${extra}` : `${kind}:${arg}`;
|
||||
}
|
||||
|
||||
/** 解析子页标识;不认识的标识返回 null,调用方应改走整页路由。 */
|
||||
export function parseLedgerSubPane(value: string): LedgerSubPane | null {
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
const [kind, arg = "", extra = ""] = value.split(":");
|
||||
if (!isLedgerSubKind(kind) || !arg) {
|
||||
return null;
|
||||
}
|
||||
return { kind, arg, extra };
|
||||
}
|
||||
|
||||
/**
|
||||
* 子页对应的整页路由。
|
||||
*
|
||||
* 转屏变窄后右栏不再渲染,靠它把用户留在正在看的那一层;
|
||||
* 也用于 `openSub()` 没接住时的兜底。
|
||||
*/
|
||||
export function getLedgerSubRoute(pane: LedgerSubPane): string {
|
||||
const { kind, arg, extra } = pane;
|
||||
switch (kind) {
|
||||
case "customer": return `/management/customers/${arg}`;
|
||||
case "account": return `/management/points/account/${arg}${extra ? `?storeId=${encodeURIComponent(extra)}` : ""}`;
|
||||
case "event": return `/management/registration-events/${arg}`;
|
||||
case "event-record": return `/management/registration-event-records/${arg}`;
|
||||
case "rule": return `/management/points/rules/${arg}`;
|
||||
default: return "/management/points/ledger";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user