424 lines
11 KiB
Vue
424 lines
11 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.packageConfig.read" class="package-config-detail">
|
||
<template v-if="config">
|
||
<section class="hero" v-entrance-transition>
|
||
<div class="header">
|
||
<span class="eyebrow" v-text="'套餐管理'" />
|
||
<t-tag
|
||
:content="getPackageConfigStatusText(config.status)"
|
||
variant="light-outline"
|
||
:theme="getStatusTheme(config.status)"
|
||
/>
|
||
</div>
|
||
<h1 class="title" v-text="config.name || '未命名套餐'" />
|
||
<p class="description" v-text="config.description || '暂无套餐说明'" />
|
||
<div class="items-price">
|
||
<span v-text="`${config.itemList?.length || 0} 项产品权益`" />
|
||
<div class="price text-bold">
|
||
<span class="red">¥</span>
|
||
<span class="red value" v-text="formatPackageAmount(config.standardAmount)" />
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<t-cell-group v-if="canReadSalesOrder" theme="card" v-entrance-transition>
|
||
<t-cell title="套餐订单列表" arrow @click="toPackageOrderList">
|
||
<template #left-icon>
|
||
<t-icon name="gift" />
|
||
</template>
|
||
</t-cell>
|
||
</t-cell-group>
|
||
<t-cell-group title="基本信息" theme="card" v-entrance-transition>
|
||
<t-cell title="标准价" :note="formatPackageAmount(config.standardAmount)" />
|
||
<t-cell title="起始日期" :note="config.beginAt ? Time.toDateTime(config.beginAt) : '不限'" />
|
||
<t-cell title="终止日期" :note="config.endAt ? Time.toDateTime(config.endAt) : '不限'" />
|
||
<t-cell title="最后修改人" :note="config.updater?.nick || config.updater?.name || '未知'" />
|
||
</t-cell-group>
|
||
<t-cell-group class="product" title="产品权益" theme="card" v-entrance-transition>
|
||
<t-cell
|
||
class="item"
|
||
v-for="item in config.itemList || []"
|
||
:key="item.id || `${item.skuId}-${item.skuUnitId}`"
|
||
:note="`${item.defaultQuantity} ${item.unitSnapshot || ''}${item.remark ? `|${item.remark}` : ''}`"
|
||
>
|
||
<template #leftIcon>
|
||
<t-image
|
||
v-if="getItemPhotoURL(item)"
|
||
:src="getItemPhotoURL(item)"
|
||
:alt="item.productNameSnapshot || '产品图片'"
|
||
fit="cover"
|
||
class="avatar"
|
||
/>
|
||
<div
|
||
v-else
|
||
class="avatar fallback"
|
||
v-text="(item.productNameSnapshot || '产').slice(0, 1)"
|
||
/>
|
||
</template>
|
||
<template #title>
|
||
<div class="title">
|
||
<span v-text="item.productNameSnapshot || '未命名产品'" />
|
||
<product-sku-tags
|
||
:product-name="item.productNameSnapshot"
|
||
:fallback="item.specSummarySnapshot || item.skuNameSnapshot || '默认 SKU'"
|
||
/>
|
||
</div>
|
||
</template>
|
||
</t-cell>
|
||
<center-tips v-if="!config.itemList?.length" :content="'暂无产品权益'" />
|
||
</t-cell-group>
|
||
<t-button
|
||
v-if="canPurchase"
|
||
class="cell-button"
|
||
theme="primary"
|
||
content="购买套餐"
|
||
@click="toPurchase"
|
||
/>
|
||
<t-button
|
||
v-if="canDelete"
|
||
class="cell-button"
|
||
theme="danger"
|
||
@click="removeConfig"
|
||
content="删除"
|
||
/>
|
||
</template>
|
||
<t-empty v-else :description="isLoading ? '正在加载套餐配置' : '套餐配置不存在'" />
|
||
</div>
|
||
</main>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { DialogPlugin } from "tdesign-mobile-vue";
|
||
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
|
||
import { Time } from "timi-web";
|
||
import { useUserStore } from "timi-web-api";
|
||
import PackageAPI from "@/api/PackageAPI";
|
||
import ProductSkuTags from "@/components/ProductSkuTags.vue";
|
||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||
import { getErrorMessage } from "@/utils/error";
|
||
import { formatPackageAmount, getPackageConfigStatusText } from "@/utils/package";
|
||
import { Message } from "@/utils/message";
|
||
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||
import { getProductPhotoURL as getProductPhotoUrl } from "@/utils/product";
|
||
|
||
|
||
|
||
|
||
|
||
import type { GaoPackageConfig, PackageConfigItem, PackageConfigStatus } from "@/types/Package";
|
||
|
||
defineOptions({ name: "PackageConfigDetail" });
|
||
|
||
const props = withDefaults(defineProps<{
|
||
/** 指定套餐配置 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
|
||
configId?: string;
|
||
}>(), {
|
||
configId: ""
|
||
});
|
||
|
||
const emit = defineEmits<{
|
||
/** 内联在右栏时请求切换到编辑视图 */
|
||
edit: [];
|
||
}>();
|
||
|
||
const route = useRoute();
|
||
const router = useRouter();
|
||
|
||
/** 内联渲染时 id 来自 prop,整页渲染时来自路由参数 */
|
||
function resolveId(): string {
|
||
return props.configId || String(route.params.id || "");
|
||
}
|
||
|
||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||
useExpandToMaster({
|
||
path: "/product/package-configs",
|
||
id: () => resolveId()
|
||
});
|
||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||
const pane = usePane();
|
||
const userStore = useUserStore();
|
||
const currentStoreStore = useCurrentStoreStore();
|
||
const config = ref<GaoPackageConfig>();
|
||
const isLoading = ref(false);
|
||
const canUpdate = computed(() => !!config.value && userStore.hasPermissions(permissionCodes.packageConfig.update));
|
||
const canDelete = computed(() => !!config.value && userStore.hasPermissions(permissionCodes.packageConfig.delete));
|
||
const canReadSalesOrder = computed(() => userStore.hasPermissions(permissionCodes.salesOrder.read));
|
||
const canPurchase = computed(() =>
|
||
!!config.value
|
||
&& config.value.status === "ACTIVE"
|
||
&& userStore.hasPermissions(permissionCodes.customerPackage.create)
|
||
);
|
||
|
||
function getStatusTheme(status?: PackageConfigStatus): "success" | "warning" | "default" {
|
||
return status === "ACTIVE" ? "success" : status === "INACTIVE" ? "warning" : "default";
|
||
}
|
||
|
||
function getItemPhotoURL(item: PackageConfigItem): string {
|
||
return getProductPhotoUrl(item.sku || {});
|
||
}
|
||
|
||
async function loadData(): Promise<void> {
|
||
const id = resolveId();
|
||
if (!id) {
|
||
return;
|
||
}
|
||
isLoading.value = true;
|
||
try {
|
||
if (userStore.hasRoles(gaoRoleCodes.globalManager)) {
|
||
await currentStoreStore.loadStoreList();
|
||
} else {
|
||
await currentStoreStore.loadLoginStore();
|
||
}
|
||
config.value = await PackageAPI.configDetail(id);
|
||
} catch (error) {
|
||
Message.error(getErrorMessage(error, "套餐配置加载失败"));
|
||
} finally {
|
||
isLoading.value = false;
|
||
}
|
||
}
|
||
|
||
function goBack(): void {
|
||
if (pane) {
|
||
pane.close();
|
||
return;
|
||
}
|
||
|
||
void router.back();
|
||
}
|
||
|
||
async function toEdit(): Promise<void> {
|
||
if (!config.value?.id || !canUpdate.value) {
|
||
return;
|
||
}
|
||
|
||
// 分栏时右栏直接切到编辑视图,不跳路由,列表上下文保留
|
||
if (pane) {
|
||
emit("edit");
|
||
return;
|
||
}
|
||
|
||
await router.push(`/product/package-configs/${config.value.id}/edit`);
|
||
}
|
||
|
||
async function toPurchase(): Promise<void> {
|
||
if (config.value?.id && canPurchase.value) {
|
||
await router.push(`/product/package-configs/${config.value.id}/purchase`);
|
||
}
|
||
}
|
||
|
||
async function toPackageOrderList(): Promise<void> {
|
||
if (!config.value?.id || !canReadSalesOrder.value) {
|
||
return;
|
||
}
|
||
await router.push({
|
||
name: "SalesOrderList",
|
||
query: {
|
||
orderType: "PACKAGE",
|
||
packageConfigId: config.value.id,
|
||
packageConfigName: config.value.name || "未命名套餐",
|
||
transitionDepth: String(Number(route.meta.depth ?? 0) + 1)
|
||
}
|
||
});
|
||
}
|
||
|
||
function removeConfig(): void {
|
||
if (!config.value?.id || !canDelete.value) {
|
||
return;
|
||
}
|
||
const dialog = DialogPlugin.confirm({
|
||
title: "删除套餐配置",
|
||
content: "删除后该配置不再出现在可购买列表中,已购买的客户套餐不受影响。",
|
||
cancelBtn: "取消",
|
||
confirmBtn: { content: "删除", theme: "danger" },
|
||
onCancel() {
|
||
dialog.destroy();
|
||
},
|
||
onConfirm: async () => {
|
||
try {
|
||
await PackageAPI.configRemove(config.value!.id!);
|
||
Message.success("套餐配置已删除");
|
||
if (pane) {
|
||
pane.close(true);
|
||
return;
|
||
}
|
||
await router.replace("/product/package-configs");
|
||
} catch (error) {
|
||
Message.error(getErrorMessage(error, "套餐配置删除失败"));
|
||
} finally {
|
||
dialog.destroy();
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
onMounted(async () => {
|
||
await loadData();
|
||
if (canUpdate.value) {
|
||
}
|
||
});
|
||
|
||
|
||
</script>
|
||
|
||
<style scoped lang="less">
|
||
.package-config-detail {
|
||
gap: 1rem;
|
||
padding: 0 0 2rem;
|
||
display: flex;
|
||
flex-direction: column;
|
||
|
||
.hero {
|
||
margin: 0 1rem;
|
||
padding: 1rem;
|
||
position: relative;
|
||
overflow: hidden;
|
||
background: linear-gradient(135deg, #ecfeff 0%, #eff6ff 48%, #fff7ed 100%);
|
||
border: 1px solid rgba(255, 255, 255, .72);
|
||
box-shadow: var(--td-shadow-1);
|
||
border-radius: 1.25rem;
|
||
|
||
&::before {
|
||
content: "";
|
||
width: 9rem;
|
||
height: 9rem;
|
||
right: -3rem;
|
||
top: -4.5rem;
|
||
background: rgba(45, 212, 191, .2);
|
||
border-radius: 50%;
|
||
filter: blur(1rem);
|
||
position: absolute;
|
||
}
|
||
|
||
&::after {
|
||
content: "";
|
||
width: 7rem;
|
||
height: 7rem;
|
||
left: -3.5rem;
|
||
bottom: -4rem;
|
||
background: rgba(96, 165, 250, .16);
|
||
border-radius: 50%;
|
||
filter: blur(.75rem);
|
||
position: absolute;
|
||
}
|
||
|
||
> * {
|
||
z-index: 1;
|
||
position: relative;
|
||
}
|
||
|
||
.header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
|
||
.eyebrow {
|
||
color: var(--td-brand-color);
|
||
display: block;
|
||
font-size: .6875rem;
|
||
font-weight: 700;
|
||
letter-spacing: .08em;
|
||
}
|
||
}
|
||
|
||
.title {
|
||
margin: 0;
|
||
font-size: 1.25rem;
|
||
line-height: 1.35;
|
||
}
|
||
|
||
.description {
|
||
color: var(--td-text-color-secondary);
|
||
margin: .5rem 0 0;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
.items-price {
|
||
gap: .75rem;
|
||
display: flex;
|
||
margin-top: .75rem;
|
||
color: var(--td-text-color-secondary);
|
||
align-items: end;
|
||
justify-content: space-between;
|
||
|
||
.price {
|
||
|
||
.value {
|
||
font-size: 1.5rem;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
.product {
|
||
|
||
.item {
|
||
padding: 10px;
|
||
|
||
:deep(.t-cell__title) {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.avatar {
|
||
width: 2.5rem;
|
||
height: 2.5rem;
|
||
}
|
||
|
||
.title {
|
||
gap: .5rem;
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
:deep(.package-config-detail .avatar .t-image__img) {
|
||
width: 100%;
|
||
height: 100%;
|
||
object-fit: cover;
|
||
border-radius: inherit;
|
||
}
|
||
|
||
:global(html.theme-dark) .package-config-detail .hero {
|
||
background: linear-gradient(135deg, rgba(15, 118, 110, .3), rgba(37, 99, 235, .28) 52%, rgba(194, 65, 12, .24));
|
||
border-color: rgba(153, 246, 228, .16);
|
||
|
||
&::before {
|
||
background: rgba(45, 212, 191, .14);
|
||
}
|
||
|
||
&::after {
|
||
background: rgba(96, 165, 250, .12);
|
||
}
|
||
|
||
.eyebrow {
|
||
color: #99f6e4;
|
||
}
|
||
|
||
strong {
|
||
color: #fdba74;
|
||
}
|
||
}
|
||
|
||
</style>
|