181 lines
5.5 KiB
Vue
181 lines
5.5 KiB
Vue
<template>
|
|
<div class="tui-page-layout tui-navbar recycle-rule-detail">
|
|
<t-navbar fixed :z-index="20" title="兑换模板详情" left-arrow @left-click="exit">
|
|
<template #right>
|
|
<t-button v-if="rule" theme="primary" variant="text" size="small" content="编辑" @click="edit" />
|
|
</template>
|
|
</t-navbar>
|
|
<main class="tui-page-content scroll column" v-can="permissionCodes.recycleExchange.configManage">
|
|
<template v-if="rule">
|
|
<t-cell-group title="回收物" theme="card" v-entrance-transition>
|
|
<t-cell title="回收物" :note="rule.recycleName || '未命名回收物'" />
|
|
<t-cell title="单份回收数量" :note="getRecycleQuantityText(rule.recycleQuantity, rule.recycleUnit)" />
|
|
</t-cell-group>
|
|
<t-cell-group
|
|
class="products"
|
|
title="兑换商品"
|
|
theme="card"
|
|
v-entrance-transition
|
|
>
|
|
<t-cell
|
|
class="item"
|
|
v-for="(item, index) in rule.itemList || []"
|
|
:key="item.id || `${item.skuId}-${item.skuUnitId}-${index}`"
|
|
>
|
|
<template #left-icon>
|
|
<t-image v-if="skuMap[item.skuId] && getProductPhotoURL(skuMap[item.skuId])" :src="getProductPhotoURL(skuMap[item.skuId])" :alt="item.productName || '产品图片'" fit="cover" class="avatar" />
|
|
<div v-else class="avatar fallback" v-text="(item.productName || '产').slice(0, 1)" />
|
|
</template>
|
|
<template #title>
|
|
<div class="title">
|
|
<span class="clip-text" v-text="item.productName || '未命名产品'" />
|
|
<product-sku-tags :product-name="item.productName" :fallback="item.specSummary || item.skuName || ''" />
|
|
</div>
|
|
</template>
|
|
<template #note>
|
|
<span v-text="getRecycleQuantityText(item.exchangeQuantity, item.unitName)" />
|
|
</template>
|
|
</t-cell>
|
|
<center-tips v-if="!rule.itemList?.length" content="暂无兑换商品" />
|
|
</t-cell-group>
|
|
<t-cell-group title="其他信息" theme="card" v-entrance-transition>
|
|
<t-cell title="状态">
|
|
<template #note>
|
|
<t-tag size="small" :theme="getRecycleStatusTheme(rule.status)" :content="getRecycleStatusText(rule.status)" />
|
|
</template>
|
|
</t-cell>
|
|
<t-cell title="备注" :note="rule.remark || '无'" />
|
|
</t-cell-group>
|
|
<t-button
|
|
class="cell-button"
|
|
v-can="permissionCodes.salesOrder.create"
|
|
theme="primary"
|
|
:disabled="rule.status !== 'ACTIVE'"
|
|
content="使用该模板创建回收兑换单"
|
|
v-entrance-transition
|
|
@click="createExchange"
|
|
/>
|
|
</template>
|
|
<center-tips v-if="loading" content="正在加载兑换模板" />
|
|
</main>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
|
|
import ProductAPI from "@/api/ProductAPI";
|
|
import RecycleAPI from "@/api/RecycleAPI";
|
|
import ProductSkuTags from "@/components/ProductSkuTags.vue";
|
|
import type { ProductSku } from "@/types/Product";
|
|
import type { RecycleExchangeRule } from "@/types/Recycle";
|
|
import { getErrorMessage } from "@/utils/error";
|
|
import { Message } from "@/utils/message";
|
|
import { getProductPhotoURL } from "@/utils/product";
|
|
import { permissionCodes } from "@/utils/permission";
|
|
import { getRecycleQuantityText, getRecycleStatusText, getRecycleStatusTheme } from "@/utils/recycle";
|
|
|
|
defineOptions({ name: "RecycleRuleDetail" });
|
|
|
|
const props = withDefaults(defineProps<{ ruleId?: string }>(), { ruleId: "" });
|
|
const emit = defineEmits<{ edit: [] }>();
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
const pane = usePane();
|
|
const currentId = computed(() => props.ruleId || String(route.params.id || ""));
|
|
const rule = ref<RecycleExchangeRule>();
|
|
const loading = ref(false);
|
|
const skuMap = reactive<Record<string, ProductSku>>({});
|
|
let loadVersion = 0;
|
|
|
|
useExpandToMaster({ path: "/product/recycle-rules", id: () => currentId.value });
|
|
|
|
function exit(): void {
|
|
if (pane) {
|
|
pane.close();
|
|
return;
|
|
}
|
|
void router.back();
|
|
}
|
|
|
|
async function edit(): Promise<void> {
|
|
if (pane) {
|
|
emit("edit");
|
|
return;
|
|
}
|
|
if (currentId.value) {
|
|
await router.push({ name: "RecycleRuleEdit", params: { id: currentId.value } });
|
|
}
|
|
}
|
|
|
|
async function createExchange(): Promise<void> {
|
|
if (rule.value?.status === "ACTIVE" && currentId.value) {
|
|
await router.push({ name: "RecycleExchangeCreate", query: { ruleId: currentId.value } });
|
|
}
|
|
}
|
|
|
|
async function load(): Promise<void> {
|
|
const id = currentId.value;
|
|
const version = ++loadVersion;
|
|
rule.value = undefined;
|
|
if (!id) {
|
|
loading.value = false;
|
|
return;
|
|
}
|
|
loading.value = true;
|
|
try {
|
|
const result = await RecycleAPI.ruleDetail(id);
|
|
if (version === loadVersion) {
|
|
rule.value = result;
|
|
const ids = [...new Set((result.itemList || []).map(item => item.skuId).filter(id => id && !skuMap[id]))];
|
|
const results = await Promise.allSettled(ids.map(async id => await ProductAPI.skuDetail(id)));
|
|
results.forEach((item, index) => {
|
|
if (item.status === "fulfilled") {
|
|
skuMap[ids[index]] = item.value;
|
|
}
|
|
});
|
|
}
|
|
} catch (error) {
|
|
if (version === loadVersion) {
|
|
Message.error(getErrorMessage(error, "兑换模板加载失败"));
|
|
}
|
|
} finally {
|
|
if (version === loadVersion) {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
watch(currentId, load, { immediate: true });
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
.recycle-rule-detail {
|
|
|
|
.products {
|
|
|
|
.item {
|
|
padding: 10px;
|
|
|
|
:deep(.t-cell__title) {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.avatar {
|
|
width: 2.5rem;
|
|
height: 2.5rem;
|
|
}
|
|
|
|
.title {
|
|
gap: .5rem;
|
|
height: 100%;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
min-width: 0;
|
|
align-items: center;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</style>
|