Files
gao-customer-h5/src/pages/package/PackageConfigList.vue
T
2026-10-28 14:21:26 +08:00

298 lines
7.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="page-layout navbar package-config-list">
<t-navbar
fixed
:z-index="20"
title="套餐配置"
left-arrow
@left-click="$router.back()"
>
<template #right>
<t-button
v-if="canCreate"
theme="primary"
variant="text"
size="small"
content="新增"
@click="toCreate"
/>
</template>
</t-navbar>
<main v-can="permissionCodes.packageConfig.read" class="page-content scroll column list">
<t-pull-down-refresh
class="pull-refresh"
v-model="isRefreshing"
:refresh-timeout="30000"
@refresh="reload"
@scrolltolower="loadMore"
>
<div class="filters glass">
<t-input
v-model.trim="keyword"
class="keyword"
borderless
clearable
placeholder="搜索套餐名称或说明"
/>
<t-dropdown-menu class="menus">
<t-dropdown-item
v-model="status"
label="状态"
:options="statusOptions"
@change="selectStatus"
/>
</t-dropdown-menu>
</div>
<t-cell-group
v-if="configList.length"
class="list fix-last-cell-line empty-cell-title-margin"
theme="card"
>
<t-cell
class="item"
v-for="item in configList"
:key="item.id"
v-entrance-transition="{ step: 30 }"
>
<template #title>
<div class="title">
<strong v-text="item.name || '未命名套餐'" />
<t-tag :content="getPackageConfigStatusText(item.status)" variant="light-outline" :theme="getStatusTheme(item.status)" />
</div>
</template>
<template #description>
<div class="description">
<div class="products">
<t-tag
v-for="productItem in item.itemList || []"
:key="productItem.id || `${productItem.skuId}-${productItem.skuUnitId}`"
:content="getProductRightText(productItem)"
theme="primary"
variant="light"
/>
<t-tag v-if="!item.itemList?.length" content="暂无产品权益" />
</div>
<div class="price-actions">
<div class="price">
<span class="red">¥</span>
<span class="value red" v-text="formatPackageAmount(item.standardAmount)" />
</div>
<div v-if="item.id" class="actions" @click.stop>
<t-button
class="detail"
theme="primary"
size="extra-small"
content="详情"
@click.stop="toDetail(item)"
/>
</div>
</div>
</div>
</template>
</t-cell>
</t-cell-group>
<center-tips v-else :content="loading ? '正在加载套餐配置' : '暂无套餐配置'" />
<center-tips :content="loadStateText" />
</t-pull-down-refresh>
</main>
</div>
</template>
<script setup lang="ts">
import { type DropdownValue } from "tdesign-mobile-vue";
import { Toolkit } from "timi-web";
import { useUserStore } from "timi-web-api";
import PackageAPI from "@/api/PackageAPI";
import type { GaoPackageConfig, PackageConfigItem, PackageConfigStatus } from "@/types/Package";
import { formatPackageAmount, getPackageConfigStatusText, getPackageQuantityText } from "@/utils/package";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { getProductSkuSnapshotText } from "@/utils/product";
import { getErrorMessage } from "@/utils/error";
defineOptions({ name: "PackageConfigList" });
const router = useRouter();
const userStore = useUserStore();
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.packageConfig.create));
const keyword = ref("");
const status = ref("ALL");
const configList = ref<GaoPackageConfig[]>([]);
const pageIndex = ref(0);
const total = ref(0);
const loading = ref(false);
const isRefreshing = ref(false);
const noMore = ref(false);
const statusOptions = [
{ label: "全部状态", value: "ALL" },
{ label: "草稿", value: "DRAFT" },
{ label: "启用", value: "ACTIVE" },
{ label: "停用", value: "INACTIVE" }
];
const loadStateText = computed(() => loading.value ? "正在加载" : noMore.value ? "已经到底了" : "上拉加载更多");
async function loadMore(): Promise<void> {
if (loading.value || noMore.value) {
return;
}
loading.value = true;
try {
const result = await PackageAPI.configList({
index: pageIndex.value,
size: 15,
keyword: keyword.value || undefined,
status: status.value === "ALL" ? undefined : status.value as PackageConfigStatus
});
const list = result.list || [];
configList.value = configList.value.concat(list);
total.value = result.total || 0;
pageIndex.value += 1;
noMore.value = list.length < 15 || total.value <= configList.value.length;
} finally {
loading.value = false;
}
}
async function reload(): Promise<void> {
if (loading.value) {
return;
}
pageIndex.value = 0;
configList.value = [];
total.value = 0;
noMore.value = false;
await loadMore();
}
async function selectStatus(value: DropdownValue): Promise<void> {
if (Array.isArray(value)) {
return;
}
status.value = String(value);
await reload();
}
const reloadByKeyword = Toolkit.debounce(async () => {
try {
await reload();
} catch (error) {
Message.error(getErrorMessage(error, "套餐配置加载失败"));
}
}, false);
watch(keyword, () => {
reloadByKeyword();
});
async function toCreate(): Promise<void> {
await router.push("/management/package-configs/create");
}
async function toDetail(item: GaoPackageConfig): Promise<void> {
if (item.id) {
await router.push(`/management/package-configs/${item.id}`);
}
}
function getStatusTheme(statusValue?: PackageConfigStatus): "success" | "warning" | "default" {
return statusValue === "ACTIVE" ? "success" : statusValue === "INACTIVE" ? "warning" : "default";
}
function getProductRightText(item: PackageConfigItem): string {
const quantity = getPackageQuantityText(item.defaultQuantity);
const skuText = getProductSkuSnapshotText(item.productNameSnapshot, item.skuNameSnapshot, item.specSummarySnapshot);
return `${item.productNameSnapshot || "未命名产品"}${skuText ? `(${skuText})` : " "}${quantity}${item.unitSnapshot ? ` ${item.unitSnapshot}` : ""}`;
}
onMounted(async () => {
try {
await reload();
} catch (error) {
Message.error(getErrorMessage(error, "套餐配置加载失败"));
}
});
onUnmounted(() => {
reloadByKeyword.cancel();
});
</script>
<style scoped lang="less">
.package-config-list {
padding: var(--app-nav-height) 0 1rem;
.list {
gap: 1rem;
display: flex;
flex-direction: column;
.item {
padding: 10px;
min-width: 0;
:deep(.t-cell__title) {
min-width: 0;
}
.title {
gap: .5rem;
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
}
.description {
display: flex;
flex-direction: column;
min-width: 0;
.products {
gap: .35rem;
width: 100%;
display: flex;
min-width: 0;
max-width: 100%;
flex-wrap: nowrap;
margin-top: .5rem;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
scrollbar-width: none;
-webkit-overflow-scrolling: touch;
:deep(.t-tag) {
flex: 0 0 auto;
}
&::-webkit-scrollbar {
display: none;
}
}
.price-actions {
gap: .5rem;
display: flex;
margin-top: .5rem;
align-items: center;
justify-content: end;
.price {
.value {
font-size: 1.25rem;
}
}
}
}
}
}
}
</style>