395 lines
13 KiB
Vue
395 lines
13 KiB
Vue
<template>
|
|
<div class="tui-page-layout tui-navbar recycle-ledger-list">
|
|
<t-navbar fixed :z-index="20" title="回收物流水" left-arrow @left-click="$router.back()" />
|
|
<master-detail-page v-can="permissionCodes.recycleAccount.read" class="list" :split="isWide" :selected="!!selectedId" :direction="paneDirection" :sub="!!orderPane?.view">
|
|
<template #master>
|
|
<t-pull-down-refresh
|
|
v-model="refreshing"
|
|
class="pull-refresh"
|
|
:refresh-timeout="30000"
|
|
@refresh="reload"
|
|
@scrolltolower="loadMore"
|
|
>
|
|
<div class="filters glass">
|
|
<t-input
|
|
v-model="keyword"
|
|
borderless
|
|
clearable
|
|
placeholder="搜索客户姓名、拼音或编码"
|
|
@enter="reload"
|
|
>
|
|
<template #suffix-icon>
|
|
<t-button
|
|
size="extra-small"
|
|
theme="primary"
|
|
variant="outline"
|
|
:content="customerId ? '更换客户' : '选择客户'"
|
|
@click.stop="customerVisible = true"
|
|
/>
|
|
</template>
|
|
</t-input>
|
|
<t-dropdown-menu class="menus">
|
|
<t-dropdown-item
|
|
v-model="dateType"
|
|
:label="dateLabel"
|
|
:options="dateOptions"
|
|
@change="selectDate"
|
|
/>
|
|
<t-dropdown-item
|
|
v-model="bizType"
|
|
label="流水类型"
|
|
:options="typeOptions"
|
|
@change="reload"
|
|
/>
|
|
</t-dropdown-menu>
|
|
</div>
|
|
<t-cell-group v-if="customerId || dateType === 'custom'" theme="card">
|
|
<t-cell v-if="customerId" title="已选择客户" note="清除" arrow @click="clearCustomer" />
|
|
<template v-if="dateType === 'custom'">
|
|
<t-cell title="开始时间" :note="dateRange[0] || '-'" arrow @click="openDate(false)" />
|
|
<t-cell title="结束时间" :note="dateRange[1] || '-'" arrow @click="openDate(true)" />
|
|
</template>
|
|
</t-cell-group>
|
|
<t-cell-group v-if="records.length" class="records empty-cell-title-margin" theme="card">
|
|
<t-cell v-for="record in records" :key="record.id" class="item" :arrow="!!record.id" :hover="!!record.id" @click="openRecord(record)" v-entrance-transition="{ step: 30 }">
|
|
<template #leftIcon>
|
|
<t-image
|
|
v-if="getCustomerPhotoURL(record.customer ?? undefined, 64)"
|
|
class="avatar"
|
|
:src="getCustomerPhotoURL(record.customer ?? undefined, 64)"
|
|
:alt="record.customerName || record.customerCode || '客户头像'"
|
|
fit="cover"
|
|
/>
|
|
<div v-else class="avatar fallback" v-text="(record.customerName || record.customerCode || '客').slice(0, 1)" />
|
|
</template>
|
|
<template #title>
|
|
<div class="title">
|
|
<span class="actor" v-text="record.customerName || record.customerCode || '未知客户'" />
|
|
<strong class="operation" :class="getTypeClass(record.bizType)" v-text="getRecycleLedgerTypeText(record.bizType)" />
|
|
<strong class="name clip-text" v-text="record.recycleName || '回收物'" />
|
|
</div>
|
|
</template>
|
|
<template #description>
|
|
<div class="description">
|
|
<time-label :timestamp="record.createdAt" underline />
|
|
<div class="deltas">
|
|
<span v-if="!isReservation(record.bizType)">余额 <span class="value" :class="getDeltaClass(record.balanceDelta)" v-text="quantityText(record.balanceDelta, record.recycleUnit)" /></span>
|
|
<span v-else>预占 <span class="value" :class="getDeltaClass(record.reservedDelta)" v-text="quantityText(record.reservedDelta, record.recycleUnit)" /></span>
|
|
</div>
|
|
</div>
|
|
<div v-if="record.reason" class="reason" v-text="record.reason" />
|
|
</template>
|
|
</t-cell>
|
|
</t-cell-group>
|
|
<center-tips v-else :content="loading ? '正在加载回收物流水' : '暂无回收物流水'" />
|
|
<center-tips
|
|
v-if="records.length"
|
|
:content="loading ? '正在加载' : noMore ? '已经到底了' : '上拉加载更多'"
|
|
/>
|
|
</t-pull-down-refresh>
|
|
</template>
|
|
<template #detail>
|
|
<sales-order-detail v-if="orderPane" :key="`order-${orderPane.orderId}`" :order-id="orderPane.orderId" />
|
|
<recycle-account v-else-if="accountId" :key="`account-${accountId}`" :initial-customer-id="accountId" />
|
|
<recycle-ledger-detail v-else :key="`detail-${selectedId}-${detailVersion}`" :record-id="selectedId" />
|
|
</template>
|
|
<template #sub>
|
|
<sales-order-sub-view
|
|
v-if="orderPane?.view"
|
|
:key="`sub-${orderPane.view}`"
|
|
:view="orderPane.view"
|
|
:order-id="orderPane.orderId"
|
|
@saved="handleOrderSubSaved"
|
|
/>
|
|
</template>
|
|
</master-detail-page>
|
|
<customer-selector
|
|
v-model="customerId"
|
|
v-model:visible="customerVisible"
|
|
@change="reload"
|
|
/>
|
|
<t-popup v-model="dateVisible" placement="bottom">
|
|
<t-date-time-picker
|
|
v-if="dateVisible"
|
|
v-model="dateDraft"
|
|
format="YYYY-MM-DD HH:mm"
|
|
:mode="['date', 'minute']"
|
|
:title="editingEnd ? '结束时间' : '开始时间'"
|
|
@cancel="dateVisible = false" @confirm="confirmDate"
|
|
/>
|
|
</t-popup>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { MasterDetailPage, providePane, useMasterDetailPane } from "timi-tdesign-mobile";
|
|
import RecycleLedgerDetail from "@/pages/recycle/RecycleLedgerDetail.vue";
|
|
import RecycleAccount from "@/pages/recycle/RecycleAccount.vue";
|
|
import SalesOrderDetail from "@/pages/salesOrder/SalesOrderDetail.vue";
|
|
import SalesOrderSubView from "@/pages/salesOrder/component/SalesOrderSubView.vue";
|
|
import { buildOrderPaneView, getOrderPaneRoute, parseOrderPaneView } from "@/pages/salesOrder/component/orderPane";
|
|
import type { DropdownValue } from "tdesign-mobile-vue";
|
|
import { Time, TimeLabel } from "timi-web";
|
|
import RecycleAPI from "@/api/RecycleAPI";
|
|
import CustomerSelector from "@/components/CustomerSelector.vue";
|
|
import type { RecycleLedger } from "@/types/Recycle";
|
|
import { buildPresetDateRange, parseDateTime } from "@/utils/date";
|
|
import { DATE_FILTER_OPTIONS as dateOptions, type DateFilterType } from "@/utils/dateFilter";
|
|
import { getErrorMessage } from "@/utils/error";
|
|
import { getCustomerPhotoURL } from "@/utils/customer";
|
|
import { Message } from "@/utils/message";
|
|
import { permissionCodes } from "@/utils/permission";
|
|
import { getRecycleLedgerTypeText, getRecycleQuantityText } from "@/utils/recycle";
|
|
|
|
defineOptions({ name: "RecycleLedgerList" });
|
|
const route = useRoute();
|
|
const customerId = ref(typeof route.query.customerId === "string" ? route.query.customerId : "");
|
|
const { selectedId, detailVersion, subView, paneDirection, isWide, openDetail, openSub, close } = useMasterDetailPane({
|
|
path: "/product/recycle-payments",
|
|
detail: id => {
|
|
const order = parseOrderPaneView(subView.value || "");
|
|
if (order) return getOrderPaneRoute(order);
|
|
if (accountId.value) return `/management/recycle-accounts?customerId=${encodeURIComponent(accountId.value)}`;
|
|
const query = new URLSearchParams();
|
|
if (customerId.value) query.set("customerId", customerId.value);
|
|
const depth = Number(route.query.transitionDepth || route.meta.depth || 0);
|
|
query.set("transitionDepth", String(depth + 1));
|
|
return `/product/recycle-ledgers/${encodeURIComponent(id)}?${query}`;
|
|
}
|
|
});
|
|
const orderPane = computed(() => parseOrderPaneView(subView.value || ""));
|
|
const accountId = computed(() => {
|
|
const view = subView.value || "";
|
|
return view.startsWith("recycle-account:") ? view.slice("recycle-account:".length) : "";
|
|
});
|
|
|
|
providePane({
|
|
close: saved => close(saved),
|
|
openSub: view => openSub(orderPane.value && !parseOrderPaneView(view) ? buildOrderPaneView(orderPane.value.orderId, view) : view)
|
|
});
|
|
|
|
watch(orderPane, (next, previous) => {
|
|
if (previous?.view && !next?.view) paneDirection.value = "back";
|
|
});
|
|
|
|
function handleOrderSubSaved(kind: string, id: string): void {
|
|
const order = orderPane.value;
|
|
if (!order || !id) return;
|
|
if (kind === "fulfillment-create") openSub(buildOrderPaneView(order.orderId, `fulfillment-detail:${id}`));
|
|
if (kind === "recycle-register") openSub(buildOrderPaneView(order.orderId, `recycle-payment-detail:${order.view.split(":")[1] || ""}:${id}`));
|
|
}
|
|
|
|
const customerVisible = ref(false);
|
|
const keyword = ref("");
|
|
const bizType = ref("ALL");
|
|
const dateType = ref<DateFilterType>("all");
|
|
const dateRange = ref<[string, string]>(["", ""]);
|
|
const dateVisible = ref(false);
|
|
const dateDraft = ref("");
|
|
const editingEnd = ref(false);
|
|
const dateLabel = computed(() => dateOptions.find(item => item.value === dateType.value)?.label || "时间范围");
|
|
const typeOptions = [
|
|
{ label: "全部类型", value: "ALL" }, ...[
|
|
"FULFILLMENT_YIELD",
|
|
"FULFILLMENT_REVOKE",
|
|
"MANUAL",
|
|
"PAYMENT_RESERVE",
|
|
"PAYMENT_RELEASE",
|
|
"PAYMENT_VERIFY",
|
|
"PAYMENT_REVOKE"
|
|
].map(value => ({ label: getRecycleLedgerTypeText(value), value }))
|
|
];
|
|
const records = ref<RecycleLedger[]>([]);
|
|
const loading = ref(false);
|
|
const refreshing = ref(false);
|
|
const noMore = ref(false);
|
|
let version = 0;
|
|
let index = 0;
|
|
|
|
function openRecord(record: RecycleLedger): void {
|
|
if (record.id) openDetail(record.id);
|
|
}
|
|
|
|
function isReservation(type?: string): boolean {
|
|
return type === "PAYMENT_RESERVE" || type === "PAYMENT_RELEASE";
|
|
}
|
|
|
|
function quantityText(value?: number | string, unit?: string): string {
|
|
return `${0 < Number(value ?? 0) ? "+" : ""}${getRecycleQuantityText(value ?? 0, unit)}`;
|
|
}
|
|
|
|
function getDeltaClass(value?: number | string): string {
|
|
const amount = Number(value ?? 0);
|
|
return 0 < amount ? "positive" : amount < 0 ? "negative" : "";
|
|
}
|
|
|
|
function getTypeClass(type?: string): string {
|
|
return ({
|
|
FULFILLMENT_YIELD: "yield",
|
|
FULFILLMENT_REVOKE: "fulfillment-revoke",
|
|
MANUAL: "manual",
|
|
ADJUST: "manual",
|
|
PAYMENT_RESERVE: "reserve",
|
|
PAYMENT_RELEASE: "release",
|
|
PAYMENT_VERIFY: "verify",
|
|
PAYMENT_REVOKE: "payment-revoke"
|
|
} as Record<string, string>)[type || ""] || "";
|
|
}
|
|
|
|
async function loadMore(): Promise<void> {
|
|
if (loading.value || noMore.value) return;
|
|
const token = version;
|
|
loading.value = true;
|
|
try {
|
|
const result = await RecycleAPI.ledgerList({
|
|
index, size: 20, customerId: customerId.value || undefined, keyword: keyword.value || undefined,
|
|
bizType: bizType.value === "ALL" ? undefined : bizType.value,
|
|
beginAt: dateRange.value[0] ? Time.toTimestamp(parseDateTime(dateRange.value[0], false)) : undefined,
|
|
endAt: dateRange.value[1] ? Time.toTimestamp(parseDateTime(dateRange.value[1], true)) : undefined
|
|
});
|
|
if (token !== version) return;
|
|
records.value.push(...result.list);
|
|
index++;
|
|
noMore.value = !(records.value.length < result.total) || !result.list.length;
|
|
} catch (error) {
|
|
if (token === version) Message.error(getErrorMessage(error, "回收物流水加载失败"));
|
|
} finally {
|
|
if (token === version) {
|
|
loading.value = false;
|
|
refreshing.value = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
async function reload(): Promise<void> {
|
|
version++;
|
|
index = 0;
|
|
records.value = [];
|
|
loading.value = false;
|
|
noMore.value = false;
|
|
await loadMore();
|
|
}
|
|
|
|
async function clearCustomer(): Promise<void> {
|
|
customerId.value = "";
|
|
await reload();
|
|
}
|
|
|
|
async function selectDate(value: DropdownValue): Promise<void> {
|
|
if (Array.isArray(value)) return;
|
|
dateType.value = String(value) as DateFilterType;
|
|
dateRange.value = dateType.value === "custom" ? ["", ""] : buildPresetDateRange(dateType.value);
|
|
await reload();
|
|
}
|
|
|
|
function openDate(end: boolean): void {
|
|
editingEnd.value = end;
|
|
dateDraft.value = dateRange.value[end ? 1 : 0];
|
|
dateVisible.value = true;
|
|
}
|
|
|
|
async function confirmDate(value?: string | number): Promise<void> {
|
|
dateVisible.value = false;
|
|
const next = String(value || dateDraft.value);
|
|
const [begin, end] = editingEnd.value ? [dateRange.value[0], next] : [next, dateRange.value[1]];
|
|
if (begin && end && parseDateTime(end, true) < parseDateTime(begin, false)) {
|
|
Message.warning("结束时间不能早于开始时间");
|
|
return;
|
|
}
|
|
dateRange.value = [begin, end];
|
|
await reload();
|
|
}
|
|
|
|
onMounted(async () => await reload());
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
.recycle-ledger-list {
|
|
.records {
|
|
margin: 0;
|
|
|
|
.item {
|
|
padding: .625rem;
|
|
min-width: 0;
|
|
|
|
.avatar {
|
|
width: 3.5rem;
|
|
height: 3.5rem;
|
|
}
|
|
|
|
.title {
|
|
gap: .25rem;
|
|
flex: 1;
|
|
display: flex;
|
|
min-width: 0;
|
|
max-width: 100%;
|
|
font-size: .75rem;
|
|
align-items: center;
|
|
white-space: nowrap;
|
|
|
|
.actor {
|
|
flex: 0 0 auto;
|
|
color: var(--td-text-color-brand);
|
|
}
|
|
|
|
.operation {
|
|
flex: 0 0 auto;
|
|
color: var(--operation-color, var(--td-text-color-secondary));
|
|
font-weight: 700;
|
|
|
|
&.yield { --operation-color: #15803d; }
|
|
&.fulfillment-revoke { --operation-color: #c2410c; }
|
|
&.manual { --operation-color: #2563eb; }
|
|
&.reserve { --operation-color: #7c3aed; }
|
|
&.release { --operation-color: #0891b2; }
|
|
&.verify { --operation-color: #dc2626; }
|
|
&.payment-revoke { --operation-color: #4f46e5; }
|
|
}
|
|
|
|
.name {
|
|
flex: 0 1 auto;
|
|
color: var(--td-text-color-primary);
|
|
}
|
|
}
|
|
|
|
.description {
|
|
gap: .5rem;
|
|
display: flex;
|
|
font-size: .75rem;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
|
|
.deltas {
|
|
gap: .5rem;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
|
|
.value { font-size: 1.25rem; }
|
|
}
|
|
}
|
|
|
|
.reason {
|
|
color: var(--td-text-color-secondary);
|
|
font-size: .75rem;
|
|
word-break: break-all;
|
|
}
|
|
}
|
|
}
|
|
|
|
.positive { color: var(--td-success-color); }
|
|
.negative { color: var(--td-error-color); }
|
|
}
|
|
|
|
:global(html.theme-dark) .recycle-ledger-list .operation {
|
|
&.yield { --operation-color: #86efac; }
|
|
&.fulfillment-revoke { --operation-color: #fdba74; }
|
|
&.manual { --operation-color: #93c5fd; }
|
|
&.reserve { --operation-color: #c4b5fd; }
|
|
&.release { --operation-color: #67e8f9; }
|
|
&.verify { --operation-color: #fca5a5; }
|
|
&.payment-revoke { --operation-color: #a5b4fc; }
|
|
}
|
|
</style>
|