v1.3.1 #9
@@ -3,6 +3,7 @@ import type {
|
|||||||
OrderTransaction,
|
OrderTransaction,
|
||||||
RecycleAccount,
|
RecycleAccount,
|
||||||
RecycleAccountAdjustRequest,
|
RecycleAccountAdjustRequest,
|
||||||
|
RecycleCustomerAccountPage,
|
||||||
RecycleExchange,
|
RecycleExchange,
|
||||||
RecycleExchangeCreateRequest,
|
RecycleExchangeCreateRequest,
|
||||||
RecycleExchangeDetail,
|
RecycleExchangeDetail,
|
||||||
@@ -117,6 +118,18 @@ async function accountList(customerId: string): Promise<RecycleAccount[]> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 按客户分页查询有余额的回收物及全门店汇总。 */
|
||||||
|
async function accountCustomers(offset: number, limit: number, recycleItemId?: string, keyword?: string, customerIds?: string[]): Promise<RecycleCustomerAccountPage> {
|
||||||
|
return await axios.post(`${ACCOUNT_URI}/customers`, undefined, {
|
||||||
|
params: { storeId: getCurrentStoreId() || undefined, offset, limit, recycleItemId: recycleItemId || undefined, keyword: keyword || undefined, customerIds: customerIds?.length ? customerIds.join(",") : undefined }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取额度查询可用的回收物选项。 */
|
||||||
|
async function accountItems(): Promise<RecycleItem[]> {
|
||||||
|
return await axios.post(`${ACCOUNT_URI}/items`, undefined, { params: { storeId: getCurrentStoreId() || undefined } });
|
||||||
|
}
|
||||||
|
|
||||||
/** 额度流水,服务端当前最多返回 100 条。 */
|
/** 额度流水,服务端当前最多返回 100 条。 */
|
||||||
async function accountLedger(customerId: string): Promise<RecycleLedger[]> {
|
async function accountLedger(customerId: string): Promise<RecycleLedger[]> {
|
||||||
return await axios.post(`${ACCOUNT_URI}/ledger`, undefined, {
|
return await axios.post(`${ACCOUNT_URI}/ledger`, undefined, {
|
||||||
@@ -244,6 +257,8 @@ export default {
|
|||||||
create,
|
create,
|
||||||
detail,
|
detail,
|
||||||
accountList,
|
accountList,
|
||||||
|
accountCustomers,
|
||||||
|
accountItems,
|
||||||
accountLedger,
|
accountLedger,
|
||||||
accountAdjust,
|
accountAdjust,
|
||||||
yieldList,
|
yieldList,
|
||||||
|
|||||||
@@ -0,0 +1,185 @@
|
|||||||
|
<template>
|
||||||
|
<div class="tui-page-layout tui-navbar customer-recycle-list">
|
||||||
|
<t-navbar fixed :z-index="20" title="客户回收物" left-arrow @left-click="$router.back()" />
|
||||||
|
<main v-can="permissionCodes.recycleAccount.read" class="tui-page-content scroll column">
|
||||||
|
<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.trim="keyword" type="search" borderless clearable placeholder="搜索客户姓名、拼音、编码">
|
||||||
|
<template #suffix-icon>
|
||||||
|
<t-button size="extra-small" theme="primary" variant="outline" :content="customerIds.length ? `已选 ${customerIds.length} 人` : '选择客户'" @click.stop="customerVisible = true" />
|
||||||
|
</template>
|
||||||
|
</t-input>
|
||||||
|
<t-dropdown-menu ref="filterMenuRef" class="menus">
|
||||||
|
<t-dropdown-item :label="selectedName" :options="[]" @open="openItemPicker" />
|
||||||
|
</t-dropdown-menu>
|
||||||
|
</div>
|
||||||
|
<t-cell-group theme="card">
|
||||||
|
<t-cell title="汇总">
|
||||||
|
<template v-if="selectedId" #note>
|
||||||
|
<t-button size="extra-small" variant="outline" content="清除" @click="clearItem" />
|
||||||
|
</template>
|
||||||
|
<template #description>
|
||||||
|
<div class="tags">
|
||||||
|
<t-tag v-for="item in displayedTotals" :key="item.recycleItemId" theme="primary"
|
||||||
|
variant="light"
|
||||||
|
:content="accountText(item)" />
|
||||||
|
<span v-if="!displayedTotals.length" v-text="loading ? '正在加载' : '暂无回收物'" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</t-cell>
|
||||||
|
</t-cell-group>
|
||||||
|
<t-cell-group v-if="items.length" theme="card" class="fix-last-cell-line">
|
||||||
|
<customer-cell v-for="row in items" :key="row.customer.id" :customer="row.customer" arrow hover
|
||||||
|
@click="openCustomer(row.customer)">
|
||||||
|
<template #description>
|
||||||
|
<div class="tags">
|
||||||
|
<t-tag v-for="account in row.accounts" :key="account.recycleItemId" theme="primary"
|
||||||
|
variant="light"
|
||||||
|
:content="accountText(account)" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</customer-cell>
|
||||||
|
</t-cell-group>
|
||||||
|
<center-tips v-else :content="loading ? '正在加载客户回收物' : '暂无客户回收物'" />
|
||||||
|
<center-tips v-if="items.length"
|
||||||
|
:content="loading ? '正在加载' : noMore ? `共 ${total} 位客户` : '上拉加载更多'" />
|
||||||
|
</t-pull-down-refresh>
|
||||||
|
</main>
|
||||||
|
<customer-selector v-model="customerIds" v-model:visible="customerVisible" :initial-keyword="keyword" selection-mode="multiple" />
|
||||||
|
<recycle-item-picker-popup v-model:visible="filterVisible" :selected-id="selectedId" account-items @select="selectItem" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import RecycleAPI from "@/api/RecycleAPI";
|
||||||
|
import RecycleItemPickerPopup from "@/pages/recycle/components/RecycleItemPickerPopup.vue";
|
||||||
|
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||||
|
import type { Customer } from "@/types/Customer";
|
||||||
|
import type { RecycleAccount, RecycleCustomerAccountPage, RecycleItem } from "@/types/Recycle";
|
||||||
|
import { getErrorMessage } from "@/utils/error";
|
||||||
|
import { Message } from "@/utils/message";
|
||||||
|
import { permissionCodes } from "@/utils/permission";
|
||||||
|
import { getRecycleQuantityText } from "@/utils/recycle";
|
||||||
|
|
||||||
|
defineOptions({ name: "CustomerRecycleList" });
|
||||||
|
const router = useRouter();
|
||||||
|
const items = ref<RecycleCustomerAccountPage["list"]>([]);
|
||||||
|
const totals = ref<RecycleAccount[]>([]);
|
||||||
|
const selectedId = ref("");
|
||||||
|
const selectedItem = ref<RecycleItem>();
|
||||||
|
const filterVisible = ref(false);
|
||||||
|
const customerIds = ref<string[]>([]);
|
||||||
|
const customerVisible = ref(false);
|
||||||
|
const filterMenuRef = ref<{ collapseMenu: () => void }>();
|
||||||
|
const keyword = ref("");
|
||||||
|
let searchTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
const loading = ref(false);
|
||||||
|
const refreshing = ref(false);
|
||||||
|
const noMore = ref(false);
|
||||||
|
const total = ref(0);
|
||||||
|
let version = 0;
|
||||||
|
const selectedName = computed(() => selectedItem.value?.name || "全部回收物");
|
||||||
|
const displayedTotals = computed(() => selectedId.value ? totals.value.filter(item => item.recycleItemId === selectedId.value) : totals.value);
|
||||||
|
|
||||||
|
function accountText(account: RecycleAccount): string {
|
||||||
|
return `${account.recycleName || "未命名回收物"} ${getRecycleQuantityText(account.balance, account.recycleUnit)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchPage(reset: boolean): Promise<void> {
|
||||||
|
if (!reset && (loading.value || noMore.value)) return;
|
||||||
|
const token = reset ? ++version : version;
|
||||||
|
const offset = reset ? 0 : items.value.length;
|
||||||
|
if (reset) {
|
||||||
|
items.value = [];
|
||||||
|
noMore.value = false;
|
||||||
|
}
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const result = await RecycleAPI.accountCustomers(offset, 20, selectedId.value, keyword.value, customerIds.value);
|
||||||
|
if (token !== version) return;
|
||||||
|
items.value = reset ? result.list : [...items.value, ...result.list];
|
||||||
|
totals.value = result.totals;
|
||||||
|
total.value = result.total;
|
||||||
|
noMore.value = result.list.length < 20 || !(items.value.length < total.value);
|
||||||
|
} catch (error) {
|
||||||
|
if (token === version) Message.error(getErrorMessage(error, "客户回收物加载失败"));
|
||||||
|
} finally {
|
||||||
|
if (token === version) {
|
||||||
|
loading.value = false;
|
||||||
|
refreshing.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reload(): Promise<void> {
|
||||||
|
await fetchPage(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadMore(): Promise<void> {
|
||||||
|
await fetchPage(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openItemPicker(): Promise<void> {
|
||||||
|
filterVisible.value = true;
|
||||||
|
await nextTick();
|
||||||
|
filterMenuRef.value?.collapseMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateItem(id: string): Promise<void> {
|
||||||
|
if (selectedId.value === id) return;
|
||||||
|
selectedId.value = id;
|
||||||
|
if (searchTimer) clearTimeout(searchTimer);
|
||||||
|
await reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function selectItem(item: RecycleItem): Promise<void> {
|
||||||
|
selectedItem.value = item;
|
||||||
|
await updateItem(item.id || "");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function clearItem(): Promise<void> {
|
||||||
|
selectedItem.value = undefined;
|
||||||
|
await updateItem("");
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(customerIds, async () => {
|
||||||
|
if (searchTimer) clearTimeout(searchTimer);
|
||||||
|
await reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(keyword, () => {
|
||||||
|
version++;
|
||||||
|
if (searchTimer) clearTimeout(searchTimer);
|
||||||
|
searchTimer = setTimeout(() => {
|
||||||
|
void reload();
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (searchTimer) clearTimeout(searchTimer);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function openCustomer(customer: Customer): Promise<void> {
|
||||||
|
if (customer.id) await router.push({ name: "RecycleAccount", query: { customerId: customer.id } });
|
||||||
|
}
|
||||||
|
|
||||||
|
let wasDeactivated = false;
|
||||||
|
onMounted(reload);
|
||||||
|
onDeactivated(() => { wasDeactivated = true; });
|
||||||
|
onActivated(async () => {
|
||||||
|
if (!wasDeactivated) return;
|
||||||
|
wasDeactivated = false;
|
||||||
|
await reload();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="less">
|
||||||
|
.customer-recycle-list {
|
||||||
|
.tags {
|
||||||
|
gap: .375rem;
|
||||||
|
display: flex;
|
||||||
|
padding: .25rem 0;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -56,6 +56,7 @@ const props = withDefaults(defineProps<{
|
|||||||
title?: string;
|
title?: string;
|
||||||
manage?: boolean;
|
manage?: boolean;
|
||||||
showStatus?: boolean;
|
showStatus?: boolean;
|
||||||
|
accountItems?: boolean;
|
||||||
selectedId?: string;
|
selectedId?: string;
|
||||||
items?: RecycleItem[];
|
items?: RecycleItem[];
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
@@ -65,6 +66,7 @@ const props = withDefaults(defineProps<{
|
|||||||
title: "选择回收物",
|
title: "选择回收物",
|
||||||
manage: false,
|
manage: false,
|
||||||
showStatus: false,
|
showStatus: false,
|
||||||
|
accountItems: false,
|
||||||
selectedId: "",
|
selectedId: "",
|
||||||
loading: false,
|
loading: false,
|
||||||
emptyText: "暂无回收物"
|
emptyText: "暂无回收物"
|
||||||
@@ -86,6 +88,10 @@ async function load(): Promise<void> {
|
|||||||
if (internalLoading.value) return;
|
if (internalLoading.value) return;
|
||||||
internalLoading.value = true;
|
internalLoading.value = true;
|
||||||
try {
|
try {
|
||||||
|
if (props.accountItems) {
|
||||||
|
loadedItems.value = await RecycleAPI.accountItems();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const result: RecycleItem[] = [];
|
const result: RecycleItem[] = [];
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|||||||
@@ -149,6 +149,12 @@ const menuGroupList = computed<MenuGroup[]>(() => [
|
|||||||
title: "客户邀请关系",
|
title: "客户邀请关系",
|
||||||
visible: userStore.hasPermissions(permissionCodes.customer.read)
|
visible: userStore.hasPermissions(permissionCodes.customer.read)
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
icon: "layers",
|
||||||
|
path: "/management/customer-recycle-accounts",
|
||||||
|
title: "客户回收物",
|
||||||
|
visible: userStore.hasPermissions(permissionCodes.recycleAccount.read)
|
||||||
|
},
|
||||||
{
|
{
|
||||||
icon: "chart-combo",
|
icon: "chart-combo",
|
||||||
path: "/management/customer-data-charts",
|
path: "/management/customer-data-charts",
|
||||||
|
|||||||
@@ -76,6 +76,12 @@ export default [
|
|||||||
},
|
},
|
||||||
meta: meta(4)
|
meta: meta(4)
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/management/customer-recycle-accounts",
|
||||||
|
name: "CustomerRecycleList",
|
||||||
|
component: () => import("@/pages/customer/CustomerRecycleList.vue"),
|
||||||
|
meta: meta()
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/management/recycle-accounts",
|
path: "/management/recycle-accounts",
|
||||||
name: "RecycleAccount",
|
name: "RecycleAccount",
|
||||||
|
|||||||
@@ -188,6 +188,13 @@ export type RecycleAccount = {
|
|||||||
updatedAt?: number;
|
updatedAt?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 客户回收物分页与按回收物分组的余额汇总。 */
|
||||||
|
export type RecycleCustomerAccountPage = {
|
||||||
|
list: { customer: Customer; accounts: RecycleAccount[] }[];
|
||||||
|
total: number;
|
||||||
|
totals: RecycleAccount[];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 额度流水。
|
* 额度流水。
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user