v1.3.0 #8
Generated
+3
-1
@@ -1,7 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/android" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
|
||||
Vendored
+1
@@ -45,6 +45,7 @@ declare module 'vue' {
|
||||
SegmentedSlider: typeof import('./src/components/SegmentedSlider.vue')['default']
|
||||
StoreRemoveDialog: typeof import('./src/components/StoreRemoveDialog.vue')['default']
|
||||
TagSelector: typeof import('./src/components/TagSelector.vue')['default']
|
||||
TAvatar: typeof import('tdesign-mobile-vue')['Avatar']
|
||||
TBadge: typeof import('tdesign-mobile-vue')['Badge']
|
||||
TButton: typeof import('tdesign-mobile-vue')['Button']
|
||||
TCalendar: typeof import('tdesign-mobile-vue')['Calendar']
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "gao-customer-h5",
|
||||
"private": true,
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --host",
|
||||
@@ -30,7 +30,7 @@
|
||||
"less": "^4.3.0",
|
||||
"pinia": "^3.0.2",
|
||||
"tdesign-mobile-vue": "^1.17.1",
|
||||
"timi-tdesign-mobile": "^1.0.2",
|
||||
"timi-tdesign-mobile": "^1.1.1",
|
||||
"timi-ts": "^1.0.0",
|
||||
"timi-web": "^1.0.2",
|
||||
"timi-web-api": "^1.0.2",
|
||||
|
||||
Generated
+5
-5
@@ -47,8 +47,8 @@ importers:
|
||||
specifier: ^1.17.1
|
||||
version: 1.17.1(patch_hash=c98db305008fbfd00046666ca890e1c6cb88257c0619418694689cddf8cd78c3)(vue@3.5.40(typescript@5.8.3))
|
||||
timi-tdesign-mobile:
|
||||
specifier: ^1.0.2
|
||||
version: 1.0.2(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3))
|
||||
specifier: ^1.1.1
|
||||
version: 1.1.1(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3))
|
||||
timi-ts:
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0
|
||||
@@ -2748,8 +2748,8 @@ packages:
|
||||
through2@4.0.2:
|
||||
resolution: {integrity: sha512-iOqSav00cVxEEICeD7TjLB1sueEL+81Wpzp2bY17uZjZN0pWZPuo4suZ/61VujxmqSGFfgOcNuTZ85QJwNZQpw==}
|
||||
|
||||
timi-tdesign-mobile@1.0.2:
|
||||
resolution: {integrity: sha512-7qjwUUqIjMB9TJbOWguK61JfQ15PLf3gnfUDU1gY2eS4cjbgo/PD2U/eHNV6CZ0VB/hBjPNp84xKZ0qr03tsmw==}
|
||||
timi-tdesign-mobile@1.1.1:
|
||||
resolution: {integrity: sha512-aR6SKu8zVbaqHRJHRtria3amvp9UKS6jTT99FNei38ZrP1sJDBsvCoQmWi0xzUD3F/wkGnSECWWrJQToqso6PQ==}
|
||||
engines: {node: '>=20.0.0'}
|
||||
peerDependencies:
|
||||
vue: ^3.5.0
|
||||
@@ -5849,7 +5849,7 @@ snapshots:
|
||||
dependencies:
|
||||
readable-stream: 3.6.2
|
||||
|
||||
timi-tdesign-mobile@1.0.2(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3)):
|
||||
timi-tdesign-mobile@1.1.1(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3)):
|
||||
dependencies:
|
||||
tdesign-mobile-vue: 1.17.1(patch_hash=c98db305008fbfd00046666ca890e1c6cb88257c0619418694689cddf8cd78c3)(vue@3.5.40(typescript@5.8.3))
|
||||
timi-web: 1.0.2(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue@3.5.40(typescript@5.8.3))
|
||||
|
||||
+130
-27
@@ -1,16 +1,22 @@
|
||||
import { axios } from "timi-web-api";
|
||||
import type {
|
||||
OrderTransaction,
|
||||
RecycleAccount,
|
||||
RecycleAccountAdjustRequest,
|
||||
RecycleExchange,
|
||||
RecycleExchangeActionRequest,
|
||||
RecycleExchangeCreateRequest,
|
||||
RecycleExchangeDetail,
|
||||
RecycleExchangePage,
|
||||
RecycleExchangeRule,
|
||||
RecycleExchangeRulePage,
|
||||
RecycleExchangeStatRow,
|
||||
RecycleItem,
|
||||
RecycleItemPage,
|
||||
RecycleLedger,
|
||||
RecyclePageResult,
|
||||
RecyclePayment,
|
||||
RecyclePaymentRequest,
|
||||
RecycleProductYield,
|
||||
RecycleRuleRequest,
|
||||
RecycleStatRow
|
||||
} from "@/types/Recycle";
|
||||
import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents";
|
||||
@@ -18,6 +24,8 @@ import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store";
|
||||
|
||||
const CONFIG_URI = "/gao/recycle/config";
|
||||
const EXCHANGE_URI = "/gao/recycle/exchange";
|
||||
const ACCOUNT_URI = "/gao/recycle/account";
|
||||
const PAYMENT_URI = "/gao/recycle/payment";
|
||||
const STAT_URI = "/gao/recycle/stat";
|
||||
|
||||
/** 配置接口的 storeId 走查询参数,可省略时由后端按登录用户门店范围解析。 */
|
||||
@@ -46,7 +54,7 @@ async function itemList(page: RecycleItemPage): Promise<RecyclePageResult<Recycl
|
||||
return await axios.post(`${CONFIG_URI}/items`, undefined, { params: configParams(page) });
|
||||
}
|
||||
|
||||
/** 回收物配置详情,回填服务端拼接好的来源产品与 SKU 名称。 */
|
||||
/** 回收物配置详情。 */
|
||||
async function itemDetail(id: string): Promise<RecycleItem> {
|
||||
return await axios.post(`${CONFIG_URI}/item/detail`, undefined, {
|
||||
params: { storeId: getCurrentStoreId() || undefined, id }
|
||||
@@ -75,11 +83,18 @@ async function ruleDetail(id: string): Promise<RecycleExchangeRule> {
|
||||
});
|
||||
}
|
||||
|
||||
/** 保存规则配置:新增不传 id,修改必须提交完整配置。 */
|
||||
async function ruleSave(rule: RecycleExchangeRule): Promise<RecycleExchangeRule> {
|
||||
/** 保存模板:新增不传 id,修改必须提交完整明细。 */
|
||||
async function ruleSave(rule: RecycleRuleRequest): Promise<RecycleExchangeRule> {
|
||||
return await axios.post(`${CONFIG_URI}/rule/save`, withCurrentStoreId(rule));
|
||||
}
|
||||
|
||||
/** 删除模板。已创建的兑换单保存了快照,不依赖模板继续履约。 */
|
||||
async function ruleDelete(id: string): Promise<void> {
|
||||
await axios.post(`${CONFIG_URI}/rule/delete`, undefined, {
|
||||
params: { storeId: getCurrentStoreId() || undefined, id }
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- 兑换单 ----------
|
||||
|
||||
/** 创建兑换单。requestNo 为幂等号,重试必须原样复用。 */
|
||||
@@ -88,34 +103,109 @@ async function create(request: RecycleExchangeCreateRequest): Promise<RecycleExc
|
||||
return notifyPendingNoticeChanged(result);
|
||||
}
|
||||
|
||||
/** 兑换单分页,按业务时间、创建时间及 ID 倒序。 */
|
||||
async function page(request: RecycleExchangePage): Promise<RecyclePageResult<RecycleExchange>> {
|
||||
return await axios.post(`${EXCHANGE_URI}/page`, withCurrentStoreId(request));
|
||||
}
|
||||
|
||||
/** 兑换单详情。兑换单列表已并入交易订单查询,这里只保留详情与动作。 */
|
||||
async function detail(id: string): Promise<RecycleExchangeDetail> {
|
||||
return await axios.post(`${EXCHANGE_URI}/detail`, undefined, { params: { id } });
|
||||
}
|
||||
|
||||
// ---------- 客户额度 ----------
|
||||
|
||||
/** 客户额度账户列表,按回收物类型逐项返回余额与预占。 */
|
||||
async function accountList(customerId: string): Promise<RecycleAccount[]> {
|
||||
return await axios.post(`${ACCOUNT_URI}/list`, undefined, {
|
||||
params: { storeId: getCurrentStoreId() || undefined, customerId }
|
||||
});
|
||||
}
|
||||
|
||||
/** 额度流水,服务端当前最多返回 100 条。 */
|
||||
async function accountLedger(customerId: string): Promise<RecycleLedger[]> {
|
||||
return await axios.post(`${ACCOUNT_URI}/ledger`, undefined, {
|
||||
params: { storeId: getCurrentStoreId() || undefined, customerId }
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 核销待核销单。成功返回的兑换单状态可能已被并发操作改变,页面应重新查询详情。
|
||||
* 门店由服务端按兑换单自身归属解析,请求不需要带 storeId。
|
||||
* 人工调整额度。
|
||||
*
|
||||
* 减少不能超过可用额度;调整只动账面,不代表门店收到实物。
|
||||
*/
|
||||
async function verify(request: RecycleExchangeActionRequest): Promise<RecycleExchange> {
|
||||
const result = await axios.post(`${EXCHANGE_URI}/verify`, request);
|
||||
return notifyPendingNoticeChanged(result);
|
||||
async function accountAdjust(request: RecycleAccountAdjustRequest): Promise<void> {
|
||||
await axios.post(`${ACCOUNT_URI}/adjust`, withCurrentStoreId(request));
|
||||
}
|
||||
|
||||
/** 撤销待核销单,recycleReturned 决定回收物是否全部退还客户。门店同理由服务端取。 */
|
||||
async function cancel(request: RecycleExchangeActionRequest): Promise<RecycleExchange> {
|
||||
const result = await axios.post(`${EXCHANGE_URI}/cancel`, request);
|
||||
return notifyPendingNoticeChanged(result);
|
||||
/** 某 SKU 的回收物产出配置。 */
|
||||
async function yieldList(skuId: string): Promise<RecycleProductYield[]> {
|
||||
return await axios.post(`${ACCOUNT_URI}/yield/list`, undefined, {
|
||||
params: { storeId: getCurrentStoreId() || undefined, skuId }
|
||||
});
|
||||
}
|
||||
|
||||
/** 冲正已核销单。库存商品必须 stockReturned 且至少一张 PHOTO。门店同理由服务端取。 */
|
||||
async function revoke(request: RecycleExchangeActionRequest): Promise<RecycleExchange> {
|
||||
const result = await axios.post(`${EXCHANGE_URI}/revoke`, request);
|
||||
return notifyPendingNoticeChanged(result);
|
||||
/** 某产品下所有 SKU 的回收物产出配置,产品详情里配置产出用。 */
|
||||
async function yieldProductList(productId: string): Promise<RecycleProductYield[]> {
|
||||
return await axios.post(`${ACCOUNT_URI}/yield/product/list`, undefined, {
|
||||
params: { storeId: getCurrentStoreId() || undefined, productId }
|
||||
});
|
||||
}
|
||||
|
||||
/** 保存产出比例,同一 SKU 与回收物组合会覆盖。 */
|
||||
async function yieldSave(skuId: string, recycleItemId: string, quantityPerBase: string): Promise<void> {
|
||||
await axios.post(`${ACCOUNT_URI}/yield/save`, undefined, {
|
||||
params: { storeId: getCurrentStoreId() || undefined, skuId, recycleItemId, quantityPerBase }
|
||||
});
|
||||
}
|
||||
|
||||
/** 删除产出配置。历史额度流水仍会保留来源。 */
|
||||
async function yieldDelete(skuId: string, recycleItemId: string): Promise<void> {
|
||||
await axios.post(`${ACCOUNT_URI}/yield/delete`, undefined, {
|
||||
params: { storeId: getCurrentStoreId() || undefined, skuId, recycleItemId }
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- 回收物支付 ----------
|
||||
|
||||
/** 登记一笔待核销支付,创建即预占客户额度。 */
|
||||
async function paymentCreate(request: RecyclePaymentRequest): Promise<RecyclePayment> {
|
||||
return await axios.post(`${PAYMENT_URI}/create`, withCurrentStoreId(request));
|
||||
}
|
||||
|
||||
/** 创建并立即核销,预占转扣减并记录实物收到。 */
|
||||
async function paymentCreateAndVerify(request: RecyclePaymentRequest): Promise<RecyclePayment> {
|
||||
return await axios.post(`${PAYMENT_URI}/create-and-verify`, withCurrentStoreId(request));
|
||||
}
|
||||
|
||||
/** 某订单的回收物支付记录。 */
|
||||
async function paymentList(orderId: string): Promise<RecyclePayment[]> {
|
||||
return await axios.post(`${PAYMENT_URI}/list`, undefined, { params: { orderId } });
|
||||
}
|
||||
|
||||
/** 按客户、时间和状态分页查询回收流水。 */
|
||||
async function paymentSearch(params: { customerId?: string; orderId?: string; status?: string; beginAt?: number; endAt?: number; offset: number; limit: number }): Promise<RecyclePayment[]> {
|
||||
return await axios.post(`${PAYMENT_URI}/search`, undefined, { params: { ...params, storeId: getCurrentStoreId() || undefined } });
|
||||
}
|
||||
|
||||
/** 某订单的统一交易视图,资金流水与回收物支付按权限混合返回。 */
|
||||
async function paymentTransactions(orderId: string): Promise<OrderTransaction[]> {
|
||||
return await axios.post(`${PAYMENT_URI}/transactions`, undefined, { params: { orderId } });
|
||||
}
|
||||
|
||||
/** 核销待核销支付。 */
|
||||
async function paymentVerify(paymentId: string): Promise<RecyclePayment> {
|
||||
return await axios.post(`${PAYMENT_URI}/verify`, { paymentId });
|
||||
}
|
||||
|
||||
/** 拒绝待核销支付并释放预占。 */
|
||||
async function paymentReject(request: RecyclePaymentRequest): Promise<RecyclePayment> {
|
||||
return await axios.post(`${PAYMENT_URI}/reject`, request);
|
||||
}
|
||||
|
||||
/** 撤销待核销支付并释放预占,普通撤销仅限提交人。 */
|
||||
async function paymentCancel(request: RecyclePaymentRequest): Promise<RecyclePayment> {
|
||||
return await axios.post(`${PAYMENT_URI}/cancel`, request);
|
||||
}
|
||||
|
||||
/** 整笔冲正已核销支付并返还额度。 */
|
||||
async function paymentRevoke(request: RecyclePaymentRequest): Promise<RecyclePayment> {
|
||||
return await axios.post(`${PAYMENT_URI}/revoke`, withCurrentStoreId(request));
|
||||
}
|
||||
|
||||
// ---------- 统计 ----------
|
||||
@@ -150,12 +240,25 @@ export default {
|
||||
activeRuleList,
|
||||
ruleDetail,
|
||||
ruleSave,
|
||||
ruleDelete,
|
||||
create,
|
||||
page,
|
||||
detail,
|
||||
verify,
|
||||
cancel,
|
||||
revoke,
|
||||
accountList,
|
||||
accountLedger,
|
||||
accountAdjust,
|
||||
yieldList,
|
||||
yieldProductList,
|
||||
yieldSave,
|
||||
yieldDelete,
|
||||
paymentCreate,
|
||||
paymentCreateAndVerify,
|
||||
paymentList,
|
||||
paymentSearch,
|
||||
paymentTransactions,
|
||||
paymentVerify,
|
||||
paymentReject,
|
||||
paymentCancel,
|
||||
paymentRevoke,
|
||||
statRecycle,
|
||||
statExchange
|
||||
};
|
||||
|
||||
@@ -189,12 +189,6 @@ html.theme-dark body {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.form-tips {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .8125rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.empty-cell-title-margin {
|
||||
--td-spacer-2: .25rem;
|
||||
}
|
||||
@@ -231,11 +225,6 @@ html.theme-dark body {
|
||||
}
|
||||
}
|
||||
|
||||
.t-pull-down-refresh {
|
||||
height: auto;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.t-dropdown-menu {
|
||||
|
||||
&:after {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
@toggle="toggleSku"
|
||||
@check="toggleProduct"
|
||||
/>
|
||||
<center-tips v-else :content="loading ? (props.productScope === 'all' ? '正在加载产品' : '正在加载可售产品') : emptyProductText" />
|
||||
<center-tips v-else :content="loading ? '正在加载可售产品' : emptyProductText" />
|
||||
</div>
|
||||
</div>
|
||||
</bottom-popup>
|
||||
@@ -46,14 +46,12 @@ interface Props {
|
||||
modelValue?: ProductSkuSelectionValue;
|
||||
visible?: boolean;
|
||||
selectionMode?: ProductSkuSelectionMode;
|
||||
/** sellable 只列可售产品;all 连停售产品一起列,用于来源产品这类仅作识别的场景 */
|
||||
productScope?: "sellable" | "all";
|
||||
selectableProductIdList?: string[];
|
||||
selectableSkuIdList?: string[];
|
||||
selectedSkuIdList?: string[];
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), { selectionMode: "single", productScope: "sellable" });
|
||||
const props = withDefaults(defineProps<Props>(), { selectionMode: "single" });
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [value: Props["modelValue"]];
|
||||
"update:visible": [value: boolean];
|
||||
@@ -97,7 +95,7 @@ const visibleProductList = computed(() => {
|
||||
});
|
||||
const emptyProductText = computed(() => props.selectableProductIdList?.length === 0
|
||||
? "客户暂无已购可履约产品"
|
||||
: (props.productScope === "all" ? "暂无产品" : "暂无可售产品"));
|
||||
: "暂无可售产品");
|
||||
const selectorItemList = computed<ProductSkuSelectorItem[]>(() => visibleProductList.value.map((summary, index) => {
|
||||
const key = getProductKey(summary, index);
|
||||
const product = productDetailMap.value[key] || (summary.skuList?.length ? summary : undefined);
|
||||
@@ -136,11 +134,9 @@ watch(popupVisible, async visible => {
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
productList.value = props.productScope === "all"
|
||||
? (await ProductAPI.list({ index: 0, size: 1000 })).list || []
|
||||
: await ProductAPI.sellableList({ index: 0, size: 1000 });
|
||||
productList.value = await ProductAPI.sellableList({ index: 0, size: 1000 });
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, props.productScope === "all" ? "产品加载失败" : "可售产品加载失败"));
|
||||
Message.error(getErrorMessage(error, "可售产品加载失败"));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<t-collapse
|
||||
v-model="expandedProductKeyList"
|
||||
class="product-sku-selector"
|
||||
class="product-sku-selector fix-last-cell-line"
|
||||
theme="card"
|
||||
:expand-mutex="true"
|
||||
@change="handleChange"
|
||||
|
||||
@@ -56,7 +56,7 @@ const userStore = useUserStore();
|
||||
/** 与 AppShell 内部的断点参数保持一致,用于判断页面是否需要底部留白。 */
|
||||
const { railVisible } = useLayout({ tablet: true });
|
||||
|
||||
const cachedRouteNames = new Set(["EventRecordRank", "SalesOrderList", "ProductList", "ProductStockList", "ProductStockBatchSelect", "ProductStockBatchConfigure"]);
|
||||
const cachedRouteNames = new Set(["EventRecordRank", "SalesOrderList", "ProductList", "ProductStockList", "ProductStockBatchSelect", "ProductStockBatchConfigure", "RecycleRuleList", "RecycleItemList"]);
|
||||
|
||||
function shouldKeepAlive(sourceRoute: RouteLocationNormalizedLoaded): boolean {
|
||||
return cachedRouteNames.has(String(sourceRoute.name));
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
:z-index="20"
|
||||
:title="routeNavBarTitle"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
@left-click="goBack"
|
||||
/>
|
||||
<main v-can="permissionCodes.stat.read" class="tui-page-content scroll column">
|
||||
<div class="filters glass">
|
||||
@@ -88,6 +88,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Time } from "timi-web";
|
||||
import { usePane } from "timi-tdesign-mobile";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||
import type { EventRecordCalendarListPayload } from "@/components/EventRecordCalendar.vue";
|
||||
@@ -104,8 +105,11 @@ defineOptions({
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const props = withDefaults(defineProps<{ customerId?: string }>(), { customerId: "" });
|
||||
const pane = usePane();
|
||||
|
||||
const routeNavBarTitle = computed(() => {
|
||||
if (props.customerId) return "客户数据图表";
|
||||
switch (route.name) {
|
||||
case "CustomerDataCharts":
|
||||
return "客户数据";
|
||||
@@ -119,11 +123,16 @@ const router = useRouter();
|
||||
|
||||
// ---------- 路由 ----------
|
||||
|
||||
const routeCustomerId = computed(() => String(route.params.id || ""));
|
||||
const routeCustomerId = computed(() => props.customerId || String(route.params.id || ""));
|
||||
const routeCustomerCode = computed(() => String(route.query.customerCode || ""));
|
||||
const customerCode = ref(routeCustomerCode.value);
|
||||
const selectedCustomerId = ref(routeCustomerId.value);
|
||||
|
||||
function goBack(): void {
|
||||
if (pane) pane.close();
|
||||
else void router.back();
|
||||
}
|
||||
|
||||
watch(routeCustomerCode, async (value) => {
|
||||
customerCode.value = value;
|
||||
await loadCustomer(value);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar">
|
||||
<div class="tui-page-layout tui-navbar customer-detail">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
@@ -18,149 +18,159 @@
|
||||
/>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div
|
||||
v-if="customer"
|
||||
v-can="permissionCodes.customer.read"
|
||||
class="customer-detail"
|
||||
<main
|
||||
v-if="customer"
|
||||
class="tui-page-content scroll column"
|
||||
v-can="permissionCodes.customer.read"
|
||||
>
|
||||
<customer-profile-card
|
||||
v-entrance-transition
|
||||
class="customer"
|
||||
:customer="customer"
|
||||
/>
|
||||
<t-cell-group v-entrance-transition class="info" theme="card">
|
||||
<t-cell title="出生日期">
|
||||
<span
|
||||
v-if="isLunarBirthdate"
|
||||
class="birthdate-trigger gray"
|
||||
type="button"
|
||||
@click.stop="toggleBirthdateText"
|
||||
>
|
||||
<span v-text="birthdateText" />
|
||||
</span>
|
||||
<span v-else v-text="birthdateText" />
|
||||
</t-cell>
|
||||
<t-cell title="年龄" :note="ageText" />
|
||||
<t-cell title="调理部位" :note="selectedAreaText" arrow @click="openBodyAreaPicker" />
|
||||
<t-cell title="住址" :note="Text.display(customer.address)" />
|
||||
<t-cell title="病症" :note="Text.display(customer.disease)" />
|
||||
<t-cell title="备注" :note="Text.display(customer.remark)" />
|
||||
<t-cell title="录入用户" :note="Text.display(customer.creatorUser?.nick || customer.creatorUser?.name)" />
|
||||
<t-cell title="录入时间">
|
||||
<template #note>
|
||||
<time-label :timestamp="customer.createdAt" underline />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<card-container v-entrance-transition>
|
||||
<attachment-selector
|
||||
class="attachment-selector"
|
||||
:items="photoItemList"
|
||||
title="照片列表"
|
||||
readonly
|
||||
>
|
||||
<template #item-label="{ item }">
|
||||
<span v-text="getAttachmentTypeText(item.attachType)" />
|
||||
</template>
|
||||
<template #viewer-actions="{ item, index, close }">
|
||||
<attachment-viewer-actions
|
||||
v-if="canUpdateCustomer"
|
||||
:attach-type="item.attachType"
|
||||
:busy="isPhotoSaving"
|
||||
@change-type="changePhotoType(index, $event, close)"
|
||||
@remove="removePhoto(index, close)"
|
||||
/>
|
||||
</template>
|
||||
</attachment-selector>
|
||||
</card-container>
|
||||
<customer-tag-card
|
||||
v-if="canReadTag"
|
||||
:editable="canApplyTag"
|
||||
:tag-list="customerTagList"
|
||||
v-entrance-transition
|
||||
@edit="openTagSelector"
|
||||
/>
|
||||
<t-cell-group v-if="canReadSalesOrder" title="交易订单" theme="card" v-entrance-transition>
|
||||
<t-cell title="产品订单列表" arrow @click="toProductOrderList">
|
||||
<template #left-icon>
|
||||
<t-icon name="task" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="套餐订单列表" arrow @click="toPackageOrderList">
|
||||
<template #left-icon>
|
||||
<t-icon name="gift" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell v-if="canReadRecycleExchange" title="回收兑换订单" arrow @click="toRecycleOrderList">
|
||||
<template #left-icon>
|
||||
<t-icon name="swap" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="canReadRecycleAccount" title="回收物" theme="card" v-entrance-transition>
|
||||
<t-cell title="回收物额度" arrow @click="toRecycleAccount">
|
||||
<template #left-icon>
|
||||
<t-icon name="swap" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group theme="card" v-entrance-transition>
|
||||
<t-cell v-if="canReadEventRecord" title="最近登记事件" arrow @click="toEventRecordList">
|
||||
<template #left-icon>
|
||||
<t-icon name="history" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell v-if="canReadStat" title="客户数据图表" arrow @click="toCustomerDataCharts">
|
||||
<template #left-icon>
|
||||
<t-icon name="chart" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell
|
||||
v-if="canReadPointAccount"
|
||||
title="积分余额"
|
||||
:note="pointBalanceText"
|
||||
arrow
|
||||
@click="toPointAccount"
|
||||
>
|
||||
<template #left-icon>
|
||||
<t-icon name="money" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group
|
||||
v-if="inviter"
|
||||
:title="`由 ${inviter.name} 邀请`"
|
||||
theme="card"
|
||||
v-entrance-transition
|
||||
>
|
||||
<customer-profile-card
|
||||
v-entrance-transition
|
||||
class="customer"
|
||||
:customer="customer"
|
||||
/>
|
||||
<t-cell-group v-entrance-transition class="info" theme="card">
|
||||
<t-cell title="出生日期">
|
||||
<span
|
||||
v-if="isLunarBirthdate"
|
||||
class="birthdate-trigger gray"
|
||||
type="button"
|
||||
@click.stop="toggleBirthdateText"
|
||||
>
|
||||
<span v-text="birthdateText" />
|
||||
</span>
|
||||
<span v-else v-text="birthdateText" />
|
||||
</t-cell>
|
||||
<t-cell title="年龄" :note="ageText" />
|
||||
<t-cell title="调理部位" :note="selectedAreaText" arrow @click="openBodyAreaPicker" />
|
||||
<t-cell title="住址" :note="Text.display(customer.address)" />
|
||||
<t-cell title="病症" :note="Text.display(customer.disease)" />
|
||||
<t-cell title="备注" :note="Text.display(customer.remark)" />
|
||||
<t-cell title="录入用户" :note="Text.display(customer.creatorUser?.nick || customer.creatorUser?.name)" />
|
||||
<t-cell title="录入时间">
|
||||
<template #note>
|
||||
<time-label :timestamp="customer.createdAt" underline />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<card-container v-entrance-transition>
|
||||
<attachment-selector
|
||||
class="attachment-selector"
|
||||
:items="photoItemList"
|
||||
title="照片列表"
|
||||
readonly
|
||||
>
|
||||
<template #item-label="{ item }">
|
||||
<span v-text="getAttachmentTypeText(item.attachType)" />
|
||||
</template>
|
||||
<template #viewer-actions="{ item, index, close }">
|
||||
<attachment-viewer-actions
|
||||
v-if="canUpdateCustomer"
|
||||
:attach-type="item.attachType"
|
||||
:busy="isPhotoSaving"
|
||||
@change-type="changePhotoType(index, $event, close)"
|
||||
@remove="removePhoto(index, close)"
|
||||
/>
|
||||
</template>
|
||||
</attachment-selector>
|
||||
</card-container>
|
||||
<customer-tag-card
|
||||
v-if="canReadTag"
|
||||
:editable="canApplyTag"
|
||||
:tag-list="customerTagList"
|
||||
v-entrance-transition
|
||||
@edit="openTagSelector"
|
||||
/>
|
||||
<t-cell-group v-if="canReadSalesOrder" title="销售订单" theme="card" v-entrance-transition>
|
||||
<t-cell title="产品订单列表" arrow @click="toProductOrderList">
|
||||
<template #left-icon>
|
||||
<t-icon name="task" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="套餐订单列表" arrow @click="toPackageOrderList">
|
||||
<template #left-icon>
|
||||
<t-icon name="gift" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group theme="card" v-entrance-transition>
|
||||
<t-cell v-if="canReadEventRecord" title="最近登记事件" arrow @click="toEventRecordList">
|
||||
<template #left-icon>
|
||||
<t-icon name="history" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell v-if="canReadStat" title="客户数据图表" arrow @click="toCustomerDataCharts">
|
||||
<template #left-icon>
|
||||
<t-icon name="chart" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell
|
||||
v-if="canReadPointAccount"
|
||||
title="积分余额"
|
||||
:note="pointBalanceText"
|
||||
arrow
|
||||
@click="toPointAccount"
|
||||
>
|
||||
<template #left-icon>
|
||||
<t-icon name="money" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group
|
||||
v-if="inviter"
|
||||
:title="`由 ${inviter.name} 邀请`"
|
||||
theme="card"
|
||||
v-entrance-transition
|
||||
>
|
||||
<customer-profile-card :customer="inviter" @click="toCustomerDetail(inviter)"/>
|
||||
</t-cell-group>
|
||||
<t-cell-group theme="card">
|
||||
<t-cell title="邀请客户" :note="inviteeCountText" arrow @click="toInviteeList" />
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="canReadFollowUpReminder" title="客户跟进" theme="card">
|
||||
<t-cell title="跟进提醒" note="查看客户提醒" arrow @click="toFollowUpReminderList" />
|
||||
</t-cell-group>
|
||||
<t-button
|
||||
v-can="permissionCodes.customer.delete"
|
||||
class="delete-action"
|
||||
theme="danger"
|
||||
:loading="isRemoving"
|
||||
@click="confirmRemoveCustomer"
|
||||
>
|
||||
删除客户
|
||||
</t-button>
|
||||
<tag-selector
|
||||
v-model="selectedTagIdList"
|
||||
v-model:visible="tagSelectorVisible"
|
||||
@change="handleTagSelected"
|
||||
/>
|
||||
<bottom-popup
|
||||
v-model="bodyAreaPickerVisible"
|
||||
title="调理部位"
|
||||
height="38rem"
|
||||
left-button-text="关闭"
|
||||
right-button-text=""
|
||||
@left-button-click="closeBodyAreaPicker"
|
||||
>
|
||||
<body-area-selector :model-value="selectedAreas" readonly />
|
||||
</bottom-popup>
|
||||
<customer-remove-dialog
|
||||
v-model:visible="removeDialogVisible"
|
||||
:customer="removeTarget"
|
||||
:loading="isRemoving"
|
||||
@confirm="removeConfirmedCustomer"
|
||||
/>
|
||||
</div>
|
||||
<customer-profile-card :customer="inviter" @click="toCustomerDetail(inviter)"/>
|
||||
</t-cell-group>
|
||||
<t-cell-group theme="card">
|
||||
<t-cell title="邀请客户" :note="inviteeCountText" arrow @click="toInviteeList" />
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="canReadFollowUpReminder" title="客户跟进" theme="card">
|
||||
<t-cell title="跟进提醒" note="查看客户提醒" arrow @click="toFollowUpReminderList" />
|
||||
</t-cell-group>
|
||||
<t-button
|
||||
v-can="permissionCodes.customer.delete"
|
||||
class="delete-action"
|
||||
theme="danger"
|
||||
:loading="isRemoving"
|
||||
@click="confirmRemoveCustomer"
|
||||
>
|
||||
删除客户
|
||||
</t-button>
|
||||
<tag-selector
|
||||
v-model="selectedTagIdList"
|
||||
v-model:visible="tagSelectorVisible"
|
||||
@change="handleTagSelected"
|
||||
/>
|
||||
<bottom-popup
|
||||
v-model="bodyAreaPickerVisible"
|
||||
title="调理部位"
|
||||
height="38rem"
|
||||
left-button-text="关闭"
|
||||
right-button-text=""
|
||||
@left-button-click="closeBodyAreaPicker"
|
||||
>
|
||||
<body-area-selector :model-value="selectedAreas" readonly />
|
||||
</bottom-popup>
|
||||
<customer-remove-dialog
|
||||
v-model:visible="removeDialogVisible"
|
||||
:customer="removeTarget"
|
||||
:loading="isRemoving"
|
||||
@confirm="removeConfirmedCustomer"
|
||||
/>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
@@ -227,6 +237,8 @@ const canReadStat = computed(() => userStore.hasPermissions(permissionCodes.stat
|
||||
const canReadEventRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.read));
|
||||
const canReadPointAccount = computed(() => userStore.hasPermissions(permissionCodes.point.accountRead));
|
||||
const canReadSalesOrder = computed(() => userStore.hasPermissions(permissionCodes.salesOrder.read));
|
||||
const canReadRecycleExchange = computed(() => userStore.hasPermissions(permissionCodes.salesOrder.read));
|
||||
const canReadRecycleAccount = computed(() => userStore.hasPermissions(permissionCodes.recycleAccount.read));
|
||||
const canReadTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.read));
|
||||
const canApplyTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.apply));
|
||||
const canUpdateCustomer = computed(() => userStore.hasPermissions(permissionCodes.customer.update));
|
||||
@@ -469,6 +481,7 @@ async function toInviteeList(): Promise<void> {
|
||||
if (!customer.value?.id) {
|
||||
return;
|
||||
}
|
||||
if (pane?.openSub("invitees")) return;
|
||||
await router.push(`/management/customers/${customer.value.id}/invitees`);
|
||||
}
|
||||
|
||||
@@ -497,6 +510,24 @@ async function toEventRecordList(): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
async function toRecycleOrderList(): Promise<void> {
|
||||
await toSalesOrderList("RECYCLE");
|
||||
}
|
||||
|
||||
async function toRecycleAccount(): Promise<void> {
|
||||
if (!customer.value?.id) {
|
||||
return;
|
||||
}
|
||||
if (pane?.openSub("recycle-account")) return;
|
||||
await router.push({
|
||||
name: "RecycleAccount",
|
||||
query: {
|
||||
customerId: customer.value.id,
|
||||
transitionDepth: String(Number(route.meta.depth ?? 0) + 1)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function toSalesOrderList(orderType: GaoSalesOrderType): Promise<void> {
|
||||
if (!customer.value?.id || !canReadSalesOrder.value) {
|
||||
return;
|
||||
@@ -570,9 +601,11 @@ async function toPointAccount(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
if (!pointAccount.value?.id) {
|
||||
if (pane?.openSub("point-list")) return;
|
||||
await router.push({ name: "PointAccountList" });
|
||||
return;
|
||||
}
|
||||
if (pane?.openSub(`point-account:${pointAccount.value.id}:${customer.value.storeId || ""}`)) return;
|
||||
await router.push({
|
||||
name: "PointAccountDetail",
|
||||
params: { id: pointAccount.value.id },
|
||||
@@ -596,6 +629,7 @@ async function toCustomerDataCharts(): Promise<void> {
|
||||
if (!customer.value?.id) {
|
||||
return;
|
||||
}
|
||||
if (pane?.openSub("charts")) return;
|
||||
|
||||
await router.push(`/management/customers/${customer.value.id}/data-charts`);
|
||||
}
|
||||
@@ -609,10 +643,6 @@ watch(() => [props.customerId, route.params.id], loadCustomer);
|
||||
|
||||
<style scoped lang="less">
|
||||
.customer-detail {
|
||||
gap: 1rem;
|
||||
padding: 0 0 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.customer {
|
||||
margin: 0 1rem;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
:z-index="20"
|
||||
title="邀请客户"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
@left-click="goBack"
|
||||
/>
|
||||
<main class="tui-page-content scroll column list">
|
||||
<div class="pull-refresh">
|
||||
@@ -93,7 +93,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import { BottomPopup, usePane } from "timi-tdesign-mobile";
|
||||
import { Message } from "@/utils/message";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
@@ -109,6 +109,8 @@ defineOptions({
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const props = withDefaults(defineProps<{ customerId?: string }>(), { customerId: "" });
|
||||
const pane = usePane();
|
||||
const router = useRouter();
|
||||
const settingStore = useSettingStore();
|
||||
const userStore = useUserStore();
|
||||
@@ -125,10 +127,15 @@ let latestDecodedText = "";
|
||||
|
||||
const canUpdateCustomer = computed(() => userStore.hasPermissions(permissionCodes.customer.update));
|
||||
|
||||
function goBack(): void {
|
||||
if (pane) pane.close();
|
||||
else void router.back();
|
||||
}
|
||||
|
||||
// ---------- 加载 ----------
|
||||
|
||||
async function loadCustomer(): Promise<void> {
|
||||
const customerId = String(route.params.id || "");
|
||||
const customerId = props.customerId || String(route.params.id || "");
|
||||
if (!customerId) {
|
||||
customer.value = undefined;
|
||||
invitees.value = [];
|
||||
@@ -271,7 +278,7 @@ async function toCustomerDetail(target: Customer): Promise<void> {
|
||||
}
|
||||
|
||||
onMounted(loadCustomer);
|
||||
watch(() => route.params.id, loadCustomer);
|
||||
watch(() => [props.customerId, route.params.id], loadCustomer);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
:split="isWide"
|
||||
:selected="!!selectedId"
|
||||
:direction="paneDirection"
|
||||
:sub="!!subView"
|
||||
>
|
||||
<template #master>
|
||||
<t-pull-down-refresh
|
||||
@@ -164,6 +165,13 @@
|
||||
@edit="openEdit"
|
||||
/>
|
||||
</template>
|
||||
<template #sub>
|
||||
<recycle-account v-if="subKind === 'recycle-account'" :initial-customer-id="selectedId" />
|
||||
<customer-data-charts v-else-if="subKind === 'charts'" :customer-id="selectedId" />
|
||||
<customer-invitee-list v-else-if="subKind === 'invitees'" :customer-id="selectedId" />
|
||||
<point-account-detail v-else-if="subKind === 'point-account'" :account-id="subArg" :store-id="subView?.split(':')[2] || ''" />
|
||||
<point-account-list v-else-if="subKind === 'point-list'" />
|
||||
</template>
|
||||
</master-detail-page>
|
||||
</div>
|
||||
|
||||
@@ -203,6 +211,11 @@ import CustomerAPI from "@/api/CustomerAPI";
|
||||
import CodeScanner from "@/components/CodeScanner.vue";
|
||||
import CustomerDetail from "@/pages/customer/CustomerDetail.vue";
|
||||
import CustomerEdit from "@/pages/customer/CustomerEdit.vue";
|
||||
import CustomerDataCharts from "@/pages/customer/CustomerDataCharts.vue";
|
||||
import CustomerInviteeList from "@/pages/customer/CustomerInviteeList.vue";
|
||||
import RecycleAccount from "@/pages/recycle/RecycleAccount.vue";
|
||||
import PointAccountDetail from "@/pages/point/PointAccountDetail.vue";
|
||||
import PointAccountList from "@/pages/point/PointAccountList.vue";
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import CustomerRemoveDialog from "@/pages/customer/component/CustomerRemoveDialog.vue";
|
||||
import TagSelector from "@/components/TagSelector.vue";
|
||||
@@ -226,12 +239,14 @@ const settingStore = useSettingStore();
|
||||
const createPaneId = "__create__";
|
||||
|
||||
// 选中项、编辑态、切换方向、关闭逻辑、转屏、query 同步都在这里
|
||||
const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
|
||||
const { selectedId, subView, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
|
||||
useMasterDetailPane({
|
||||
path: "/management/customers",
|
||||
detail: id => id === createPaneId ? "/management/customers/create" : `/management/customers/${id}`,
|
||||
edit: id => `/management/customers/${id}/edit`
|
||||
});
|
||||
const subKind = computed(() => subView.value?.split(":")[0] || "");
|
||||
const subArg = computed(() => subView.value?.split(":")[1] || "");
|
||||
|
||||
const isRefreshing = ref(false);
|
||||
const isRemoving = ref(false);
|
||||
|
||||
@@ -12,7 +12,7 @@ export const dataExportModuleOptionList: DataExportModuleOption[] = [
|
||||
{ label: "客户跟进提醒", value: "CUSTOMER_FOLLOW_UP_REMINDER" },
|
||||
{ label: "客户套餐", value: "CUSTOMER_PACKAGE" },
|
||||
{ label: "事件登记", value: "EVENT_RECORD" },
|
||||
{ label: "销售订单", value: "SALES_ORDER" },
|
||||
{ label: "交易订单", value: "SALES_ORDER" },
|
||||
{ label: "履约记录", value: "ORDER_FULFILLMENT" },
|
||||
{ label: "资金流水", value: "FUND_RECORD" },
|
||||
{ label: "积分账户", value: "POINT_ACCOUNT" },
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar">
|
||||
<div class="tui-page-layout tui-navbar fulfillment-create">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="创建履约单"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
@left-click="exit"
|
||||
>
|
||||
<template #right>
|
||||
<t-button
|
||||
@@ -17,119 +17,117 @@
|
||||
/>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div v-can="permissionCodes.orderFulfillment.create" class="fulfillment-create">
|
||||
<t-cell-group title="履约来源" theme="card">
|
||||
<t-cell title="销售订单" :note="order?.orderNo || order?.id || '未找到来源订单'" />
|
||||
<t-cell title="客户" :note="order?.customer?.name || order?.customerId || '未选择'" />
|
||||
<t-cell title="来源类型" :note="isPackage ? '套餐权益' : '直接产品'" />
|
||||
</t-cell-group>
|
||||
<t-form v-if="sourceItems.length" class="items form">
|
||||
<t-form-item v-for="item in sourceItems" :key="item.id" class="item" label-width="0">
|
||||
<div class="content">
|
||||
<div class="photo">
|
||||
<t-image
|
||||
v-if="getProductPhotoURL(item)"
|
||||
:src="getProductPhotoURL(item)"
|
||||
:alt="item.productNameSnapshot || '产品图片'"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="avatar fallback"
|
||||
v-text="(item.productNameSnapshot || '产').slice(0, 1)"
|
||||
/>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="title">
|
||||
<div class="heading">
|
||||
<div class="name-gift">
|
||||
<strong v-text="item.productNameSnapshot || '未命名产品'"/>
|
||||
<t-tag
|
||||
v-if="item.gifted"
|
||||
size="small"
|
||||
theme="primary"
|
||||
content="赠送"
|
||||
<main v-can="permissionCodes.orderFulfillment.create" class="tui-page-content scroll column">
|
||||
<customer-profile-card v-if="order" class="customer" :customer="order.customer" />
|
||||
<t-cell-group title="履约来源" theme="card" v-entrance-transition>
|
||||
<t-cell title="交易订单" :note="order?.orderNo || order?.id || '未找到来源订单'" />
|
||||
<t-cell title="来源类型" :note="sourceTypeText" />
|
||||
</t-cell-group>
|
||||
<t-form v-if="sourceItems.length" class="items form" v-entrance-transition>
|
||||
<t-form-item v-for="item in sourceItems" :key="item.id" class="item" label-width="0">
|
||||
<div class="content">
|
||||
<div class="photo">
|
||||
<t-image
|
||||
v-if="getProductPhotoURL(item)"
|
||||
:src="getProductPhotoURL(item)"
|
||||
:alt="item.productNameSnapshot || '产品图片'"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="avatar fallback"
|
||||
v-text="(item.productNameSnapshot || '产').slice(0, 1)"
|
||||
/>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="title">
|
||||
<div class="heading">
|
||||
<div class="name-gift">
|
||||
<strong v-text="item.productNameSnapshot || '未命名产品'"/>
|
||||
<t-tag
|
||||
v-if="item.gifted"
|
||||
size="small"
|
||||
theme="primary"
|
||||
content="赠送"
|
||||
/>
|
||||
<div
|
||||
v-if="item.skuCodeSnapshot || item.skuSpecSnapshot?.length || item.skuNameSnapshot || item.specSummarySnapshot || item.unitSnapshot"
|
||||
class="sku-tags"
|
||||
>
|
||||
<product-sku-tags
|
||||
:product-name="item.productNameSnapshot"
|
||||
:snapshot="item.skuSpecSnapshot"
|
||||
:fallback="item.specSummarySnapshot || item.skuNameSnapshot"
|
||||
/>
|
||||
<div
|
||||
v-if="item.skuCodeSnapshot || item.skuSpecSnapshot?.length || item.skuNameSnapshot || item.specSummarySnapshot || item.unitSnapshot"
|
||||
class="sku-tags"
|
||||
>
|
||||
<product-sku-tags
|
||||
:product-name="item.productNameSnapshot"
|
||||
:snapshot="item.skuSpecSnapshot"
|
||||
:fallback="item.specSummarySnapshot || item.skuNameSnapshot"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<span class="can-fulfill" v-text="getItemDescription(item)" />
|
||||
</div>
|
||||
<span class="can-fulfill" v-text="getItemDescription(item)" />
|
||||
</div>
|
||||
<div class="input">
|
||||
<div class="quantity">
|
||||
<t-stepper
|
||||
v-model="quantityMap[item.id || '']"
|
||||
class="stepper"
|
||||
size="large"
|
||||
:max="Number.MAX_SAFE_INTEGER"
|
||||
:min="0"
|
||||
:step="getQuantityStep(item)"
|
||||
:integer="!allowsDecimalQuantity(item)"
|
||||
:disabled="!getFulfillmentUnit(item)"
|
||||
theme="outline"
|
||||
@change="scheduleStockPreview"
|
||||
/>
|
||||
<t-button
|
||||
class="unit"
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
:content="getFulfillmentUnit(item)?.name || '选择实际单位'"
|
||||
@click.stop="openUnitPicker(item)"
|
||||
/>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
:disabled="getAvailableBaseQuantity(item) === '0' || (directVerify && isStockChecking)"
|
||||
@click.stop="fillAllQuantity(item)"
|
||||
>全部履约</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input">
|
||||
<div class="quantity">
|
||||
<t-stepper
|
||||
v-model="quantityMap[item.id || '']"
|
||||
class="stepper"
|
||||
size="large"
|
||||
:max="Number.MAX_SAFE_INTEGER"
|
||||
:min="0"
|
||||
:step="getQuantityStep(item)"
|
||||
:integer="!allowsDecimalQuantity(item)"
|
||||
:disabled="!getFulfillmentUnit(item)"
|
||||
theme="outline"
|
||||
@change="scheduleStockPreview"
|
||||
/>
|
||||
<t-button
|
||||
class="unit"
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
:content="getFulfillmentUnit(item)?.name || '选择实际单位'"
|
||||
@click.stop="openUnitPicker(item)"
|
||||
/>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
:disabled="getAvailableBaseQuantity(item) === '0' || (directVerify && isStockChecking)"
|
||||
@click.stop="fillAllQuantity(item)"
|
||||
>全部履约</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<center-tips v-else :content="'暂无可履约明细,请返回订单详情检查'" />
|
||||
<t-form class="form card" label-width="7rem">
|
||||
<t-form-item label="履约时间" content-align="right">
|
||||
<date-time-now-picker v-model="deliveredAtText" title="履约时间" />
|
||||
</t-form-item>
|
||||
<t-form-item v-if="canDirectVerify" label="直接核销履约" content-align="right">
|
||||
<t-switch v-model="directVerify" size="small" :disabled="isSaving || isStockChecking" />
|
||||
</t-form-item>
|
||||
<t-form-item v-if="directVerify || stockPreviewList.length" label-width="0">
|
||||
<div class="stock-tips">
|
||||
<span v-if="directVerify" class="tips red">直接核销会立即扣减实物库存</span>
|
||||
<product-stock-preview v-if="stockPreviewList.length" :items="stockPreviewList" />
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label="备注">
|
||||
<t-textarea v-model="remark" borderless autosize maxlength="500" />
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<attachment-selector
|
||||
v-if="order"
|
||||
v-model:items="photoItems"
|
||||
:upload="uploadPhotoList"
|
||||
required
|
||||
title="履约凭证照片"
|
||||
/>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<t-popup v-model="unitPickerVisible" placement="bottom">
|
||||
<t-picker v-model="unitPickerDraft" :columns="unitPickerOptions" title="选择实际履约单位" @cancel="unitPickerVisible = false" @confirm="confirmUnitPicker" />
|
||||
</t-popup>
|
||||
</div>
|
||||
</div>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<center-tips v-else :content="'暂无可履约明细,请返回订单详情检查'" v-entrance-transition />
|
||||
<t-form class="form card" label-width="7rem" v-entrance-transition>
|
||||
<t-form-item label="履约时间" content-align="right">
|
||||
<date-time-now-picker v-model="deliveredAtText" title="履约时间" />
|
||||
</t-form-item>
|
||||
<t-form-item v-if="canDirectVerify" label="直接核销履约" content-align="right">
|
||||
<t-switch v-model="directVerify" size="small" :disabled="isSaving || isStockChecking" />
|
||||
</t-form-item>
|
||||
<t-form-item v-if="directVerify || stockPreviewList.length" label-width="0">
|
||||
<div class="stock-tips">
|
||||
<span v-if="directVerify" class="tips red">直接核销会立即扣减实物库存</span>
|
||||
<product-stock-preview v-if="stockPreviewList.length" :items="stockPreviewList" />
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label="备注">
|
||||
<t-textarea v-model="remark" borderless autosize maxlength="500" />
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<attachment-selector
|
||||
v-if="order"
|
||||
v-model:items="photoItems"
|
||||
:upload="uploadPhotoList"
|
||||
required
|
||||
title="履约凭证照片"
|
||||
/>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<t-popup v-model="unitPickerVisible" placement="bottom">
|
||||
<t-picker v-model="unitPickerDraft" :columns="unitPickerOptions" title="选择实际履约单位" @cancel="unitPickerVisible = false" @confirm="confirmUnitPicker" />
|
||||
</t-popup>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
@@ -140,9 +138,11 @@ import SalesOrderAPI from "@/api/SalesOrderAPI";
|
||||
import FulfillmentAPI from "@/api/FulfillmentAPI";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
|
||||
import ProductSkuTags from "@/components/ProductSkuTags.vue";
|
||||
import ProductStockPreview from "@/components/ProductStockPreview.vue";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { usePane } from "timi-tdesign-mobile";
|
||||
import type { GaoOrderFulfillmentItemRequest } from "@/types/Fulfillment";
|
||||
import type { GaoSalesOrderItem, SalesOrder } from "@/types/SalesOrder";
|
||||
import type { FulfillmentProductSku, ProductSkuUnit } from "@/types/Product";
|
||||
@@ -175,8 +175,36 @@ import { getProductPhotoURL, getProductQuantityStep } from "@/utils/product";
|
||||
import type { Attachment } from "timi-web-api";
|
||||
|
||||
defineOptions({ name: "OrderFulfillmentCreate" });
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** 指定订单 ID:内嵌在订单详情里时直接用它,不读 query。 */
|
||||
salesOrderId?: string;
|
||||
/**
|
||||
* 内嵌模式:作为订单详情的第三层(详情 + 创建履约单)渲染。
|
||||
*
|
||||
* 提交成功后由宿主显示履约单详情。
|
||||
*/
|
||||
embedded?: boolean;
|
||||
}>(), {
|
||||
salesOrderId: "",
|
||||
embedded: false
|
||||
});
|
||||
const emit = defineEmits<{ saved: [fulfillmentId?: string] }>();
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
/** 内嵌时宿主页面提供了栏上下文,返回要交回去而不是 router.back()。 */
|
||||
const pane = usePane();
|
||||
/** 来源订单:内嵌时来自 prop,整页时来自 query。 */
|
||||
const sourceOrderId = computed(() => props.salesOrderId || String(route.query.salesOrderId || ""));
|
||||
|
||||
function exit(): void {
|
||||
if (pane) {
|
||||
pane.close();
|
||||
return;
|
||||
}
|
||||
void router.back();
|
||||
}
|
||||
const userStore = useUserStore();
|
||||
const order = ref<SalesOrder>();
|
||||
const quantityMap = reactive<Record<string, string | number>>({});
|
||||
@@ -196,14 +224,15 @@ const stockPreviewList = ref<ProductStockPreviewItem[]>([]);
|
||||
let stockCheckToken = 0;
|
||||
let stockPreviewTimer: number | undefined;
|
||||
const isPackage = computed(() => order.value?.orderType === "PACKAGE");
|
||||
const expectedItemType = computed(() => isPackage.value ? "PACKAGE_ENTITLEMENT" : "DIRECT_PRODUCT");
|
||||
const sourceTypeText = computed(() => order.value?.orderType === "RECYCLE" ? "回收兑换权益" : isPackage.value ? "套餐权益" : "直接产品");
|
||||
const expectedItemType = computed(() => order.value?.orderType === "RECYCLE" ? "RECYCLE_ENTITLEMENT" : isPackage.value ? "PACKAGE_ENTITLEMENT" : "DIRECT_PRODUCT");
|
||||
const sourceItems = computed<GaoSalesOrderItem[]>(() => (order.value?.itemList || []).filter(item => item.itemType === expectedItemType.value
|
||||
&& 0 < comparePackageQuantity(item.availableBaseQuantity ?? "0", "0")));
|
||||
const unitPickerOptions = computed(() => {
|
||||
const item = sourceItems.value.find(value => value.id === unitPickerSourceItemId.value);
|
||||
return item ? getFulfillmentUnitList(item).map(unit => ({ label: unit.name, value: unit.id || "" })) : [];
|
||||
});
|
||||
const canFulfillByPayment = computed(() => order.value?.paymentStatus === "PAID" || userStore.hasRoles(gaoRoleCodes.storeManager));
|
||||
const canFulfillByPayment = computed(() => order.value?.paymentStatus === "PAID" || userStore.hasPermissions(permissionCodes.orderFulfillment.unsettled));
|
||||
const canDirectVerify = computed(() => userStore.hasRoles(gaoRoleCodes.storeManager)
|
||||
&& userStore.hasPermissions(permissionCodes.orderFulfillment.create)
|
||||
&& userStore.hasPermissions(permissionCodes.orderFulfillment.verify)
|
||||
@@ -229,10 +258,10 @@ watch(directVerify, async value => {
|
||||
});
|
||||
|
||||
async function loadData(): Promise<void> {
|
||||
const salesOrderId = String(route.query.salesOrderId || "");
|
||||
const salesOrderId = sourceOrderId.value;
|
||||
if (!salesOrderId) {
|
||||
Message.warning("请从订单详情进入履约创建");
|
||||
await router.replace("/management/order-fulfillments");
|
||||
await router.replace("/product/order-fulfillments");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -586,7 +615,12 @@ async function save(): Promise<void> {
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, request.salesOrderId);
|
||||
emitListDataChanged(listDataEventKeys.productStockChanged);
|
||||
Message.success(directVerify.value ? "履约单创建并核销成功" : "履约单已提交");
|
||||
await router.replace(`/management/order-fulfillments/${result.id}`);
|
||||
if (props.embedded) {
|
||||
emit("saved", result.id);
|
||||
if (!result.id) pane?.close(true);
|
||||
return;
|
||||
}
|
||||
await router.replace(`/product/order-fulfillments/${result.id}`);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "履约单创建失败,重试会复用同一请求号"));
|
||||
} finally {
|
||||
@@ -604,10 +638,10 @@ onUnmounted(() => {
|
||||
|
||||
<style scoped lang="less">
|
||||
.fulfillment-create {
|
||||
gap: 1rem;
|
||||
padding: 0 0 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.customer {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.items {
|
||||
margin: 0 1rem;
|
||||
@@ -619,10 +653,10 @@ onUnmounted(() => {
|
||||
|
||||
.content {
|
||||
gap: .5rem;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
flex: 1 1 auto;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
|
||||
.photo {
|
||||
gap: .5rem;
|
||||
@@ -706,11 +740,6 @@ onUnmounted(() => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tips {
|
||||
font-size: .875rem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
<div v-can="permissionCodes.orderFulfillment.read" class="fulfillment-detail">
|
||||
<template v-if="fulfillment">
|
||||
<t-cell-group title="履约单信息" theme="card" v-entrance-transition>
|
||||
<t-cell title="销售订单" arrow @click="toOrder" />
|
||||
<t-cell title="订单项类型" :note="getSalesOrderItemTypeText(sourceItemType)" />
|
||||
<t-cell title="交易订单" arrow @click="toOrder" />
|
||||
<t-cell v-if="isRecycle" title="来源" note="回收兑换订单" />
|
||||
<t-cell v-else title="订单项类型" :note="getSalesOrderItemTypeText(sourceItemType)" />
|
||||
<t-cell title="状态"><template #note><t-tag :content="getFulfillmentStatusText(fulfillment.status)" variant="light-outline" :theme="getStatusTheme(fulfillment.status)" /></template></t-cell>
|
||||
<t-cell title="履约时间">
|
||||
<template #note>
|
||||
@@ -220,7 +221,7 @@ function resolveId(): string {
|
||||
|
||||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||||
useExpandToMaster({
|
||||
path: "/management/order-fulfillments",
|
||||
path: "/product/order-fulfillments",
|
||||
id: () => resolveId()
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
@@ -261,13 +262,16 @@ const isWaitingStock = computed(() => fulfillment.value?.status === "WAITING_STO
|
||||
const isPending = computed(() => fulfillment.value?.status === "PENDING");
|
||||
const isVerified = computed(() => fulfillment.value?.status === "VERIFIED");
|
||||
const isOrderCancelled = computed(() => order.value?.status === "CANCELLED");
|
||||
const isRecycle = computed(() => order.value?.orderType === "RECYCLE");
|
||||
const canVerify = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.verify));
|
||||
const canCancel = computed(() => {
|
||||
const loginUserId = userStore.loginUser.user?.id || userStore.loginUser.id;
|
||||
return userStore.hasPermissions(permissionCodes.orderFulfillment.create)
|
||||
const createPermission = permissionCodes.orderFulfillment.create;
|
||||
return userStore.hasPermissions(createPermission)
|
||||
&& (userStore.hasRoles(gaoRoleCodes.storeManager) || (!!loginUserId && loginUserId === fulfillment.value?.operatorUserId));
|
||||
});
|
||||
const canRevoke = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.revoke));
|
||||
/** 回收订单退货会按原流水撤销额度,流程与普通订单一致 */
|
||||
const canReturn = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.return));
|
||||
const reasonOptions: Record<ReasonAction, string[]> = {
|
||||
reject: [
|
||||
@@ -390,11 +394,12 @@ async function loadData(): Promise<void> {
|
||||
async function toOrder(): Promise<void> {
|
||||
if (fulfillment.value?.salesOrderId) {
|
||||
await router.push({
|
||||
path: `/management/sales-orders/${fulfillment.value.salesOrderId}`,
|
||||
path: `/product/sales-orders/${fulfillment.value.salesOrderId}`,
|
||||
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentRouteDepth(): number {
|
||||
const transitionDepth = Array.isArray(route.query.transitionDepth)
|
||||
? route.query.transitionDepth[0]
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar fulfillment-list">
|
||||
<div class="tui-page-layout tui-navbar fulfillment-list" :class="{ embedded }">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="履约记录"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
@left-click="exit"
|
||||
>
|
||||
<template #right>
|
||||
<navbar-actions :actions="actions" :visible="canCreate" />
|
||||
@@ -14,7 +14,7 @@
|
||||
<master-detail-page
|
||||
v-can="permissionCodes.orderFulfillment.read"
|
||||
class="list"
|
||||
:split="isWide"
|
||||
:split="isWide && !embedded"
|
||||
:selected="!!selectedId"
|
||||
:direction="paneDirection"
|
||||
>
|
||||
@@ -184,7 +184,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import { MasterDetailPage, useMasterDetailPane, usePane } from "timi-tdesign-mobile";
|
||||
import type { NavbarAction } from "@/types/NavbarAction.ts";
|
||||
import OrderFulfillmentDetail from "@/pages/fulfillment/OrderFulfillmentDetail.vue";
|
||||
import { type DropdownValue } from "tdesign-mobile-vue";
|
||||
@@ -209,18 +209,45 @@ import type { GaoFulfillmentStatus, OrderFulfillment } from "@/types/Fulfillment
|
||||
|
||||
defineOptions({ name: "OrderFulfillmentList" });
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** 指定订单 ID:内嵌在订单详情里时只列本单的履约单。 */
|
||||
salesOrderId?: string;
|
||||
/**
|
||||
* 内嵌模式:不分栏、不动路由,返回交给宿主页面。
|
||||
*
|
||||
* 用于订单详情的第三层(详情 + 履约记录),此时本页只是右栏里的一段列表。
|
||||
*/
|
||||
embedded?: boolean;
|
||||
}>(), {
|
||||
salesOrderId: "",
|
||||
embedded: false
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
/** 内嵌时宿主页面提供了栏上下文,返回要交回去而不是 router.back()。 */
|
||||
const pane = usePane();
|
||||
/** 订单筛选条件:内嵌时来自 prop,整页时来自 query。 */
|
||||
const orderId = computed(() => props.salesOrderId || getQueryText(route.query.salesOrderId));
|
||||
|
||||
function exit(): void {
|
||||
if (pane) {
|
||||
pane.close();
|
||||
return;
|
||||
}
|
||||
void router.back();
|
||||
}
|
||||
|
||||
// 选中项、切换方向、关闭逻辑、转屏、query 同步都在这里;履约单没有内联编辑视图
|
||||
const { selectedId, paneDirection, isWide, openDetail } = useMasterDetailPane({
|
||||
path: "/management/order-fulfillments",
|
||||
detail: id => `/management/order-fulfillments/${id}`
|
||||
path: "/product/order-fulfillments",
|
||||
detail: id => `/product/order-fulfillments/${id}`
|
||||
});
|
||||
const filterMenuRef = ref<{ collapseMenu: () => void }>();
|
||||
const userStore = useUserStore();
|
||||
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.create));
|
||||
const actions = computed<NavbarAction[]>(() => [
|
||||
/** 列表合并了两个来源,创建入口只有交易订单这条线;回收兑换从兑换单详情发起领取 */
|
||||
const actions = computed<NavbarAction[]>(() => canCreate.value ? [
|
||||
{
|
||||
key: "quick-fulfillment",
|
||||
text: "快速履约",
|
||||
@@ -242,7 +269,7 @@ const actions = computed<NavbarAction[]>(() => [
|
||||
theme: "primary",
|
||||
action: toPackageOrderList
|
||||
}
|
||||
]);
|
||||
] : []);
|
||||
type SkuFilterOption = { skuId: string; productName: string; skuName: string };
|
||||
|
||||
const customerId = ref(getQueryText(route.query.customerId));
|
||||
@@ -330,7 +357,7 @@ async function fetchList(reset: boolean): Promise<void> {
|
||||
const result = await FulfillmentAPI.list({
|
||||
index: pageIndex.value,
|
||||
size: pageSize,
|
||||
salesOrderId: getQueryText(route.query.salesOrderId) || undefined,
|
||||
salesOrderId: orderId.value || undefined,
|
||||
customerId: customerId.value || undefined,
|
||||
skuIdList: selectedSkuIdList.value.length ? selectedSkuIdList.value : undefined,
|
||||
beginAt,
|
||||
@@ -420,13 +447,13 @@ async function clearCustomer(): Promise<void> {
|
||||
}
|
||||
|
||||
async function loadSalesOrder(): Promise<void> {
|
||||
const salesOrderId = getQueryText(route.query.salesOrderId);
|
||||
if (!salesOrderId) {
|
||||
const currentOrderId = orderId.value;
|
||||
if (!currentOrderId) {
|
||||
salesOrder.value = undefined;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
salesOrder.value = await SalesOrderAPI.detail(salesOrderId);
|
||||
salesOrder.value = await SalesOrderAPI.detail(currentOrderId);
|
||||
} catch (error) {
|
||||
salesOrder.value = undefined;
|
||||
Message.error(getErrorMessage(error, "订单信息加载失败"));
|
||||
@@ -490,7 +517,7 @@ async function confirmCustomRange(): Promise<void> {
|
||||
|
||||
function buildFilterQuery(transitionDepth = getQueryText(route.query.transitionDepth)): Record<string, string> {
|
||||
const query = {
|
||||
salesOrderId: getQueryText(route.query.salesOrderId),
|
||||
salesOrderId: orderId.value,
|
||||
customerId: customerId.value,
|
||||
skuIds: selectedSkuIdList.value.join(","),
|
||||
dateType: dateFilterType.value,
|
||||
@@ -505,6 +532,10 @@ function buildFilterQuery(transitionDepth = getQueryText(route.query.transitionD
|
||||
}
|
||||
|
||||
async function replaceFilterQuery(): Promise<void> {
|
||||
// 内嵌时路由归宿主页面所有,改 query 会把它顶掉,筛选只留在内存里
|
||||
if (props.embedded) {
|
||||
return;
|
||||
}
|
||||
await router.replace({
|
||||
name: "OrderFulfillmentList",
|
||||
query: buildFilterQuery()
|
||||
@@ -527,6 +558,12 @@ function buildUnixRange(): [number | undefined, number | undefined] {
|
||||
}
|
||||
|
||||
async function toDetail(item: OrderFulfillment): Promise<void> {
|
||||
if (props.embedded) {
|
||||
if (!item.id) return;
|
||||
if (pane?.openSub(`fulfillment-detail:${item.id}`)) return;
|
||||
await router.push({ name: "OrderFulfillmentDetail", params: { id: item.id } });
|
||||
return;
|
||||
}
|
||||
openDetail(item.id || "");
|
||||
}
|
||||
|
||||
@@ -566,7 +603,6 @@ function getCurrentRouteDepth(): number {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
try {
|
||||
await loadSalesOrder();
|
||||
if (customerId.value) {
|
||||
@@ -582,8 +618,16 @@ onMounted(async () => {
|
||||
|
||||
<style scoped lang="less">
|
||||
.fulfillment-list {
|
||||
padding: var(--tui-nav-height) 0 1rem;
|
||||
|
||||
&.embedded {
|
||||
|
||||
// 外层分栏样式会影响嵌套的主栏,内嵌列表应占满自己的容器。
|
||||
:deep(.tui-master-detail:not(.split) > .master) {
|
||||
inset: auto;
|
||||
position: relative;
|
||||
border-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.list-wrap {
|
||||
gap: 1rem;
|
||||
|
||||
@@ -14,12 +14,21 @@
|
||||
<div class="main">
|
||||
<div class="customer-status">
|
||||
<strong class="customer" v-text="customerName" />
|
||||
<t-tag
|
||||
:content="statusText"
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
:theme="statusTheme"
|
||||
/>
|
||||
<div class="tags">
|
||||
<t-tag
|
||||
:content="statusText"
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
:theme="statusTheme"
|
||||
/>
|
||||
<t-tag
|
||||
v-if="isRecycle"
|
||||
content="回收兑换"
|
||||
size="small"
|
||||
theme="warning"
|
||||
variant="light"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<time-label class="time" :timestamp="fulfillment.deliveredAt" underline />
|
||||
@@ -84,6 +93,8 @@ const customerName = computed(() => props.fulfillment.customer?.name || props.fu
|
||||
const avatarText = computed(() => customerName.value.slice(0, 1) || "客");
|
||||
const photoURL = computed(() => getCustomerPhotoURL(props.fulfillment.customer, 64));
|
||||
const statusText = computed(() => getFulfillmentStatusText(props.fulfillment.status));
|
||||
/** 回收兑换订单的领取也走统一履约,列表按订单类型打标签区分来源 */
|
||||
const isRecycle = computed(() => props.fulfillment.orderType === "RECYCLE");
|
||||
const statusTheme = computed(() => getStatusTheme(props.fulfillment.status));
|
||||
const operatorName = computed(() => getUserName(props.fulfillment.operator, props.fulfillment.operatorUserId, "未知操作人"));
|
||||
const verifierName = computed(() => getUserName(props.fulfillment.verifier, props.fulfillment.verifierUserId, "未知核销人"));
|
||||
@@ -151,6 +162,12 @@ function getProductText(item: OrderFulfillmentItem): string {
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.tags {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.time {
|
||||
|
||||
@@ -151,7 +151,7 @@ function resolveId(): string {
|
||||
|
||||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||||
useExpandToMaster({
|
||||
path: "/management/package-configs",
|
||||
path: "/product/package-configs",
|
||||
id: () => resolveId()
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
@@ -217,12 +217,12 @@ async function toEdit(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
await router.push(`/management/package-configs/${config.value.id}/edit`);
|
||||
await router.push(`/product/package-configs/${config.value.id}/edit`);
|
||||
}
|
||||
|
||||
async function toPurchase(): Promise<void> {
|
||||
if (config.value?.id && canPurchase.value) {
|
||||
await router.push(`/management/package-configs/${config.value.id}/purchase`);
|
||||
await router.push(`/product/package-configs/${config.value.id}/purchase`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ function removeConfig(): void {
|
||||
pane.close(true);
|
||||
return;
|
||||
}
|
||||
await router.replace("/management/package-configs");
|
||||
await router.replace("/product/package-configs");
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "套餐配置删除失败"));
|
||||
} finally {
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
v-model="item.defaultQuantity"
|
||||
size="large"
|
||||
:max="Number.MAX_SAFE_INTEGER"
|
||||
:min="getQuantityStep(item)"
|
||||
:min="getSku(item)?.allowDecimalQuantity ? .001 : 1"
|
||||
:step="getQuantityStep(item)"
|
||||
:integer="!getSku(item)?.allowDecimalQuantity"
|
||||
theme="outline"
|
||||
@@ -192,7 +192,7 @@ const router = useRouter();
|
||||
// 竖屏整页编辑转横屏:回到分栏,并用 view=edit 让列表页把右栏还原成编辑。
|
||||
// 新增(Create)返回空 id,不触发——右栏没有可依附的选中项
|
||||
useExpandToMaster({
|
||||
path: "/management/package-configs",
|
||||
path: "/product/package-configs",
|
||||
id: () => (route.name === "PackageConfigCreate" ? "" : currentId.value),
|
||||
query: { view: "edit" }
|
||||
});
|
||||
@@ -455,7 +455,7 @@ async function save(): Promise<void> {
|
||||
pane.close(true);
|
||||
return;
|
||||
}
|
||||
await router.replace(`/management/package-configs/${id}`);
|
||||
await router.replace(`/product/package-configs/${id}`);
|
||||
return;
|
||||
}
|
||||
await PackageAPI.configUpdate(payload);
|
||||
@@ -464,7 +464,7 @@ async function save(): Promise<void> {
|
||||
pane.close(true);
|
||||
return;
|
||||
}
|
||||
await router.replace(`/management/package-configs/${routeId.value}`);
|
||||
await router.replace(`/product/package-configs/${routeId.value}`);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "套餐配置保存失败"));
|
||||
} finally {
|
||||
|
||||
@@ -139,9 +139,9 @@ const userStore = useUserStore();
|
||||
// 选中项、编辑态、切换方向、关闭逻辑、转屏、query 同步都在这里
|
||||
const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
|
||||
useMasterDetailPane({
|
||||
path: "/management/package-configs",
|
||||
detail: id => `/management/package-configs/${id}`,
|
||||
edit: id => `/management/package-configs/${id}/edit`
|
||||
path: "/product/package-configs",
|
||||
detail: id => `/product/package-configs/${id}`,
|
||||
edit: id => `/product/package-configs/${id}/edit`
|
||||
});
|
||||
|
||||
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.packageConfig.create));
|
||||
@@ -216,7 +216,7 @@ watch(keyword, () => {
|
||||
});
|
||||
|
||||
async function toCreate(): Promise<void> {
|
||||
await router.push("/management/package-configs/create");
|
||||
await router.push("/product/package-configs/create");
|
||||
}
|
||||
|
||||
function toDetail(item: GaoPackageConfig): void {
|
||||
|
||||
@@ -118,7 +118,7 @@ const router = useRouter();
|
||||
|
||||
// 竖屏整页编辑转横屏:回到分栏,右栏直接是编辑视图
|
||||
useExpandToMaster({
|
||||
path: "/management/points/redeem-skus",
|
||||
path: "/product/points/redeem-skus",
|
||||
id: () => (route.name === "PointRedeemSkuCreate" ? "" : currentId.value)
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
|
||||
@@ -116,8 +116,8 @@ defineOptions({ name: "PointRedeemSkuList" });
|
||||
|
||||
// 选中项、编辑态、切换方向、关闭逻辑、转屏、query 同步都在这里;兑换商品没有独立的详情视图,选中即进编辑
|
||||
const { selectedId, isWide, paneDirection, openDetail } = useMasterDetailPane({
|
||||
path: "/management/points/redeem-skus",
|
||||
detail: id => `/management/points/redeem-skus/${id}/edit`
|
||||
path: "/product/points/redeem-skus",
|
||||
detail: id => `/product/points/redeem-skus/${id}/edit`
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
<t-stepper
|
||||
v-model="quantity"
|
||||
size="large"
|
||||
:min="quantityStep"
|
||||
:min="quantityIsInteger ? 1 : .001"
|
||||
:step="quantityStep"
|
||||
:integer="quantityIsInteger"
|
||||
theme="outline"
|
||||
|
||||
@@ -115,7 +115,7 @@ function resolveId(): string {
|
||||
|
||||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||||
useExpandToMaster({
|
||||
path: "/management/points/redemptions",
|
||||
path: "/product/points/redemptions",
|
||||
id: () => resolveId()
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
|
||||
@@ -225,8 +225,8 @@ const router = useRouter();
|
||||
|
||||
// 选中项、切换方向、关闭逻辑、转屏、query 同步都在这里;兑换单没有内联编辑视图
|
||||
const { selectedId, paneDirection, isWide, openDetail } = useMasterDetailPane({
|
||||
path: "/management/points/redemptions",
|
||||
detail: id => `/management/points/redemptions/${id}`
|
||||
path: "/product/points/redemptions",
|
||||
detail: id => `/product/points/redemptions/${id}`
|
||||
});
|
||||
const userStore = useUserStore();
|
||||
const result = reactive({ total: 0, list: [] as PointRedemption[] });
|
||||
|
||||
@@ -34,7 +34,12 @@
|
||||
@click="viewStock"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<t-cell-group title="SKU 列表" theme="card" class="skus" v-entrance-transition>
|
||||
<t-cell-group
|
||||
class="skus empty-cell-title-margin"
|
||||
title="SKU 列表"
|
||||
theme="card"
|
||||
v-entrance-transition
|
||||
>
|
||||
<t-cell
|
||||
class="sku"
|
||||
v-for="sku in product.skuList || []"
|
||||
@@ -58,26 +63,32 @@
|
||||
<template #title>
|
||||
<div class="title">
|
||||
<h5 class="name" v-text="getSkuTitle(sku)" />
|
||||
<t-tag
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
:theme="sku.status === 'ACTIVE' ? 'success' : 'warning'"
|
||||
:content="sku.status === 'ACTIVE' ? '启用' : '停用'"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template #note>
|
||||
<t-tag
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
:theme="sku.status === 'ACTIVE' ? 'success' : 'warning'"
|
||||
:content="sku.status === 'ACTIVE' ? '启用' : '停用'"
|
||||
/>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="tags">
|
||||
<t-tag
|
||||
v-for="unit in sku.unitList || []"
|
||||
:key="unit.id || unit.name"
|
||||
size="small"
|
||||
theme="primary"
|
||||
variant="light-outline"
|
||||
:content="`${unit.name}${unit.isBase ? '(基础)' : ''}`"
|
||||
/>
|
||||
<div class="sku-description">
|
||||
<div class="tags">
|
||||
<t-tag
|
||||
v-for="unit in sku.unitList || []"
|
||||
:key="unit.id || unit.name"
|
||||
size="small"
|
||||
theme="primary"
|
||||
variant="light-outline"
|
||||
:content="`${unit.name}${unit.isBase ? '(基础)' : ''}`"
|
||||
/>
|
||||
<t-tag
|
||||
v-if="getYieldRowsForSku(sku).length"
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
:content="`产出 ${getYieldRowsForSku(sku).length} 个回收物`"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
@@ -87,63 +98,24 @@
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<bottom-popup
|
||||
v-model="skuDetailVisible"
|
||||
title="SKU 详情"
|
||||
height="min(80vh, 48rem)"
|
||||
left-button-text="关闭"
|
||||
right-button-text=""
|
||||
:z-index="skuDetailPopupZIndex"
|
||||
:overlay-props="{ zIndex: skuDetailPopupZIndex - 1 }"
|
||||
@left-button-click="closeSkuDetail"
|
||||
>
|
||||
<div v-if="selectedSku" class="sku-popup">
|
||||
<t-cell-group>
|
||||
<t-cell title="明细名称" :note="selectedSku.name || '未命名 SKU'" />
|
||||
<t-cell title="SKU 编码" :note="selectedSku.code || '无编码'" />
|
||||
<t-cell v-if="selectedSku.barcode" title="SKU 条码" :note="selectedSku.barcode" />
|
||||
<t-cell title="库存管理" :note="selectedSku.stockEnabled ? '启用' : '关闭'" />
|
||||
<t-cell title="允许小数数量" :note="selectedSku.allowDecimalQuantity ? '允许' : '不允许'" />
|
||||
<t-cell v-if="selectedSku.stockEnabled" title="最低库存" :note="`${getProductQuantityText(selectedSku.minStockQuantity)} 基础单位`" />
|
||||
<t-cell v-if="selectedSku.remark" title="备注" :note="Text.display(selectedSku.remark)" />
|
||||
</t-cell-group>
|
||||
<div class="media-wrap">
|
||||
<attachment-selector
|
||||
v-if="skuPhotoItemList.length"
|
||||
:items="skuPhotoItemList"
|
||||
title="SKU 图片"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
<div class="unit">
|
||||
<div class="header">
|
||||
<strong>销售单位</strong>
|
||||
<span>采购、销售和库存操作共用</span>
|
||||
</div>
|
||||
<product-sku-unit-list v-if="selectedSku.unitList?.length" :unit-list="selectedSku.unitList" />
|
||||
<center-tips v-else :content="'暂无销售单位'" />
|
||||
</div>
|
||||
</div>
|
||||
</bottom-popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { NavbarAction } from "@/types/NavbarAction.ts";
|
||||
import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import ProductProfile from "@/pages/product/component/ProductProfile.vue";
|
||||
import ProductSkuUnitList from "@/pages/product/component/ProductSkuUnitList.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { Product, ProductSku } from "@/types/Product";
|
||||
import type { RecycleProductYield } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
|
||||
import { emitListDataChanged, events, isCurrentStoreEvent, listDataEventKeys, type ListDataChangedPayload } from "@/utils/listDataEvents";
|
||||
import {
|
||||
getProductPhotoURL,
|
||||
getProductQuantityText,
|
||||
getProductStatusText
|
||||
} from "@/utils/product";
|
||||
import { Message } from "@/utils/message";
|
||||
@@ -173,7 +145,7 @@ function resolveId(): string {
|
||||
|
||||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||||
useExpandToMaster({
|
||||
path: "/management/products",
|
||||
path: "/product/products",
|
||||
id: () => resolveId()
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
@@ -184,9 +156,6 @@ const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const product = ref<Product>();
|
||||
const isLoading = ref(false);
|
||||
const selectedSku = ref<ProductSku>();
|
||||
const skuDetailVisible = ref(false);
|
||||
const skuDetailPopupZIndex = 1000;
|
||||
const attachmentItemList = computed<PhotoItem[]>(() => (product.value?.attachmentList || [])
|
||||
.filter(item => !!item.id)
|
||||
.map(item => ({
|
||||
@@ -195,14 +164,6 @@ const attachmentItemList = computed<PhotoItem[]>(() => (product.value?.attachmen
|
||||
previewUrl: getAttachmentReadURL(item.id || ""),
|
||||
url: getAttachmentReadURL(item.id || "", 90)
|
||||
})));
|
||||
const skuPhotoItemList = computed<PhotoItem[]>(() => (selectedSku.value?.attachmentList || [])
|
||||
.filter(item => !!item.id)
|
||||
.map(item => ({
|
||||
attachment: item,
|
||||
attachType: item.attachType || "PHOTO",
|
||||
previewUrl: getAttachmentReadURL(item.id || ""),
|
||||
url: getAttachmentReadURL(item.id || "", 90)
|
||||
})));
|
||||
const actionList = computed<NavbarAction[]>(() => {
|
||||
const list: NavbarAction[] = [];
|
||||
if (userStore.hasPermissions(permissionCodes.product.update)) {
|
||||
@@ -226,6 +187,10 @@ async function load(): Promise<void> {
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
// 没有回收配置权限时列表不展示,也就没有必要多打一次接口
|
||||
if (canManageYield.value) {
|
||||
await loadYieldList();
|
||||
}
|
||||
}
|
||||
|
||||
async function edit(): Promise<void> {
|
||||
@@ -239,7 +204,7 @@ async function edit(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
await router.push(`/management/products/${product.value.id}/edit`);
|
||||
await router.push(`/product/products/${product.value.id}/edit`);
|
||||
}
|
||||
|
||||
function goBack(): void {
|
||||
@@ -269,13 +234,52 @@ function getSkuTitle(sku: NonNullable<Product["skuList"]>[number]): string {
|
||||
return sku.specSummary || sku.name || "未命名 SKU";
|
||||
}
|
||||
|
||||
function openSkuDetail(sku: ProductSku): void {
|
||||
selectedSku.value = sku;
|
||||
skuDetailVisible.value = true;
|
||||
async function openSkuDetail(sku: ProductSku): Promise<void> {
|
||||
const productId = product.value?.id;
|
||||
const skuId = sku.id;
|
||||
if (!productId || !skuId) {
|
||||
return;
|
||||
}
|
||||
if (pane) {
|
||||
await router.push({
|
||||
path: route.path,
|
||||
query: {
|
||||
...route.query,
|
||||
skuProductId: productId,
|
||||
skuId
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
name: "ProductSkuDetail",
|
||||
params: { productId, skuId },
|
||||
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
|
||||
});
|
||||
}
|
||||
|
||||
function closeSkuDetail(): void {
|
||||
skuDetailVisible.value = false;
|
||||
// ---------- 产出回收物 ----------
|
||||
|
||||
const canManageYield = computed(() => userStore.hasPermissions(permissionCodes.recycleExchange.configManage));
|
||||
const yieldRowList = ref<RecycleProductYield[]>([]);
|
||||
let unregisterYieldChanged: (() => void) | undefined;
|
||||
|
||||
async function loadYieldList(): Promise<void> {
|
||||
const id = product.value?.id;
|
||||
if (!id) {
|
||||
yieldRowList.value = [];
|
||||
return;
|
||||
}
|
||||
try {
|
||||
yieldRowList.value = await RecycleAPI.yieldProductList(id);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "产出回收物加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
function getYieldRowsForSku(sku: ProductSku): RecycleProductYield[] {
|
||||
const skuId = sku.id || "";
|
||||
return yieldRowList.value.filter(row => row.skuId === skuId);
|
||||
}
|
||||
|
||||
function getCurrentRouteDepth(): number {
|
||||
@@ -335,7 +339,7 @@ function remove(): void {
|
||||
pane.close();
|
||||
return;
|
||||
}
|
||||
await router.replace("/management/products");
|
||||
await router.replace("/product/products");
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "产品移除失败"));
|
||||
} finally {
|
||||
@@ -350,6 +354,11 @@ watch(() => [props.productId, route.params.id], async () => {
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
unregisterYieldChanged = events.register(listDataEventKeys.productYieldChanged, async (payload: ListDataChangedPayload) => {
|
||||
if (isCurrentStoreEvent(payload) && payload.entityId === resolveId()) {
|
||||
await loadYieldList();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await load();
|
||||
@@ -359,6 +368,11 @@ onMounted(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
unregisterYieldChanged?.();
|
||||
unregisterYieldChanged = undefined;
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -380,8 +394,10 @@ onMounted(async () => {
|
||||
|
||||
.title {
|
||||
gap: .5rem;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.name {
|
||||
margin: 0;
|
||||
@@ -393,37 +409,13 @@ onMounted(async () => {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.sku-popup {
|
||||
padding: 0 0 calc(1rem + env(safe-area-inset-bottom, 0px));
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
|
||||
.media-wrap {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.unit {
|
||||
margin-top: .75rem;
|
||||
border-top: 1px solid var(--td-component-border);
|
||||
|
||||
.header {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
padding: .75rem 1rem .5rem;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
|
||||
span {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
text-align: right;
|
||||
.sku-description {
|
||||
gap: .375rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,12 +428,4 @@ onMounted(async () => {
|
||||
|
||||
}
|
||||
|
||||
:global(html.theme-dark) .sku-popup {
|
||||
.sku-spec-panel,
|
||||
.sku-spec-item,
|
||||
.unit-item {
|
||||
background: rgba(148, 163, 184, .12);
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -265,7 +265,7 @@ const routeId = computed(() => props.productId || String(route.params.id || ""))
|
||||
|
||||
// 竖屏整页编辑转横屏:回到分栏,并用 view=edit 让列表页把右栏还原成编辑
|
||||
useExpandToMaster({
|
||||
path: "/management/products",
|
||||
path: "/product/products",
|
||||
id: () => routeId.value,
|
||||
query: { view: "edit" }
|
||||
});
|
||||
@@ -1087,7 +1087,7 @@ async function save(): Promise<void> {
|
||||
emitListDataChanged(listDataEventKeys.productChanged, productId);
|
||||
emitListDataChanged(listDataEventKeys.productStockChanged, productId);
|
||||
Message.success("产品已创建");
|
||||
await router.replace(`/management/products/${productId}`);
|
||||
await router.replace(`/product/products/${productId}`);
|
||||
return;
|
||||
}
|
||||
const productId = form.id;
|
||||
@@ -1112,7 +1112,7 @@ async function save(): Promise<void> {
|
||||
pane.close(true);
|
||||
return;
|
||||
}
|
||||
await router.replace(`/management/products/${productId}`);
|
||||
await router.replace(`/product/products/${productId}`);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "产品保存失败,请检查 SKU 编码、规格组合和单位配置"));
|
||||
} finally {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
class="list"
|
||||
:split="isWide"
|
||||
:selected="!!selectedId"
|
||||
:direction="paneDirection"
|
||||
:direction="paneTransitionDirection"
|
||||
>
|
||||
<template #master>
|
||||
<t-pull-down-refresh
|
||||
@@ -115,7 +115,13 @@
|
||||
</t-pull-down-refresh>
|
||||
</template>
|
||||
<template #detail>
|
||||
<product-edit v-if="selectedId === createPaneId" :key="createPaneId" />
|
||||
<product-sku-detail
|
||||
v-if="showingSkuDetail"
|
||||
:key="`${skuDetailProductId}-${skuDetailId}`"
|
||||
:product-id="skuDetailProductId"
|
||||
:sku-id="skuDetailId"
|
||||
/>
|
||||
<product-edit v-else-if="selectedId === createPaneId" :key="createPaneId" />
|
||||
<product-edit
|
||||
v-else-if="editing"
|
||||
:key="`edit-${selectedId}`"
|
||||
@@ -135,9 +141,10 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { type DropdownValue } from "tdesign-mobile-vue";
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import { MasterDetailPage, useMasterDetailPane, type PaneDirection } from "timi-tdesign-mobile";
|
||||
import ProductDetail from "@/pages/product/ProductDetail.vue";
|
||||
import ProductEdit from "@/pages/product/ProductEdit.vue";
|
||||
import ProductSkuDetail from "@/pages/product/ProductSkuDetail.vue";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { onBeforeRouteLeave } from "vue-router";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
@@ -158,10 +165,32 @@ const route = useRoute();
|
||||
const createPaneId = "__create__";
|
||||
const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
|
||||
useMasterDetailPane({
|
||||
path: "/management/products",
|
||||
detail: id => id === createPaneId ? "/management/products/create" : `/management/products/${id}`,
|
||||
edit: id => `/management/products/${id}/edit`
|
||||
path: "/product/products",
|
||||
detail: id => id === createPaneId ? "/product/products/create" : `/product/products/${id}`,
|
||||
edit: id => `/product/products/${id}/edit`
|
||||
});
|
||||
const skuDetailProductId = computed(() => String(route.query.skuProductId || ""));
|
||||
const skuDetailId = computed(() => String(route.query.skuId || ""));
|
||||
const showingSkuDetail = computed(() => !!skuDetailId.value && skuDetailProductId.value === selectedId.value);
|
||||
const paneTransitionDirection = ref<PaneDirection>(paneDirection.value || "forward");
|
||||
|
||||
watch(paneDirection, direction => {
|
||||
if (direction) {
|
||||
paneTransitionDirection.value = direction;
|
||||
}
|
||||
});
|
||||
|
||||
watch([skuDetailProductId, skuDetailId], ([productId, skuId], [previousProductId, previousSkuId]) => {
|
||||
const wasSkuDetail = !!previousSkuId && previousProductId === selectedId.value;
|
||||
const isSkuDetail = !!skuId && productId === selectedId.value;
|
||||
if (!wasSkuDetail && isSkuDetail) {
|
||||
paneTransitionDirection.value = "forward";
|
||||
} else if (wasSkuDetail && !isSkuDetail) {
|
||||
paneTransitionDirection.value = "back";
|
||||
} else if (wasSkuDetail && isSkuDetail && previousSkuId !== skuId) {
|
||||
paneTransitionDirection.value = "none";
|
||||
}
|
||||
});
|
||||
const productListRef = ref<ComponentPublicInstance | null>(null);
|
||||
const userStore = useUserStore();
|
||||
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.product.create));
|
||||
@@ -419,10 +448,20 @@ async function toCreate(): Promise<void> {
|
||||
openDetail(createPaneId);
|
||||
return;
|
||||
}
|
||||
await router.push("/management/products/create");
|
||||
await router.push("/product/products/create");
|
||||
}
|
||||
|
||||
async function toDetail(item: Product): Promise<void> {
|
||||
if (route.query.skuId || route.query.skuProductId) {
|
||||
await router.replace({
|
||||
path: route.path,
|
||||
query: {
|
||||
...route.query,
|
||||
skuProductId: undefined,
|
||||
skuId: undefined
|
||||
}
|
||||
});
|
||||
}
|
||||
openDetail(item.id || "");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,380 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
:title="skuTitle"
|
||||
left-arrow
|
||||
@left-click="goBack"
|
||||
/>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div v-can="permissionCodes.product.read" class="product-sku-detail">
|
||||
<t-loading v-if="isLoading" class="loading" size="32px" />
|
||||
<template v-if="sku && product">
|
||||
<t-cell-group theme="card" v-entrance-transition>
|
||||
<t-cell title="所属产品" :note="product.name || '未命名产品'" />
|
||||
<t-cell title="SKU 名称" :note="sku.name || '未命名 SKU'" />
|
||||
<t-cell title="SKU 编码" :note="sku.code || '无编码'" />
|
||||
<t-cell v-if="sku.barcode" title="SKU 条码" :note="sku.barcode" />
|
||||
<t-cell title="状态" :note="getProductStatusText(sku.status)" />
|
||||
<t-cell title="库存管理" :note="sku.stockEnabled ? '启用' : '关闭'" />
|
||||
<t-cell title="允许小数数量" :note="sku.allowDecimalQuantity ? '允许' : '不允许'" />
|
||||
<t-cell v-if="sku.stockEnabled" title="最低库存" :note="`${getProductQuantityText(sku.minStockQuantity)} 基础单位`" />
|
||||
<t-cell v-if="sku.remark" title="备注" :note="Text.display(sku.remark)" />
|
||||
<div v-if="skuPhotoItemList.length" class="attach-wrap bg-white">
|
||||
<attachment-selector :items="skuPhotoItemList" title="SKU 图片" readonly />
|
||||
</div>
|
||||
</t-cell-group>
|
||||
<product-sku-unit-list :unit-list="sku.unitList" />
|
||||
<t-cell-group
|
||||
v-if="canManageYield"
|
||||
class="yields fix-last-cell-line empty-cell-title-margin"
|
||||
theme="card"
|
||||
title="产出回收物"
|
||||
>
|
||||
<t-swipe-cell
|
||||
class="item"
|
||||
v-for="row in yieldRowList"
|
||||
:key="getYieldKey(row)"
|
||||
>
|
||||
<t-cell class="yield">
|
||||
<template #leftIcon>
|
||||
<t-image v-if="getYieldCoverId(row)" class="avatar" :src="getAttachmentReadURL(getYieldCoverId(row), 96)" :alt="row.recycleName || '回收物图片'" fit="cover" />
|
||||
<div v-else class="avatar fallback" v-text="(row.recycleName || '产').slice(0, 1)" />
|
||||
</template>
|
||||
<template #title>
|
||||
<div class="title">
|
||||
<span v-text="row.recycleName || '未知回收物'"></span>
|
||||
<div class="actions">
|
||||
<template v-if="editingKey === getYieldKey(row)">
|
||||
<t-button theme="primary" size="extra-small" :loading="saving" content="保存" @click.stop="saveYield(row)" />
|
||||
<t-button size="extra-small" content="取消" :disabled="saving" @click.stop="cancelEdit" />
|
||||
</template>
|
||||
<t-button v-else theme="primary" size="extra-small" content="编辑" :disabled="!!editingKey || saving || yieldLoading" @click.stop="editYield(row)" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="editor">
|
||||
<span>产出</span>
|
||||
<t-stepper
|
||||
:model-value="editingKey === getYieldKey(row) ? editingQuantity : row.quantityPerBase"
|
||||
:integer="!row.allowDecimalQuantity"
|
||||
:min="row.allowDecimalQuantity ? .001 : 1"
|
||||
:max="Number.MAX_SAFE_INTEGER"
|
||||
:step="row.allowDecimalQuantity ? .05 : 1"
|
||||
size="large"
|
||||
theme="outline"
|
||||
:disabled="saving || editingKey !== getYieldKey(row)"
|
||||
@update:model-value="editingQuantity = $event"
|
||||
/>
|
||||
<t-tag
|
||||
variant="light"
|
||||
:content="row.recycleUnit || '单位'"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
<template #right>
|
||||
<t-button v-if="draftKey !== getYieldKey(row)" theme="danger" :disabled="!!editingKey || saving" @click.stop="deleteYield(row)">删除</t-button>
|
||||
</template>
|
||||
</t-swipe-cell>
|
||||
<t-cell
|
||||
title="添加"
|
||||
:disabled="yieldLoading || saving || !!editingKey"
|
||||
arrow
|
||||
@click="pickerVisible = true"
|
||||
/>
|
||||
<center-tips v-if="!yieldRowList.length" :content="yieldLoading ? '正在加载' : '该 SKU 不产出回收物'" />
|
||||
</t-cell-group>
|
||||
</template>
|
||||
<center-tips v-if="!isLoading && !sku" :content="'SKU 不存在或已被移除'" />
|
||||
</div>
|
||||
</main>
|
||||
<recycle-item-picker-popup v-model:visible="pickerVisible" title="选择产出物" manage empty-text="暂无回收物,可点击右上角新建" @select="selectItem" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import ProductSkuUnitList from "@/pages/product/component/ProductSkuUnitList.vue";
|
||||
import RecycleItemPickerPopup from "@/pages/recycle/components/RecycleItemPickerPopup.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { Product, ProductSku } from "@/types/Product";
|
||||
import type { RecycleItem, RecycleProductYield } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
|
||||
import { normalizePackageQuantity } from "@/utils/package";
|
||||
import { getProductQuantityText, getProductStatusText } from "@/utils/product";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { Text } from "timi-web";
|
||||
|
||||
defineOptions({ name: "ProductSkuDetail" });
|
||||
|
||||
const props = defineProps<{
|
||||
productId?: string;
|
||||
skuId?: string;
|
||||
}>();
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
|
||||
function resolveProductId(): string {
|
||||
return props.productId || String(route.params.productId || "");
|
||||
}
|
||||
|
||||
function resolveSkuId(): string {
|
||||
return props.skuId || String(route.params.skuId || "");
|
||||
}
|
||||
|
||||
const product = ref<Product>();
|
||||
const sku = ref<ProductSku>();
|
||||
const isLoading = ref(false);
|
||||
const skuTitle = computed(() => sku.value?.specSummary || sku.value?.name || "SKU 详情");
|
||||
const skuPhotoItemList = computed<PhotoItem[]>(() => (sku.value?.attachmentList || [])
|
||||
.filter(item => !!item.id)
|
||||
.map(item => ({
|
||||
attachment: item,
|
||||
attachType: item.attachType || "PHOTO",
|
||||
previewUrl: getAttachmentReadURL(item.id || ""),
|
||||
url: getAttachmentReadURL(item.id || "", 90)
|
||||
})));
|
||||
|
||||
async function goBack(): Promise<void> {
|
||||
await router.back();
|
||||
}
|
||||
|
||||
const canManageYield = computed(() => userStore.hasPermissions(permissionCodes.recycleExchange.configManage));
|
||||
const yieldRowList = ref<RecycleProductYield[]>([]);
|
||||
const yieldLoading = ref(false);
|
||||
const pickerVisible = ref(false);
|
||||
const editingKey = ref("");
|
||||
const editingQuantity = ref<string | number>(1);
|
||||
const draftKey = ref("");
|
||||
const saving = ref(false);
|
||||
|
||||
async function load(): Promise<void> {
|
||||
const productId = resolveProductId();
|
||||
const skuId = resolveSkuId();
|
||||
if (!productId || !skuId) {
|
||||
return;
|
||||
}
|
||||
isLoading.value = true;
|
||||
sku.value = undefined;
|
||||
yieldRowList.value = [];
|
||||
editingKey.value = "";
|
||||
draftKey.value = "";
|
||||
try {
|
||||
const [productResult, skuResult] = await Promise.all([
|
||||
ProductAPI.detail(productId),
|
||||
ProductAPI.skuDetail(skuId)
|
||||
]);
|
||||
if (skuResult.productId && skuResult.productId !== productId) {
|
||||
Message.error("SKU 与所属产品不匹配");
|
||||
return;
|
||||
}
|
||||
product.value = productResult;
|
||||
sku.value = skuResult;
|
||||
if (canManageYield.value) {
|
||||
await loadYieldList();
|
||||
}
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "SKU 详情加载失败"));
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadYieldList(): Promise<void> {
|
||||
const skuId = sku.value?.id || resolveSkuId();
|
||||
if (!skuId) {
|
||||
yieldRowList.value = [];
|
||||
return;
|
||||
}
|
||||
yieldLoading.value = true;
|
||||
try {
|
||||
const rowList = await RecycleAPI.yieldList(skuId);
|
||||
yieldRowList.value = rowList.map(row => ({ ...row, skuId }));
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "产出回收物加载失败"));
|
||||
} finally {
|
||||
yieldLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getYieldCoverId(row: RecycleProductYield): string {
|
||||
return row.attachmentList?.find(attachment => attachment.id && attachment.mimeType?.startsWith("image/"))?.id || "";
|
||||
}
|
||||
|
||||
function getYieldKey(row: RecycleProductYield): string {
|
||||
return `${row.skuId || ""}-${row.recycleItemId || ""}`;
|
||||
}
|
||||
|
||||
function editYield(row: RecycleProductYield): void {
|
||||
if (saving.value || editingKey.value) return;
|
||||
editingKey.value = getYieldKey(row);
|
||||
editingQuantity.value = row.quantityPerBase ?? 1;
|
||||
}
|
||||
|
||||
function cancelEdit(): void {
|
||||
if (draftKey.value) yieldRowList.value = yieldRowList.value.filter(row => getYieldKey(row) !== draftKey.value);
|
||||
draftKey.value = "";
|
||||
editingKey.value = "";
|
||||
}
|
||||
|
||||
function selectItem(item: RecycleItem): void {
|
||||
const skuId = sku.value?.id;
|
||||
if (!skuId || !item.id) return;
|
||||
if (yieldRowList.value.some(row => row.recycleItemId === item.id)) {
|
||||
Message.warning("该产出关系已存在");
|
||||
return;
|
||||
}
|
||||
const row: RecycleProductYield = {
|
||||
skuId, recycleItemId: item.id, recycleName: item.name, recycleUnit: item.unitName,
|
||||
attachmentList: item.attachmentList, allowDecimalQuantity: item.allowDecimalQuantity, quantityPerBase: "1"
|
||||
};
|
||||
yieldRowList.value.push(row);
|
||||
draftKey.value = getYieldKey(row);
|
||||
editYield(row);
|
||||
}
|
||||
|
||||
function notifyYieldChange(): void {
|
||||
const productId = product.value?.id || sku.value?.productId;
|
||||
if (productId) emitListDataChanged(listDataEventKeys.productYieldChanged, productId);
|
||||
}
|
||||
|
||||
async function saveYield(row: RecycleProductYield): Promise<void> {
|
||||
const quantity = normalizePackageQuantity(editingQuantity.value);
|
||||
if (!row.skuId || !row.recycleItemId || saving.value) return;
|
||||
if (!quantity || quantity === "0") {
|
||||
Message.warning("产出数量必须大于零,最多三位小数");
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
await RecycleAPI.yieldSave(row.skuId, row.recycleItemId, quantity);
|
||||
draftKey.value = "";
|
||||
editingKey.value = "";
|
||||
Message.success("产出配置已保存");
|
||||
notifyYieldChange();
|
||||
await loadYieldList();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "产出配置保存失败"));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function deleteYield(row: RecycleProductYield): void {
|
||||
if (!row.skuId || !row.recycleItemId || saving.value || editingKey.value) return;
|
||||
const skuId = row.skuId;
|
||||
const itemId = row.recycleItemId;
|
||||
const dialog = DialogPlugin.confirm({
|
||||
title: "移除产出回收物",
|
||||
content: `移除后该 SKU 不再产出${row.recycleName || "该回收物"},已产生的额度仍会保留。确定移除?`,
|
||||
cancelBtn: "取消",
|
||||
confirmBtn: { content: "移除", theme: "danger" },
|
||||
onConfirm: async () => {
|
||||
dialog.destroy();
|
||||
saving.value = true;
|
||||
try {
|
||||
await RecycleAPI.yieldDelete(skuId, itemId);
|
||||
Message.success("产出回收物已移除");
|
||||
notifyYieldChange();
|
||||
await loadYieldList();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "产出回收物移除失败"));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
watch(() => [props.productId, props.skuId, route.params.productId, route.params.skuId], async () => {
|
||||
await load();
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await load();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.product-sku-detail {
|
||||
gap: 1rem;
|
||||
display: flex;
|
||||
padding: 0 0 1rem;
|
||||
flex-direction: column;
|
||||
|
||||
.attach-wrap {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.unit {
|
||||
.header {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
padding: .75rem 1rem .5rem;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
|
||||
span {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.yields {
|
||||
--td-button-extra-small-height: 24px;
|
||||
|
||||
.item {
|
||||
|
||||
.yield {
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
gap: .5rem;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.actions {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.editor {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: end;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.avatar .t-image__img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: inherit;
|
||||
}
|
||||
</style>
|
||||
@@ -148,7 +148,7 @@ function resolveId(): string {
|
||||
// 没带 productId(从别处跳进来)时不动,避免落到无效的列表路径
|
||||
const masterProductId = props.productId || String(route.query.productId || "");
|
||||
useExpandToMaster({
|
||||
path: `/management/product-stocks/${masterProductId}/skus`,
|
||||
path: `/product/product-stocks/${masterProductId}/skus`,
|
||||
id: () => (masterProductId ? resolveId() : "")
|
||||
});
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ function resolveId(): string {
|
||||
|
||||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||||
useExpandToMaster({
|
||||
path: "/management/product-stock-records",
|
||||
path: "/product/product-stock-records",
|
||||
id: () => resolveId()
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
@@ -270,7 +270,7 @@ async function toFulfillment(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
path: `/management/order-fulfillments/${relatedFulfillmentId.value}`,
|
||||
path: `/product/order-fulfillments/${relatedFulfillmentId.value}`,
|
||||
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -240,8 +240,8 @@ const route = useRoute();
|
||||
|
||||
// 选中项、切换方向、关闭逻辑、转屏、query 同步都在这里;库存流水没有内联编辑视图
|
||||
const { selectedId, detailVersion, paneDirection, isWide, openDetail } = useMasterDetailPane({
|
||||
path: "/management/product-stock-records",
|
||||
detail: id => `/management/product-stock-records/${id}`
|
||||
path: "/product/product-stock-records",
|
||||
detail: id => `/product/product-stock-records/${id}`
|
||||
});
|
||||
|
||||
const pageNavBarBackTo = ref<string>();
|
||||
|
||||
@@ -160,9 +160,9 @@ const emptyText = computed(() => {
|
||||
// ---------- 主从分栏 ----------
|
||||
|
||||
const { selectedId, detailVersion, paneDirection, isWide, openDetail } = useMasterDetailPane({
|
||||
path: `/management/product-stocks/${productId.value}/skus`,
|
||||
path: `/product/product-stocks/${productId.value}/skus`,
|
||||
// 整页详情带上 productId,转回分栏时才知道该回到哪个产品的 SKU 列表
|
||||
detail: id => `/management/product-stocks/${id}?productId=${encodeURIComponent(productId.value)}`
|
||||
detail: id => `/product/product-stocks/${id}?productId=${encodeURIComponent(productId.value)}`
|
||||
});
|
||||
|
||||
function getSkuPhotoURL(item: ProductStock): string {
|
||||
|
||||
@@ -25,42 +25,46 @@
|
||||
</div>
|
||||
</section>
|
||||
<div class="chart-list">
|
||||
<product-stock-calendar :key="calendarVersion" :store-id="storeId" />
|
||||
<product-stock-movement-chart
|
||||
<product-stock-calendar
|
||||
:key="calendarVersion"
|
||||
:store-id="storeId"
|
||||
v-entrance-transition
|
||||
/>
|
||||
<product-stock-movement-chart
|
||||
:date-text-list="dateTextList"
|
||||
:list="stockMovementList"
|
||||
:loading="isLoading"
|
||||
v-entrance-transition
|
||||
/>
|
||||
<product-sales-trend-chart
|
||||
v-entrance-transition
|
||||
:date-text-list="dateTextList"
|
||||
:list="salesDailyList"
|
||||
:loading="isLoading"
|
||||
v-entrance-transition
|
||||
/>
|
||||
<div class="two-columns">
|
||||
<product-sales-rank-chart
|
||||
v-entrance-transition
|
||||
:list="salesRankList"
|
||||
:loading="isLoading"
|
||||
v-entrance-transition
|
||||
/>
|
||||
<product-fulfillment-rank-chart
|
||||
v-entrance-transition
|
||||
:list="fulfillmentRankList"
|
||||
:loading="isLoading"
|
||||
v-entrance-transition
|
||||
/>
|
||||
</div>
|
||||
<product-fulfillment-trend-chart
|
||||
v-entrance-transition
|
||||
:date-text-list="dateTextList"
|
||||
:list="fulfillmentDailyList"
|
||||
:loading="isLoading"
|
||||
v-entrance-transition
|
||||
/>
|
||||
<product-stock-health-table
|
||||
v-entrance-transition
|
||||
:list="stockHealthList"
|
||||
:sku-health-list="skuHealthList"
|
||||
:loading="isLoading"
|
||||
v-entrance-transition
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -94,10 +94,6 @@
|
||||
</div>
|
||||
</t-form>
|
||||
<div class="unit">
|
||||
<div class="header">
|
||||
<strong>销售单位</strong>
|
||||
<span>采购、销售和库存操作共用</span>
|
||||
</div>
|
||||
<product-sku-unit-list :unit-list="sku.unitList" />
|
||||
<t-button
|
||||
class="cell-button"
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
<template>
|
||||
<t-cell-group
|
||||
v-if="unitList.length"
|
||||
class="items empty-cell-title-margin"
|
||||
title="销售单位"
|
||||
theme="card"
|
||||
>
|
||||
<template v-if="!unitList.length">
|
||||
<center-tips content="暂无销售单位" />
|
||||
</template>
|
||||
<t-cell
|
||||
v-else
|
||||
v-for="unit in unitList"
|
||||
:key="unit.id || unit.clientKey || unit.name"
|
||||
class="item"
|
||||
@@ -91,11 +95,6 @@ function getSalePrice(unit: ProductSkuUnitItem): number | undefined {
|
||||
|
||||
<style scoped lang="less">
|
||||
.items {
|
||||
margin: 0;
|
||||
|
||||
:deep(.t-cell-group) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.item {
|
||||
|
||||
|
||||
@@ -10,18 +10,38 @@
|
||||
content="产品规格"
|
||||
@click="selectorVisible = true"
|
||||
>
|
||||
<template #icon><t-icon name="filter" /></template>
|
||||
<template #icon>
|
||||
<t-icon name="filter" />
|
||||
</template>
|
||||
</t-button>
|
||||
</template>
|
||||
<template #subtitle>
|
||||
<div class="selection">
|
||||
<span v-text="selectionText" />
|
||||
<t-button v-if="selection" size="extra-small" variant="text" @click="clearSelection">清除</t-button>
|
||||
<t-button
|
||||
v-if="selection && 1 < units.length"
|
||||
size="extra-small"
|
||||
variant="text"
|
||||
@click="nextUnit"
|
||||
:content="`单位:${currentUnit?.name}`"
|
||||
/>
|
||||
<t-button
|
||||
v-if="selection"
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
content="清除"
|
||||
@click="clearSelection"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template #day="{ day }">
|
||||
<span v-if="daily(day)?.inQuantity" class="quantity in" v-text="`入 ${daily(day)?.inQuantity}`" />
|
||||
<span v-if="daily(day)?.outQuantity" class="quantity out" v-text="`出 ${daily(day)?.outQuantity}`" />
|
||||
<template v-if="selection">
|
||||
<span v-if="daily(day)?.inQuantity" class="quantity in"
|
||||
v-text="formatQuantity(daily(day)?.inQuantity)" />
|
||||
<span v-if="daily(day)?.outQuantity" class="quantity out"
|
||||
v-text="formatQuantity(daily(day)?.outQuantity)" />
|
||||
</template>
|
||||
<span class="movement-bar" :style="movementStyle(day)" />
|
||||
</template>
|
||||
</month-calendar>
|
||||
<t-loading v-if="loading" text="加载中" />
|
||||
@@ -31,45 +51,78 @@
|
||||
v-model:visible="selectorVisible"
|
||||
@select="selectProduct"
|
||||
/>
|
||||
<bottom-popup v-model="visible" :title="`${selectedDate} 库存流水`" left-button-text="关闭" @left-button-click="visible = false">
|
||||
<div v-if="canReadRecords" class="records">
|
||||
<div class="directions">
|
||||
<t-button size="small" :theme="direction === 'IN' ? 'primary' : 'default'" @click="selectDirection('IN')">入库</t-button>
|
||||
<t-button size="small" :theme="direction === 'OUT' ? 'primary' : 'default'" @click="selectDirection('OUT')">出库</t-button>
|
||||
</div>
|
||||
<t-cell-group v-if="records.length">
|
||||
<t-cell
|
||||
v-for="record in records"
|
||||
:key="record.id"
|
||||
:title="record.productNameSnapshot || '未命名产品'"
|
||||
:description="record.skuNameSnapshot || ''"
|
||||
:note="`${getStockOperationText(record.operationType)} ${record.onHandDelta || 0}(基础单位)`"
|
||||
/>
|
||||
<bottom-popup
|
||||
v-model="visible"
|
||||
:title="`${selectedDate} 库存流水`"
|
||||
left-button-text="关闭"
|
||||
@left-button-click="visible = false"
|
||||
>
|
||||
<div class="records">
|
||||
<template v-if="canReadRecords">
|
||||
<div class="directions">
|
||||
<t-segmented block :value="direction" :options="directionOptions" @change="changeDirection" />
|
||||
</div>
|
||||
<div class="record-list">
|
||||
<t-cell-group v-if="records.length" class="list empty-cell-title-margin" theme="card">
|
||||
<t-cell v-for="record in records" :key="record.id" class="item">
|
||||
<template #leftIcon>
|
||||
<t-image v-if="getCustomerPhotoURL(record.customer, 64)" :src="getCustomerPhotoURL(record.customer, 64)"
|
||||
:alt="getCustomerText(record)" fit="cover" class="avatar" />
|
||||
<div v-else-if="record.customer" class="avatar fallback" v-text="getCustomerText(record).slice(0, 1)" />
|
||||
<t-image v-else-if="record.operator" :src="getOperatorAvatar(record)" :alt="getOperatorText(record)" fit="cover" class="avatar" />
|
||||
<span v-else class="icon" :class="getDeltaClass(record.onHandDelta)"><t-icon name="history" size="1.25rem" /></span>
|
||||
</template>
|
||||
<template #title>
|
||||
<div class="record-title">
|
||||
<span v-if="record.customer" class="actor" v-text="getCustomerText(record)" />
|
||||
<span v-else-if="record.operator" class="actor" v-text="getOperatorText(record)" />
|
||||
<strong class="operation" :class="getOperationClass(record.operationType)" v-text="getStockOperationText(record.operationType)" />
|
||||
<strong class="product-name" v-text="record.productNameSnapshot || '未命名产品'" />
|
||||
<t-tag v-if="record.skuNameSnapshot && record.productNameSnapshot !== record.skuNameSnapshot"
|
||||
size="small" :content="record.skuNameSnapshot" />
|
||||
<span v-if="record.quantity !== undefined && record.quantity !== null && record.quantity !== ''"
|
||||
class="record-quantity" v-text="`${getProductQuantityText(record.quantity)} ${record.unitSnapshot || ''}`" />
|
||||
</div>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<time-label :timestamp="record.occurredAt" underline />
|
||||
<div><span class="delta" :class="getDeltaClass(record.onHandDelta)" v-text="getDeltaText(record.onHandDelta)" /></div>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-empty v-else-if="!recordsLoading" description="当天暂无流水" />
|
||||
<t-button v-if="!noMore" block variant="text" :loading="recordsLoading" @click="loadRecords">加载更多</t-button>
|
||||
<t-button v-if="!noMore" block variant="text" :loading="recordsLoading" @click="loadRecords">加载更多
|
||||
</t-button>
|
||||
</div>
|
||||
</template>
|
||||
<t-empty v-else description="暂无库存流水查看权限" />
|
||||
</div>
|
||||
<t-empty v-else description="暂无库存流水查看权限" />
|
||||
</bottom-popup>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { TimeLabel } from "timi-web";
|
||||
import { UserAPI, useUserStore } from "timi-web-api";
|
||||
import GaoProductChartAPI from "@/api/GaoProductChartAPI";
|
||||
import GaoProductSkuChartAPI from "@/api/GaoProductSkuChartAPI";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import StoreChartAPI from "@/api/StoreChartAPI";
|
||||
import MonthCalendar from "@/components/monthCalendar/MonthCalendar.vue";
|
||||
import ProductSelectPopup from "@/components/productSelector/ProductSelectPopup.vue";
|
||||
import { buildMonthCalendarDays, type MonthCalendarDay } from "@/components/monthCalendar/monthCalendar";
|
||||
import type { GaoProductStockMovementDailyStatView } from "@/types/GaoChart";
|
||||
import type { ProductSelection, StockRecord, StockRecordDirection } from "@/types/Product";
|
||||
import type { ProductSkuSelectionValue } from "@/types/ProductSkuSelection";
|
||||
import { getProductBaseUnitName, getStockOperationText } from "@/utils/product";
|
||||
import { getProductQuantityText, getStockOperationText } from "@/utils/product";
|
||||
import { buildFallbackAvatar } from "@/utils/avatar";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { getCustomerPhotoURL } from "@/utils/customer";
|
||||
|
||||
const props = defineProps<{ storeId: string }>();
|
||||
const userStore = useUserStore();
|
||||
@@ -80,15 +133,68 @@ const selectedProductSku = ref<ProductSkuSelectionValue>();
|
||||
const selection = ref<ProductSelection>();
|
||||
const skuId = computed(() => selection.value?.sku.id || "");
|
||||
const selectionText = computed(() => {
|
||||
if (!selection.value) return "全部产品规格 · 数量按各规格基础单位汇总";
|
||||
if (!selection.value) return "全部产品规格 · 颜色表示出入库情况";
|
||||
const { product, sku } = selection.value;
|
||||
const name = sku.specSummary || (sku.name !== product.name ? sku.name : "");
|
||||
return [product.name || product.code, name, `基础单位:${getProductBaseUnitName(sku) || "未知"}`].filter(Boolean).join(" · ");
|
||||
return [
|
||||
product.name || product.code,
|
||||
name
|
||||
].filter(Boolean).join(" · ");
|
||||
});
|
||||
const unitIndex = ref(0);
|
||||
const units = computed(() => selection.value?.sku.unitList || []);
|
||||
const currentUnit = computed(() => units.value[unitIndex.value]);
|
||||
|
||||
function getCustomerText(record: StockRecord): string {
|
||||
return record.customer?.name || record.customer?.code || "未知客户";
|
||||
}
|
||||
|
||||
function getOperatorText(record: StockRecord): string {
|
||||
return record.operator?.nick || record.operator?.name || "未知操作人";
|
||||
}
|
||||
function getOperatorAvatar(record: StockRecord): string {
|
||||
return UserAPI.getAvatarURL(record.operator) || buildFallbackAvatar(getOperatorText(record), "#0f766e");
|
||||
}
|
||||
function getOperationClass(type?: string): string {
|
||||
return ({
|
||||
INITIAL_IN: "initial-in", MANUAL_IN: "manual-in", MANUAL_OUT: "manual-out", MANUAL_REVOKE: "manual-revoke",
|
||||
ORDER_RESERVE: "order-reserve", ORDER_RELEASE: "order-release", ORDER_OUT: "order-out", ORDER_REVOKE: "order-revoke",
|
||||
ORDER_RETURN_IN: "return-in", POINT_REDEMPTION_OUT: "manual-out", POINT_REDEMPTION_RETURN_IN: "return-in",
|
||||
STOCKTAKE_GAIN: "stocktake-gain", STOCKTAKE_LOSS: "stocktake-loss"
|
||||
} as Record<string, string>)[type || ""] || "unknown";
|
||||
}
|
||||
function getDeltaClass(value?: number | string): string {
|
||||
const amount = Number(value || 0);
|
||||
return 0 < amount ? "positive" : amount < 0 ? "negative" : "gray";
|
||||
}
|
||||
function getDeltaText(value?: number | string): string {
|
||||
const amount = Number(value || 0);
|
||||
return `${0 < amount ? "+" : amount < 0 ? "-" : ""}${getProductQuantityText(String(value || "0").replace(/^-/, ""))}`;
|
||||
}
|
||||
function nextUnit(): void {
|
||||
unitIndex.value = (unitIndex.value + 1) % units.value.length;
|
||||
}
|
||||
|
||||
function formatQuantity(value: number | string | undefined): string {
|
||||
const ratio = Number(currentUnit.value?.baseQuantityPerUnit) || 1;
|
||||
return String(Number((Number(value || 0) / ratio).toFixed(4)));
|
||||
}
|
||||
|
||||
function movementStyle(day: MonthCalendarDay): Record<string, string> {
|
||||
const item = daily(day);
|
||||
const incoming = Math.abs(Number(item?.inQuantity) || 0);
|
||||
const outgoing = Math.abs(Number(item?.outQuantity) || 0);
|
||||
if (!incoming && !outgoing) return { background: "var(--td-component-stroke)" };
|
||||
const percentage = incoming / (incoming + outgoing) * 100;
|
||||
return { background: `linear-gradient(90deg, var(--tui-green) ${percentage}%, var(--tui-red) ${percentage}%)` };
|
||||
}
|
||||
|
||||
function selectProduct(value: ProductSelection): void {
|
||||
if (!value.sku.id) return;
|
||||
selection.value = value;
|
||||
unitIndex.value = Math.max(0, (value.sku.unitList || []).findIndex(unit => unit.id === value.unit.id));
|
||||
}
|
||||
|
||||
function clearSelection(): void {
|
||||
selection.value = undefined;
|
||||
selectedProductSku.value = undefined;
|
||||
@@ -98,13 +204,27 @@ const month = ref(new Date(new Date().getFullYear(), new Date().getMonth(), 1));
|
||||
const stats = ref<GaoProductStockMovementDailyStatView[]>([]);
|
||||
const loading = ref(false);
|
||||
let monthToken = 0;
|
||||
let restDayToken = 0;
|
||||
const restDaySet = ref<Set<number>>(new Set());
|
||||
watch([month, () => props.storeId], async () => {
|
||||
const token = ++restDayToken;
|
||||
const days = buildMonthCalendarDays(month.value);
|
||||
try {
|
||||
const list = await StoreChartAPI.businessDayCalendar(props.storeId, Number(days[0].dateText.replaceAll("-", "")), Number(days[days.length - 1].dateText.replaceAll("-", "")));
|
||||
if (token === restDayToken) restDaySet.value = new Set(list.filter(item => item.status === "CLOSED" && item.dateValue).map(item => item.dateValue as number));
|
||||
} catch {
|
||||
if (token === restDayToken) restDaySet.value = new Set();
|
||||
}
|
||||
}, { immediate: true });
|
||||
const calendarDays = computed(() => buildMonthCalendarDays(month.value).map(day => ({
|
||||
...day,
|
||||
marked: !!(daily(day)?.inQuantity || daily(day)?.outQuantity)
|
||||
isRestDay: restDaySet.value.has(Number(day.dateText.replaceAll("-", "")))
|
||||
})));
|
||||
|
||||
function daily(day: MonthCalendarDay): GaoProductStockMovementDailyStatView | undefined {
|
||||
return stats.value.find(item => item.dateValue === Number(day.dateText.replaceAll("-", "")));
|
||||
}
|
||||
|
||||
watch([month, () => props.storeId, skuId], async () => {
|
||||
const token = ++monthToken;
|
||||
stats.value = [];
|
||||
@@ -130,11 +250,16 @@ const visible = ref(false);
|
||||
const selectedDate = ref("");
|
||||
const selectedStart = ref(0);
|
||||
const direction = ref<StockRecordDirection>("IN");
|
||||
const directionOptions = [{ label: "入库", value: "IN" }, { label: "出库", value: "OUT" }];
|
||||
async function changeDirection(event: { value: string | number }): Promise<void> {
|
||||
if (event.value === "IN" || event.value === "OUT") await selectDirection(event.value);
|
||||
}
|
||||
const records = ref<StockRecord[]>([]);
|
||||
const recordsLoading = ref(false);
|
||||
const noMore = ref(false);
|
||||
let page = 0;
|
||||
let recordToken = 0;
|
||||
|
||||
async function openDay(day: MonthCalendarDay): Promise<void> {
|
||||
const [year, monthNumber, dateNumber] = day.dateText.split("-").map(Number);
|
||||
const date = new Date(year, monthNumber - 1, dateNumber);
|
||||
@@ -143,6 +268,7 @@ async function openDay(day: MonthCalendarDay): Promise<void> {
|
||||
visible.value = true;
|
||||
if (canReadRecords.value) await selectDirection("IN");
|
||||
}
|
||||
|
||||
async function selectDirection(value: StockRecordDirection): Promise<void> {
|
||||
direction.value = value;
|
||||
recordToken++;
|
||||
@@ -152,6 +278,7 @@ async function selectDirection(value: StockRecordDirection): Promise<void> {
|
||||
recordsLoading.value = false;
|
||||
await loadRecords();
|
||||
}
|
||||
|
||||
async function loadRecords(): Promise<void> {
|
||||
if (recordsLoading.value || noMore.value) return;
|
||||
const token = ++recordToken;
|
||||
@@ -159,7 +286,16 @@ async function loadRecords(): Promise<void> {
|
||||
try {
|
||||
const start = new Date(selectedStart.value);
|
||||
const endAt = new Date(start.getFullYear(), start.getMonth(), start.getDate() + 1).getTime() - 1;
|
||||
const result = await ProductAPI.recordList({ storeId: props.storeId, skuId: skuId.value || undefined, beginAt: selectedStart.value, endAt, direction: direction.value, index: page, size: 15 });
|
||||
const result = await ProductAPI.recordList({
|
||||
storeId: props.storeId,
|
||||
productId: selection.value?.product.id || undefined,
|
||||
skuId: skuId.value || undefined,
|
||||
beginAt: selectedStart.value,
|
||||
endAt,
|
||||
direction: direction.value,
|
||||
index: page,
|
||||
size: 15
|
||||
});
|
||||
if (token !== recordToken) return;
|
||||
const list = result.list || [];
|
||||
records.value.push(...list);
|
||||
@@ -171,6 +307,7 @@ async function loadRecords(): Promise<void> {
|
||||
if (token === recordToken) recordsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch([() => props.storeId, skuId], () => {
|
||||
visible.value = false;
|
||||
recordToken++;
|
||||
@@ -193,19 +330,109 @@ watch(() => props.storeId, () => {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
justify-content: end;
|
||||
}
|
||||
|
||||
.movement-bar {
|
||||
width: 100%;
|
||||
height: .25rem;
|
||||
flex-shrink: 0;
|
||||
margin-top: auto;
|
||||
border-radius: .125rem;
|
||||
}
|
||||
|
||||
.quantity {
|
||||
margin-bottom: .125rem;
|
||||
}
|
||||
|
||||
.quantity {
|
||||
overflow: hidden;
|
||||
max-width: 100%;
|
||||
font-size: .625rem;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
&.in { color: var(--td-success-color); }
|
||||
&.out { color: var(--td-error-color); }
|
||||
|
||||
&.in {
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
&.out {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
.records { overflow: auto; max-height: 60vh; }
|
||||
.directions { display: flex; gap: .5rem; padding: .75rem; }
|
||||
|
||||
}
|
||||
|
||||
.records {
|
||||
height: 60vh;
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
flex-direction: column;
|
||||
|
||||
.directions {
|
||||
padding: .75rem;
|
||||
min-width: 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.record-list {
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.list { margin: 0; }
|
||||
.item { padding: .625rem; min-width: 0; }
|
||||
.icon { width: 2.25rem; height: 2.25rem; display: inline-flex; background: var(--td-bg-color-secondarycontainer); align-items: center; border-radius: 50%; justify-content: center; }
|
||||
.record-title {
|
||||
gap: .25rem;
|
||||
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, .record-quantity { flex: 0 0 auto; }
|
||||
.operation {
|
||||
color: var(--operation-color, var(--td-text-color-secondary));
|
||||
&.initial-in { --operation-color: #2563eb; }
|
||||
&.manual-in { --operation-color: #15803d; }
|
||||
&.manual-out { --operation-color: #c2410c; }
|
||||
&.manual-revoke { --operation-color: #be123c; }
|
||||
&.order-reserve { --operation-color: #7c3aed; }
|
||||
&.order-release { --operation-color: #0891b2; }
|
||||
&.order-out { --operation-color: #dc2626; }
|
||||
&.order-revoke { --operation-color: #4f46e5; }
|
||||
&.return-in { --operation-color: #15803d; }
|
||||
&.stocktake-gain { --operation-color: #0f766e; }
|
||||
&.stocktake-loss { --operation-color: #a16207; }
|
||||
}
|
||||
.product-name { overflow: hidden; flex: 0 1 auto; text-overflow: ellipsis; }
|
||||
.record-quantity { color: var(--td-text-color-secondary); }
|
||||
}
|
||||
.description { gap: .5rem; display: flex; font-size: .75rem; align-items: center; justify-content: space-between; }
|
||||
.delta { font-size: 1.25rem; }
|
||||
.positive { color: var(--td-success-color); }
|
||||
.negative { color: var(--td-error-color); }
|
||||
}
|
||||
:global(html.theme-dark) .records .operation {
|
||||
&.initial-in { --operation-color: #93c5fd; }
|
||||
&.manual-in, &.return-in { --operation-color: #86efac; }
|
||||
&.manual-out { --operation-color: #fdba74; }
|
||||
&.manual-revoke { --operation-color: #fda4af; }
|
||||
&.order-reserve { --operation-color: #c4b5fd; }
|
||||
&.order-release { --operation-color: #67e8f9; }
|
||||
&.order-out { --operation-color: #fca5a5; }
|
||||
&.order-revoke { --operation-color: #a5b4fc; }
|
||||
&.stocktake-gain { --operation-color: #5eead4; }
|
||||
&.stocktake-loss { --operation-color: #fcd34d; }
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar recycle-account">
|
||||
<t-navbar fixed :z-index="20" title="客户回收物额度" left-arrow @left-click="goBack" />
|
||||
<main v-can="permissionCodes.recycleAccount.read" class="tui-page-content scroll column">
|
||||
<customer-profile-card
|
||||
class="customer"
|
||||
:customer="customer"
|
||||
/>
|
||||
<template v-if="customerId">
|
||||
<t-cell-group title="额度账户" theme="card" v-entrance-transition>
|
||||
<t-cell
|
||||
class="item"
|
||||
v-for="account in accountList"
|
||||
:key="account.id || account.recycleItemId"
|
||||
:title="account.recycleName || '回收物'"
|
||||
>
|
||||
<template #leftIcon>
|
||||
<t-image v-if="coverId(account)" class="avatar" :src="getAttachmentReadURL(coverId(account), 96)" :alt="account.recycleName || '回收物'" fit="cover" />
|
||||
<div v-else class="avatar fallback" v-text="(account.recycleName || '回').slice(0, 1)" />
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="amounts">
|
||||
<span class="balance" v-text="`余额 ${getRecycleQuantityText(account.balance, account.recycleUnit)}`" />
|
||||
<span class="reserved" v-text="`预占 ${getRecycleQuantityText(account.reserved, account.recycleUnit)}`" />
|
||||
</div>
|
||||
</template>
|
||||
<template #note>
|
||||
<span class="available text-bold" v-text="getRecycleQuantityText(getRecycleAvailable(account).toFixed(3), account.recycleUnit)" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell v-if="!accountList.length" title="暂无额度" :note="accountLoading ? '正在加载' : '该客户还没有回收物额度'" />
|
||||
</t-cell-group>
|
||||
<t-cell-group theme="card">
|
||||
<t-cell v-if="canAdjust" title="调整额度" arrow @click="adjustPopup?.open()" />
|
||||
<t-cell title="回收流水" arrow @click="openPayments" />
|
||||
</t-cell-group>
|
||||
</template>
|
||||
<t-empty v-else description="请选择客户查看额度" />
|
||||
</main>
|
||||
<customer-selector v-model="customerId" v-model:visible="customerVisible" :enable-scan="false" @change="onCustomerChange" />
|
||||
<recycle-account-adjust-popup ref="adjustPopup" :customer-id="customerId" @success="loadAccounts" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { usePane } from "timi-tdesign-mobile";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
|
||||
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||
import RecycleAccountAdjustPopup from "@/pages/recycle/components/RecycleAccountAdjustPopup.vue";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { RecycleAccount, RecycleItem } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getRecycleAvailable, getRecycleQuantityText } from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecycleAccount" });
|
||||
const props = withDefaults(defineProps<{ initialCustomerId?: string }>(), { initialCustomerId: "" });
|
||||
const pane = usePane();
|
||||
const userStore = useUserStore();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const customerId = ref("");
|
||||
const customerVisible = ref(false);
|
||||
const customer = ref<Customer>();
|
||||
const accountList = ref<RecycleAccount[]>([]);
|
||||
const accountLoading = ref(false);
|
||||
const items = ref<RecycleItem[]>([]);
|
||||
const adjustPopup = ref<InstanceType<typeof RecycleAccountAdjustPopup>>();
|
||||
const canAdjust = computed(() => userStore.hasPermissions(permissionCodes.recycleAccount.adjust));
|
||||
|
||||
async function onCustomerChange(value: string | string[]): Promise<void> {
|
||||
const id = Array.isArray(value) ? String(value[0] || "") : value;
|
||||
customerId.value = id;
|
||||
customer.value = undefined;
|
||||
accountList.value = [];
|
||||
if (!id) return;
|
||||
try {
|
||||
const result = await CustomerAPI.detail(id);
|
||||
if (customerId.value === id) customer.value = result;
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "客户信息加载失败"));
|
||||
}
|
||||
await loadAccounts();
|
||||
}
|
||||
|
||||
async function loadAccounts(): Promise<void> {
|
||||
const id = customerId.value;
|
||||
if (!id) return;
|
||||
accountLoading.value = true;
|
||||
try {
|
||||
const result = await RecycleAPI.accountList(id);
|
||||
if (customerId.value === id) accountList.value = result;
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "额度账户加载失败"));
|
||||
} finally {
|
||||
accountLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadItems(): Promise<void> {
|
||||
try {
|
||||
const result: RecycleItem[] = [];
|
||||
let total = 0;
|
||||
do {
|
||||
const page = await RecycleAPI.itemList({ offset: result.length, limit: 100 });
|
||||
const rows = page.list || [];
|
||||
result.push(...rows);
|
||||
total = page.total || 0;
|
||||
if (!rows.length) break;
|
||||
} while (result.length < total);
|
||||
items.value = result;
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收物图片加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
function coverId(account: RecycleAccount): string {
|
||||
return items.value.find(item => item.id === account.recycleItemId)?.attachmentList?.find(item => item.id && item.mimeType?.startsWith("image/"))?.id || "";
|
||||
}
|
||||
|
||||
async function openPayments(): Promise<void> {
|
||||
const queryDepth = Number(Array.isArray(route.query.transitionDepth) ? route.query.transitionDepth[0] : route.query.transitionDepth);
|
||||
const currentDepth = route.query.transitionDepth && Number.isInteger(queryDepth) && 0 <= queryDepth && !(20 < queryDepth)
|
||||
? queryDepth : Number(route.meta.depth ?? 0);
|
||||
await router.push({ name: "RecyclePaymentAll", query: { customerId: customerId.value, transitionDepth: String(currentDepth + 1) } });
|
||||
}
|
||||
|
||||
function goBack(): void {
|
||||
if (pane) pane.close();
|
||||
else void router.back();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const id = props.initialCustomerId || (typeof route.query.customerId === "string" ? route.query.customerId : "");
|
||||
await Promise.all([loadItems(), onCustomerChange(id)]);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-account {
|
||||
|
||||
.customer {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.item {
|
||||
padding: 10px;
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.amounts {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
font-size: .75rem;
|
||||
|
||||
.balance {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
.reserved {
|
||||
color: var(--td-warning-color);
|
||||
}
|
||||
}
|
||||
|
||||
.available {
|
||||
color: var(--td-success-color);
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,498 +0,0 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="兑换单详情"
|
||||
left-arrow
|
||||
@left-click="goBack"
|
||||
/>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div v-can="permissionCodes.recycleExchange.query" class="recycle-exchange-detail">
|
||||
<customer-profile-card
|
||||
v-if="customer"
|
||||
class="customer-profile"
|
||||
:customer="customer"
|
||||
v-entrance-transition
|
||||
/>
|
||||
<template v-if="exchange">
|
||||
<t-cell-group title="兑换单信息" theme="card" v-entrance-transition>
|
||||
<t-cell title="客户" :note="customer?.name || customer?.code || exchange.customerId || '-'" />
|
||||
<t-cell title="状态">
|
||||
<template #note>
|
||||
<t-tag
|
||||
:content="statusText"
|
||||
variant="light-outline"
|
||||
:theme="statusTheme"
|
||||
/>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="兑换时间">
|
||||
<template #note>
|
||||
<time-label :timestamp="exchange.occurredAt" underline />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="操作人" :note="operatorName" />
|
||||
<t-cell v-if="exchange.remark" title="备注" :note="exchange.remark" />
|
||||
<t-cell title="单据编号" :note="exchange.id || '-'" />
|
||||
</t-cell-group>
|
||||
<t-cell-group class="exchange-card" title="回收与兑换" theme="card" v-entrance-transition>
|
||||
<t-cell title="回收物" :note="recycleItemText" />
|
||||
<t-cell title="兑换产品">
|
||||
<template #note>
|
||||
<div class="product-note">
|
||||
<span class="clip-text" v-text="productText" />
|
||||
<product-sku-tags
|
||||
:product-name="exchange.productNameSnapshot"
|
||||
:snapshot="exchange.skuSpecSnapshot"
|
||||
:fallback="exchange.specSummarySnapshot || exchange.skuNameSnapshot || ''"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="兑换比例" :note="ruleText" />
|
||||
<t-cell title="倍数" :note="`${exchange.multiple ?? 1} 倍`" />
|
||||
<t-cell title="预设数量" :note="defaultText" />
|
||||
<t-cell title="实际数量">
|
||||
<template #note>
|
||||
<span :class="{ adjusted: adjusted }" v-text="actualText" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="库存" :note="exchange.stockEnabledSnapshot ? '创建时已预占库存' : '不管理库存'" />
|
||||
</t-cell-group>
|
||||
<section class="photo-wrap bg-white" v-entrance-transition>
|
||||
<attachment-selector :items="photoItems" title="兑换凭证" readonly />
|
||||
</section>
|
||||
<t-cell-group v-if="actionList.length" class="records" title="操作记录" theme="card" v-entrance-transition>
|
||||
<div
|
||||
v-for="action in actionList"
|
||||
:key="action.id"
|
||||
class="record"
|
||||
>
|
||||
<div class="record-head">
|
||||
<div class="record-title">
|
||||
<t-tag
|
||||
size="small"
|
||||
:content="getRecycleActionText(action.actionType)"
|
||||
:theme="action.actionType === 'REVOKE' ? 'danger' : 'primary'"
|
||||
variant="light"
|
||||
/>
|
||||
<time-label class="time" :timestamp="action.occurredAt" underline />
|
||||
</div>
|
||||
<span class="operator" v-text="getActionOperatorName(action)" />
|
||||
</div>
|
||||
<div v-if="action.reason" class="record-line">
|
||||
<span class="label">原因</span>
|
||||
<span v-text="action.reason" />
|
||||
</div>
|
||||
<div v-if="action.remark" class="record-line">
|
||||
<span class="label">备注</span>
|
||||
<span v-text="action.remark" />
|
||||
</div>
|
||||
<div v-if="action.recycleReturned !== null && action.recycleReturned !== undefined" class="record-line">
|
||||
<span class="label">回收物</span>
|
||||
<span v-text="action.recycleReturned ? '全部退还客户' : '未退还客户'" />
|
||||
</div>
|
||||
<div v-if="action.stockReturned !== null && action.stockReturned !== undefined" class="record-line">
|
||||
<span class="label">兑换商品</span>
|
||||
<span v-text="action.stockReturned ? '已退回门店' : '未退回门店'" />
|
||||
</div>
|
||||
<attachment-selector
|
||||
v-if="getActionPhotoItems(action).length"
|
||||
class="record-photos"
|
||||
:items="getActionPhotoItems(action)"
|
||||
title="退货凭证"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="stockRecordList.length" class="records" title="库存流水" theme="card" v-entrance-transition>
|
||||
<t-cell
|
||||
v-for="record in stockRecordList"
|
||||
:key="record.id"
|
||||
:title="getStockOperationText(record.operationType)"
|
||||
:note="`${getRecycleQuantityText(record.quantity, record.unitSnapshot)}`"
|
||||
:description="record.remark || ''"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<section v-if="actionVisible" class="actions" v-entrance-transition>
|
||||
<div v-if="canVerify || canCancel" class="pair">
|
||||
<t-button
|
||||
v-if="canVerify"
|
||||
theme="primary"
|
||||
content="核销兑换"
|
||||
@click="confirmVerifyVisible = true"
|
||||
/>
|
||||
<t-button
|
||||
v-if="canCancel"
|
||||
theme="danger"
|
||||
content="撤销兑换"
|
||||
@click="cancelVisible = true"
|
||||
/>
|
||||
</div>
|
||||
<t-button
|
||||
v-if="canRevoke"
|
||||
theme="danger"
|
||||
content="冲正兑换"
|
||||
@click="revokeVisible = true"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
<t-empty v-else :description="loading ? '正在加载兑换单' : '兑换单不存在'" />
|
||||
<t-dialog
|
||||
v-model:visible="confirmVerifyVisible"
|
||||
title="核销兑换单"
|
||||
cancel-btn="取消"
|
||||
confirm-btn="确认核销"
|
||||
@cancel="confirmVerifyVisible = false"
|
||||
@confirm="verify"
|
||||
>
|
||||
<div class="verify-tip" v-text="verifyTipText" />
|
||||
</t-dialog>
|
||||
<recycle-exchange-action-popup
|
||||
v-if="exchange"
|
||||
v-model:visible="cancelVisible"
|
||||
:exchange="exchange"
|
||||
action="CANCEL"
|
||||
@success="load"
|
||||
/>
|
||||
<recycle-exchange-action-popup
|
||||
v-if="exchange"
|
||||
v-model:visible="revokeVisible"
|
||||
:exchange="exchange"
|
||||
action="REVOKE"
|
||||
@success="load"
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
|
||||
import { TimeLabel } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
|
||||
import ProductSkuTags from "@/components/ProductSkuTags.vue";
|
||||
import RecycleExchangeActionPopup from "@/pages/recycle/components/RecycleExchangeActionPopup.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { StockRecord } from "@/types/Product";
|
||||
import type { RecycleExchange, RecycleExchangeAction } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getStockOperationText } from "@/utils/product";
|
||||
import {
|
||||
canCancelExchange,
|
||||
canRevokeExchange,
|
||||
canVerifyExchange,
|
||||
getRecycleActionText,
|
||||
getRecycleExchangeStatusText,
|
||||
getRecycleExchangeStatusTheme,
|
||||
getRecycleQuantityText,
|
||||
isRecycleQuantityAdjusted
|
||||
} from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecycleExchangeDetail" });
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** 指定兑换单 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
|
||||
exchangeId?: string;
|
||||
}>(), {
|
||||
exchangeId: ""
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
|
||||
function resolveId(): string {
|
||||
return props.exchangeId || String(route.params.id || "");
|
||||
}
|
||||
|
||||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中
|
||||
useExpandToMaster({
|
||||
path: "/management/recycle-exchanges",
|
||||
id: () => resolveId()
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
const pane = usePane();
|
||||
|
||||
function goBack(): void {
|
||||
if (pane) {
|
||||
pane.close();
|
||||
return;
|
||||
}
|
||||
|
||||
void router.back();
|
||||
}
|
||||
|
||||
// ---------- 数据 ----------
|
||||
|
||||
const exchange = ref<RecycleExchange>();
|
||||
const actionList = ref<RecycleExchangeAction[]>([]);
|
||||
const actionAttachmentMap = ref<Record<string, PhotoItem[]>>({});
|
||||
const photoItems = ref<PhotoItem[]>([]);
|
||||
const stockRecordList = ref<StockRecord[]>([]);
|
||||
const loading = ref(false);
|
||||
const operating = ref(false);
|
||||
const confirmVerifyVisible = ref(false);
|
||||
const cancelVisible = ref(false);
|
||||
const revokeVisible = ref(false);
|
||||
|
||||
// 客户与操作人由服务端随单据一起返回,不再单独回查
|
||||
const customer = computed(() => exchange.value?.customer);
|
||||
const statusText = computed(() => getRecycleExchangeStatusText(exchange.value?.status));
|
||||
const statusTheme = computed(() => getRecycleExchangeStatusTheme(exchange.value?.status));
|
||||
const operatorName = computed(() => exchange.value?.operator?.nick || exchange.value?.operator?.name || exchange.value?.operatorUserId || "未知操作人");
|
||||
const adjusted = computed(() => !!exchange.value && isRecycleQuantityAdjusted(exchange.value));
|
||||
const recycleItemText = computed(() => {
|
||||
const current = exchange.value;
|
||||
if (!current) {
|
||||
return "-";
|
||||
}
|
||||
const name = current.recycleNameSnapshot || "回收物";
|
||||
return `${name} · ${getRecycleQuantityText(current.recycleQuantity, current.recycleUnitSnapshot)}`;
|
||||
});
|
||||
const productText = computed(() => {
|
||||
const current = exchange.value;
|
||||
if (!current) {
|
||||
return "-";
|
||||
}
|
||||
const productName = current.productNameSnapshot || current.skuNameSnapshot || "未命名产品";
|
||||
return `${productName} · ${getRecycleQuantityText(current.exchangeQuantity, current.unitSnapshot)}`;
|
||||
});
|
||||
const ruleText = computed(() => {
|
||||
const current = exchange.value;
|
||||
if (!current) {
|
||||
return "-";
|
||||
}
|
||||
const recycleText = getRecycleQuantityText(current.ruleRecycleQuantity, current.recycleUnitSnapshot);
|
||||
const exchangeText = getRecycleQuantityText(current.ruleExchangeQuantity, current.unitSnapshot);
|
||||
return `${recycleText} 兑换 ${exchangeText}`;
|
||||
});
|
||||
const defaultText = computed(() => {
|
||||
const current = exchange.value;
|
||||
if (!current) {
|
||||
return "-";
|
||||
}
|
||||
const recycleText = getRecycleQuantityText(current.defaultRecycleQuantity, current.recycleUnitSnapshot);
|
||||
const exchangeText = getRecycleQuantityText(current.defaultExchangeQuantity, current.unitSnapshot);
|
||||
return `${recycleText} 兑换 ${exchangeText}`;
|
||||
});
|
||||
const actualText = computed(() => {
|
||||
const current = exchange.value;
|
||||
if (!current) {
|
||||
return "-";
|
||||
}
|
||||
return `${getRecycleQuantityText(current.recycleQuantity, current.recycleUnitSnapshot)} 兑换 ${getRecycleQuantityText(current.exchangeQuantity, current.unitSnapshot)}`;
|
||||
});
|
||||
const verifyTipText = computed(() => {
|
||||
const current = exchange.value;
|
||||
if (!current) {
|
||||
return "";
|
||||
}
|
||||
const recycleText = getRecycleQuantityText(current.recycleQuantity, current.recycleUnitSnapshot);
|
||||
const exchangeText = getRecycleQuantityText(current.exchangeQuantity, current.unitSnapshot);
|
||||
return `本次收到 ${recycleText},兑换 ${exchangeText}。核销后不能撤销,只能冲正。`;
|
||||
});
|
||||
|
||||
// ---------- 操作权限 ----------
|
||||
|
||||
const canVerify = computed(() => canVerifyExchange(exchange.value?.status)
|
||||
&& userStore.hasPermissions(permissionCodes.recycleExchange.verify));
|
||||
const canCancel = computed(() => canCancelExchange(exchange.value?.status)
|
||||
&& userStore.hasPermissions(permissionCodes.recycleExchange.cancel));
|
||||
const canRevoke = computed(() => canRevokeExchange(exchange.value?.status)
|
||||
&& userStore.hasPermissions(permissionCodes.recycleExchange.revoke));
|
||||
const actionVisible = computed(() => canVerify.value || canCancel.value || canRevoke.value);
|
||||
|
||||
// ---------- 附件 ----------
|
||||
|
||||
function toPhotoItemList(attachmentList?: Array<{ id?: string; attachType?: string; mimeType?: string }>): PhotoItem[] {
|
||||
return (attachmentList || []).filter(item => !!item.id).map(item => ({
|
||||
attachment: item,
|
||||
attachType: item.attachType || "PHOTO",
|
||||
mimeType: item.mimeType,
|
||||
previewUrl: getAttachmentReadURL(item.id || ""),
|
||||
url: getAttachmentReadURL(item.id || "", 90)
|
||||
}));
|
||||
}
|
||||
|
||||
function getActionPhotoItems(action: RecycleExchangeAction): PhotoItem[] {
|
||||
return action.id ? actionAttachmentMap.value[action.id] || [] : [];
|
||||
}
|
||||
|
||||
/** 操作记录的操作人由服务端填充,缺失时退回 ID。 */
|
||||
function getActionOperatorName(action: RecycleExchangeAction): string {
|
||||
return action.operator?.nick || action.operator?.name || action.operatorUserId || "未知操作人";
|
||||
}
|
||||
|
||||
// ---------- 加载 ----------
|
||||
|
||||
async function load(): Promise<void> {
|
||||
const id = resolveId();
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await RecycleAPI.detail(id);
|
||||
exchange.value = result.exchange;
|
||||
actionList.value = result.actionList || [];
|
||||
photoItems.value = toPhotoItemList(result.attachmentList);
|
||||
stockRecordList.value = result.stockRecordList || [];
|
||||
actionAttachmentMap.value = Object.fromEntries(Object.entries(result.actionAttachments || {})
|
||||
.map(([actionId, attachmentList]) => [actionId, toPhotoItemList(attachmentList)]));
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换单加载失败"));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 核销 ----------
|
||||
|
||||
async function verify(): Promise<void> {
|
||||
const id = exchange.value?.id;
|
||||
if (operating.value || !id) {
|
||||
return;
|
||||
}
|
||||
operating.value = true;
|
||||
try {
|
||||
// 核销不保存请求中的附件,无需上传照片
|
||||
await RecycleAPI.verify({
|
||||
exchangeId: id,
|
||||
requestNo: window.crypto.randomUUID()
|
||||
});
|
||||
confirmVerifyVisible.value = false;
|
||||
Message.success("兑换单已核销");
|
||||
await load();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换单核销失败"));
|
||||
} finally {
|
||||
operating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
watch(() => [props.exchangeId, route.params.id], load);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-exchange-detail {
|
||||
gap: 1rem;
|
||||
padding: 0 0 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.customer-profile {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.exchange-card {
|
||||
|
||||
.product-note {
|
||||
gap: .375rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.adjusted {
|
||||
color: var(--td-warning-color, #ED7B2F);
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.photo-wrap {
|
||||
padding: .75rem 1rem;
|
||||
}
|
||||
|
||||
.records {
|
||||
padding: 0 1rem;
|
||||
|
||||
.record {
|
||||
gap: .375rem;
|
||||
display: flex;
|
||||
padding: .75rem 0;
|
||||
flex-direction: column;
|
||||
border-bottom: 1px solid var(--td-component-border);
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.record-head {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.record-title {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
|
||||
.time {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.operator {
|
||||
color: var(--td-text-color-secondary);
|
||||
flex: 0 0 auto;
|
||||
font-size: .75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.record-line {
|
||||
gap: .375rem;
|
||||
display: flex;
|
||||
font-size: .8125rem;
|
||||
line-height: 1.5;
|
||||
|
||||
.label {
|
||||
color: var(--td-text-color-secondary);
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
.record-photos {
|
||||
margin-top: .25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.actions {
|
||||
--td-button-border-radius: 1rem;
|
||||
|
||||
gap: .5rem;
|
||||
padding: 0 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.pair {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
|
||||
.t-button {
|
||||
width: calc(50% - .25rem);
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.verify-tip {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .875rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,517 +0,0 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar recycle-exchange-list">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="回收兑换"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<navbar-actions :actions="actions" />
|
||||
</template>
|
||||
</t-navbar>
|
||||
<master-detail-page
|
||||
v-can="permissionCodes.recycleExchange.query"
|
||||
class="list"
|
||||
:split="isWide"
|
||||
:selected="!!selectedId"
|
||||
:direction="paneDirection"
|
||||
>
|
||||
<template #master>
|
||||
<t-pull-down-refresh
|
||||
class="pull-refresh"
|
||||
v-model="refreshing"
|
||||
:refresh-timeout="30000"
|
||||
@refresh="refresh"
|
||||
@scrolltolower="loadMore"
|
||||
>
|
||||
<div class="filters glass">
|
||||
<t-input
|
||||
class="customer"
|
||||
:value="customerDisplayText"
|
||||
readonly
|
||||
borderless
|
||||
placeholder="选择客户"
|
||||
@click="customerSelectorVisible = true"
|
||||
>
|
||||
<template #suffix-icon>
|
||||
<div class="customer-actions">
|
||||
<t-button
|
||||
v-if="customerId"
|
||||
shape="circle"
|
||||
theme="danger"
|
||||
variant="text"
|
||||
size="extra-small"
|
||||
aria-label="清除客户选择"
|
||||
@click.stop="clearCustomer"
|
||||
>
|
||||
<t-icon name="close" size="1rem" />
|
||||
</t-button>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
theme="primary"
|
||||
variant="outline"
|
||||
content="选择客户"
|
||||
@click.stop="customerSelectorVisible = true"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</t-input>
|
||||
<t-dropdown-menu class="menus">
|
||||
<t-dropdown-item
|
||||
v-model="dateFilterType"
|
||||
:label="dateFilterLabel"
|
||||
:options="dateOptions"
|
||||
@change="selectDateFilter"
|
||||
/>
|
||||
<t-dropdown-item
|
||||
v-model="status"
|
||||
label="兑换状态"
|
||||
:options="statusOptions"
|
||||
@change="selectStatus"
|
||||
/>
|
||||
</t-dropdown-menu>
|
||||
</div>
|
||||
<div class="list-wrap">
|
||||
<t-cell-group v-if="isCustomDate" class="date-summary" theme="card">
|
||||
<t-cell
|
||||
title="开始时间"
|
||||
:note="dateRange[0] || '-'"
|
||||
arrow
|
||||
@click="openStartTime"
|
||||
/>
|
||||
<t-cell
|
||||
title="结束时间"
|
||||
:note="dateRange[1] || '-'"
|
||||
arrow
|
||||
@click="openEndTime"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="list.length" class="summary" theme="card">
|
||||
<t-cell title="兑换单数" :note="`${total} 单`" />
|
||||
</t-cell-group>
|
||||
<div v-if="list.length" class="items">
|
||||
<recycle-exchange-list-cell
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
class="item"
|
||||
:exchange="item"
|
||||
v-entrance-transition="{ step: 30 }"
|
||||
@detail="toDetail(item)"
|
||||
/>
|
||||
</div>
|
||||
<center-tips v-else :content="loading ? '正在加载兑换单' : '暂无兑换单'" />
|
||||
<center-tips :content="loading ? '正在加载' : noMore ? '已经到底了' : '上拉加载更多'" />
|
||||
</div>
|
||||
</t-pull-down-refresh>
|
||||
</template>
|
||||
<template #detail>
|
||||
<recycle-exchange-detail
|
||||
:key="`detail-${selectedId}`"
|
||||
:exchange-id="selectedId"
|
||||
/>
|
||||
</template>
|
||||
</master-detail-page>
|
||||
|
||||
<customer-selector
|
||||
v-model="customerId"
|
||||
v-model:visible="customerSelectorVisible"
|
||||
@change="handleCustomerChange"
|
||||
/>
|
||||
<t-popup v-model="startVisible" placement="bottom">
|
||||
<t-date-time-picker
|
||||
v-if="startVisible"
|
||||
v-model="startDraft"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
:mode="['date', 'minute']"
|
||||
title="开始时间"
|
||||
:default-value="dateRange[0]"
|
||||
@cancel="cancelStartTime"
|
||||
@confirm="confirmStartTime"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="endVisible" placement="bottom">
|
||||
<t-date-time-picker
|
||||
v-if="endVisible"
|
||||
v-model="endDraft"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
:mode="['date', 'minute']"
|
||||
title="结束时间"
|
||||
:default-value="dateRange[1]"
|
||||
@cancel="cancelEndTime"
|
||||
@confirm="confirmEndTime"
|
||||
/>
|
||||
</t-popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import type { DropdownValue } from "tdesign-mobile-vue";
|
||||
import { Time } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||
import RecycleExchangeDetail from "@/pages/recycle/RecycleExchangeDetail.vue";
|
||||
import RecycleExchangeListCell from "@/pages/recycle/components/RecycleExchangeListCell.vue";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { NavbarAction } from "@/types/NavbarAction";
|
||||
import type { RecycleExchange, RecycleExchangeStatus } from "@/types/Recycle";
|
||||
import { buildPresetDateRange, parseDateFilterType, parseDateTime } from "@/utils/date";
|
||||
import { DATE_FILTER_OPTIONS as dateOptions, type DateFilterType } from "@/utils/dateFilter";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
|
||||
defineOptions({ name: "RecycleExchangeList" });
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
|
||||
// 兑换单没有内联编辑视图,选中项、转屏、query 同步都交给分栏状态机
|
||||
const { selectedId, paneDirection, isWide, openDetail } = useMasterDetailPane({
|
||||
path: "/management/recycle-exchanges",
|
||||
detail: id => `/management/recycle-exchanges/${id}`
|
||||
});
|
||||
|
||||
// ---------- 顶部操作 ----------
|
||||
|
||||
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.recycleExchange.create));
|
||||
const canManageConfig = computed(() => userStore.hasPermissions(permissionCodes.recycleExchange.configManage));
|
||||
const actions = computed<NavbarAction[]>(() => [
|
||||
{
|
||||
key: "create",
|
||||
text: "新建兑换单",
|
||||
icon: "add",
|
||||
theme: "primary",
|
||||
visible: canCreate.value,
|
||||
action: toCreate
|
||||
},
|
||||
{
|
||||
key: "config",
|
||||
text: "回收物与规则",
|
||||
icon: "setting",
|
||||
theme: "primary",
|
||||
visible: canManageConfig.value,
|
||||
action: toConfig
|
||||
},
|
||||
{
|
||||
key: "stat",
|
||||
text: "回收兑换统计",
|
||||
icon: "chart-combo",
|
||||
theme: "primary",
|
||||
action: toStat
|
||||
}
|
||||
]);
|
||||
|
||||
// ---------- 筛选 ----------
|
||||
|
||||
const customerId = ref(getQueryText(route.query.customerId));
|
||||
const selectedCustomer = ref<Customer>();
|
||||
const customerSelectorVisible = ref(false);
|
||||
const dateFilterType = ref<DateFilterType>(parseDateFilterType(getQueryText(route.query.dateType), dateOptions, "all"));
|
||||
const dateRange = ref<[string, string]>(parseDateRange(dateFilterType.value));
|
||||
const startDraft = ref("");
|
||||
const endDraft = ref("");
|
||||
const startVisible = ref(false);
|
||||
const endVisible = ref(false);
|
||||
const status = ref<"ALL" | RecycleExchangeStatus>(getInitialStatus(route.query.status));
|
||||
const statusOptions = [
|
||||
{ label: "全部状态", value: "ALL" },
|
||||
{ label: "待核销", value: "PENDING" },
|
||||
{ label: "已核销", value: "VERIFIED" },
|
||||
{ label: "已撤销", value: "CANCELLED" },
|
||||
{ label: "已冲正", value: "REVOKED" }
|
||||
];
|
||||
const dateFilterLabel = computed(() => dateOptions.find(item => item.value === dateFilterType.value)?.label || "时间范围");
|
||||
const customerDisplayText = computed(() => selectedCustomer.value?.name || selectedCustomer.value?.code || "");
|
||||
const isCustomDate = computed(() => dateFilterType.value === "custom");
|
||||
|
||||
// ---------- 列表 ----------
|
||||
|
||||
const list = ref<RecycleExchange[]>([]);
|
||||
const pageIndex = ref(0);
|
||||
const total = ref(0);
|
||||
const loading = ref(false);
|
||||
const refreshing = ref(false);
|
||||
const noMore = ref(false);
|
||||
const pageSize = 16;
|
||||
|
||||
function getQueryText(value: unknown): string {
|
||||
return Array.isArray(value) ? "" : typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
function getInitialStatus(value: unknown): "ALL" | RecycleExchangeStatus {
|
||||
const statusValue = getQueryText(value);
|
||||
if (["PENDING", "VERIFIED", "CANCELLED", "REVOKED"].includes(statusValue)) {
|
||||
return statusValue as RecycleExchangeStatus;
|
||||
}
|
||||
return "ALL";
|
||||
}
|
||||
|
||||
function parseDateRange(type: DateFilterType): [string, string] {
|
||||
if (type !== "custom") {
|
||||
return buildPresetDateRange(type);
|
||||
}
|
||||
return [getQueryText(route.query.beginAt), getQueryText(route.query.endAt)];
|
||||
}
|
||||
|
||||
async function fetchList(reset: boolean): Promise<void> {
|
||||
if (loading.value || (!reset && noMore.value)) {
|
||||
return;
|
||||
}
|
||||
if (reset) {
|
||||
pageIndex.value = 0;
|
||||
total.value = 0;
|
||||
noMore.value = false;
|
||||
list.value = [];
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
const [beginAt, endAt] = buildUnixRange();
|
||||
const result = await RecycleAPI.page({
|
||||
index: pageIndex.value,
|
||||
size: pageSize,
|
||||
customerId: customerId.value || undefined,
|
||||
beginAt,
|
||||
endAt,
|
||||
status: status.value === "ALL" ? undefined : status.value
|
||||
});
|
||||
const rows = result.list || [];
|
||||
list.value = reset ? rows : list.value.concat(rows);
|
||||
total.value = result.total || 0;
|
||||
pageIndex.value += 1;
|
||||
noMore.value = rows.length < pageSize || total.value <= list.value.length;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function reloadList(): Promise<void> {
|
||||
try {
|
||||
await fetchList(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换单加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
async function refresh(): Promise<void> {
|
||||
try {
|
||||
await fetchList(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换单加载失败"));
|
||||
} finally {
|
||||
refreshing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMore(): Promise<void> {
|
||||
try {
|
||||
await fetchList(false);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换单加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
async function selectStatus(value: DropdownValue): Promise<void> {
|
||||
if (Array.isArray(value)) {
|
||||
return;
|
||||
}
|
||||
status.value = String(value) as "ALL" | RecycleExchangeStatus;
|
||||
await replaceFilterQuery();
|
||||
await reloadList();
|
||||
}
|
||||
|
||||
async function handleCustomerChange(value: string | string[]): Promise<void> {
|
||||
customerId.value = Array.isArray(value) ? String(value[0] || "") : value;
|
||||
try {
|
||||
selectedCustomer.value = customerId.value ? await CustomerAPI.detail(customerId.value) : undefined;
|
||||
await replaceFilterQuery();
|
||||
await fetchList(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "客户兑换单加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
async function clearCustomer(): Promise<void> {
|
||||
customerId.value = "";
|
||||
selectedCustomer.value = undefined;
|
||||
await replaceFilterQuery();
|
||||
await reloadList();
|
||||
}
|
||||
|
||||
async function selectDateFilter(value: DropdownValue): Promise<void> {
|
||||
if (Array.isArray(value)) {
|
||||
return;
|
||||
}
|
||||
dateFilterType.value = String(value) as DateFilterType;
|
||||
if (dateFilterType.value !== "custom") {
|
||||
dateRange.value = buildPresetDateRange(dateFilterType.value);
|
||||
await replaceFilterQuery();
|
||||
await reloadList();
|
||||
} else {
|
||||
await replaceFilterQuery();
|
||||
}
|
||||
}
|
||||
|
||||
function openStartTime(): void {
|
||||
startDraft.value = dateRange.value[0];
|
||||
startVisible.value = true;
|
||||
}
|
||||
|
||||
function openEndTime(): void {
|
||||
endDraft.value = dateRange.value[1];
|
||||
endVisible.value = true;
|
||||
}
|
||||
|
||||
function cancelStartTime(): void {
|
||||
startVisible.value = false;
|
||||
startDraft.value = dateRange.value[0];
|
||||
}
|
||||
|
||||
function cancelEndTime(): void {
|
||||
endVisible.value = false;
|
||||
endDraft.value = dateRange.value[1];
|
||||
}
|
||||
|
||||
async function confirmStartTime(value?: string | number): Promise<void> {
|
||||
startVisible.value = false;
|
||||
dateRange.value = [String(value || startDraft.value), dateRange.value[1]];
|
||||
await confirmCustomRange();
|
||||
}
|
||||
|
||||
async function confirmEndTime(value?: string | number): Promise<void> {
|
||||
endVisible.value = false;
|
||||
dateRange.value = [dateRange.value[0], String(value || endDraft.value)];
|
||||
await confirmCustomRange();
|
||||
}
|
||||
|
||||
async function confirmCustomRange(): Promise<void> {
|
||||
if (dateRange.value[0] && dateRange.value[1] && dateRange.value[1] < dateRange.value[0]) {
|
||||
dateRange.value = [dateRange.value[1], dateRange.value[0]];
|
||||
}
|
||||
dateFilterType.value = "custom";
|
||||
await replaceFilterQuery();
|
||||
await reloadList();
|
||||
}
|
||||
|
||||
function buildFilterQuery(transitionDepth = getQueryText(route.query.transitionDepth)): Record<string, string> {
|
||||
const query: Record<string, string> = {
|
||||
customerId: customerId.value,
|
||||
dateType: dateFilterType.value,
|
||||
beginAt: dateRange.value[0] || "",
|
||||
endAt: dateRange.value[1] || "",
|
||||
status: status.value === "ALL" ? "" : status.value
|
||||
};
|
||||
// 分栏时改筛选不能把右栏选中项冲掉,否则详情会被关闭
|
||||
if (selectedId.value) {
|
||||
query.detail = selectedId.value;
|
||||
}
|
||||
if (isValidTransitionDepth(transitionDepth)) {
|
||||
query.transitionDepth = transitionDepth;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
async function replaceFilterQuery(): Promise<void> {
|
||||
await router.replace({
|
||||
name: "RecycleExchangeList",
|
||||
query: buildFilterQuery()
|
||||
});
|
||||
}
|
||||
|
||||
function isValidTransitionDepth(value: string): boolean {
|
||||
const depth = Number(value);
|
||||
return value !== "" && Number.isInteger(depth) && 0 <= depth && depth <= 20;
|
||||
}
|
||||
|
||||
/** 状态接口的业务时间筛选起止均包含,结束时间补到当天 23:59:59。 */
|
||||
function buildUnixRange(): [number | undefined, number | undefined] {
|
||||
if (dateFilterType.value === "all") {
|
||||
return [0, Time.toTimestamp(new Date())];
|
||||
}
|
||||
return [
|
||||
Time.toTimestamp(parseDateTime(dateRange.value[0], false)),
|
||||
Time.toTimestamp(parseDateTime(dateRange.value[1], true))
|
||||
];
|
||||
}
|
||||
|
||||
// ---------- 跳转 ----------
|
||||
|
||||
async function toDetail(item: RecycleExchange): Promise<void> {
|
||||
openDetail(item.id || "");
|
||||
}
|
||||
|
||||
async function toCreate(): Promise<void> {
|
||||
await router.push({ name: "RecycleExchangeCreate" });
|
||||
}
|
||||
|
||||
async function toConfig(): Promise<void> {
|
||||
await router.push({ name: "RecycleItemList" });
|
||||
}
|
||||
|
||||
async function toStat(): Promise<void> {
|
||||
await router.push({ name: "RecycleStat" });
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
if (customerId.value) {
|
||||
selectedCustomer.value = await CustomerAPI.detail(customerId.value);
|
||||
}
|
||||
await fetchList(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换单加载失败"));
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-exchange-list {
|
||||
padding: var(--tui-nav-height) 0 1rem;
|
||||
|
||||
.filters {
|
||||
|
||||
.customer-actions {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
.list-wrap {
|
||||
gap: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.date-summary {
|
||||
|
||||
:deep(.t-cell__title) {
|
||||
flex: 0 0 4.5rem;
|
||||
}
|
||||
|
||||
:deep(.t-cell__note) {
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-align: right;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.items {
|
||||
gap: 1rem;
|
||||
display: flex;
|
||||
padding: 0 1rem;
|
||||
flex-direction: column;
|
||||
|
||||
.item {
|
||||
border-radius: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar">
|
||||
<t-navbar fixed :z-index="20" title="回收物详情" left-arrow @left-click="exit">
|
||||
<template #right>
|
||||
<t-button
|
||||
v-if="item"
|
||||
theme="primary"
|
||||
variant="text"
|
||||
size="small"
|
||||
content="编辑"
|
||||
@click="edit"
|
||||
/>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main v-can="permissionCodes.recycleExchange.configManage" class="tui-page-content scroll column">
|
||||
<center-tips v-if="loading" content="正在加载回收物" />
|
||||
<t-cell-group v-if="item" theme="card" v-entrance-transition>
|
||||
<t-cell title="名称" :note="item.name" />
|
||||
<t-cell title="计量单位" :note="item.unitName" />
|
||||
<t-cell
|
||||
title="允许小数"
|
||||
:note="item.allowDecimalQuantity ? '是' : '否'"
|
||||
/>
|
||||
<t-cell title="状态">
|
||||
<template #note>
|
||||
<t-tag
|
||||
:theme="getRecycleStatusTheme(item.status)"
|
||||
:content="getRecycleStatusText(item.status)"
|
||||
/>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="备注" :note="item.remark || '无'" />
|
||||
<div class="attachments bg-white">
|
||||
<attachment-selector
|
||||
:items="attachments"
|
||||
title="图片及附件"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
</t-cell-group>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { RecycleItem } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getRecycleStatusText, getRecycleStatusTheme } from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecycleItemDetail" });
|
||||
const props = withDefaults(defineProps<{ itemId?: string }>(), { itemId: "" });
|
||||
const emit = defineEmits<{ edit: [] }>();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const pane = usePane();
|
||||
const id = computed(() => props.itemId || String(route.params.id || ""));
|
||||
const item = ref<RecycleItem>();
|
||||
const loading = ref(false);
|
||||
let version = 0;
|
||||
const attachments = computed<PhotoItem[]>(() => (item.value?.attachmentList || []).filter(entry => entry.id).map(entry => ({
|
||||
attachment: entry, attachType: entry.attachType, mimeType: entry.mimeType, url: getAttachmentReadURL(entry.id || "")
|
||||
})));
|
||||
useExpandToMaster({ path: "/product/recycle-items", id: () => id.value });
|
||||
|
||||
function exit(): void {
|
||||
if (pane) pane.close(); else void router.back();
|
||||
}
|
||||
|
||||
async function edit(): Promise<void> {
|
||||
if (pane) emit("edit");
|
||||
else await router.push({ name: "RecycleItemEdit", params: { id: id.value } });
|
||||
}
|
||||
|
||||
watch(id, async value => {
|
||||
const current = ++version;
|
||||
item.value = undefined;
|
||||
if (!value) {
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await RecycleAPI.itemDetail(value);
|
||||
if (current === version) item.value = result;
|
||||
} catch (error) {
|
||||
if (current === version) Message.error(getErrorMessage(error, "回收物加载失败"));
|
||||
} finally {
|
||||
if (current === version) loading.value = false;
|
||||
}
|
||||
}, { immediate: true });
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.attachments {
|
||||
padding: 1rem;
|
||||
}
|
||||
</style>
|
||||
@@ -3,287 +3,59 @@
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
:title="isCreate ? '新增回收物' : '编辑回收物'"
|
||||
:title="id ? '编辑回收物' : '新增回收物'"
|
||||
left-arrow
|
||||
@left-click="exit()"
|
||||
@left-click="exit"
|
||||
>
|
||||
<template #right>
|
||||
<t-button
|
||||
:loading="saving"
|
||||
theme="primary"
|
||||
variant="text"
|
||||
size="small"
|
||||
content="保存"
|
||||
@click="save()"
|
||||
:loading="formRef?.saving"
|
||||
:disabled="!canSave"
|
||||
content="保存" @click="formRef?.save()"
|
||||
/>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div v-can="permissionCodes.recycleExchange.configManage" class="recycle-item-edit">
|
||||
<t-form class="form card" label-width="7rem" v-entrance-transition>
|
||||
<t-form-item label="回收物名称" required-mark>
|
||||
<t-input
|
||||
v-model.trim="form.name"
|
||||
align="right"
|
||||
borderless
|
||||
maxlength="128"
|
||||
placeholder="例如空瓶"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label="计量单位" required-mark>
|
||||
<t-input
|
||||
v-model.trim="form.unitName"
|
||||
align="right"
|
||||
borderless
|
||||
maxlength="32"
|
||||
placeholder="例如个、公斤"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label="来源产品" content-align="right" arrow @click="productPopupVisible = true">
|
||||
<span class="clip-text" v-text="sourceProductName || '可不选,仅用于识别'" />
|
||||
</t-form-item>
|
||||
<t-form-item v-if="hasSource" label="来源 SKU" content-align="right">
|
||||
<div class="clear-row">
|
||||
<product-sku-tags :fallback="sourceSkuText" />
|
||||
<t-button
|
||||
size="extra-small"
|
||||
theme="danger"
|
||||
variant="text"
|
||||
content="清除"
|
||||
@click="clearSource"
|
||||
/>
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<span class="tips" v-text="'来源产品不影响库存,也不校验客户购买历史'" />
|
||||
</t-form-item>
|
||||
<t-form-item label="配置状态" content-align="right" arrow @click="statusVisible = true">
|
||||
<span v-text="getRecycleStatusText(form.status)" />
|
||||
</t-form-item>
|
||||
<t-form-item label="备注">
|
||||
<t-textarea v-model.trim="form.remark" borderless autosize maxlength="500" placeholder="可不填" />
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<span class="tips footer-tips" v-text="'配置保存后不能删除,不再使用请把状态改成停用。停用不影响已创建的兑换单。'" />
|
||||
<t-button
|
||||
v-if="!isCreate"
|
||||
class="cell-button"
|
||||
theme="default"
|
||||
v-entrance-transition
|
||||
:content="form.status === 'ACTIVE' ? '停用回收物' : '启用回收物'"
|
||||
@click="toggleStatus"
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
<t-popup v-model="statusVisible" placement="bottom">
|
||||
<t-picker
|
||||
v-model="statusDraft"
|
||||
:columns="statusOptions"
|
||||
title="配置状态"
|
||||
@cancel="statusVisible = false"
|
||||
@confirm="confirmStatus"
|
||||
<main v-can="permissionCodes.recycleExchange.configManage" class="tui-page-content scroll column">
|
||||
<recycle-item-form
|
||||
ref="formRef"
|
||||
class="card"
|
||||
:item-id="id"
|
||||
v-entrance-transition
|
||||
@saved="handleSaved"
|
||||
/>
|
||||
</t-popup>
|
||||
<product-select-popup
|
||||
v-model="selection"
|
||||
v-model:visible="productPopupVisible"
|
||||
product-scope="all"
|
||||
@select="handleProductSelection"
|
||||
/>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import ProductSelectPopup from "@/components/productSelector/ProductSelectPopup.vue";
|
||||
import ProductSkuTags from "@/components/ProductSkuTags.vue";
|
||||
import type { ProductSelection } from "@/types/Product";
|
||||
import type { ProductSkuSelectionValue } from "@/types/ProductSkuSelection";
|
||||
import type { RecycleStatus } from "@/types/Recycle";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import RecycleItemForm from "@/pages/recycle/components/RecycleItemForm.vue";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getRecycleStatusText } from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecycleItemEdit" });
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** 指定回收物 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
|
||||
itemId?: string;
|
||||
}>(), {
|
||||
itemId: ""
|
||||
});
|
||||
const emit = defineEmits<{
|
||||
saved: [];
|
||||
}>();
|
||||
|
||||
const props = withDefaults(defineProps<{ itemId?: string }>(), { itemId: "" });
|
||||
const emit = defineEmits<{ saved: [] }>();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const currentId = computed(() => props.itemId || String(route.params.id || ""));
|
||||
const isCreate = computed(() => !currentId.value);
|
||||
|
||||
// 竖屏整页编辑转横屏:回到分栏,右栏直接是编辑视图
|
||||
useExpandToMaster({
|
||||
path: "/management/recycle-items",
|
||||
id: () => currentId.value
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
const pane = usePane();
|
||||
const id = computed(() => props.itemId || String(route.params.id || ""));
|
||||
const formRef = ref<InstanceType<typeof RecycleItemForm>>();
|
||||
const canSave = computed(() => !!formRef.value?.ready && !formRef.value.loading && !formRef.value.uploading && !formRef.value.saving);
|
||||
useExpandToMaster({
|
||||
path: "/product/recycle-items",
|
||||
id: () => id.value || "__create__",
|
||||
query: id.value ? { view: "edit" } : {}
|
||||
});
|
||||
|
||||
function exit(saved = false): void {
|
||||
if (pane) {
|
||||
pane.close(saved);
|
||||
return;
|
||||
}
|
||||
|
||||
void router.back();
|
||||
if (pane) pane.close(saved); else void router.back();
|
||||
}
|
||||
|
||||
// ---------- 表单 ----------
|
||||
|
||||
const form = reactive({
|
||||
id: "",
|
||||
name: "",
|
||||
unitName: "",
|
||||
status: "ACTIVE" as RecycleStatus,
|
||||
remark: ""
|
||||
});
|
||||
const selection = ref<ProductSkuSelectionValue>();
|
||||
const picked = ref<ProductSelection>();
|
||||
const productPopupVisible = ref(false);
|
||||
// 来源产品与 SKU 名称由服务端随配置返回,未改选前直接展示
|
||||
const sourceSnapshot = reactive({ productName: "", skuText: "", productId: "", skuId: "" });
|
||||
const statusVisible = ref(false);
|
||||
const statusDraft = ref<Array<string | number>>(["ACTIVE"]);
|
||||
const saving = ref(false);
|
||||
const statusOptions = [
|
||||
{ label: "启用", value: "ACTIVE" },
|
||||
{ label: "停用", value: "INACTIVE" }
|
||||
];
|
||||
const hasSource = computed(() => !!picked.value || !!sourceSnapshot.productName);
|
||||
const sourceProductName = computed(() => picked.value?.product?.name || sourceSnapshot.productName);
|
||||
const sourceSkuText = computed(() => {
|
||||
const sku = picked.value?.sku;
|
||||
return sku ? sku.specSummary?.trim() || sku.name?.trim() || "" : sourceSnapshot.skuText;
|
||||
});
|
||||
|
||||
function handleProductSelection(value: ProductSelection): void {
|
||||
picked.value = value;
|
||||
selection.value = { skuId: value.sku.id || "", skuUnitId: value.unit.id || "" };
|
||||
function handleSaved(): void {
|
||||
emit("saved");
|
||||
exit(true);
|
||||
}
|
||||
|
||||
function clearSource(): void {
|
||||
selection.value = undefined;
|
||||
picked.value = undefined;
|
||||
sourceSnapshot.productName = "";
|
||||
sourceSnapshot.skuText = "";
|
||||
sourceSnapshot.productId = "";
|
||||
sourceSnapshot.skuId = "";
|
||||
}
|
||||
|
||||
function confirmStatus(value: Array<string | number>): void {
|
||||
form.status = String(value[0]) as RecycleStatus;
|
||||
statusVisible.value = false;
|
||||
}
|
||||
|
||||
// ---------- 数据 ----------
|
||||
|
||||
async function load(): Promise<void> {
|
||||
const id = currentId.value;
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const target = await RecycleAPI.itemDetail(id);
|
||||
form.id = target.id || "";
|
||||
form.name = target.name || "";
|
||||
form.unitName = target.unitName || "";
|
||||
form.status = target.status || "ACTIVE";
|
||||
form.remark = target.remark || "";
|
||||
sourceSnapshot.productName = target.sourceProductName || "";
|
||||
sourceSnapshot.skuText = target.sourceSkuName || "";
|
||||
sourceSnapshot.productId = target.productId || "";
|
||||
sourceSnapshot.skuId = target.skuId || "";
|
||||
selection.value = target.skuId ? { skuId: target.skuId, skuUnitId: "" } : undefined;
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收物配置加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 保存 ----------
|
||||
|
||||
async function save(status?: RecycleStatus): Promise<void> {
|
||||
const name = form.name.trim();
|
||||
const unitName = form.unitName.trim();
|
||||
if (saving.value || !name || !unitName) {
|
||||
Message.warning("请填写回收物名称和计量单位");
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
await RecycleAPI.itemSave({
|
||||
id: form.id || undefined,
|
||||
name,
|
||||
unitName,
|
||||
productId: picked.value?.product?.id || sourceSnapshot.productId || null,
|
||||
skuId: picked.value?.sku?.id || sourceSnapshot.skuId || null,
|
||||
status: status || form.status,
|
||||
remark: form.remark || null
|
||||
});
|
||||
Message.success("回收物配置已保存");
|
||||
form.status = status || form.status;
|
||||
emit("saved");
|
||||
exit(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收物配置保存失败"));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 停用走同一条保存接口,提交完整配置。 */
|
||||
async function toggleStatus(): Promise<void> {
|
||||
await save(form.status === "ACTIVE" ? "INACTIVE" : "ACTIVE");
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
watch(() => [props.itemId, route.params.id], load);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-item-edit {
|
||||
gap: 1rem;
|
||||
display: flex;
|
||||
padding: 0 0 2rem;
|
||||
flex-direction: column;
|
||||
|
||||
.form {
|
||||
|
||||
.tips {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .8125rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.clear-row {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.clear {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.footer-tips {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .8125rem;
|
||||
line-height: 1.6;
|
||||
padding: 0 2rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar recycle-item-list">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="回收物配置"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<t-navbar fixed :z-index="20" title="回收物管理" left-arrow @left-click="$router.back()">
|
||||
<template #right>
|
||||
<navbar-actions :actions="actions" />
|
||||
<t-button theme="primary" variant="text" size="small" content="新增" @click="create" />
|
||||
</template>
|
||||
</t-navbar>
|
||||
<master-detail-page
|
||||
@@ -16,66 +10,75 @@
|
||||
class="list"
|
||||
:split="isWide"
|
||||
:selected="!!selectedId"
|
||||
:direction="paneDirection"
|
||||
>
|
||||
:direction="paneDirection">
|
||||
<template #master>
|
||||
<t-pull-down-refresh
|
||||
class="pull-refresh"
|
||||
v-model="refreshing"
|
||||
class="pull-refresh"
|
||||
:refresh-timeout="30000"
|
||||
@refresh="reload"
|
||||
@scrolltolower="loadMore"
|
||||
>
|
||||
<div class="filters glass">
|
||||
<t-input
|
||||
v-model.trim="keyword"
|
||||
class="keyword"
|
||||
v-model="keyword"
|
||||
type="search"
|
||||
borderless
|
||||
clearable
|
||||
placeholder="搜索回收物名称"
|
||||
/>
|
||||
</div>
|
||||
<t-cell-group v-if="list.length" theme="card">
|
||||
<t-cell-group
|
||||
v-if="items.length"
|
||||
theme="card"
|
||||
class="fix-last-cell-line"
|
||||
>
|
||||
<t-cell
|
||||
v-for="item in list"
|
||||
class="cell"
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
class="item"
|
||||
:arrow="!!item.id"
|
||||
:title="item.name || '未命名回收物'"
|
||||
:description="`按${item.unitName || '单位'}计量`"
|
||||
arrow
|
||||
v-entrance-transition="{ step: 30 }"
|
||||
@click="toEdit(item)"
|
||||
@click="openDetail(item.id || '')"
|
||||
>
|
||||
<template #left-icon>
|
||||
<div class="avatar fallback" v-text="(item.name || '回').slice(0, 1)" />
|
||||
</template>
|
||||
<template #title>
|
||||
<span class="clip-text" v-text="item.name || '未命名回收物'" />
|
||||
<template #leftIcon>
|
||||
<t-image
|
||||
v-if="coverId(item)"
|
||||
class="avatar"
|
||||
:src="getAttachmentReadURL(coverId(item), 96)"
|
||||
:alt="item.name"
|
||||
fit="cover"
|
||||
/>
|
||||
<div v-else class="avatar fallback" v-text="(item.name || '回').slice(0, 1)" />
|
||||
</template>
|
||||
<template #note>
|
||||
<t-tag
|
||||
size="small"
|
||||
:theme="getRecycleStatusTheme(item.status)"
|
||||
:content="getRecycleStatusText(item.status)"
|
||||
/>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<t-tag size="small" variant="light-outline" :content="`按${item.unitName || '单位'}计量`" />
|
||||
<span v-if="getSourceText(item)" class="source" v-text="getSourceText(item)" />
|
||||
</div>
|
||||
<t-tag size="small" :theme="getRecycleStatusTheme(item.status)"
|
||||
:content="getRecycleStatusText(item.status)" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<center-tips v-else :content="loading ? '正在加载回收物' : '暂无回收物配置'" />
|
||||
<center-tips :content="loading ? '正在加载' : noMore ? `共 ${total} 条配置` : '上拉加载更多'" />
|
||||
<center-tips v-else :content="loading ? '正在加载回收物' : '暂无回收物'" />
|
||||
<center-tips
|
||||
v-if="items.length"
|
||||
:content="loading ? '正在加载' : noMore ? `共 ${total} 条回收物` : '上拉加载更多'"
|
||||
/>
|
||||
</t-pull-down-refresh>
|
||||
</template>
|
||||
<template #detail>
|
||||
<recycle-item-edit
|
||||
:key="`item-${selectedId}`"
|
||||
:item-id="selectedId"
|
||||
v-if="selectedId === createId || editing"
|
||||
:key="`edit-${selectedId}`"
|
||||
:item-id="selectedId === createId ? '' : selectedId"
|
||||
@saved="reload"
|
||||
/>
|
||||
<recycle-item-detail
|
||||
v-else
|
||||
:key="`detail-${selectedId}-${detailVersion}`"
|
||||
:item-id="selectedId"
|
||||
@edit="openEdit"
|
||||
/>
|
||||
</template>
|
||||
</master-detail-page>
|
||||
</div>
|
||||
@@ -83,170 +86,93 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import { Toolkit } from "timi-web";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import RecycleItemDetail from "@/pages/recycle/RecycleItemDetail.vue";
|
||||
import RecycleItemEdit from "@/pages/recycle/RecycleItemEdit.vue";
|
||||
import type { NavbarAction } from "@/types/NavbarAction";
|
||||
import type { RecycleItem } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getRecycleStatusText, getRecycleStatusTheme } from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecycleItemList" });
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
// 回收物没有独立详情,选中即进编辑
|
||||
const { selectedId, isWide, paneDirection, openDetail } = useMasterDetailPane({
|
||||
path: "/management/recycle-items",
|
||||
detail: id => `/management/recycle-items/${id}`
|
||||
const createId = "__create__";
|
||||
const { selectedId, editing, detailVersion, isWide, paneDirection, openDetail, openEdit } = useMasterDetailPane({
|
||||
path: "/product/recycle-items",
|
||||
detail: id => id === createId ? "/product/recycle-items/create" : `/product/recycle-items/${id}`,
|
||||
edit: id => `/product/recycle-items/${id}/edit`
|
||||
});
|
||||
|
||||
const actions = computed<NavbarAction[]>(() => [
|
||||
{
|
||||
key: "create",
|
||||
text: "新增回收物",
|
||||
icon: "add",
|
||||
theme: "primary",
|
||||
action: toCreate
|
||||
},
|
||||
{
|
||||
key: "rules",
|
||||
text: "兑换规则",
|
||||
icon: "swap",
|
||||
theme: "primary",
|
||||
action: toRuleList
|
||||
}
|
||||
]);
|
||||
|
||||
// ---------- 列表 ----------
|
||||
|
||||
const list = ref<RecycleItem[]>([]);
|
||||
const items = ref<RecycleItem[]>([]);
|
||||
const keyword = ref("");
|
||||
const pageIndex = ref(0);
|
||||
const total = ref(0);
|
||||
const loading = ref(false);
|
||||
const refreshing = ref(false);
|
||||
const noMore = ref(false);
|
||||
const pageSize = 20;
|
||||
const total = ref(0);
|
||||
let version = 0;
|
||||
let searchTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
async function fetchList(reset: boolean): Promise<void> {
|
||||
if (loading.value || (!reset && noMore.value)) {
|
||||
return;
|
||||
}
|
||||
if (reset) {
|
||||
pageIndex.value = 0;
|
||||
total.value = 0;
|
||||
noMore.value = false;
|
||||
list.value = [];
|
||||
}
|
||||
function coverId(item: RecycleItem): string {
|
||||
return item.attachmentList?.find(attachment => attachment.id && attachment.mimeType?.startsWith("image/"))?.id || "";
|
||||
}
|
||||
|
||||
async function fetchPage(reset: boolean): Promise<void> {
|
||||
if (!reset && (loading.value || noMore.value)) return;
|
||||
const requestVersion = reset ? ++version : version;
|
||||
const offset = reset ? 0 : items.value.length;
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await RecycleAPI.itemList({
|
||||
offset: pageIndex.value * pageSize,
|
||||
limit: pageSize,
|
||||
keyword: keyword.value.trim() || undefined
|
||||
});
|
||||
const result = await RecycleAPI.itemList({ offset, limit: 20, keyword: keyword.value || undefined });
|
||||
if (requestVersion !== version) return;
|
||||
const rows = result.list || [];
|
||||
list.value = reset ? rows : list.value.concat(rows);
|
||||
items.value = reset ? rows : [...items.value, ...rows];
|
||||
total.value = result.total || 0;
|
||||
pageIndex.value += 1;
|
||||
noMore.value = rows.length < pageSize || total.value <= list.value.length;
|
||||
noMore.value = rows.length < 20 || total.value <= items.value.length;
|
||||
} catch (error) {
|
||||
if (requestVersion === version) Message.error(getErrorMessage(error, "回收物加载失败"));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
if (requestVersion === version) {
|
||||
loading.value = false;
|
||||
refreshing.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function reload(): Promise<void> {
|
||||
try {
|
||||
await fetchList(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收物配置加载失败"));
|
||||
} finally {
|
||||
refreshing.value = false;
|
||||
}
|
||||
await fetchPage(true);
|
||||
}
|
||||
|
||||
async function loadMore(): Promise<void> {
|
||||
try {
|
||||
await fetchList(false);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收物配置加载失败"));
|
||||
}
|
||||
await fetchPage(false);
|
||||
}
|
||||
|
||||
const reloadByKeyword = Toolkit.debounce(async () => {
|
||||
await reload();
|
||||
}, false);
|
||||
|
||||
/** 来源产品名称由服务端回填,仅用于识别,不做库存和销售校验。 */
|
||||
function getSourceText(item: RecycleItem): string {
|
||||
const productName = item.sourceProductName || "";
|
||||
const skuText = item.sourceSkuName || "";
|
||||
return [productName, skuText && skuText !== productName ? skuText : ""].filter(Boolean).join(" · ");
|
||||
async function create(): Promise<void> {
|
||||
if (isWide.value) openDetail(createId);
|
||||
else await router.push({ name: "RecycleItemCreate" });
|
||||
}
|
||||
|
||||
// ---------- 跳转 ----------
|
||||
|
||||
function toEdit(item: RecycleItem): void {
|
||||
openDetail(item.id || "");
|
||||
}
|
||||
|
||||
async function toCreate(): Promise<void> {
|
||||
await router.push({ name: "RecycleItemCreate" });
|
||||
}
|
||||
|
||||
async function toRuleList(): Promise<void> {
|
||||
await router.push({ name: "RecycleRuleList" });
|
||||
}
|
||||
|
||||
onMounted(reload);
|
||||
watch(keyword, () => {
|
||||
reloadByKeyword();
|
||||
if (searchTimer) clearTimeout(searchTimer);
|
||||
searchTimer = setTimeout(() => {
|
||||
void reload();
|
||||
}, 300);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
reloadByKeyword.cancel();
|
||||
if (searchTimer) clearTimeout(searchTimer);
|
||||
});
|
||||
onActivated(async () => await reload());
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-item-list {
|
||||
display: flex;
|
||||
padding: var(--tui-nav-height) 0 5rem;
|
||||
flex-direction: column;
|
||||
|
||||
.item {
|
||||
.cell {
|
||||
padding: 10px;
|
||||
|
||||
.avatar {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.description {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
|
||||
.source {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:global(html.theme-dark) {
|
||||
.recycle-item-list {
|
||||
|
||||
.fallback {
|
||||
color: #ccfbf1;
|
||||
background: #115e59;
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar recycle-payment-create">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="登记回收物"
|
||||
left-arrow
|
||||
@left-click="exit()"
|
||||
>
|
||||
<template #right>
|
||||
<t-button v-if="exchange" theme="primary" variant="text" size="small" content="提交" :loading="saving" :disabled="!loaded || saving" @click="submit" />
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="tui-page-content scroll column">
|
||||
<customer-profile-card
|
||||
class="customer"
|
||||
:customer="customer"
|
||||
v-entrance-transition
|
||||
/>
|
||||
<t-cell-group v-if="exchange" theme="card" v-entrance-transition>
|
||||
<t-cell class="name" :note="exchange.recycleNameSnapshot || '未命名回收物'">
|
||||
<template #left-icon>
|
||||
<div class="title">
|
||||
<t-image
|
||||
v-if="recyclePhotoId"
|
||||
class="avatar"
|
||||
:src="getAttachmentReadURL(recyclePhotoId)"
|
||||
:alt="exchange.recycleNameSnapshot || '回收物'"
|
||||
fit="cover"
|
||||
/>
|
||||
<div v-else class="avatar fallback" v-text="(exchange.recycleNameSnapshot || '回').slice(0, 1)" />
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="可用额度" :note="availableText" />
|
||||
<t-cell title="剩余待回收" :note="remainingText" />
|
||||
</t-cell-group>
|
||||
<t-form
|
||||
v-if="exchange"
|
||||
class="form card"
|
||||
label-width="7.5rem"
|
||||
v-entrance-transition
|
||||
>
|
||||
<t-form-item label="回收数量" content-align="right" required-mark>
|
||||
<div class="amount">
|
||||
<t-stepper
|
||||
size="large"
|
||||
theme="outline"
|
||||
:input-width="60"
|
||||
:min="exchange.allowDecimalQuantity ? .001 : 1"
|
||||
:max="Math.max(remaining, exchange.allowDecimalQuantity ? .001 : 1)"
|
||||
:step="exchange.allowDecimalQuantity ? .05 : 1"
|
||||
:integer="!exchange.allowDecimalQuantity"
|
||||
v-model="quantity"
|
||||
/>
|
||||
<span v-text="exchange.recycleUnitSnapshot || ''" />
|
||||
<t-button
|
||||
size="extra-small"
|
||||
theme="primary"
|
||||
:disabled="!loaded || 0 >= remaining"
|
||||
variant="outline"
|
||||
content="全部回收"
|
||||
@click="fillRemaining"
|
||||
/>
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item v-if="canVerify" label="直接核销回收" content-align="right">
|
||||
<t-switch v-model="verifyNow" size="small" />
|
||||
</t-form-item>
|
||||
<t-form-item label="收取时间" content-align="right">
|
||||
<date-time-now-picker v-model="occurredAtText" title="收取时间" />
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<attachment-selector
|
||||
v-model:items="photoItems"
|
||||
:upload="uploadPhotoList"
|
||||
required
|
||||
title="收取凭证照片"
|
||||
/>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { usePane } from "timi-tdesign-mobile";
|
||||
import { Time } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
|
||||
import DateTimeNowPicker from "@/components/DateTimeNowPicker.vue";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { RecycleExchange } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { parseDateTime } from "@/utils/date";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { uploadPhotoList } from "@/utils/photo";
|
||||
import { getRecycleAvailable, getRecycleQuantityText } from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecyclePaymentCreate" });
|
||||
const props = withDefaults(defineProps<{ exchangeId?: string; embedded?: boolean }>(), {
|
||||
exchangeId: "",
|
||||
embedded: false
|
||||
});
|
||||
const emit = defineEmits<{ saved: [paymentId?: string] }>();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const pane = usePane();
|
||||
const userStore = useUserStore();
|
||||
const exchange = ref<RecycleExchange>();
|
||||
const customer = ref<Customer>();
|
||||
const availableText = ref("加载中");
|
||||
const remaining = ref(0);
|
||||
const quantity = ref("0");
|
||||
const verifyNow = ref(false);
|
||||
const canVerify = computed(() => userStore.hasPermissions(permissionCodes.fundReceive.verify));
|
||||
const occurredAtText = ref("");
|
||||
const photoItems = ref<PhotoItem[]>([]);
|
||||
const requestNo = ref("");
|
||||
const saving = ref(false);
|
||||
const loaded = ref(false);
|
||||
const recyclePhotoId = computed(() => exchange.value?.recycleItemAttachments?.find(item => item.id && item.mimeType?.startsWith("image/"))?.id || "");
|
||||
const remainingText = computed(() => getRecycleQuantityText(remaining.value.toFixed(3), exchange.value?.recycleUnitSnapshot));
|
||||
|
||||
function exit(changed = false): void {
|
||||
if (props.embedded && pane) {
|
||||
pane.close(changed);
|
||||
return;
|
||||
}
|
||||
router.back();
|
||||
}
|
||||
|
||||
function fillRemaining(): void {
|
||||
quantity.value = getRecycleQuantityText(remaining.value.toFixed(3));
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
try {
|
||||
const id = props.exchangeId || String(route.params.id || "");
|
||||
const result = await RecycleAPI.detail(id);
|
||||
exchange.value = result.exchange;
|
||||
if (exchange.value?.customerId) {
|
||||
const customerId = exchange.value.customerId;
|
||||
const [customerResult, accountResult] = await Promise.allSettled([
|
||||
CustomerAPI.detail(customerId),
|
||||
RecycleAPI.accountList(customerId)
|
||||
]);
|
||||
if (customerResult.status === "fulfilled") customer.value = customerResult.value;
|
||||
else Message.error(getErrorMessage(customerResult.reason, "客户信息加载失败"));
|
||||
if (accountResult.status === "fulfilled" && exchange.value.recycleItemId) {
|
||||
const account = accountResult.value.find(item => item.recycleItemId === exchange.value?.recycleItemId);
|
||||
availableText.value = getRecycleQuantityText(getRecycleAvailable(account).toFixed(3), exchange.value.recycleUnitSnapshot);
|
||||
} else {
|
||||
availableText.value = "无法获取";
|
||||
if (accountResult.status === "rejected") Message.error(getErrorMessage(accountResult.reason, "可用额度加载失败"));
|
||||
}
|
||||
} else {
|
||||
availableText.value = "无法获取";
|
||||
}
|
||||
if (!exchange.value?.salesOrderId) return;
|
||||
const payments = await RecycleAPI.paymentList(exchange.value.salesOrderId);
|
||||
const reserved = payments.filter(item => item.status === "PENDING" || (item.status === "VERIFIED" && !item.sourcePaymentId))
|
||||
.reduce((sum, item) => sum + Number(item.quantity ?? 0), 0);
|
||||
remaining.value = Math.max(Number(exchange.value.recycleQuantity ?? 0) - reserved, 0);
|
||||
fillRemaining();
|
||||
loaded.value = true;
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收信息加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
if (saving.value || !loaded.value || !exchange.value?.salesOrderId) return;
|
||||
const value = Number(quantity.value);
|
||||
if (!Number.isFinite(value) || 0 >= value || remaining.value < value) {
|
||||
Message.warning("回收数量必须大于零且不能超过剩余待回收数量");
|
||||
return;
|
||||
}
|
||||
const attachmentList = photoItems.value.flatMap(item => item.tempFileId ? [
|
||||
{
|
||||
tempFileId: item.tempFileId,
|
||||
attachType: "PHOTO"
|
||||
}
|
||||
] : []);
|
||||
if (!attachmentList.length) {
|
||||
Message.warning("请上传收取凭证照片");
|
||||
return;
|
||||
}
|
||||
if (!requestNo.value) requestNo.value = window.crypto.randomUUID();
|
||||
saving.value = true;
|
||||
try {
|
||||
const request = {
|
||||
orderId: exchange.value.salesOrderId,
|
||||
requestNo: requestNo.value,
|
||||
quantity: quantity.value,
|
||||
occurredAt: occurredAtText.value ? Time.toTimestamp(parseDateTime(occurredAtText.value, false)) : undefined,
|
||||
attachmentList
|
||||
};
|
||||
const payment = verifyNow.value ? await RecycleAPI.paymentCreateAndVerify(request) : await RecycleAPI.paymentCreate(request);
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, exchange.value.salesOrderId);
|
||||
emit("saved", payment.id);
|
||||
Message.success(verifyNow.value ? "回收物已收取并核销" : "回收物已登记,待核销");
|
||||
if (!props.embedded || !pane || !payment.id) exit(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收登记失败,重试会复用同一请求号"));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch([quantity, verifyNow, occurredAtText, photoItems], () => {
|
||||
requestNo.value = "";
|
||||
}, { deep: true });
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-payment-create {
|
||||
|
||||
.customer {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.name {
|
||||
|
||||
.title {
|
||||
display: flex;
|
||||
justify-content: end;
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.amount {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,287 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar recycle-payment-detail">
|
||||
<t-navbar fixed :z-index="20" title="回收流水详情" left-arrow @left-click="exit" />
|
||||
<main class="tui-page-content scroll column">
|
||||
<template v-if="payment">
|
||||
<t-cell-group title="回收记录" theme="card" v-entrance-transition>
|
||||
<t-cell title="回收物" :note="exchange?.recycleNameSnapshot || '-'" />
|
||||
<t-cell title="数量" :note="paymentQuantity(payment)" />
|
||||
<t-cell title="状态">
|
||||
<template #note>
|
||||
<t-tag
|
||||
:content="getRecyclePaymentStatusText(payment.status)"
|
||||
:theme="getRecyclePaymentStatusTheme(payment.status)"
|
||||
variant="light-outline"
|
||||
/>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell v-if="payment.sourcePaymentId" title="类型" note="冲正记录" />
|
||||
<t-cell v-if="payment.reason" title="原因" :note="payment.reason" />
|
||||
<t-cell
|
||||
v-if="payment.returnedToCustomer !== null && payment.returnedToCustomer !== undefined"
|
||||
title="实物已退还客户"
|
||||
:note="payment.returnedToCustomer ? '是' : '否'"
|
||||
/>
|
||||
<t-cell
|
||||
title="发起人"
|
||||
:note="payment.operator?.nick || payment.operator?.name || '未知'"
|
||||
/>
|
||||
<t-cell
|
||||
v-if="payment.verifierUserId"
|
||||
:title="payment.status === 'VERIFIED' ? '核销人' : '处理人'"
|
||||
:note="payment.verifier?.nick || payment.verifier?.name || '未知'"
|
||||
/>
|
||||
<t-cell title="发起时间">
|
||||
<template #note>
|
||||
<time-label :timestamp="payment.occurredAt" underline />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell v-if="payment.verifiedAt" title="处理时间">
|
||||
<template #note>
|
||||
<time-label :timestamp="payment.verifiedAt" underline />
|
||||
</template>
|
||||
</t-cell>
|
||||
<div class="attach-wrap bg-white">
|
||||
<attachment-selector
|
||||
v-if="photoItems.length"
|
||||
:items="photoItems"
|
||||
title="业务照片"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
</t-cell-group>
|
||||
<section v-if="canVerify || canCancel || canRevoke" class="actions">
|
||||
<div v-if="canVerify" class="pair">
|
||||
<t-button
|
||||
theme="primary"
|
||||
:loading="operating"
|
||||
content="核销回收"
|
||||
v-entrance-transition
|
||||
@click="verifyPayment"
|
||||
/>
|
||||
<t-button
|
||||
theme="danger"
|
||||
content="拒绝回收"
|
||||
v-entrance-transition
|
||||
@click="openPayment('reject')"
|
||||
/>
|
||||
</div>
|
||||
<t-button
|
||||
v-if="canCancel"
|
||||
theme="default"
|
||||
content="撤销回收"
|
||||
v-entrance-transition
|
||||
@click="openPayment('cancel')"
|
||||
/>
|
||||
<t-button
|
||||
v-if="canRevoke"
|
||||
theme="danger"
|
||||
content="回收冲正"
|
||||
v-entrance-transition
|
||||
@click="openRevoke"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
<center-tips
|
||||
v-else
|
||||
:content="loading ? '正在加载回收流水' : '回收流水不存在'"
|
||||
/>
|
||||
<t-dialog
|
||||
v-model:visible="reasonDialogVisible"
|
||||
:title="reasonAction === 'reject' ? '拒绝回收' : '撤销回收'"
|
||||
cancel-btn="取消"
|
||||
:confirm-btn="reasonAction === 'reject' ? '拒绝' : '撤销'"
|
||||
@cancel="reasonDialogVisible = false"
|
||||
@confirm="submitReason"
|
||||
>
|
||||
<t-textarea v-model.trim="reasonText" borderless autosize maxlength="500" placeholder="请输入原因" />
|
||||
</t-dialog>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { usePane } from "timi-tdesign-mobile";
|
||||
import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { TimeLabel } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { RecycleExchange, RecyclePayment } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import {
|
||||
getRecyclePaymentStatusText,
|
||||
getRecyclePaymentStatusTheme,
|
||||
getRecycleQuantityText,
|
||||
isPaymentPending,
|
||||
isPaymentVerified
|
||||
} from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecyclePaymentDetail" });
|
||||
const props = withDefaults(defineProps<{ exchangeId?: string; paymentId?: string }>(), {
|
||||
exchangeId: "",
|
||||
paymentId: ""
|
||||
});
|
||||
const emit = defineEmits<{ changed: [] }>();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const pane = usePane();
|
||||
const userStore = useUserStore();
|
||||
const currentExchangeId = computed(() => props.exchangeId || String(route.params.id || ""));
|
||||
const currentPaymentId = computed(() => props.paymentId || String(route.params.paymentId || ""));
|
||||
const exchange = ref<RecycleExchange>();
|
||||
const payment = ref<RecyclePayment>();
|
||||
const loading = ref(false);
|
||||
const operating = ref(false);
|
||||
const reasonDialogVisible = ref(false);
|
||||
const reasonAction = ref<"reject" | "cancel">("reject");
|
||||
const reasonText = ref("");
|
||||
const photoItems = computed<PhotoItem[]>(() => (payment.value?.attachmentList || []).flatMap(item => item.id
|
||||
? [{ attachment: item, attachType: item.attachType, mimeType: item.mimeType, url: getAttachmentReadURL(item.id) }]
|
||||
: []));
|
||||
const canVerify = computed(() => !!payment.value && isPaymentPending(payment.value) && userStore.hasPermissions(permissionCodes.fundReceive.verify));
|
||||
const loginUserId = computed(() => userStore.loginUser.user?.id || userStore.loginUser.id || "");
|
||||
const canCancel = computed(() => !!payment.value && isPaymentPending(payment.value) && userStore.hasPermissions(permissionCodes.fundReceive.create)
|
||||
&& payment.value.operatorUserId === loginUserId.value);
|
||||
const canRevoke = computed(() => !!payment.value && isPaymentVerified(payment.value) && userStore.hasPermissions(permissionCodes.fund.revoke));
|
||||
|
||||
function exit(): void {
|
||||
if (props.exchangeId && pane) {
|
||||
if (0 < Number(window.history.state?.paneLevel || 0)) pane.close();
|
||||
else pane.openSub(`recycle-payments:${currentExchangeId.value}`);
|
||||
return;
|
||||
}
|
||||
router.back();
|
||||
}
|
||||
|
||||
function paymentQuantity(value: RecyclePayment): string {
|
||||
return getRecycleQuantityText(Number(value.signedQuantity ?? value.quantity ?? 0).toFixed(3), exchange.value?.recycleUnitSnapshot);
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
if (!currentExchangeId.value || !currentPaymentId.value) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await RecycleAPI.detail(currentExchangeId.value);
|
||||
exchange.value = result.exchange;
|
||||
const payments = exchange.value?.salesOrderId ? await RecycleAPI.paymentList(exchange.value.salesOrderId) : [];
|
||||
payment.value = payments.find(item => item.id === currentPaymentId.value);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收流水加载失败"));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function reloadAfterChange(): Promise<void> {
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, exchange.value?.salesOrderId);
|
||||
emit("changed");
|
||||
await load();
|
||||
}
|
||||
|
||||
async function verifyPayment(): Promise<void> {
|
||||
if (!payment.value?.id || operating.value || !canVerify.value) return;
|
||||
const paymentId = payment.value.id;
|
||||
const dialog = DialogPlugin.confirm({
|
||||
title: "核销回收",
|
||||
content: "确认核销该笔回收记录?",
|
||||
confirmBtn: "确认核销",
|
||||
cancelBtn: "取消",
|
||||
onConfirm: async () => {
|
||||
operating.value = true;
|
||||
try {
|
||||
await RecycleAPI.paymentVerify(paymentId);
|
||||
Message.success("回收物已核销");
|
||||
await reloadAfterChange();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "核销失败"));
|
||||
} finally {
|
||||
operating.value = false;
|
||||
dialog.destroy();
|
||||
}
|
||||
},
|
||||
onCancel: () => dialog.destroy()
|
||||
});
|
||||
}
|
||||
|
||||
function openPayment(action: "reject" | "cancel"): void {
|
||||
if (operating.value || !(action === "reject" ? canVerify.value : canCancel.value)) return;
|
||||
reasonAction.value = action;
|
||||
reasonText.value = "";
|
||||
reasonDialogVisible.value = true;
|
||||
}
|
||||
|
||||
async function submitReason(): Promise<void> {
|
||||
if (operating.value) return;
|
||||
if (!payment.value?.id || !(reasonAction.value === "reject" ? canVerify.value : canCancel.value)) return;
|
||||
if (!reasonText.value.trim()) {
|
||||
Message.warning("请输入原因");
|
||||
return;
|
||||
}
|
||||
operating.value = true;
|
||||
try {
|
||||
const request = { paymentId: payment.value.id, reason: reasonText.value.trim() };
|
||||
if (reasonAction.value === "reject") await RecycleAPI.paymentReject(request);
|
||||
else await RecycleAPI.paymentCancel(request);
|
||||
reasonDialogVisible.value = false;
|
||||
Message.success(reasonAction.value === "reject" ? "回收物支付已拒绝,预占已释放" : "回收物支付已撤销,预占已释放");
|
||||
await reloadAfterChange();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收物支付处理失败,请刷新后确认状态"));
|
||||
} finally {
|
||||
operating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function openRevoke(): Promise<void> {
|
||||
if (!canRevoke.value || !payment.value?.id) return;
|
||||
if (pane?.openSub(`recycle-payment-revoke:${currentExchangeId.value}:${payment.value.id}`)) return;
|
||||
const queryDepth = Number(Array.isArray(route.query.transitionDepth) ? route.query.transitionDepth[0] : route.query.transitionDepth);
|
||||
const currentDepth = route.query.transitionDepth && Number.isInteger(queryDepth) && 0 <= queryDepth && !(20 < queryDepth)
|
||||
? queryDepth : Number(route.meta.depth ?? 0);
|
||||
await router.push({ name: "RecyclePaymentRevoke", params: { id: currentExchangeId.value, paymentId: payment.value.id }, query: { transitionDepth: String(currentDepth + 1) } });
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onActivated(load);
|
||||
watch([currentExchangeId, currentPaymentId], load);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-payment-detail {
|
||||
|
||||
.attach-wrap {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.actions {
|
||||
--td-button-border-radius: 1rem;
|
||||
|
||||
gap: .5rem;
|
||||
padding: 0 1rem;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.pair {
|
||||
gap: .5rem;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
|
||||
.t-button {
|
||||
flex: 1 1 0;
|
||||
width: calc(50% - .25rem);
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.t-button {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,448 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar recycle-payment-list">
|
||||
<t-navbar fixed :z-index="20" title="回收流水" left-arrow @left-click="exit">
|
||||
<template #right>
|
||||
<t-button
|
||||
v-if="canRegister"
|
||||
theme="primary"
|
||||
variant="text"
|
||||
size="small"
|
||||
content="添加"
|
||||
@click="openRegister"
|
||||
/>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="tui-page-content list">
|
||||
<t-pull-down-refresh
|
||||
class="pull-refresh"
|
||||
v-model="refreshing"
|
||||
:refresh-timeout="30000"
|
||||
@refresh="reload"
|
||||
@scrolltolower="loadMore">
|
||||
<div class="filters glass">
|
||||
<t-input
|
||||
class="customer"
|
||||
v-model="customerSearchKeyword"
|
||||
borderless
|
||||
placeholder="输入客户编码或姓名"
|
||||
@enter="applyCustomerSearch"
|
||||
>
|
||||
<template #suffix-icon>
|
||||
<div class="actions">
|
||||
<t-button
|
||||
v-if="customerId"
|
||||
shape="circle"
|
||||
theme="danger"
|
||||
variant="text"
|
||||
size="extra-small"
|
||||
aria-label="清除客户选择"
|
||||
@click.stop="clearCustomer"
|
||||
>
|
||||
<t-icon name="close" size="1rem" />
|
||||
</t-button>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
theme="primary"
|
||||
variant="outline"
|
||||
content="选择客户"
|
||||
@click.stop="customerSelectorVisible = true"
|
||||
/>
|
||||
</div>
|
||||
</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="status"
|
||||
label="状态"
|
||||
:options="statusOptions"
|
||||
@change="reload"
|
||||
/>
|
||||
</t-dropdown-menu>
|
||||
</div>
|
||||
<t-cell-group v-if="dateType === 'custom'" class="date-summary" theme="card">
|
||||
<t-cell title="开始时间" :note="dateRange[0] || '-'" arrow @click="openDate(false)" />
|
||||
<t-cell title="结束时间" :note="dateRange[1] || '-'" arrow @click="openDate(true)" />
|
||||
</t-cell-group>
|
||||
<t-cell-group
|
||||
v-if="paymentList.length"
|
||||
class="empty-cell-title-margin"
|
||||
theme="card"
|
||||
>
|
||||
<t-cell
|
||||
class="item"
|
||||
v-for="payment in paymentList"
|
||||
:key="payment.id"
|
||||
arrow
|
||||
v-entrance-transition
|
||||
@click="openDetail(payment)"
|
||||
>
|
||||
<template #leftIcon>
|
||||
<t-image
|
||||
v-if="getCustomerPhotoURL(payment.customer, 64)"
|
||||
class="avatar"
|
||||
:src="getCustomerPhotoURL(payment.customer, 64)"
|
||||
:alt="customerName(payment)"
|
||||
fit="cover"
|
||||
/>
|
||||
<div v-else class="avatar fallback" v-text="customerName(payment).slice(0, 1)" />
|
||||
</template>
|
||||
<template #title>
|
||||
<div class="title">
|
||||
<span class="customer clip-text" v-text="customerName(payment)" />
|
||||
<span
|
||||
class="type"
|
||||
:class="payment.sourcePaymentId ? 'revoke' : 'receive'"
|
||||
v-text="payment.sourcePaymentId ? '回收冲正' : '回收登记'"
|
||||
/>
|
||||
<t-tag
|
||||
:content="getRecyclePaymentStatusText(payment.status)"
|
||||
:theme="getRecyclePaymentStatusTheme(payment.status)"
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<div class="operator">
|
||||
<div class="field"><span class="label">发起人</span><span class="text-bold"
|
||||
v-text="payment.operator?.nick || payment.operator?.name || '未知'" />
|
||||
</div>
|
||||
<div v-if="payment.verifierUserId" class="field">
|
||||
<span
|
||||
class="label"
|
||||
v-text="payment.status === 'VERIFIED' ? '核销人' : '处理人'" />
|
||||
<span
|
||||
class="text-bold"
|
||||
v-text="payment.verifier?.nick || payment.verifier?.name || '未知'"
|
||||
/>
|
||||
</div>
|
||||
<time-label :timestamp="payment.occurredAt" underline />
|
||||
</div>
|
||||
<div class="quantity">
|
||||
<strong class="red" v-text="paymentQuantity(payment)" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<center-tips v-else :content="loading ? '正在加载回收流水' : '暂无回收流水'" />
|
||||
<center-tips
|
||||
v-if="paymentList.length"
|
||||
:content="loading ? '正在加载' : noMore ? '已经到底了' : '上拉加载更多'"
|
||||
/>
|
||||
</t-pull-down-refresh>
|
||||
</main>
|
||||
<customer-selector
|
||||
v-model="customerId"
|
||||
v-model:visible="customerSelectorVisible"
|
||||
@change="handleCustomerChange"
|
||||
/>
|
||||
<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 { usePane } from "timi-tdesign-mobile";
|
||||
import type { DropdownValue } from "tdesign-mobile-vue";
|
||||
import { Time, TimeLabel } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { RecycleExchange, RecyclePayment } from "@/types/Recycle";
|
||||
import { getCustomerPhotoURL } from "@/utils/customer";
|
||||
import { buildPresetDateRange, parseDateTime } from "@/utils/date";
|
||||
import { DATE_FILTER_OPTIONS as dateOptions, type DateFilterType } from "@/utils/dateFilter";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getRecyclePaymentStatusText, getRecyclePaymentStatusTheme, getRecycleQuantityText } from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecyclePaymentList" });
|
||||
const props = withDefaults(defineProps<{ exchangeId?: string }>(), { exchangeId: "" });
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const pane = usePane();
|
||||
const userStore = useUserStore();
|
||||
const currentId = computed(() => props.exchangeId || (typeof route.params.id === "string" ? route.params.id : ""));
|
||||
const exchange = ref<RecycleExchange>();
|
||||
const remaining = ref(0);
|
||||
const paymentList = ref<RecyclePayment[]>([]);
|
||||
const loading = ref(false);
|
||||
const refreshing = ref(false);
|
||||
const noMore = ref(false);
|
||||
const customerId = ref(typeof route.query.customerId === "string" ? route.query.customerId : "");
|
||||
const selectedCustomer = ref<Customer>();
|
||||
const customerSearchKeyword = ref("");
|
||||
const customerSelectorVisible = ref(false);
|
||||
const status = ref("ALL");
|
||||
const dateType = ref<DateFilterType>("all");
|
||||
const dateRange = ref<[string, string]>(["", ""]);
|
||||
const dateVisible = ref(false);
|
||||
const dateDraft = ref("");
|
||||
const editingEnd = ref(false);
|
||||
const statusOptions = [
|
||||
{ label: "全部状态", value: "ALL" }, { label: "待核销", value: "PENDING" },
|
||||
{ label: "已核销", value: "VERIFIED" }, { label: "已拒绝", value: "REJECTED" },
|
||||
{ label: "已撤销", value: "CANCELLED" }, { label: "已冲正", value: "REVOKED" }
|
||||
];
|
||||
const dateLabel = computed(() => dateOptions.find(item => item.value === dateType.value)?.label || "时间范围");
|
||||
const canRegister = computed(() => !!exchange.value && 0 < remaining.value && userStore.hasPermissions(permissionCodes.fundReceive.create));
|
||||
let requestVersion = 0;
|
||||
|
||||
function exit(): void {
|
||||
if (pane) {
|
||||
pane.close();
|
||||
return;
|
||||
}
|
||||
router.back();
|
||||
}
|
||||
|
||||
function customerName(payment: RecyclePayment): string {
|
||||
return payment.customer?.name || payment.customer?.code || "未知客户";
|
||||
}
|
||||
|
||||
function paymentQuantity(payment: RecyclePayment): string {
|
||||
const quantity = Number(payment.signedQuantity ?? payment.quantity ?? 0);
|
||||
return getRecycleQuantityText(quantity.toFixed(3), payment.recycleUnit || exchange.value?.recycleUnitSnapshot);
|
||||
}
|
||||
|
||||
async function loadMore(): Promise<void> {
|
||||
if (loading.value || noMore.value || (currentId.value && !exchange.value?.salesOrderId)) return;
|
||||
const version = requestVersion;
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await RecycleAPI.paymentSearch({
|
||||
orderId: exchange.value?.salesOrderId,
|
||||
customerId: customerId.value || undefined,
|
||||
status: status.value === "ALL" ? undefined : status.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,
|
||||
offset: paymentList.value.length,
|
||||
limit: 21
|
||||
});
|
||||
if (version !== requestVersion) return;
|
||||
paymentList.value.push(...result.slice(0, 20));
|
||||
noMore.value = 21 > result.length;
|
||||
} catch (error) {
|
||||
if (version === requestVersion) Message.error(getErrorMessage(error, "回收流水加载失败"));
|
||||
} finally {
|
||||
if (version === requestVersion) {
|
||||
loading.value = false;
|
||||
refreshing.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function reload(): Promise<void> {
|
||||
requestVersion += 1;
|
||||
const version = requestVersion;
|
||||
loading.value = false;
|
||||
paymentList.value = [];
|
||||
noMore.value = false;
|
||||
if (currentId.value) {
|
||||
exchange.value = undefined;
|
||||
try {
|
||||
const result = await RecycleAPI.detail(currentId.value);
|
||||
if (version !== requestVersion) return;
|
||||
exchange.value = result.exchange;
|
||||
if (!exchange.value?.salesOrderId) {
|
||||
Message.error("未找到兑换订单");
|
||||
refreshing.value = false;
|
||||
return;
|
||||
}
|
||||
const payments = await RecycleAPI.paymentList(exchange.value.salesOrderId);
|
||||
if (version !== requestVersion) return;
|
||||
const reserved = payments.filter(item => item.status === "PENDING" || (item.status === "VERIFIED" && !item.sourcePaymentId))
|
||||
.reduce((sum, item) => sum + Number(item.quantity ?? 0), 0);
|
||||
remaining.value = Math.max(Number(exchange.value.recycleQuantity ?? 0) - reserved, 0);
|
||||
} catch (error) {
|
||||
if (version === requestVersion) {
|
||||
Message.error(getErrorMessage(error, "回收信息加载失败"));
|
||||
refreshing.value = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else exchange.value = undefined;
|
||||
await loadMore();
|
||||
}
|
||||
|
||||
async function handleCustomerChange(value: string | string[]): Promise<void> {
|
||||
customerId.value = Array.isArray(value) ? value[0] || "" : value;
|
||||
try {
|
||||
selectedCustomer.value = customerId.value ? await CustomerAPI.detail(customerId.value) : undefined;
|
||||
customerSearchKeyword.value = selectedCustomer.value?.name || selectedCustomer.value?.code || "";
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "客户信息加载失败"));
|
||||
}
|
||||
await reload();
|
||||
}
|
||||
|
||||
async function clearCustomer(): Promise<void> {
|
||||
customerId.value = "";
|
||||
selectedCustomer.value = undefined;
|
||||
customerSearchKeyword.value = "";
|
||||
await reload();
|
||||
}
|
||||
|
||||
async function applyCustomerSearch(): Promise<void> {
|
||||
const keyword = customerSearchKeyword.value.trim();
|
||||
if (!keyword) {
|
||||
await clearCustomer();
|
||||
return;
|
||||
}
|
||||
if (keyword === (selectedCustomer.value?.name || selectedCustomer.value?.code)) return;
|
||||
try {
|
||||
const customer = await CustomerAPI.findByCode(keyword) || await CustomerAPI.findByName(keyword);
|
||||
if (!customer?.id) {
|
||||
Message.warning("未找到客户");
|
||||
return;
|
||||
}
|
||||
customerId.value = customer.id;
|
||||
selectedCustomer.value = customer;
|
||||
customerSearchKeyword.value = customer.name || customer.code || "";
|
||||
await reload();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "客户信息加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
async function openDetail(payment: RecyclePayment): Promise<void> {
|
||||
const exchangeId = payment.recycleExchangeId || currentId.value;
|
||||
if (!payment.id || !exchangeId) {
|
||||
Message.warning("未找到关联兑换单");
|
||||
return;
|
||||
}
|
||||
if (pane?.openSub(`recycle-payment-detail:${exchangeId}:${payment.id}`)) return;
|
||||
const queryDepth = Number(Array.isArray(route.query.transitionDepth) ? route.query.transitionDepth[0] : route.query.transitionDepth);
|
||||
const currentDepth = route.query.transitionDepth && Number.isInteger(queryDepth) && 0 <= queryDepth && !(20 < queryDepth)
|
||||
? queryDepth : Number(route.meta.depth ?? 0);
|
||||
await router.push({ name: "RecyclePaymentDetail", params: { id: exchangeId, paymentId: payment.id }, query: { transitionDepth: String(currentDepth + 1) } });
|
||||
}
|
||||
|
||||
async function openRegister(): Promise<void> {
|
||||
if (pane?.openSub(`recycle-register:${currentId.value}`)) return;
|
||||
await router.push({ name: "RecyclePaymentCreate", params: { id: currentId.value } });
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const id = typeof route.query.customerId === "string" ? route.query.customerId : "";
|
||||
if (id) {
|
||||
await handleCustomerChange(id);
|
||||
} else {
|
||||
await reload();
|
||||
}
|
||||
});
|
||||
onActivated(reload);
|
||||
watch(currentId, reload);
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
.recycle-payment-list {
|
||||
|
||||
.item {
|
||||
padding: 10px;
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
gap: .25rem;
|
||||
display: flex;
|
||||
font-size: .75rem;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.customer { font-weight: 600; }
|
||||
.type {
|
||||
font-weight: 700;
|
||||
|
||||
&.receive { color: #15803d; }
|
||||
&.revoke { color: #7c3aed; }
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
display: flex;
|
||||
align-items: start;
|
||||
justify-content: space-between;
|
||||
|
||||
.operator {
|
||||
color: var(--td-text-color-secondary);
|
||||
display: flex;
|
||||
font-size: .75rem;
|
||||
line-height: 1.5;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.field {
|
||||
gap: .25rem;
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.quantity {
|
||||
gap: .25rem;
|
||||
display: flex;
|
||||
font-size: 1.25rem;
|
||||
align-items: baseline;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:global(html.theme-dark) .recycle-payment-list {
|
||||
.type {
|
||||
&.receive { color: #86efac; }
|
||||
&.revoke { color: #c4b5fd; }
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,224 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar recycle-payment-revoke">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="回收冲正"
|
||||
left-arrow
|
||||
@left-click="exit"
|
||||
>
|
||||
<template #right>
|
||||
<t-button
|
||||
v-if="canRevoke"
|
||||
theme="danger"
|
||||
variant="text"
|
||||
size="small"
|
||||
content="提交"
|
||||
:loading="saving"
|
||||
:disabled="saving || !payment"
|
||||
@click="save"
|
||||
/>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main v-can="permissionCodes.fund.revoke" class="tui-page-content scroll column">
|
||||
<t-cell-group
|
||||
v-if="payment"
|
||||
title="原回收记录"
|
||||
theme="card"
|
||||
v-entrance-transition
|
||||
>
|
||||
<t-cell title="回收物" :note="exchange?.recycleNameSnapshot || '-'" />
|
||||
<t-cell title="数量">
|
||||
<span class="red" v-text="paymentText" />
|
||||
</t-cell>
|
||||
<t-cell title="原状态" :note="getRecyclePaymentStatusText(payment.status)" />
|
||||
<t-cell
|
||||
title="发起人"
|
||||
:note="payment.operator?.nick || payment.operator?.name || '未知'"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<t-form
|
||||
v-if="payment"
|
||||
class="form card"
|
||||
label-width="7.5rem"
|
||||
v-entrance-transition
|
||||
>
|
||||
<t-form-item label="冲正原因" required-mark>
|
||||
<div class="reason">
|
||||
<t-textarea v-model="reason" borderless autosize maxlength="500" placeholder="请输入或选择冲正原因" />
|
||||
<t-button size="extra-small" theme="primary" variant="outline" @click="openReasonPicker">选择</t-button>
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label="冲正时间" content-align="right">
|
||||
<date-time-now-picker v-model="occurredAtText" title="冲正时间" />
|
||||
</t-form-item>
|
||||
<t-form-item label="实物已退还" required-mark content-align="right">
|
||||
<t-switch v-model="returnedToCustomer" size="small" />
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<span class="red">冲正会返还客户额度,并生成冲正记录</span>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<attachment-selector
|
||||
v-model:items="photoItems"
|
||||
:upload="uploadPhotoList"
|
||||
required
|
||||
title="退还凭证照片"
|
||||
/>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<center-tips v-else :content="loading ? '正在加载回收记录' : '回收记录不存在'" />
|
||||
<t-popup v-model="reasonPickerVisible" placement="bottom">
|
||||
<t-picker v-if="reasonPickerVisible" v-model="reasonPickerDraft" :columns="reasonPickerColumns" title="选择冲正原因" @cancel="reasonPickerVisible = false" @confirm="confirmReason" />
|
||||
</t-popup>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { usePane } from "timi-tdesign-mobile";
|
||||
import { Time } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import DateTimeNowPicker from "@/components/DateTimeNowPicker.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { RecycleExchange, RecyclePayment } from "@/types/Recycle";
|
||||
import { parseDateTime } from "@/utils/date";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { uploadPhotoList } from "@/utils/photo";
|
||||
import { getRecyclePaymentStatusText, getRecycleQuantityText, isPaymentVerified } from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecyclePaymentRevoke" });
|
||||
const props = withDefaults(defineProps<{ exchangeId?: string; paymentId?: string }>(), {
|
||||
exchangeId: "",
|
||||
paymentId: ""
|
||||
});
|
||||
const emit = defineEmits<{ changed: [] }>();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const pane = usePane();
|
||||
const userStore = useUserStore();
|
||||
const exchangeId = computed(() => props.exchangeId || String(route.params.id || ""));
|
||||
const paymentId = computed(() => props.paymentId || String(route.params.paymentId || ""));
|
||||
const exchange = ref<RecycleExchange>();
|
||||
const payment = ref<RecyclePayment>();
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const reason = ref("");
|
||||
const reasonPickerVisible = ref(false);
|
||||
const reasonPickerDraft = ref<string[]>([]);
|
||||
const reasonOptions = ["客户申请退还回收物", "回收数量填写有误", "回收物类型选择有误", "回收登记重复", "回收登记有误", "订单信息有误"];
|
||||
const reasonPickerColumns = reasonOptions.map(item => ({ label: item, value: item }));
|
||||
const occurredAtText = ref("");
|
||||
const returnedToCustomer = ref(false);
|
||||
const photoItems = ref<PhotoItem[]>([]);
|
||||
const requestNo = ref("");
|
||||
const canRevoke = computed(() => userStore.hasPermissions(permissionCodes.fund.revoke));
|
||||
const paymentText = computed(() => getRecycleQuantityText(payment.value?.quantity, exchange.value?.recycleUnitSnapshot));
|
||||
|
||||
function openReasonPicker(): void {
|
||||
reasonPickerDraft.value = [reasonOptions.includes(reason.value.trim()) ? reason.value.trim() : reasonOptions[0]];
|
||||
reasonPickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmReason(value: Array<string | number>): void {
|
||||
reason.value = String(value[0] || reasonPickerDraft.value[0] || "");
|
||||
reasonPickerVisible.value = false;
|
||||
}
|
||||
|
||||
function exit(): void {
|
||||
if (props.exchangeId && pane) {
|
||||
if (0 < Number(window.history.state?.paneLevel || 0)) pane.close();
|
||||
else pane.openSub(`recycle-payment-detail:${exchangeId.value}:${paymentId.value}`);
|
||||
return;
|
||||
}
|
||||
router.back();
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
if (!exchangeId.value || !paymentId.value) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await RecycleAPI.detail(exchangeId.value);
|
||||
exchange.value = result.exchange;
|
||||
const payments = exchange.value?.salesOrderId ? await RecycleAPI.paymentList(exchange.value.salesOrderId) : [];
|
||||
payment.value = payments.find(item => item.id === paymentId.value);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收记录加载失败"));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function save(): Promise<void> {
|
||||
if (saving.value || !canRevoke.value) return;
|
||||
if (!payment.value?.id || !isPaymentVerified(payment.value)) {
|
||||
Message.warning("只有已核销且未冲正的回收记录可以冲正");
|
||||
return;
|
||||
}
|
||||
if (!reason.value.trim()) {
|
||||
Message.warning("请输入冲正原因");
|
||||
return;
|
||||
}
|
||||
if (!returnedToCustomer.value) {
|
||||
Message.warning("请确认回收物已退还客户");
|
||||
return;
|
||||
}
|
||||
const attachmentList = photoItems.value.flatMap(item => item.tempFileId ? [
|
||||
{
|
||||
tempFileId: item.tempFileId,
|
||||
attachType: "PHOTO"
|
||||
}
|
||||
] : []);
|
||||
if (!attachmentList.length) {
|
||||
Message.warning("冲正必须上传退还凭证照片");
|
||||
return;
|
||||
}
|
||||
if (!requestNo.value) requestNo.value = window.crypto.randomUUID();
|
||||
saving.value = true;
|
||||
try {
|
||||
await RecycleAPI.paymentRevoke({
|
||||
paymentId: payment.value.id,
|
||||
requestNo: requestNo.value,
|
||||
reason: reason.value.trim(),
|
||||
occurredAt: occurredAtText.value ? Time.toTimestamp(parseDateTime(occurredAtText.value, false)) : undefined,
|
||||
returnedToCustomer: returnedToCustomer.value,
|
||||
attachmentList
|
||||
});
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, exchange.value?.salesOrderId);
|
||||
emit("changed");
|
||||
Message.success("回收物已冲正,额度已返还");
|
||||
exit();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收冲正失败,重试会复用同一请求号"));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch([reason, occurredAtText, returnedToCustomer, photoItems], () => {
|
||||
requestNo.value = "";
|
||||
}, { deep: true });
|
||||
onMounted(load);
|
||||
watch([exchangeId, paymentId], load);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-payment-revoke {
|
||||
.reason {
|
||||
gap: .5rem;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
|
||||
.t-textarea {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,180 @@
|
||||
<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>
|
||||
@@ -3,7 +3,7 @@
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
:title="isCreate ? '新增兑换规则' : '编辑兑换规则'"
|
||||
:title="isCreate ? '新增兑换模板' : '编辑兑换模板'"
|
||||
left-arrow
|
||||
@left-click="exit()"
|
||||
>
|
||||
@@ -20,108 +20,88 @@
|
||||
</t-navbar>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div v-can="permissionCodes.recycleExchange.configManage" class="recycle-rule-edit">
|
||||
<t-form class="form card" label-width="7.5rem" v-entrance-transition>
|
||||
<t-form-item label="回收物" required-mark content-align="right" arrow @click="openItemPicker">
|
||||
<span class="clip-text" v-text="recycleItemName || '请选择回收物'" />
|
||||
<t-form class="form card" label-width="7rem" v-entrance-transition>
|
||||
<t-form-item label="回收物" required-mark arrow content-align="right" @click="itemPickerVisible = true">
|
||||
<span v-text="recycleItemName || '请选择'" />
|
||||
</t-form-item>
|
||||
<t-form-item label="单份回收数量" required-mark>
|
||||
<t-input
|
||||
v-model.trim="form.recycleQuantity"
|
||||
type="number"
|
||||
align="right"
|
||||
borderless
|
||||
:placeholder="`按${recycleUnitName || '回收单位'}填写`"
|
||||
/>
|
||||
<div class="quantity">
|
||||
<t-input
|
||||
v-model.trim="recycleQuantityText"
|
||||
type="number"
|
||||
align="right"
|
||||
borderless
|
||||
:placeholder="`按${recycleUnitName || '回收单位'}填写`"
|
||||
/>
|
||||
<span class="unit" v-text="recycleUnitName" />
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label="兑换产品" required-mark content-align="right" arrow @click="productPopupVisible = true">
|
||||
<span class="clip-text" v-text="productDisplayName || '请选择兑换产品'" />
|
||||
<t-form-item v-if="itemRows.length" class="detail" label-width="0">
|
||||
<t-form class="items" label-width="0">
|
||||
<t-form-item v-for="(row, index) in itemRows" :key="row.key" class="item">
|
||||
<div class="item-content">
|
||||
<div class="photo">
|
||||
<t-image v-if="row.sku && getProductPhotoURL(row.sku)" :src="getProductPhotoURL(row.sku)" :alt="row.productName || '产品图片'" fit="cover" class="avatar" />
|
||||
<div v-else class="avatar fallback" v-text="(row.productName || '产').slice(0, 1)" />
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="head">
|
||||
<div class="title">
|
||||
<strong class="name clip-text" v-text="row.productName || '未命名产品'" />
|
||||
<product-sku-tags :product-name="row.productName" :fallback="row.skuText" />
|
||||
</div>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
theme="danger"
|
||||
variant="text"
|
||||
content="移除"
|
||||
@click="removeItem(index)"
|
||||
/>
|
||||
</div>
|
||||
<div class="quantity">
|
||||
<t-stepper
|
||||
:model-value="Number(row.exchangeQuantityText) || 0"
|
||||
size="large"
|
||||
theme="outline"
|
||||
:min="0"
|
||||
:max="Number.MAX_SAFE_INTEGER"
|
||||
:step="getProductQuantityStep({ allowDecimalQuantity: row.allowDecimalQuantity })"
|
||||
:integer="!row.allowDecimalQuantity"
|
||||
@update:model-value="row.exchangeQuantityText = String($event)"
|
||||
/>
|
||||
<t-tag :content="row.unitName || '单位'" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-form-item>
|
||||
<t-form-item v-if="skuDisplayText || unitDisplayText" label="产品 SKU" content-align="right">
|
||||
<product-sku-tags :fallback="skuDisplayText" :unit="unitDisplayText" />
|
||||
<t-form-item arrow content-align="right" @click="openProductPicker">
|
||||
<span>添加商品</span>
|
||||
</t-form-item>
|
||||
<t-form-item label="单份兑换数量" required-mark>
|
||||
<t-input
|
||||
v-model.trim="form.exchangeQuantity"
|
||||
type="number"
|
||||
align="right"
|
||||
borderless
|
||||
:placeholder="`按${unitDisplayText || '业务单位'}填写`"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<span class="tips" v-text="ratioTipText" />
|
||||
</t-form-item>
|
||||
<t-form-item label="规则状态" content-align="right" arrow @click="statusVisible = true">
|
||||
<span v-text="getRecycleStatusText(form.status)" />
|
||||
</t-form-item>
|
||||
<t-form-item label="排序值">
|
||||
<t-input
|
||||
v-model.trim="form.sortText"
|
||||
type="number"
|
||||
align="right"
|
||||
borderless
|
||||
placeholder="默认 0,越小越靠前"
|
||||
/>
|
||||
<t-form-item label="状态" content-align="right">
|
||||
<t-switch v-model="form.status" size="small" :custom-value="['ACTIVE', 'INACTIVE']" />
|
||||
</t-form-item>
|
||||
<t-form-item label="备注">
|
||||
<t-textarea v-model.trim="form.remark" borderless autosize maxlength="500" placeholder="可不填" />
|
||||
<t-textarea v-model="form.remark" borderless autosize maxlength="500" placeholder="选填" />
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<span class="tips" v-text="footerTipText" />
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<span class="tips footer-tips" v-text="footerTipText" />
|
||||
<t-button
|
||||
v-if="!isCreate"
|
||||
class="cell-button"
|
||||
theme="default"
|
||||
v-entrance-transition
|
||||
:content="form.status === 'ACTIVE' ? '停用规则' : '启用规则'"
|
||||
@click="toggleStatus"
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
<bottom-popup
|
||||
v-model="itemPickerVisible"
|
||||
title="选择回收物"
|
||||
height="60vh"
|
||||
right-button-text=""
|
||||
@left-button-click="itemPickerVisible = false"
|
||||
>
|
||||
<div class="item-picker">
|
||||
<t-cell
|
||||
v-for="item in itemList"
|
||||
:key="item.id"
|
||||
class="item"
|
||||
:class="{ active: item.id === form.recycleItemId }"
|
||||
@click="selectItem(item)"
|
||||
>
|
||||
<template #left-icon>
|
||||
<div class="avatar fallback" v-text="(item.name || '回').slice(0, 1)" />
|
||||
</template>
|
||||
<template #title>
|
||||
<span class="clip-text" v-text="item.name || '未命名回收物'" />
|
||||
</template>
|
||||
<template #note>
|
||||
<t-tag
|
||||
size="small"
|
||||
:theme="getRecycleStatusTheme(item.status)"
|
||||
:content="getRecycleStatusText(item.status)"
|
||||
/>
|
||||
</template>
|
||||
<template #description>
|
||||
<span v-text="`按${item.unitName || '单位'}计量`" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<center-tips v-if="!itemList.length" :content="itemLoading ? '正在加载回收物' : '暂无回收物,请先配置回收物'" />
|
||||
</div>
|
||||
</bottom-popup>
|
||||
<t-popup v-model="statusVisible" placement="bottom">
|
||||
<t-picker
|
||||
v-model="statusDraft"
|
||||
:columns="statusOptions"
|
||||
title="规则状态"
|
||||
@cancel="statusVisible = false"
|
||||
@confirm="confirmStatus"
|
||||
/>
|
||||
</t-popup>
|
||||
<recycle-item-picker-popup
|
||||
v-model:visible="itemPickerVisible"
|
||||
:items="itemList"
|
||||
:loading="itemLoading"
|
||||
:selected-id="form.recycleItemId"
|
||||
empty-text="暂无回收物,可点击右上角新建"
|
||||
manage
|
||||
show-status
|
||||
@select="selectItem"
|
||||
@saved="reloadItems"
|
||||
/>
|
||||
<product-select-popup
|
||||
v-model="selection"
|
||||
v-model:visible="productPopupVisible"
|
||||
@@ -131,18 +111,20 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup, useExpandToMaster, usePane } from "timi-tdesign-mobile";
|
||||
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import ProductSelectPopup from "@/components/productSelector/ProductSelectPopup.vue";
|
||||
import ProductSkuTags from "@/components/ProductSkuTags.vue";
|
||||
import type { ProductSelection } from "@/types/Product";
|
||||
import ProductSelectPopup from "@/components/productSelector/ProductSelectPopup.vue";
|
||||
import RecycleItemPickerPopup from "@/pages/recycle/components/RecycleItemPickerPopup.vue";
|
||||
import type { ProductSelection, ProductSku } from "@/types/Product";
|
||||
import type { ProductSkuSelectionValue } from "@/types/ProductSkuSelection";
|
||||
import type { RecycleItem, RecycleStatus } from "@/types/Recycle";
|
||||
import type { RecycleExchangeRule, RecycleItem, RecycleRuleItem, RecycleStatus } from "@/types/Recycle";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { normalizePackageQuantity } from "@/utils/package";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getRecycleQuantityText, getRecycleStatusText, getRecycleStatusTheme } from "@/utils/recycle";
|
||||
import { getProductPhotoURL, getProductQuantityStep, getProductSkuSnapshotText } from "@/utils/product";
|
||||
|
||||
defineOptions({ name: "RecycleRuleEdit" });
|
||||
|
||||
@@ -162,8 +144,9 @@ const currentId = computed(() => props.ruleId || String(route.params.id || ""));
|
||||
const isCreate = computed(() => !currentId.value);
|
||||
|
||||
useExpandToMaster({
|
||||
path: "/management/recycle-rules",
|
||||
id: () => currentId.value
|
||||
path: "/product/recycle-rules",
|
||||
id: () => currentId.value || "__create__",
|
||||
query: currentId.value ? { view: "edit" } : {}
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
const pane = usePane();
|
||||
@@ -182,61 +165,116 @@ function exit(saved = false): void {
|
||||
const form = reactive({
|
||||
id: "",
|
||||
recycleItemId: "",
|
||||
recycleQuantity: "",
|
||||
exchangeQuantity: "",
|
||||
status: "ACTIVE" as RecycleStatus,
|
||||
sortText: "",
|
||||
sort: undefined as number | undefined,
|
||||
remark: ""
|
||||
});
|
||||
const recycleQuantityText = ref("");
|
||||
const selection = ref<ProductSkuSelectionValue>();
|
||||
const picked = ref<ProductSelection>();
|
||||
const productPopupVisible = ref(false);
|
||||
// 规则详情自带产品与单位名称,未改选前直接用它展示,不必再查产品库
|
||||
const ruleSnapshot = reactive({ productName: "", skuText: "", unitName: "" });
|
||||
const itemPickerVisible = ref(false);
|
||||
const itemList = ref<RecycleItem[]>([]);
|
||||
const itemLoading = ref(false);
|
||||
const selectedItem = ref<RecycleItem>();
|
||||
const statusVisible = ref(false);
|
||||
const statusDraft = ref<Array<string | number>>(["ACTIVE"]);
|
||||
const saving = ref(false);
|
||||
const statusOptions = [
|
||||
{ label: "启用", value: "ACTIVE" },
|
||||
{ label: "停用", value: "INACTIVE" }
|
||||
];
|
||||
const recycleItemName = computed(() => selectedItem.value?.name || "");
|
||||
const recycleUnitName = computed(() => selectedItem.value?.unitName || "");
|
||||
const productDisplayName = computed(() => picked.value?.product?.name || ruleSnapshot.productName);
|
||||
const skuDisplayText = computed(() => {
|
||||
const sku = picked.value?.sku;
|
||||
return sku ? sku.specSummary?.trim() || sku.name?.trim() || "" : ruleSnapshot.skuText;
|
||||
});
|
||||
const unitDisplayText = computed(() => picked.value?.unit?.name || ruleSnapshot.unitName);
|
||||
const ratioTipText = computed(() => {
|
||||
const recycleText = getRecycleQuantityText(form.recycleQuantity || "0", recycleUnitName.value);
|
||||
const exchangeText = getRecycleQuantityText(form.exchangeQuantity || "0", unitDisplayText.value);
|
||||
return `创建兑换单时按倍数放大:预设 ${recycleText} 兑换 ${exchangeText}。数量最多 3 位小数。`;
|
||||
});
|
||||
const footerTipText = "启用规则要求回收物、产品和 SKU 均已启用,且所选业务单位允许销售。规则停用不影响已创建的兑换单。";
|
||||
const footerTipText = "启用模板要求回收物、产品和 SKU 均已启用,且所选业务单位允许销售。模板只是开单快捷配置,修改或删除都不影响已创建的兑换单。";
|
||||
|
||||
function openItemPicker(): void {
|
||||
itemPickerVisible.value = true;
|
||||
// ---------- 商品明细 ----------
|
||||
|
||||
/** 明细行的编辑态。key 用于 v-for 稳定,不提交给服务端。 */
|
||||
type ItemRow = {
|
||||
key: number;
|
||||
skuId: string;
|
||||
skuUnitId: string;
|
||||
productName: string;
|
||||
skuText: string;
|
||||
unitName: string;
|
||||
sku?: ProductSku;
|
||||
allowDecimalQuantity: boolean;
|
||||
exchangeQuantityText: string;
|
||||
};
|
||||
const itemRows = ref<ItemRow[]>([]);
|
||||
let rowSeed = 0;
|
||||
|
||||
function createRow(source: Partial<RecycleRuleItem> & { productName?: string | null; unitName?: string | null }): ItemRow {
|
||||
rowSeed += 1;
|
||||
return {
|
||||
key: rowSeed,
|
||||
skuId: source.skuId || "",
|
||||
skuUnitId: source.skuUnitId || "",
|
||||
productName: source.productName || "",
|
||||
skuText: getProductSkuSnapshotText(source.productName, source.skuName, source.specSummary),
|
||||
unitName: source.unitName || "",
|
||||
allowDecimalQuantity: source.allowDecimalQuantity ?? false,
|
||||
exchangeQuantityText: source.exchangeQuantity === undefined || source.exchangeQuantity === null ? "" : String(source.exchangeQuantity)
|
||||
};
|
||||
}
|
||||
|
||||
/** 同款 SKU 换单位是允许的,只有「同 SKU + 同单位」才算重复。 */
|
||||
function isDuplicate(skuId: string, skuUnitId: string, ignoreIndex = -1): boolean {
|
||||
return itemRows.value.some((row, index) => index !== ignoreIndex && row.skuId === skuId && row.skuUnitId === skuUnitId);
|
||||
}
|
||||
|
||||
function openProductPicker(): void {
|
||||
productPopupVisible.value = true;
|
||||
}
|
||||
|
||||
function handleProductSelection(value: ProductSelection): void {
|
||||
const skuId = value.sku.id || "";
|
||||
const skuUnitId = value.unit.id || "";
|
||||
if (isDuplicate(skuId, skuUnitId)) {
|
||||
Message.warning("该商品的这个单位已在模板中");
|
||||
return;
|
||||
}
|
||||
const row = createRow({
|
||||
skuId,
|
||||
skuUnitId,
|
||||
productName: value.product.name,
|
||||
skuName: value.sku.name,
|
||||
specSummary: value.sku.specSummary,
|
||||
unitName: value.unit.name,
|
||||
allowDecimalQuantity: value.sku.allowDecimalQuantity,
|
||||
exchangeQuantity: ""
|
||||
});
|
||||
row.sku = value.sku;
|
||||
itemRows.value.push(row);
|
||||
}
|
||||
|
||||
function removeItem(index: number): void {
|
||||
itemRows.value.splice(index, 1);
|
||||
}
|
||||
|
||||
/** 补充详情接口未返回的 SKU 图片,同一 SKU 只请求一次。 */
|
||||
async function loadRowSkus(rows: ItemRow[]): Promise<void> {
|
||||
const ids = [...new Set(rows.map(row => row.skuId).filter(Boolean))];
|
||||
const results = await Promise.allSettled(ids.map(async id => await ProductAPI.skuDetail(id)));
|
||||
results.forEach((result, index) => {
|
||||
if (result.status !== "fulfilled") {
|
||||
return;
|
||||
}
|
||||
for (const row of rows) {
|
||||
if (row.skuId === ids[index]) {
|
||||
row.sku = result.value;
|
||||
row.allowDecimalQuantity = result.value.allowDecimalQuantity;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- 回收物 ----------
|
||||
|
||||
function selectItem(item: RecycleItem): void {
|
||||
form.recycleItemId = item.id || "";
|
||||
selectedItem.value = item;
|
||||
itemPickerVisible.value = false;
|
||||
}
|
||||
|
||||
function handleProductSelection(value: ProductSelection): void {
|
||||
picked.value = value;
|
||||
selection.value = { skuId: value.sku.id || "", skuUnitId: value.unit.id || "" };
|
||||
}
|
||||
|
||||
function confirmStatus(value: Array<string | number>): void {
|
||||
form.status = String(value[0]) as RecycleStatus;
|
||||
statusVisible.value = false;
|
||||
/** 回收物新建或改名后重新取列表,已选中的回收物同步最新名称 */
|
||||
async function reloadItems(): Promise<void> {
|
||||
await loadItems();
|
||||
selectedItem.value = itemList.value.find(item => item.id === form.recycleItemId);
|
||||
}
|
||||
|
||||
// ---------- 数据 ----------
|
||||
@@ -265,6 +303,17 @@ async function loadItems(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
function applyRule(rule: RecycleExchangeRule): void {
|
||||
form.id = rule.id || "";
|
||||
form.recycleItemId = rule.recycleItemId || "";
|
||||
recycleQuantityText.value = String(rule.recycleQuantity ?? "");
|
||||
form.status = rule.status || "ACTIVE";
|
||||
form.sort = rule.sort ?? undefined;
|
||||
form.remark = rule.remark || "";
|
||||
selectedItem.value = itemList.value.find(item => item.id === rule.recycleItemId);
|
||||
itemRows.value = (rule.itemList || []).map(source => createRow(source));
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
const id = currentId.value;
|
||||
try {
|
||||
@@ -272,129 +321,165 @@ async function load(): Promise<void> {
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
const rule = await RecycleAPI.ruleDetail(id);
|
||||
form.id = rule.id || "";
|
||||
form.recycleItemId = rule.recycleItemId || "";
|
||||
form.recycleQuantity = String(rule.recycleQuantity ?? "");
|
||||
form.exchangeQuantity = String(rule.exchangeQuantity ?? "");
|
||||
form.status = rule.status || "ACTIVE";
|
||||
form.sortText = rule.sort === null || rule.sort === undefined ? "" : String(rule.sort);
|
||||
form.remark = rule.remark || "";
|
||||
selectedItem.value = itemList.value.find(item => item.id === rule.recycleItemId);
|
||||
selection.value = { skuId: rule.skuId, skuUnitId: rule.skuUnitId };
|
||||
ruleSnapshot.productName = rule.productName || "";
|
||||
ruleSnapshot.skuText = rule.specSummary?.trim() || rule.skuName?.trim() || "";
|
||||
ruleSnapshot.unitName = rule.unitName || "";
|
||||
applyRule(await RecycleAPI.ruleDetail(id));
|
||||
await loadRowSkus(itemRows.value);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换规则加载失败"));
|
||||
Message.error(getErrorMessage(error, "兑换模板加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 保存 ----------
|
||||
|
||||
async function save(status?: RecycleStatus): Promise<void> {
|
||||
const recycleQuantity = normalizePackageQuantity(form.recycleQuantity);
|
||||
const exchangeQuantity = normalizePackageQuantity(form.exchangeQuantity);
|
||||
const skuId = selection.value?.skuId;
|
||||
const skuUnitId = selection.value?.skuUnitId;
|
||||
async function save(): Promise<void> {
|
||||
if (saving.value) {
|
||||
return;
|
||||
}
|
||||
if (!form.recycleItemId || !skuId || !skuUnitId) {
|
||||
Message.warning("请选择回收物和兑换产品业务单位");
|
||||
const recycleQuantity = normalizePackageQuantity(recycleQuantityText.value);
|
||||
if (!form.recycleItemId) {
|
||||
Message.warning("请选择回收物");
|
||||
return;
|
||||
}
|
||||
if (!recycleQuantity || !exchangeQuantity || recycleQuantity === "0" || exchangeQuantity === "0") {
|
||||
Message.warning("单份回收数量和兑换数量必须为大于 0 的数字,最多 3 位小数");
|
||||
if (!recycleQuantity || recycleQuantity === "0") {
|
||||
Message.warning("单份回收数量必须为大于 0 的数字,最多 3 位小数");
|
||||
return;
|
||||
}
|
||||
const sort = form.sortText ? Number(form.sortText) : 0;
|
||||
if (!Number.isSafeInteger(sort)) {
|
||||
Message.warning("排序值必须为整数");
|
||||
if (!itemRows.value.length) {
|
||||
Message.warning("请至少添加一个兑换商品");
|
||||
return;
|
||||
}
|
||||
const itemList: RecycleRuleItem[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const row of itemRows.value) {
|
||||
const quantity = normalizePackageQuantity(row.exchangeQuantityText);
|
||||
if (!row.skuId || !row.skuUnitId || !quantity || quantity === "0") {
|
||||
Message.warning(`请填写「${row.productName || "未命名产品"}」的兑换数量`);
|
||||
return;
|
||||
}
|
||||
const uniqueKey = `${row.skuId}|${row.skuUnitId}`;
|
||||
if (seen.has(uniqueKey)) {
|
||||
Message.warning("同一商品和单位不能重复");
|
||||
return;
|
||||
}
|
||||
seen.add(uniqueKey);
|
||||
itemList.push({ skuId: row.skuId, skuUnitId: row.skuUnitId, exchangeQuantity: quantity });
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
await RecycleAPI.ruleSave({
|
||||
id: form.id || undefined,
|
||||
recycleItemId: form.recycleItemId,
|
||||
recycleQuantity,
|
||||
skuId,
|
||||
skuUnitId,
|
||||
exchangeQuantity,
|
||||
status: status || form.status,
|
||||
sort,
|
||||
itemList,
|
||||
status: form.status,
|
||||
sort: form.sort,
|
||||
remark: form.remark || null
|
||||
});
|
||||
Message.success("兑换规则已保存");
|
||||
form.status = status || form.status;
|
||||
Message.success("兑换模板已保存");
|
||||
emit("saved");
|
||||
exit(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换规则保存失败"));
|
||||
Message.error(getErrorMessage(error, "兑换模板保存失败"));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleStatus(): Promise<void> {
|
||||
await save(form.status === "ACTIVE" ? "INACTIVE" : "ACTIVE");
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
watch(() => [props.ruleId, route.params.id], load);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-rule-edit {
|
||||
gap: 1rem;
|
||||
display: flex;
|
||||
padding: 0 0 2rem;
|
||||
flex-direction: column;
|
||||
|
||||
.form {
|
||||
|
||||
.quantity {
|
||||
gap: .5rem;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
|
||||
.t-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.unit {
|
||||
color: var(--td-text-color-secondary);
|
||||
flex: 0 0 auto;
|
||||
font-size: .875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.detail {
|
||||
padding: 0;
|
||||
|
||||
.items {
|
||||
--td-button-extra-small-height: 24px;
|
||||
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
|
||||
.item-content {
|
||||
gap: .5rem;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.photo .avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.quantity {
|
||||
justify-content: end;
|
||||
}
|
||||
|
||||
.head {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.title {
|
||||
gap: .25rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
align-items: center;
|
||||
|
||||
.name {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
:deep(.tags) {
|
||||
flex: 0 0 auto;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
.tips {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .8125rem;
|
||||
font-size: .875rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-tips {
|
||||
padding: 0 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.item-picker {
|
||||
|
||||
.item {
|
||||
padding: .75rem 1rem;
|
||||
border-radius: 1rem;
|
||||
|
||||
&.active {
|
||||
background: var(--td-brand-color-1, rgba(0, 82, 217, .08));
|
||||
}
|
||||
|
||||
.avatar {
|
||||
font-size: 1rem;
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:global(html.theme-dark) {
|
||||
.item-picker {
|
||||
|
||||
.item.active {
|
||||
background: rgba(15, 118, 110, .22);
|
||||
}
|
||||
|
||||
.fallback {
|
||||
color: #ccfbf1;
|
||||
background: #115e59;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="兑换规则"
|
||||
title="兑换模板"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
@@ -36,58 +36,85 @@
|
||||
placeholder="搜索回收物或兑换产品"
|
||||
/>
|
||||
</div>
|
||||
<t-cell-group v-if="list.length" theme="card">
|
||||
<t-cell
|
||||
<t-cell-group
|
||||
v-if="list.length"
|
||||
class="fix-last-cell-line"
|
||||
theme="card"
|
||||
>
|
||||
<t-swipe-cell
|
||||
class="item"
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
class="item"
|
||||
:arrow="!!item.id"
|
||||
v-entrance-transition="{ step: 30 }"
|
||||
@click="toEdit(item)"
|
||||
>
|
||||
<template #left-icon>
|
||||
<div class="avatar fallback" v-text="(getRecycleItemName(item) || '规').slice(0, 1)" />
|
||||
<t-cell
|
||||
class="cell"
|
||||
:arrow="!!item.id"
|
||||
@click="toEdit(item)"
|
||||
>
|
||||
<template #left-icon>
|
||||
<div class="avatar fallback" v-text="(getRecycleItemName(item) || '模').slice(0, 1)" />
|
||||
</template>
|
||||
<template #title>
|
||||
<span class="clip-text" v-text="getRecycleItemName(item) || '未命名回收物'" />
|
||||
</template>
|
||||
<template #note>
|
||||
<span class="ratio" v-text="getRatioText(item)" />
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<t-tag
|
||||
size="small"
|
||||
:theme="getRecycleStatusTheme(item.status)"
|
||||
:content="getRecycleStatusText(item.status)"
|
||||
/>
|
||||
<span class="clip-text" v-text="getExchangeText(item)" />
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
<template #right>
|
||||
<t-button
|
||||
class="swipe-cell-button"
|
||||
theme="danger"
|
||||
:loading="deletingId === item.id"
|
||||
@click.stop="confirmDelete(item)"
|
||||
>
|
||||
删除
|
||||
</t-button>
|
||||
</template>
|
||||
<template #title>
|
||||
<span class="clip-text" v-text="getRecycleItemName(item) || '未命名回收物'" />
|
||||
</template>
|
||||
<template #note>
|
||||
<span class="ratio" v-text="getRatioText(item)" />
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<span class="clip-text" v-text="getExchangeText(item)" />
|
||||
<t-tag
|
||||
size="small"
|
||||
:theme="getRecycleStatusTheme(item.status)"
|
||||
:content="getRecycleStatusText(item.status)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-swipe-cell>
|
||||
</t-cell-group>
|
||||
<center-tips v-else :content="loading ? '正在加载兑换规则' : '暂无兑换规则'" />
|
||||
<center-tips :content="loading ? '正在加载' : noMore ? `共 ${total} 条规则` : '上拉加载更多'" />
|
||||
<center-tips v-else :content="loading ? '正在加载兑换模板' : '暂无兑换模板'" />
|
||||
<center-tips :content="loading ? '正在加载' : noMore ? `共 ${total} 条模板` : '上拉加载更多'" />
|
||||
</t-pull-down-refresh>
|
||||
</template>
|
||||
<template #detail>
|
||||
<recycle-rule-edit
|
||||
:key="`rule-${selectedId}`"
|
||||
:rule-id="selectedId"
|
||||
v-if="selectedId === createPaneId || editing"
|
||||
:key="`edit-${selectedId}`"
|
||||
:rule-id="selectedId === createPaneId ? '' : selectedId"
|
||||
@saved="reload"
|
||||
/>
|
||||
<recycle-rule-detail
|
||||
v-else
|
||||
:key="`detail-${selectedId}-${detailVersion}`"
|
||||
:rule-id="selectedId"
|
||||
@edit="openEdit"
|
||||
/>
|
||||
</template>
|
||||
</master-detail-page>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import { Toolkit } from "timi-web";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import RecycleRuleDetail from "@/pages/recycle/RecycleRuleDetail.vue";
|
||||
import RecycleRuleEdit from "@/pages/recycle/RecycleRuleEdit.vue";
|
||||
import type { NavbarAction } from "@/types/NavbarAction";
|
||||
import type { RecycleExchangeRule } from "@/types/Recycle";
|
||||
import type { RecycleExchangeRule, RecycleRuleItem } from "@/types/Recycle";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
@@ -97,25 +124,20 @@ defineOptions({ name: "RecycleRuleList" });
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const { selectedId, isWide, paneDirection, openDetail } = useMasterDetailPane({
|
||||
path: "/management/recycle-rules",
|
||||
detail: id => `/management/recycle-rules/${id}`
|
||||
const createPaneId = "__create__";
|
||||
const { selectedId, editing, detailVersion, isWide, paneDirection, openDetail, openEdit } = useMasterDetailPane({
|
||||
path: "/product/recycle-rules",
|
||||
detail: id => id === createPaneId ? "/product/recycle-rules/create" : `/product/recycle-rules/${id}`,
|
||||
edit: id => `/product/recycle-rules/${id}/edit`
|
||||
});
|
||||
|
||||
const actions = computed<NavbarAction[]>(() => [
|
||||
{
|
||||
key: "create",
|
||||
text: "新增规则",
|
||||
text: "新增模板",
|
||||
icon: "add",
|
||||
theme: "primary",
|
||||
action: toCreate
|
||||
},
|
||||
{
|
||||
key: "items",
|
||||
text: "回收物配置",
|
||||
icon: "catalog",
|
||||
theme: "primary",
|
||||
action: toItemList
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -130,24 +152,29 @@ const refreshing = ref(false);
|
||||
const noMore = ref(false);
|
||||
const pageSize = 20;
|
||||
|
||||
/** 回收物、产品、SKU 与单位名称由服务端随规则返回,无需再跨域回查。 */
|
||||
/** 回收物、产品、SKU 与单位名称由服务端随模板返回,无需再跨域回查。 */
|
||||
function getRecycleItemName(rule: RecycleExchangeRule): string {
|
||||
return rule.recycleName || "";
|
||||
}
|
||||
|
||||
function getRatioText(rule: RecycleExchangeRule): string {
|
||||
const recycleText = getRecycleQuantityText(rule.recycleQuantity, rule.recycleUnit);
|
||||
const exchangeText = getRecycleQuantityText(rule.exchangeQuantity, rule.unitName);
|
||||
return `${recycleText} → ${exchangeText}`;
|
||||
function getRuleItemList(rule: RecycleExchangeRule): RecycleRuleItem[] {
|
||||
return rule.itemList || [];
|
||||
}
|
||||
|
||||
function getRatioText(rule: RecycleExchangeRule): string {
|
||||
const recycleText = getRecycleQuantityText(rule.recycleQuantity, rule.recycleUnit);
|
||||
return `${recycleText} 换 ${getRuleItemList(rule).length} 项`;
|
||||
}
|
||||
|
||||
/** 列表只列前两项商品,其余用「等 N 项」收口,避免行高被撑开。 */
|
||||
function getExchangeText(rule: RecycleExchangeRule): string {
|
||||
const productName = rule.productName || "";
|
||||
const skuText = rule.specSummary || rule.skuName || "";
|
||||
if (!productName) {
|
||||
return skuText;
|
||||
const itemList = getRuleItemList(rule);
|
||||
if (!itemList.length) {
|
||||
return "未配置商品";
|
||||
}
|
||||
return skuText && skuText !== productName ? `${productName}(${skuText})` : productName;
|
||||
const names = itemList.slice(0, 2).map(item => item.productName || item.skuName || "未命名产品");
|
||||
const suffix = 2 < itemList.length ? ` 等 ${itemList.length} 项` : "";
|
||||
return names.join("、") + suffix;
|
||||
}
|
||||
|
||||
async function fetchList(reset: boolean): Promise<void> {
|
||||
@@ -158,7 +185,6 @@ async function fetchList(reset: boolean): Promise<void> {
|
||||
pageIndex.value = 0;
|
||||
total.value = 0;
|
||||
noMore.value = false;
|
||||
list.value = [];
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
@@ -205,15 +231,73 @@ function toEdit(item: RecycleExchangeRule): void {
|
||||
openDetail(item.id || "");
|
||||
}
|
||||
|
||||
// ---------- 删除 ----------
|
||||
|
||||
const deletingId = ref("");
|
||||
|
||||
/**
|
||||
* 删除模板。
|
||||
*
|
||||
* 已创建的兑换单保存了 ruleSnapshot,删模板不影响历史单据,
|
||||
* 但这是不可撤销操作,先确认。
|
||||
*/
|
||||
function confirmDelete(item: RecycleExchangeRule): void {
|
||||
const id = item.id;
|
||||
if (!id || deletingId.value) {
|
||||
return;
|
||||
}
|
||||
const recycleText = getRecycleQuantityText(item.recycleQuantity, item.recycleUnit);
|
||||
const dialog = DialogPlugin.confirm({
|
||||
title: "删除兑换模板",
|
||||
content: `将删除「${getRecycleItemName(item) || "未命名"} ${recycleText}」。已创建的兑换单不受影响,但模板删除后无法恢复。`,
|
||||
cancelBtn: "取消",
|
||||
confirmBtn: "删除",
|
||||
onCancel() {
|
||||
dialog.destroy();
|
||||
},
|
||||
async onConfirm() {
|
||||
dialog.destroy();
|
||||
await deleteRule(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function deleteRule(id: string): Promise<void> {
|
||||
deletingId.value = id;
|
||||
try {
|
||||
await RecycleAPI.ruleDelete(id);
|
||||
Message.success("兑换模板已删除");
|
||||
// 删的正是右栏在看的模板时清空选中,否则右栏会停在一条已消失的记录上
|
||||
if (selectedId.value === id) {
|
||||
selectedId.value = "";
|
||||
}
|
||||
await reload();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换模板删除失败"));
|
||||
} finally {
|
||||
deletingId.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
async function toCreate(): Promise<void> {
|
||||
if (isWide.value) {
|
||||
openDetail(createPaneId);
|
||||
return;
|
||||
}
|
||||
await router.push({ name: "RecycleRuleCreate" });
|
||||
}
|
||||
|
||||
async function toItemList(): Promise<void> {
|
||||
await router.push({ name: "RecycleItemList" });
|
||||
}
|
||||
|
||||
let wasDeactivated = false;
|
||||
onMounted(reload);
|
||||
onDeactivated(() => {
|
||||
wasDeactivated = true;
|
||||
});
|
||||
onActivated(async () => {
|
||||
if (wasDeactivated) {
|
||||
wasDeactivated = false;
|
||||
await reload();
|
||||
}
|
||||
});
|
||||
watch(keyword, () => {
|
||||
reloadByKeyword();
|
||||
});
|
||||
@@ -224,31 +308,31 @@ onUnmounted(() => {
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-rule-list {
|
||||
display: flex;
|
||||
padding: var(--tui-nav-height) 0 5rem;
|
||||
flex-direction: column;
|
||||
|
||||
.item {
|
||||
padding: 10px;
|
||||
|
||||
.avatar {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
.cell {
|
||||
padding: 10px;
|
||||
|
||||
.ratio {
|
||||
color: var(--td-brand-color);
|
||||
font-size: .875rem;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.description {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
.ratio {
|
||||
color: var(--td-brand-color);
|
||||
font-size: .875rem;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.description {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div v-can="permissionCodes.recycleExchange.query" class="stat-body">
|
||||
<div v-can="permissionCodes.salesOrder.read" class="stat-body">
|
||||
<t-cell-group class="range-card" theme="card" v-entrance-transition>
|
||||
<t-cell title="统计区间" :note="rangeLabel" arrow @click="rangePickerVisible = true" />
|
||||
<template v-if="isCustom">
|
||||
@@ -78,7 +78,7 @@
|
||||
<span v-text="`合计核销 ${quantityText(exchangeTotals.verified)}`" />
|
||||
<span class="net" v-text="`合计冲正 ${quantityText(exchangeTotals.revoked)}`" />
|
||||
</div>
|
||||
<div class="panel-tip" v-text="'数量按业务单位统计,兑换不计入销售金额、收款或销售订单数量。'" />
|
||||
<div class="panel-tip" v-text="'数量按业务单位统计,兑换不计入销售金额、收款或交易订单数量。'" />
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
<template>
|
||||
<div>
|
||||
<bottom-popup
|
||||
v-model="adjustVisible"
|
||||
title="调整回收物额度"
|
||||
left-button-text="取消"
|
||||
:right-button-text="operating ? '提交中' : '确认'"
|
||||
@left-button-click="adjustVisible = false"
|
||||
@right-button-click="submitAdjust"
|
||||
>
|
||||
<t-form class="adjust-form" content-align="right" label-width="7.5rem">
|
||||
<t-form-item
|
||||
label="回收物"
|
||||
required-mark
|
||||
arrow
|
||||
@click="itemPickerVisible = true"
|
||||
>
|
||||
<span v-text="adjustItemName || '请选择'" />
|
||||
</t-form-item>
|
||||
<t-form-item label="调整方式">
|
||||
<t-segmented v-model="adjustDirection" :options="directionOptions" />
|
||||
</t-form-item>
|
||||
<t-form-item label="调整数量" required-mark>
|
||||
<div class="quantity">
|
||||
<t-stepper
|
||||
v-model="adjustQuantity"
|
||||
:min="0"
|
||||
:step="allowDecimalQuantity ? .05 : 1"
|
||||
:integer="!allowDecimalQuantity"
|
||||
:disabled="!adjustItemId"
|
||||
theme="outline"
|
||||
/>
|
||||
<t-tag v-if="adjustUnit" class="unit" :content="adjustUnit" />
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<span class="red" v-text="adjustTipText" />
|
||||
</t-form-item>
|
||||
<t-form-item label="调整原因" required-mark>
|
||||
<div class="reason">
|
||||
<t-textarea v-model.trim="adjustReason" borderless autosize maxlength="500" placeholder="请输入或选择调整原因" />
|
||||
<t-button size="extra-small" theme="primary" variant="outline" @click="openReasonPicker">选择</t-button>
|
||||
</div>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</bottom-popup>
|
||||
<recycle-item-picker-popup
|
||||
v-model:visible="itemPickerVisible"
|
||||
:selected-id="adjustItemId"
|
||||
empty-text="暂无回收物,请先配置"
|
||||
@select="selectAdjustItem"
|
||||
/>
|
||||
<t-popup v-model="reasonPickerVisible" placement="bottom" :z-index="13000">
|
||||
<t-picker v-if="reasonPickerVisible" v-model="reasonPickerDraft" :columns="reasonPickerColumns" title="选择调整原因" @cancel="reasonPickerVisible = false" @confirm="confirmReason" />
|
||||
</t-popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import RecycleItemPickerPopup from "@/pages/recycle/components/RecycleItemPickerPopup.vue";
|
||||
import type { RecycleItem } from "@/types/Recycle";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { normalizePackageQuantity } from "@/utils/package";
|
||||
|
||||
defineOptions({ name: "RecycleAccountAdjustPopup" });
|
||||
const props = defineProps<{ customerId: string }>();
|
||||
const emit = defineEmits<{ success: [] }>();
|
||||
const adjustVisible = ref(false);
|
||||
const adjustItemId = ref("");
|
||||
const adjustItemName = ref("");
|
||||
const adjustUnit = ref("");
|
||||
const adjustQuantity = ref<number | string>(0);
|
||||
const adjustDirection = ref("increase");
|
||||
const directionOptions = [{ label: "增加", value: "increase" }, { label: "减少", value: "decrease" }];
|
||||
const allowDecimalQuantity = ref(false);
|
||||
const adjustReason = ref("");
|
||||
const operating = ref(false);
|
||||
const requestNo = ref("");
|
||||
const itemPickerVisible = ref(false);
|
||||
const reasonPickerVisible = ref(false);
|
||||
const reasonPickerDraft = ref<string[]>([]);
|
||||
const reasonOptions = ["补录历史额度", "额度登记有误", "重复登记额度", "盘点调整"];
|
||||
const reasonPickerColumns = reasonOptions.map(item => ({ label: item, value: item }));
|
||||
|
||||
const adjustTipText = "减少不能超过可用额度。人工调整只改账面,不代表门店收到实物。";
|
||||
|
||||
function open(): void {
|
||||
if (!props.customerId) {
|
||||
Message.warning("请先选择客户");
|
||||
return;
|
||||
}
|
||||
adjustItemId.value = "";
|
||||
adjustItemName.value = "";
|
||||
adjustUnit.value = "";
|
||||
allowDecimalQuantity.value = false;
|
||||
adjustDirection.value = "increase";
|
||||
adjustQuantity.value = 0;
|
||||
adjustReason.value = "";
|
||||
requestNo.value = "";
|
||||
adjustVisible.value = true;
|
||||
}
|
||||
|
||||
function selectAdjustItem(item: RecycleItem): void {
|
||||
adjustItemId.value = item.id || "";
|
||||
adjustItemName.value = item.name || "";
|
||||
adjustUnit.value = item.unitName || "";
|
||||
allowDecimalQuantity.value = item.allowDecimalQuantity ?? false;
|
||||
adjustQuantity.value = 0;
|
||||
itemPickerVisible.value = false;
|
||||
}
|
||||
|
||||
function openReasonPicker(): void {
|
||||
reasonPickerDraft.value = [reasonOptions.includes(adjustReason.value) ? adjustReason.value : reasonOptions[0]];
|
||||
reasonPickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmReason(value: Array<string | number>): void {
|
||||
adjustReason.value = String(value[0] || reasonPickerDraft.value[0] || "");
|
||||
reasonPickerVisible.value = false;
|
||||
}
|
||||
|
||||
async function submitAdjust(): Promise<void> {
|
||||
if (operating.value) {
|
||||
return;
|
||||
}
|
||||
const quantity = normalizePackageQuantity(adjustQuantity.value);
|
||||
if (!adjustItemId.value) {
|
||||
Message.warning("请选择回收物");
|
||||
return;
|
||||
}
|
||||
if (!quantity || "0" === quantity || (!allowDecimalQuantity.value && !Number.isInteger(Number(quantity)))) {
|
||||
Message.warning("请输入大于零的有效数量,最多三位小数");
|
||||
return;
|
||||
}
|
||||
if (!adjustReason.value.trim()) {
|
||||
Message.warning("调整原因不能为空");
|
||||
return;
|
||||
}
|
||||
if (!requestNo.value) {
|
||||
requestNo.value = window.crypto.randomUUID();
|
||||
}
|
||||
operating.value = true;
|
||||
try {
|
||||
await RecycleAPI.accountAdjust({
|
||||
customerId: props.customerId,
|
||||
recycleItemId: adjustItemId.value,
|
||||
requestNo: requestNo.value,
|
||||
quantity: adjustDirection.value === "decrease" ? `-${quantity}` : quantity,
|
||||
reason: adjustReason.value.trim()
|
||||
});
|
||||
Message.success("额度已调整");
|
||||
adjustVisible.value = false;
|
||||
emit("success");
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "额度调整失败,重试会复用同一请求号"));
|
||||
} finally {
|
||||
operating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch([adjustItemId, adjustQuantity, adjustDirection, adjustReason], () => {
|
||||
requestNo.value = "";
|
||||
});
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.adjust-form {
|
||||
margin: 0;
|
||||
padding-bottom: 1rem;
|
||||
|
||||
.quantity {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.unit {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.reason {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tips {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .8125rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -1,242 +0,0 @@
|
||||
<template>
|
||||
<bottom-popup
|
||||
v-model="visible"
|
||||
:title="isRevoke ? '冲正兑换单' : '撤销兑换单'"
|
||||
left-button-text="取消"
|
||||
:right-button-text="operating ? '提交中' : (isRevoke ? '确认冲正' : '确认撤销')"
|
||||
:z-index="popupZIndex"
|
||||
:overlay-props="{ zIndex: popupZIndex - 1 }"
|
||||
@left-button-click="visible = false"
|
||||
@right-button-click="submit"
|
||||
>
|
||||
<t-form class="action-form" label-width="7.5rem">
|
||||
<t-form-item :label="isRevoke ? '冲正原因' : '撤销原因'" :required-mark="isRevoke">
|
||||
<div class="reason">
|
||||
<t-textarea
|
||||
v-model.trim="reason"
|
||||
borderless
|
||||
autosize
|
||||
maxlength="500"
|
||||
:placeholder="isRevoke ? '请输入或选择冲正原因' : '可不填'"
|
||||
/>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
theme="primary"
|
||||
variant="outline"
|
||||
@click="openReasonPicker"
|
||||
>选择</t-button>
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label="回收物退还" required-mark>
|
||||
<t-radio-group v-model="recycleReturnedText" variant="default-filled">
|
||||
<t-radio value="true" :block="false" borderless>全部退还客户</t-radio>
|
||||
<t-radio value="false" :block="false" borderless>不退还</t-radio>
|
||||
</t-radio-group>
|
||||
</t-form-item>
|
||||
<t-form-item v-if="recycleReturnedText === 'true'" label-width="0">
|
||||
<span class="tips" v-text="returnTipText" />
|
||||
</t-form-item>
|
||||
<template v-if="isRevoke && stockEnabled">
|
||||
<t-form-item label="商品退回门店" required-mark>
|
||||
<t-checkbox v-model="stockReturned" borderless>
|
||||
<span v-text="`兑换商品 ${productText} 已退回门店`" />
|
||||
</t-checkbox>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<attachment-selector
|
||||
v-model:items="photoItems"
|
||||
:upload="uploadPhotoList"
|
||||
required
|
||||
title="退货凭证照片"
|
||||
/>
|
||||
</t-form-item>
|
||||
</template>
|
||||
<t-form-item label="备注">
|
||||
<t-textarea v-model.trim="remark" borderless autosize maxlength="500" placeholder="可不填" />
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</bottom-popup>
|
||||
<t-popup
|
||||
v-model="reasonPickerVisible"
|
||||
placement="bottom"
|
||||
:z-index="reasonPickerZIndex"
|
||||
:overlay-props="{ zIndex: reasonPickerZIndex - 1 }"
|
||||
>
|
||||
<t-picker
|
||||
v-model="reasonPickerDraft"
|
||||
:columns="reasonPickerColumns"
|
||||
:title="isRevoke ? '选择冲正原因' : '选择撤销原因'"
|
||||
@cancel="reasonPickerVisible = false"
|
||||
@confirm="confirmReason"
|
||||
/>
|
||||
</t-popup>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import type { Attachment } from "timi-web-api";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { RecycleExchange } from "@/types/Recycle";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { uploadPhotoList } from "@/utils/photo";
|
||||
import { getRecycleQuantityText } from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecycleExchangeActionPopup" });
|
||||
|
||||
const props = defineProps<{
|
||||
exchange: RecycleExchange;
|
||||
/** 撤销待核销单;冲正已核销单 */
|
||||
action: "CANCEL" | "REVOKE";
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
}>();
|
||||
const visible = defineModel<boolean>("visible", { default: false });
|
||||
|
||||
const popupZIndex = 12000;
|
||||
const reasonPickerZIndex = popupZIndex + 1;
|
||||
const operating = ref(false);
|
||||
const reason = ref("");
|
||||
const remark = ref("");
|
||||
/** 必须显式选择是否退还回收物,用字符串承接单选值 */
|
||||
const recycleReturnedText = ref("");
|
||||
const stockReturned = ref(false);
|
||||
const photoItems = ref<PhotoItem[]>([]);
|
||||
const reasonPickerVisible = ref(false);
|
||||
const reasonPickerDraft = ref<string[]>([]);
|
||||
const requestNo = ref("");
|
||||
|
||||
const isRevoke = computed(() => props.action === "REVOKE");
|
||||
const stockEnabled = computed(() => props.exchange.stockEnabledSnapshot === true);
|
||||
const returnTipText = computed(() => `将退回客户 ${getRecycleQuantityText(props.exchange.recycleQuantity, props.exchange.recycleUnitSnapshot)}`);
|
||||
const productText = computed(() => props.exchange.productNameSnapshot || props.exchange.skuNameSnapshot || "兑换商品");
|
||||
const reasonOptions = computed(() => (isRevoke.value
|
||||
? ["兑换商品退回", "兑换数量填写有误", "回收数量填写有误", "重复核销", "操作失误"]
|
||||
: ["客户取消兑换", "回收数量填写有误", "兑换数量填写有误", "重复创建兑换单", "回收物与实物不符"]));
|
||||
const reasonPickerColumns = computed(() => reasonOptions.value.map(item => ({ label: item, value: item })));
|
||||
|
||||
function resetForm(): void {
|
||||
reason.value = "";
|
||||
remark.value = "";
|
||||
recycleReturnedText.value = "";
|
||||
stockReturned.value = false;
|
||||
photoItems.value = [];
|
||||
reasonPickerVisible.value = false;
|
||||
reasonPickerDraft.value = [];
|
||||
requestNo.value = "";
|
||||
}
|
||||
|
||||
function openReasonPicker(): void {
|
||||
const currentReason = reasonOptions.value.includes(reason.value) ? reason.value : reasonOptions.value[0];
|
||||
reasonPickerDraft.value = [currentReason];
|
||||
reasonPickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmReason(value: Array<string | number>): void {
|
||||
reason.value = String(value[0] || reasonPickerDraft.value[0] || "");
|
||||
reasonPickerVisible.value = false;
|
||||
}
|
||||
|
||||
function buildAttachments(): Partial<Attachment>[] {
|
||||
return photoItems.value.flatMap(item => item.tempFileId ? [{
|
||||
tempFileId: item.tempFileId,
|
||||
attachType: "PHOTO"
|
||||
}] : []);
|
||||
}
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
const exchangeId = props.exchange.id;
|
||||
if (operating.value || !exchangeId) {
|
||||
return;
|
||||
}
|
||||
if (isRevoke.value && !reason.value.trim()) {
|
||||
Message.warning("冲正原因不能为空");
|
||||
return;
|
||||
}
|
||||
if (!recycleReturnedText.value) {
|
||||
Message.warning("请选择回收物是否退还客户");
|
||||
return;
|
||||
}
|
||||
const attachmentList = buildAttachments();
|
||||
if (isRevoke.value && stockEnabled.value) {
|
||||
if (!stockReturned.value) {
|
||||
Message.warning("请确认兑换商品已退回门店");
|
||||
return;
|
||||
}
|
||||
if (!attachmentList.length) {
|
||||
Message.warning("库存商品冲正必须上传退货凭证照片");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 内容变更后必须换新请求号;失败重试沿用同一个,服务端据此去重
|
||||
if (!requestNo.value) {
|
||||
requestNo.value = window.crypto.randomUUID();
|
||||
}
|
||||
operating.value = true;
|
||||
try {
|
||||
const request = {
|
||||
exchangeId,
|
||||
requestNo: requestNo.value,
|
||||
reason: reason.value.trim() || undefined,
|
||||
remark: remark.value || null,
|
||||
recycleReturned: recycleReturnedText.value === "true",
|
||||
stockReturned: stockReturned.value,
|
||||
attachmentList
|
||||
};
|
||||
if (isRevoke.value) {
|
||||
await RecycleAPI.revoke(request);
|
||||
} else {
|
||||
await RecycleAPI.cancel(request);
|
||||
}
|
||||
visible.value = false;
|
||||
Message.success(isRevoke.value ? "兑换单已冲正" : "兑换单已撤销");
|
||||
emit("success");
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, `兑换单${isRevoke.value ? "冲正" : "撤销"}失败,重试会复用同一请求号`));
|
||||
} finally {
|
||||
operating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(visible, value => {
|
||||
if (value) {
|
||||
resetForm();
|
||||
} else {
|
||||
reasonPickerVisible.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
// 表单任意改动都要作废旧请求号,避免内容变了还撞上服务端的幂等摘要
|
||||
watch([reason, remark, recycleReturnedText, stockReturned, photoItems], () => {
|
||||
requestNo.value = "";
|
||||
}, { deep: true });
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.action-form {
|
||||
margin: 0;
|
||||
padding-bottom: 1rem;
|
||||
|
||||
.reason {
|
||||
gap: .5rem;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: flex-start;
|
||||
|
||||
.t-textarea {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.tips {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .8125rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,239 +0,0 @@
|
||||
<template>
|
||||
<div class="recycle-cell">
|
||||
<div class="header">
|
||||
<div class="left">
|
||||
<t-image
|
||||
v-if="photoURL"
|
||||
:src="photoURL"
|
||||
:alt="customerName"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div v-else class="avatar fallback" v-text="avatarText" />
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="customer-status">
|
||||
<strong class="customer" v-text="customerName" />
|
||||
<t-tag
|
||||
:content="statusText"
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
:theme="statusTheme"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<time-label class="time" :timestamp="exchange.occurredAt" underline />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<t-divider />
|
||||
<div class="exchange">
|
||||
<div class="flow">
|
||||
<span class="recycle" v-text="recycleText" />
|
||||
<t-icon class="arrow" name="arrow-right" size="1rem" />
|
||||
<span class="product" v-text="productText" />
|
||||
</div>
|
||||
<div v-if="adjusted" class="adjusted" v-text="adjustedText" />
|
||||
</div>
|
||||
<div class="summary" v-text="summaryText" />
|
||||
<t-divider />
|
||||
<div class="footer">
|
||||
<span class="hint" v-text="recycleNameText" />
|
||||
<t-button
|
||||
theme="primary"
|
||||
size="extra-small"
|
||||
content="详情"
|
||||
@click.stop="emit('detail')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { TimeLabel } from "timi-web";
|
||||
import type { RecycleExchange } from "@/types/Recycle";
|
||||
import { getCustomerPhotoURL } from "@/utils/customer";
|
||||
import { getPackageQuantityText } from "@/utils/package";
|
||||
import {
|
||||
getRecycleExchangeStatusText,
|
||||
getRecycleExchangeStatusTheme,
|
||||
getRecycleQuantityText,
|
||||
isRecycleQuantityAdjusted
|
||||
} from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecycleExchangeListCell" });
|
||||
|
||||
const props = defineProps<{
|
||||
exchange: RecycleExchange;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
detail: [];
|
||||
}>();
|
||||
|
||||
const customerName = computed(() => props.exchange.customer?.name || props.exchange.customer?.code || props.exchange.customerId || "未知客户");
|
||||
const avatarText = computed(() => customerName.value.slice(0, 1) || "客");
|
||||
const photoURL = computed(() => getCustomerPhotoURL(props.exchange.customer, 64));
|
||||
const statusText = computed(() => getRecycleExchangeStatusText(props.exchange.status));
|
||||
const statusTheme = computed(() => getRecycleExchangeStatusTheme(props.exchange.status));
|
||||
const recycleText = computed(() => getRecycleQuantityText(props.exchange.recycleQuantity, props.exchange.recycleUnitSnapshot));
|
||||
const productText = computed(() => {
|
||||
const productName = props.exchange.productNameSnapshot?.trim() || "未命名产品";
|
||||
const skuText = props.exchange.specSummarySnapshot?.trim() || props.exchange.skuNameSnapshot?.trim() || "";
|
||||
const quantityText = getRecycleQuantityText(props.exchange.exchangeQuantity, props.exchange.unitSnapshot);
|
||||
return skuText && skuText !== productName ? `${productName}(${skuText}) ${quantityText}` : `${productName} ${quantityText}`;
|
||||
});
|
||||
const adjusted = computed(() => isRecycleQuantityAdjusted(props.exchange));
|
||||
const adjustedText = computed(() => {
|
||||
const defaultText = `${getPackageQuantityText(props.exchange.defaultRecycleQuantity)} ${props.exchange.recycleUnitSnapshot || ""}`.trim();
|
||||
const defaultExchangeText = `${getPackageQuantityText(props.exchange.defaultExchangeQuantity)} ${props.exchange.unitSnapshot || ""}`.trim();
|
||||
return `已调整数量,预设 ${defaultText} / ${defaultExchangeText}`;
|
||||
});
|
||||
const recycleNameText = computed(() => {
|
||||
const recycleName = props.exchange.recycleNameSnapshot || "回收物";
|
||||
return `${recycleName} · 倍数 ${props.exchange.multiple ?? 1}`;
|
||||
});
|
||||
const summaryText = computed(() => {
|
||||
const recycleText = getRecycleQuantityText(props.exchange.ruleRecycleQuantity, props.exchange.recycleUnitSnapshot);
|
||||
const exchangeText = getRecycleQuantityText(props.exchange.ruleExchangeQuantity, props.exchange.unitSnapshot);
|
||||
return `规则 ${recycleText} 兑换 ${exchangeText}`;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-cell {
|
||||
gap: .5rem;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
background: var(--td-bg-color-container);
|
||||
flex-direction: column;
|
||||
border-radius: 1rem;
|
||||
|
||||
.header {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
|
||||
.left {
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.main {
|
||||
gap: .5rem;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
|
||||
.customer-status {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.customer {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
|
||||
.time {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.exchange {
|
||||
gap: .25rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
|
||||
.flow {
|
||||
gap: .375rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
|
||||
.recycle,
|
||||
.product {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
font-size: .875rem;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.recycle {
|
||||
color: var(--td-text-color-secondary);
|
||||
flex: 0 1 auto;
|
||||
}
|
||||
|
||||
.product {
|
||||
flex: 1 1 auto;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
color: var(--td-text-color-placeholder);
|
||||
flex: 0 0 auto;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
}
|
||||
|
||||
.adjusted {
|
||||
color: var(--td-warning-color, #ED7B2F);
|
||||
font-size: .75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.summary {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
text-align: right;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.footer {
|
||||
gap: .75rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.hint {
|
||||
color: var(--td-text-color-secondary);
|
||||
min-width: 0;
|
||||
font-size: .75rem;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.t-button {
|
||||
--td-button-border-radius: .5rem;
|
||||
|
||||
flex: 0 0 auto;
|
||||
padding-left: 1.5rem;
|
||||
padding-right: 1.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.recycle-cell .avatar .t-image__img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: inherit;
|
||||
}
|
||||
|
||||
:global(html.theme-dark) .recycle-cell {
|
||||
.fallback {
|
||||
background: #115e59;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,295 @@
|
||||
<template>
|
||||
<div v-if="exchange" class="recycle-exchange-panel">
|
||||
<t-cell-group class="recycle-card" title="回收物信息" theme="card">
|
||||
<t-cell :note="exchange.recycleNameSnapshot || '-'">
|
||||
<template #leftIcon>
|
||||
<t-image v-if="recyclePhotoId" class="avatar" :src="getAttachmentReadURL(recyclePhotoId, 96)" :alt="exchange.recycleNameSnapshot" fit="cover" />
|
||||
<div v-else class="avatar fallback" v-text="(exchange.recycleNameSnapshot || '回').slice(0, 1)" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="应收回收" :note="requiredText" />
|
||||
<t-cell title="已生效回收">
|
||||
<template #note>
|
||||
<span class="verified" v-text="verifiedText" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="待核销回收" :note="pendingText" />
|
||||
<t-cell title="剩余待回收">
|
||||
<template #note>
|
||||
<span :class="{ outstanding: 0 < outstandingQuantity }" v-text="outstandingText" />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="状态" :note="getOrderSettlementText(order?.paymentStatus)" />
|
||||
<t-cell v-if="order?.paymentStatus === 'PAID'" title="全额实收时间" :note="order.paidAt ? Time.toDateTime(order.paidAt) : '待后端回填'" />
|
||||
<t-cell v-if="exchange.ruleId" title="兑换模板" :note="ruleText" arrow @click="emit('openRule', exchange.ruleId)" />
|
||||
<t-cell title="查看全部回收流水" arrow @click="openPayments" />
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="actionList.length" class="records" title="兑换单操作记录" theme="card">
|
||||
<div v-for="action in actionList" :key="action.id" class="record">
|
||||
<div class="record-head">
|
||||
<div class="record-title">
|
||||
<t-tag
|
||||
size="small"
|
||||
:content="getRecycleActionText(action.actionType)"
|
||||
theme="danger"
|
||||
variant="light"
|
||||
/>
|
||||
<time-label class="time" :timestamp="action.occurredAt" underline />
|
||||
</div>
|
||||
<span class="operator" v-text="getActionOperatorName(action)" />
|
||||
</div>
|
||||
<div v-if="action.reason" class="record-line">
|
||||
<span class="label">原因</span>
|
||||
<span v-text="action.reason" />
|
||||
</div>
|
||||
<div v-if="action.remark" class="record-line">
|
||||
<span class="label">备注</span>
|
||||
<span v-text="action.remark" />
|
||||
</div>
|
||||
<div class="record-line">
|
||||
<span class="label">门店保留</span>
|
||||
<span v-text="getRetainedText(action)" />
|
||||
</div>
|
||||
<attachment-selector
|
||||
v-if="getActionPhotoItems(action).length"
|
||||
class="record-photos"
|
||||
:items="getActionPhotoItems(action)"
|
||||
title="退还凭证"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
</t-cell-group>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Time, TimeLabel } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import type { Attachment } from "timi-web-api";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { RecycleExchange, RecycleExchangeAction, RecyclePayment } from "@/types/Recycle";
|
||||
import type { SalesOrder } from "@/types/SalesOrder";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getOrderSettlementText } from "@/utils/salesOrder";
|
||||
import {
|
||||
getRecycleActionText,
|
||||
getRecycleQuantityText,
|
||||
isRecycleQuantityAdjusted
|
||||
} from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecycleExchangePanel" });
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** 兑换单 ID,由订单详情按 salesOrderId 反查得到 */
|
||||
exchangeId: string;
|
||||
order?: SalesOrder;
|
||||
}>(), {
|
||||
exchangeId: ""
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 支付或取消后订单状态已变化,父级需要重新拉订单 */
|
||||
changed: [];
|
||||
openRule: [id: string];
|
||||
openPayments: [id: string];
|
||||
}>();
|
||||
|
||||
const userStore = useUserStore();
|
||||
const exchange = ref<RecycleExchange>();
|
||||
const actionList = ref<RecycleExchangeAction[]>([]);
|
||||
const actionAttachmentMap = ref<Record<string, PhotoItem[]>>({});
|
||||
const paymentList = ref<RecyclePayment[]>([]);
|
||||
const recyclePhotoId = computed(() => exchange.value?.recycleItemAttachments?.find(item => item.id && item.mimeType?.startsWith("image/"))?.id || "");
|
||||
|
||||
function openPayments(): void {
|
||||
emit("openPayments", props.exchangeId);
|
||||
}
|
||||
|
||||
const adjusted = computed(() => !!exchange.value && isRecycleQuantityAdjusted(exchange.value));
|
||||
const ruleText = computed(() => {
|
||||
const current = exchange.value;
|
||||
if (!current) {
|
||||
return "-";
|
||||
}
|
||||
const recycleText = getRecycleQuantityText(current.ruleRecycleQuantity, current.recycleUnitSnapshot);
|
||||
return `模板 ${recycleText}/份${adjusted.value ? ",已调整" : ""}`;
|
||||
});
|
||||
|
||||
// ---------- 支付进度 ----------
|
||||
|
||||
const agreedQuantity = computed(() => Number(exchange.value?.recycleQuantity ?? 0));
|
||||
const requiredText = computed(() => getRecycleQuantityText(exchange.value?.recycleQuantity, exchange.value?.recycleUnitSnapshot));
|
||||
/** 已核销只统计原始支付,冲正记录是负向的单独一条,不能回加 */
|
||||
const verifiedQuantity = computed(() => paymentList.value
|
||||
.filter(item => item.status === "VERIFIED" && !item.sourcePaymentId)
|
||||
.reduce((sum, item) => sum + Number(item.quantity ?? 0), 0));
|
||||
const pendingQuantity = computed(() => paymentList.value
|
||||
.filter(item => item.status === "PENDING")
|
||||
.reduce((sum, item) => sum + Number(item.quantity ?? 0), 0));
|
||||
const outstandingQuantity = computed(() => Math.max(agreedQuantity.value - verifiedQuantity.value - pendingQuantity.value, 0));
|
||||
const settled = computed(() => 0 >= outstandingQuantity.value);
|
||||
const verifiedText = computed(() => getRecycleQuantityText(verifiedQuantity.value.toFixed(3), exchange.value?.recycleUnitSnapshot));
|
||||
const pendingText = computed(() => getRecycleQuantityText(pendingQuantity.value.toFixed(3), exchange.value?.recycleUnitSnapshot));
|
||||
const outstandingText = computed(() => getRecycleQuantityText(outstandingQuantity.value.toFixed(3), exchange.value?.recycleUnitSnapshot));
|
||||
|
||||
// ---------- 权限 ----------
|
||||
|
||||
const canCreatePayment = computed(() => userStore.hasPermissions(permissionCodes.fundReceive.create));
|
||||
const canRegister = computed(() => canCreatePayment.value && !!exchange.value && !settled.value);
|
||||
// ---------- 加载 ----------
|
||||
|
||||
async function load(): Promise<void> {
|
||||
const id = props.exchangeId;
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await RecycleAPI.detail(id);
|
||||
exchange.value = result.exchange;
|
||||
actionList.value = result.actionList || [];
|
||||
actionAttachmentMap.value = Object.fromEntries(Object.entries(result.actionAttachments || {})
|
||||
.map(([actionId, list]) => [actionId, toPhotoItemList(list)]));
|
||||
await loadPayments();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收条款加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPayments(): Promise<void> {
|
||||
const orderId = exchange.value?.salesOrderId;
|
||||
if (!orderId) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
paymentList.value = await RecycleAPI.paymentList(orderId);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收物支付加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
/** 支付与取消都会改订单状态,重新拉自己的数据后通知父级 */
|
||||
async function reload(): Promise<void> {
|
||||
await load();
|
||||
emit("changed");
|
||||
}
|
||||
|
||||
defineExpose({ canRegister, reload });
|
||||
|
||||
// ---------- 展示辅助 ----------
|
||||
|
||||
function getActionOperatorName(action: RecycleExchangeAction): string {
|
||||
return action.operator?.nick || action.operator?.name || action.operatorUserId || "未知操作人";
|
||||
}
|
||||
|
||||
function getRetainedText(action: RecycleExchangeAction): string {
|
||||
return getRecycleQuantityText(action.retainedRecycleQuantity, exchange.value?.recycleUnitSnapshot);
|
||||
}
|
||||
|
||||
function getActionPhotoItems(action: RecycleExchangeAction): PhotoItem[] {
|
||||
return action.id ? actionAttachmentMap.value[action.id] || [] : [];
|
||||
}
|
||||
|
||||
function toPhotoItemList(list?: Attachment[]): PhotoItem[] {
|
||||
return (list || []).flatMap(item => {
|
||||
if (!item.id) {
|
||||
return [];
|
||||
}
|
||||
const url = getAttachmentReadURL(item.id);
|
||||
return url ? [{ id: item.id, url, attachType: item.attachType || undefined }] : [];
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onActivated(load);
|
||||
watch(() => props.exchangeId, load);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.recycle-exchange-panel {
|
||||
|
||||
.recycle-card {
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.verified {
|
||||
color: var(--td-success-color, #2BA471);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.outstanding {
|
||||
color: var(--td-warning-color, #ED7B2F);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.tips {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .8125rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.records {
|
||||
|
||||
.record {
|
||||
gap: .375rem;
|
||||
padding: .75rem 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-bottom: 1px solid var(--td-component-border);
|
||||
|
||||
&:last-of-type {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.record-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.record-title {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.operator {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.record-line {
|
||||
gap: .375rem;
|
||||
display: flex;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
|
||||
.label {
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
.record-photos {
|
||||
margin-top: .25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.actions {
|
||||
padding: 0 1rem;
|
||||
|
||||
.t-button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<bottom-popup
|
||||
v-model="visible"
|
||||
:title="props.itemId ? '编辑回收物' : '新增回收物'"
|
||||
left-button-text="取消"
|
||||
:right-button-text="formRef?.saving ? '保存中' : '保存'"
|
||||
:right-button-disabled="!canSave"
|
||||
:z-index="props.zIndex"
|
||||
:overlay-props="{ zIndex: props.zIndex - 1 }"
|
||||
@left-button-click="visible = false"
|
||||
@right-button-click="formRef?.save()"
|
||||
>
|
||||
<recycle-item-form v-if="visible" ref="formRef" :item-id="props.itemId" :viewer-z-index="props.zIndex + 20" @saved="handleSaved" />
|
||||
</bottom-popup>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import RecycleItemForm from "@/pages/recycle/components/RecycleItemForm.vue";
|
||||
|
||||
defineOptions({ name: "RecycleItemEditPopup" });
|
||||
const props = withDefaults(defineProps<{ itemId?: string; zIndex?: number }>(), { itemId: "", zIndex: 12100 });
|
||||
const emit = defineEmits<{ saved: [] }>();
|
||||
const visible = defineModel<boolean>("visible", { default: false });
|
||||
const formRef = ref<InstanceType<typeof RecycleItemForm>>();
|
||||
const canSave = computed(() => !!formRef.value?.ready && !formRef.value.loading && !formRef.value.uploading && !formRef.value.saving);
|
||||
function handleSaved(): void { emit("saved"); visible.value = false; }
|
||||
</script>
|
||||
@@ -0,0 +1,159 @@
|
||||
<template>
|
||||
<t-form class="form" label-width="6.5rem">
|
||||
<t-form-item label="回收物名称" required-mark>
|
||||
<t-input v-model.trim="form.name" align="right" borderless maxlength="128" placeholder="例如空瓶" />
|
||||
</t-form-item>
|
||||
<t-form-item label="计量单位" required-mark>
|
||||
<t-input
|
||||
v-model="form.unitName"
|
||||
align="right"
|
||||
borderless
|
||||
maxlength="32"
|
||||
placeholder="例如个、公斤"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label="允许小数" content-align="right">
|
||||
<t-switch v-model="form.allowDecimalQuantity" size="small" />
|
||||
</t-form-item>
|
||||
<t-form-item label="启用" content-align="right">
|
||||
<t-switch v-model="form.status" size="small" :custom-value="['ACTIVE', 'INACTIVE']" />
|
||||
</t-form-item>
|
||||
<t-form-item label="备注">
|
||||
<t-textarea
|
||||
v-model="form.remark"
|
||||
borderless
|
||||
autosize
|
||||
maxlength="500"
|
||||
placeholder="选填"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<attachment-selector
|
||||
v-model:items="attachments"
|
||||
title="图片及附件"
|
||||
:busy="uploading"
|
||||
:viewer-z-index="props.viewerZIndex"
|
||||
@select="upload($event.files)"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<span class="gray">回收物保存后不能删除,不再使用请停用。停用不影响已创建的兑换单。</span>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { AttachmentAPI } from "timi-web-api";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { RecycleStatus } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { compressUploadImageList } from "@/utils/imageCompression";
|
||||
import { Message } from "@/utils/message";
|
||||
|
||||
defineOptions({ name: "RecycleItemForm" });
|
||||
const props = withDefaults(defineProps<{ itemId?: string; viewerZIndex?: number }>(), { itemId: "" });
|
||||
const emit = defineEmits<{ saved: [] }>();
|
||||
const form = reactive({
|
||||
name: "",
|
||||
unitName: "",
|
||||
allowDecimalQuantity: false,
|
||||
status: "ACTIVE" as RecycleStatus,
|
||||
remark: ""
|
||||
});
|
||||
const attachments = ref<PhotoItem[]>([]);
|
||||
const loading = ref(false);
|
||||
const ready = ref(false);
|
||||
const saving = ref(false);
|
||||
const uploading = ref(false);
|
||||
let version = 0;
|
||||
|
||||
watch(() => props.itemId, async value => {
|
||||
const current = ++version;
|
||||
Object.assign(form, { name: "", unitName: "", allowDecimalQuantity: false, status: "ACTIVE", remark: "" });
|
||||
attachments.value = [];
|
||||
ready.value = !value;
|
||||
if (!value) {
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
const item = await RecycleAPI.itemDetail(value);
|
||||
if (current !== version) return;
|
||||
Object.assign(form, {
|
||||
name: item.name || "",
|
||||
unitName: item.unitName || "",
|
||||
allowDecimalQuantity: item.allowDecimalQuantity ?? false,
|
||||
status: item.status || "ACTIVE",
|
||||
remark: item.remark || ""
|
||||
});
|
||||
attachments.value = (item.attachmentList || []).filter(entry => entry.id).map(entry => ({
|
||||
attachment: entry,
|
||||
attachType: entry.attachType,
|
||||
mimeType: entry.mimeType,
|
||||
url: getAttachmentReadURL(entry.id || "")
|
||||
}));
|
||||
ready.value = true;
|
||||
} catch (error) {
|
||||
if (current === version) Message.error(getErrorMessage(error, "回收物加载失败"));
|
||||
} finally {
|
||||
if (current === version) loading.value = false;
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
async function upload(files: File[]): Promise<void> {
|
||||
if (!files.length || uploading.value) return;
|
||||
uploading.value = true;
|
||||
try {
|
||||
const result = await AttachmentAPI.upload(await compressUploadImageList(files));
|
||||
for (const [index, file] of result.entries()) {
|
||||
if (!file.id) continue;
|
||||
const source = files[index];
|
||||
attachments.value.push({
|
||||
attachment: { name: source?.name, mimeType: source?.type },
|
||||
attachType: source?.type.startsWith("image/") ? "PHOTO" : "OTHER",
|
||||
mimeType: source?.type,
|
||||
tempFileId: file.id,
|
||||
url: AttachmentAPI.getTempReadURL(file.id)
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "附件上传失败"));
|
||||
} finally {
|
||||
uploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function save(): Promise<void> {
|
||||
if (saving.value || uploading.value || !ready.value) return;
|
||||
if (!form.name.trim() || !form.unitName.trim()) {
|
||||
Message.warning("请填写回收物名称和计量单位");
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
await RecycleAPI.itemSave({
|
||||
id: props.itemId || undefined,
|
||||
name: form.name.trim(),
|
||||
unitName: form.unitName.trim(),
|
||||
allowDecimalQuantity: form.allowDecimalQuantity,
|
||||
status: form.status,
|
||||
remark: form.remark || null,
|
||||
attachmentList: attachments.value.flatMap(entry => entry.tempFileId
|
||||
? [{ ...entry.attachment, attachType: entry.attachType, tempFileId: entry.tempFileId }]
|
||||
: entry.attachment ? [entry.attachment] : [])
|
||||
});
|
||||
Message.success("回收物配置已保存");
|
||||
emit("saved");
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收物配置保存失败"));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ save, saving, loading, uploading, ready });
|
||||
</script>
|
||||
@@ -0,0 +1,163 @@
|
||||
<template>
|
||||
<bottom-popup
|
||||
v-model="visible"
|
||||
:title="props.title"
|
||||
height="60vh"
|
||||
right-button-text=""
|
||||
:z-index="12100"
|
||||
:overlay-props="{ zIndex: 12099 }"
|
||||
@left-button-click="visible = false"
|
||||
>
|
||||
<template v-if="props.manage" #rightButton>
|
||||
<t-button theme="primary" variant="text" size="small" content="新建" :disabled="isLoading" @click="openEdit()" />
|
||||
</template>
|
||||
<div class="picker-list">
|
||||
<t-cell-group>
|
||||
<t-swipe-cell v-for="item in displayedItems" :key="item.id">
|
||||
<template #right>
|
||||
<t-button v-if="props.manage" class="edit-button" theme="primary" content="编辑" :disabled="isLoading" @click.stop="openEdit(item.id)" />
|
||||
</template>
|
||||
<t-cell
|
||||
:title="item.name || '未命名回收物'"
|
||||
:description="`按${item.unitName || '单位'}计量`"
|
||||
class="item"
|
||||
:class="{ active: item.id === props.selectedId }"
|
||||
arrow
|
||||
@click="select(item)"
|
||||
>
|
||||
<template #note>
|
||||
<t-tag v-if="props.showStatus" size="small" :theme="getRecycleStatusTheme(item.status)" :content="getRecycleStatusText(item.status)" />
|
||||
</template>
|
||||
<template #leftIcon>
|
||||
<t-image v-if="getCoverId(item)" class="avatar" :src="getAttachmentReadURL(getCoverId(item), 96)" :alt="item.name" fit="cover" />
|
||||
<div v-else class="avatar fallback" v-text="(item.name || '产').slice(0, 1)" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-swipe-cell>
|
||||
</t-cell-group>
|
||||
<center-tips v-if="!displayedItems.length" :content="isLoading ? '正在加载回收物' : props.emptyText" />
|
||||
</div>
|
||||
<recycle-item-edit-popup v-model:visible="editVisible" :item-id="editingId" :z-index="12300" @saved="handleSaved" />
|
||||
</bottom-popup>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import RecycleItemEditPopup from "@/pages/recycle/components/RecycleItemEditPopup.vue";
|
||||
import type { RecycleItem, RecycleStatus } from "@/types/Recycle";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { getRecycleStatusText, getRecycleStatusTheme } from "@/utils/recycle";
|
||||
|
||||
defineOptions({ name: "RecycleItemPickerPopup" });
|
||||
const props = withDefaults(defineProps<{
|
||||
title?: string;
|
||||
manage?: boolean;
|
||||
showStatus?: boolean;
|
||||
selectedId?: string;
|
||||
items?: RecycleItem[];
|
||||
loading?: boolean;
|
||||
status?: RecycleStatus;
|
||||
emptyText?: string;
|
||||
}>(), {
|
||||
title: "选择回收物",
|
||||
manage: false,
|
||||
showStatus: false,
|
||||
selectedId: "",
|
||||
loading: false,
|
||||
emptyText: "暂无回收物"
|
||||
});
|
||||
const visible = defineModel<boolean>("visible", { default: false });
|
||||
const emit = defineEmits<{ select: [item: RecycleItem]; saved: [] }>();
|
||||
const loadedItems = ref<RecycleItem[]>([]);
|
||||
const internalLoading = ref(false);
|
||||
const displayedItems = computed(() => props.items ?? loadedItems.value);
|
||||
const isLoading = computed(() => props.items ? props.loading : internalLoading.value);
|
||||
const editVisible = ref(false);
|
||||
const editingId = ref("");
|
||||
|
||||
function getCoverId(item: RecycleItem): string {
|
||||
return item.attachmentList?.find(attachment => attachment.id && attachment.mimeType?.startsWith("image/"))?.id || "";
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
if (internalLoading.value) return;
|
||||
internalLoading.value = true;
|
||||
try {
|
||||
const result: RecycleItem[] = [];
|
||||
let offset = 0;
|
||||
let total = 0;
|
||||
do {
|
||||
const page = await RecycleAPI.itemList({ offset, limit: 100, status: props.status });
|
||||
const rows = page.list || [];
|
||||
result.push(...rows);
|
||||
total = page.total || 0;
|
||||
offset += rows.length;
|
||||
if (!rows.length) break;
|
||||
} while (offset < total);
|
||||
loadedItems.value = result;
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "回收物加载失败"));
|
||||
} finally {
|
||||
internalLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSaved(): Promise<void> {
|
||||
if (!props.items) await load();
|
||||
emit("saved");
|
||||
}
|
||||
|
||||
function openEdit(id = ""): void {
|
||||
editingId.value = id;
|
||||
editVisible.value = true;
|
||||
}
|
||||
|
||||
function select(item: RecycleItem): void {
|
||||
visible.value = false;
|
||||
emit("select", item);
|
||||
}
|
||||
|
||||
watch(visible, async value => {
|
||||
if (value && !props.items) await load();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.picker-list {
|
||||
.item.active {
|
||||
background: var(--td-brand-color-1, rgba(0, 82, 217, .08));
|
||||
}
|
||||
|
||||
.edit-button {
|
||||
width: 4rem;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
gap: 1rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.unit {
|
||||
font-size: .875rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
:global(html.theme-dark) .picker-list .item.active {
|
||||
background: rgba(15, 118, 110, .22);
|
||||
}
|
||||
:deep(.avatar .t-image__img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: inherit;
|
||||
}
|
||||
</style>
|
||||
@@ -232,7 +232,7 @@ const amountTotal = ref(0);
|
||||
const isLoading = ref(false);
|
||||
const isRefreshing = ref(false);
|
||||
const isNoMore = ref(false);
|
||||
const sourceTypeOptions = [{ label: "全部来源", value: "ALL" }, { label: "销售订单", value: "SALES_ORDER" }, { label: "历史消费", value: "LEGACY_EVENT" }];
|
||||
const sourceTypeOptions = [{ label: "全部来源", value: "ALL" }, { label: "交易订单", value: "SALES_ORDER" }, { label: "历史消费", value: "LEGACY_EVENT" }];
|
||||
const statusOptions = [{ label: "全部状态", value: "ALL" }, { label: "有效", value: "ACTIVE" }, { label: "已失效", value: "REVOKED" }];
|
||||
const canReadEventRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.read));
|
||||
const loadStateText = computed(() => isLoading.value ? "正在加载更多" : isNoMore.value ? "没有更多记录" : "上拉加载更多");
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<t-cell title="备注" :note="Text.display(record.remark)" />
|
||||
<t-cell v-if="record.reason" title="拒绝/撤销原因" :note="Text.display(record.reason)" />
|
||||
<t-cell
|
||||
title="销售订单详情"
|
||||
title="交易订单详情"
|
||||
:arrow="!!record.bizId && canReadSalesOrder"
|
||||
@click="toSalesOrder"
|
||||
/>
|
||||
@@ -162,7 +162,7 @@ function resolveId(): string {
|
||||
|
||||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||||
useExpandToMaster({
|
||||
path: "/management/fund-records",
|
||||
path: "/product/fund-records",
|
||||
id: () => resolveId()
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
@@ -232,7 +232,7 @@ async function toSalesOrder(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
path: `/management/sales-orders/${record.value.bizId}`,
|
||||
path: `/product/sales-orders/${record.value.bizId}`,
|
||||
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
|
||||
});
|
||||
}
|
||||
@@ -244,7 +244,7 @@ async function toSourceRecord(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
path: `/management/fund-records/${record.value.sourceRecordId}`,
|
||||
path: `/product/fund-records/${record.value.sourceRecordId}`,
|
||||
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
|
||||
});
|
||||
}
|
||||
@@ -353,7 +353,7 @@ async function submitReason(): Promise<void> {
|
||||
|
||||
async function toRevoke(): Promise<void> {
|
||||
if (record.value?.id && canRevoke.value) {
|
||||
await router.push(`/management/fund-records/${record.value.id}/revoke`);
|
||||
await router.push(`/product/fund-records/${record.value.id}/revoke`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -225,8 +225,8 @@ const router = useRouter();
|
||||
|
||||
// 选中项、切换方向、关闭逻辑、转屏、query 同步都在这里;资金流水没有内联编辑视图
|
||||
const { selectedId, paneDirection, isWide, openDetail } = useMasterDetailPane({
|
||||
path: "/management/fund-records",
|
||||
detail: id => `/management/fund-records/${id}`
|
||||
path: "/product/fund-records",
|
||||
detail: id => `/product/fund-records/${id}`
|
||||
});
|
||||
const userStore = useUserStore();
|
||||
const recordList = ref<FundRecord[]>([]);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</t-cell>
|
||||
<t-cell title="原状态" :note="getRecordStatusText(record)" />
|
||||
<t-cell
|
||||
title="销售订单详情"
|
||||
title="交易订单详情"
|
||||
:arrow="!!record.bizId && canReadSalesOrder"
|
||||
@click="toSalesOrder"
|
||||
/>
|
||||
@@ -198,7 +198,7 @@ async function toSalesOrder(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
path: `/management/sales-orders/${record.value.bizId}`,
|
||||
path: `/product/sales-orders/${record.value.bizId}`,
|
||||
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
|
||||
});
|
||||
}
|
||||
@@ -246,10 +246,10 @@ async function save(): Promise<void> {
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, record.value.bizId);
|
||||
Message.success("资金记录已冲正");
|
||||
if (record.value.bizId) {
|
||||
await router.replace(`/management/sales-orders/${record.value.bizId}`);
|
||||
await router.replace(`/product/sales-orders/${record.value.bizId}`);
|
||||
return;
|
||||
}
|
||||
await router.replace(`/management/fund-records/${result.id || record.value.id}`);
|
||||
await router.replace(`/product/fund-records/${result.id || record.value.id}`);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "资金冲正失败,请刷新后确认状态"));
|
||||
} finally {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar sales-order-cancel">
|
||||
<t-navbar fixed :z-index="20" title="取消销售订单" left-arrow @left-click="$router.back()">
|
||||
<t-navbar fixed :z-index="20" title="取消交易订单" left-arrow @left-click="exit">
|
||||
<template #right>
|
||||
<t-button
|
||||
v-if="userStore.hasPermissions(permissionCodes.salesOrder.cancel)"
|
||||
@@ -20,13 +20,13 @@
|
||||
visible
|
||||
content="请检查并处理该订单的履约和资金,勾选需要处理的记录后选择退货、退款或冲正。未勾选的记录会保留,所有处理均为可选。"
|
||||
/>
|
||||
<t-cell-group v-if="order" title="销售订单" theme="card" v-entrance-transition>
|
||||
<t-cell-group v-if="order" title="交易订单" theme="card" v-entrance-transition>
|
||||
<t-cell title="订单号" :note="order.orderNo || order.id" />
|
||||
<t-cell title="当前状态" :note="getSalesOrderStatusText(order.status)" />
|
||||
<t-cell title="有效收款" :note="`¥${formatPackageAmount(order.paidAmount)}`" />
|
||||
</t-cell-group>
|
||||
<t-form v-if="order" class="form card" label-width="6rem" v-entrance-transition>
|
||||
<t-form-item label="取消原因" required-mark>
|
||||
<t-form-item label="取消原因" content-align="right" required-mark>
|
||||
<div class="reason">
|
||||
<t-textarea v-model="reason" borderless autosize maxlength="500" placeholder="请输入取消原因" />
|
||||
<t-button size="extra-small" theme="primary" variant="outline" content="选择" @click="openCancelReasonPicker" />
|
||||
@@ -73,6 +73,7 @@
|
||||
<script setup lang="ts">
|
||||
import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { usePane } from "timi-tdesign-mobile";
|
||||
import SalesOrderAPI from "@/api/SalesOrderAPI";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
@@ -89,8 +90,18 @@ import FundCancelSection from "./component/FundCancelSection.vue";
|
||||
import { buildActionAttachmentList } from "./component/salesOrderCancelUtils";
|
||||
|
||||
defineOptions({ name: "SalesOrderCancel" });
|
||||
const props = withDefaults(defineProps<{ orderId?: string; embedded?: boolean }>(), { orderId: "", embedded: false });
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const pane = usePane();
|
||||
|
||||
function exit(): void {
|
||||
if (props.embedded && pane) {
|
||||
pane.close();
|
||||
return;
|
||||
}
|
||||
router.back();
|
||||
}
|
||||
const userStore = useUserStore();
|
||||
const order = ref<SalesOrder>();
|
||||
const loading = ref(false);
|
||||
@@ -175,7 +186,7 @@ async function validateActionData(): Promise<boolean> {
|
||||
}
|
||||
|
||||
async function loadData(): Promise<void> {
|
||||
const id = String(route.params.id || "");
|
||||
const id = props.orderId || String(route.params.id || "");
|
||||
const fulfillment = fulfillmentSection.value;
|
||||
const fund = fundSection.value;
|
||||
if (!id || !fulfillment || !fund) return;
|
||||
@@ -248,7 +259,11 @@ async function submitCancel(): Promise<void> {
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, order.value.id);
|
||||
emitListDataChanged(listDataEventKeys.productStockChanged);
|
||||
Message.success("订单已取消");
|
||||
await router.replace(`/management/sales-orders/${order.value.id}`);
|
||||
if (props.embedded && pane) {
|
||||
pane.close(true);
|
||||
return;
|
||||
}
|
||||
await router.replace(`/product/sales-orders/${order.value.id}`);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "订单取消失败,重试会复用同一请求号"));
|
||||
} finally {
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
v-model="item.quantity"
|
||||
size="large"
|
||||
:max="maxQuantity"
|
||||
:min="getQuantityStep(item)"
|
||||
:min="getSku(item)?.allowDecimalQuantity ? .001 : 1"
|
||||
:step="getQuantityStep(item)"
|
||||
:integer="!getSku(item)?.allowDecimalQuantity"
|
||||
theme="outline"
|
||||
@@ -586,10 +586,10 @@ async function submitOrder(): Promise<void> {
|
||||
});
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, result.id);
|
||||
emitListDataChanged(listDataEventKeys.productStockChanged);
|
||||
Message.success(fulfillAll.value ? "订单、收款及履约已完成" : paymentVerified.value ? "订单及已核销收款已完成" : receiveFullPayment.value ? "订单及全额收款已完成" : "销售订单已创建");
|
||||
await router.replace(`/management/sales-orders/${result.id}`);
|
||||
Message.success(fulfillAll.value ? "订单、收款及履约已完成" : paymentVerified.value ? "订单及已核销收款已完成" : receiveFullPayment.value ? "订单及全额收款已完成" : "交易订单已创建");
|
||||
await router.replace(`/product/sales-orders/${result.id}`);
|
||||
} catch (error) {
|
||||
const message = getErrorMessage(error, "销售订单创建失败,重试会复用同一请求号");
|
||||
const message = getErrorMessage(error, "交易订单创建失败,重试会复用同一请求号");
|
||||
Message.error(message);
|
||||
}
|
||||
finally { isSaving.value = false; }
|
||||
|
||||
@@ -1,231 +1,245 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar">
|
||||
<div class="tui-page-layout tui-navbar sales-order-detail">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="销售订单详情"
|
||||
title="交易订单详情"
|
||||
left-arrow
|
||||
@left-click="goBack"
|
||||
/>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div v-can="permissionCodes.salesOrder.read" class="sales-order-detail">
|
||||
<template v-if="order">
|
||||
<customer-profile-card
|
||||
v-if="order.customer"
|
||||
class="customer"
|
||||
:customer="order.customer"
|
||||
v-entrance-transition
|
||||
@click="toCustomerDetail"
|
||||
/>
|
||||
<section class="hero" v-entrance-transition>
|
||||
<div class="header">
|
||||
<span class="eyebrow">销售订单</span>
|
||||
<div class="tags">
|
||||
<t-tag :content="getSalesOrderTypeText(order.orderType)" theme="primary" variant="light-outline" />
|
||||
<t-tag :content="getSalesOrderStatusText(order.status)" variant="light-outline" :theme="getStatusTheme(order.status)" />
|
||||
</div>
|
||||
<main v-can="permissionCodes.salesOrder.read" class="tui-page-content scroll column">
|
||||
<template v-if="order">
|
||||
<customer-profile-card
|
||||
v-if="order.customer"
|
||||
class="customer"
|
||||
:customer="order.customer"
|
||||
v-entrance-transition
|
||||
@click="toCustomerDetail"
|
||||
/>
|
||||
<section class="hero" v-entrance-transition>
|
||||
<div class="header">
|
||||
<span class="eyebrow">交易订单</span>
|
||||
<div class="tags">
|
||||
<t-tag :content="getSalesOrderTypeText(order.orderType)" theme="primary" variant="light-outline" />
|
||||
<t-tag :content="getSalesOrderStatusText(order.status)" variant="light-outline" :theme="getStatusTheme(order.status)" />
|
||||
</div>
|
||||
<h1 class="no selectable" v-text="order.orderNo" />
|
||||
<div class="meta">
|
||||
<time-label class="time" :timestamp="order.purchasedAt" underline />
|
||||
<div class="amount red text-bold">
|
||||
<span>¥</span>
|
||||
<strong class="value" v-text="formatPackageAmount(order.saleAmount)" />
|
||||
</div>
|
||||
</div>
|
||||
<h1 class="no selectable" v-text="order.orderNo" />
|
||||
<div class="meta">
|
||||
<time-label class="time" :timestamp="order.purchasedAt" underline />
|
||||
<div class="amount red text-bold">
|
||||
<span>¥</span>
|
||||
<strong class="value" v-text="formatPackageAmount(order.saleAmount)" />
|
||||
</div>
|
||||
</section>
|
||||
<t-form class="info form card" title="订单信息" @submit="saveEdit" v-entrance-transition>
|
||||
<t-form-item v-if="order.sourceEventRecord?.id" label="来源登记记录" arrow @click="toEventRecord">
|
||||
<span>查看来源记录</span>
|
||||
</t-form-item>
|
||||
<t-form-item label="备注">
|
||||
<t-textarea v-if="isEditing" v-model.trim="editRemark" class="remark-editor" borderless autosize maxlength="500" placeholder="记录本单需要注意的内容" />
|
||||
<span v-else v-text="Text.display(order.remark)" />
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<div class="photo-wrap" v-entrance-transition>
|
||||
<attachment-selector :readonly="!isEditing"
|
||||
v-model:items="photoItems"
|
||||
:upload="isEditing ? uploadPhotoList : undefined"
|
||||
title="订单照片"
|
||||
/>
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item v-if="canUpdate" label-width="0">
|
||||
<div class="edit-actions">
|
||||
</div>
|
||||
</section>
|
||||
<t-form class="info form card" title="订单信息" @submit="saveEdit" v-entrance-transition>
|
||||
<t-form-item v-if="order.sourceEventRecord?.id" label="来源登记记录" arrow @click="toEventRecord">
|
||||
<span>查看来源记录</span>
|
||||
</t-form-item>
|
||||
<t-form-item label="备注">
|
||||
<t-textarea v-if="isEditing" v-model.trim="editRemark" class="remark-editor" borderless autosize maxlength="500" placeholder="记录本单需要注意的内容" />
|
||||
<span v-else v-text="Text.display(order.remark)" />
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<div class="photo-wrap" v-entrance-transition>
|
||||
<attachment-selector :readonly="!isEditing"
|
||||
v-model:items="photoItems"
|
||||
:upload="isEditing ? uploadPhotoList : undefined"
|
||||
title="订单照片"
|
||||
/>
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item v-if="canUpdate" label-width="0">
|
||||
<div class="edit-actions">
|
||||
<t-button
|
||||
v-if="!isEditing"
|
||||
type="button"
|
||||
size="extra-small"
|
||||
theme="primary"
|
||||
@click="toEdit"
|
||||
>编辑</t-button>
|
||||
<template v-else>
|
||||
<t-button
|
||||
v-if="!isEditing"
|
||||
type="button"
|
||||
size="extra-small"
|
||||
:disabled="isSaving"
|
||||
@click="cancelEdit"
|
||||
>取消</t-button>
|
||||
<t-button
|
||||
type="submit"
|
||||
theme="primary"
|
||||
@click="toEdit"
|
||||
>编辑</t-button>
|
||||
<template v-else>
|
||||
<t-button
|
||||
type="button"
|
||||
size="extra-small"
|
||||
:disabled="isSaving"
|
||||
@click="cancelEdit"
|
||||
>取消</t-button>
|
||||
<t-button
|
||||
type="submit"
|
||||
theme="primary"
|
||||
size="extra-small"
|
||||
:loading="isSaving"
|
||||
:disabled="isSaving"
|
||||
>保存</t-button>
|
||||
</template>
|
||||
</div>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<t-form
|
||||
v-if="order.itemList?.length"
|
||||
class="form card product"
|
||||
title="订单明细"
|
||||
theme="card"
|
||||
label-width="0"
|
||||
v-entrance-transition
|
||||
>
|
||||
<t-form-item class="form-item" v-for="item in order.itemList" :key="item.id">
|
||||
<div class="item">
|
||||
<div class="header">
|
||||
<div class="left">
|
||||
<t-image
|
||||
v-if="getProductPhotoURL(item)"
|
||||
:src="getProductPhotoURL(item)"
|
||||
:alt="item.productNameSnapshot || '产品图片'"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="avatar fallback"
|
||||
v-text="(item.productNameSnapshot || '产').slice(0, 1)"
|
||||
/>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="title">
|
||||
<div class="name-gift">
|
||||
<span class="name text-bold" v-text="item.productNameSnapshot || '未命名产品'" />
|
||||
<t-tag v-if="item.gifted" size="small" theme="success" content="赠送" />
|
||||
</div>
|
||||
<t-tag
|
||||
:content="getItemFulfillmentStatus(item).text"
|
||||
:theme="getItemFulfillmentStatus(item).theme"
|
||||
variant="light-outline"
|
||||
/>
|
||||
</div>
|
||||
<div class="description">
|
||||
<strong
|
||||
v-if="item.lineAmount !== null && item.lineAmount !== undefined"
|
||||
class="red"
|
||||
v-text="`¥${formatPackageAmount(item.lineAmount)}`"
|
||||
/>
|
||||
<t-tag v-else size="small" content="套餐权益" />
|
||||
<product-sku-tags
|
||||
:product-name="item.productNameSnapshot"
|
||||
:snapshot="item.skuSpecSnapshot"
|
||||
:fallback="item.specSummarySnapshot || item.skuNameSnapshot"
|
||||
:unit="item.unitSnapshot"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="metric">
|
||||
<strong v-text="getPackageQuantityText(item.quantity)" />
|
||||
<span>订单数量</span>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<strong :class="getAvailableQuantityClass(item)" v-text="getItemQuantityText(item, item.availableBaseQuantity)" />
|
||||
<span>可履约</span>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<strong :class="getAmountClass(Number(item.pendingBaseQuantity || 0), 'red')" v-text="getItemQuantityText(item, item.pendingBaseQuantity)" />
|
||||
<span>待核销</span>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<strong :class="getFulfilledQuantityClass(item)" v-text="getItemQuantityText(item, item.fulfilledBaseQuantity)" />
|
||||
<span>已履约</span>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<strong :class="getRemainingQuantityClass(item)" v-text="getItemQuantityText(item, item.remainingBaseQuantity)" />
|
||||
<span>剩余</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label="履约记录" arrow @click="toFulfillmentList">
|
||||
查看本单所有履约单
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<t-button
|
||||
v-if="canCreateFulfillment && canFulfillByPayment && order.status === 'ACTIVE'"
|
||||
class="cell-button"
|
||||
theme="primary"
|
||||
content="履约产品"
|
||||
@click="toCreateFulfillment"
|
||||
/>
|
||||
<t-cell-group class="finance-panel" title="资金摘要" theme="card">
|
||||
<t-cell title="成交金额">
|
||||
<template #note><span :class="getPaymentAmountClass(order.paymentStatus)" v-text="formatPackageAmount(order.saleAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="已生效收款">
|
||||
<template #note><span :class="getAmountClass(order.paidAmount, 'green')" v-text="formatPackageAmount(order.paidAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="待核销收款">
|
||||
<template #note><span :class="getAmountClass(order.pendingPaidAmount, 'orange')" v-text="formatPackageAmount(order.pendingPaidAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="剩余待收款">
|
||||
<template #note><span :class="getRemainingAmountClass(order.unpaidAmount)" v-text="formatPackageAmount(order.unpaidAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="有效退款">
|
||||
<template #note><span :class="getAmountClass(order.refundedAmount, 'red')" v-text="formatPackageAmount(order.refundedAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="收款状态" :note="getSalesPaymentStatusText(order.paymentStatus)" />
|
||||
<t-cell v-if="order.paymentStatus === 'PAID'" title="全额实收时间" :note="getPaidAtText(order.paidAt)" />
|
||||
<t-cell title="退款状态" :note="getSalesRefundStatusText(order.refundStatus)" />
|
||||
<t-cell
|
||||
v-if="canReadFund || canReadMyReceive"
|
||||
:title="canReadFund ? '查看全部资金流水' : '查看我的收款申请'"
|
||||
arrow
|
||||
@click="toFundRecords"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="order.status === 'CANCELLED'" class="cancel-info" title="取消记录" theme="card">
|
||||
<t-cell title="取消时间">
|
||||
<template #note>
|
||||
<time-label :timestamp="order.cancelledAt" underline />
|
||||
size="extra-small"
|
||||
:loading="isSaving"
|
||||
:disabled="isSaving"
|
||||
>保存</t-button>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="取消人" :note="order.cancelOperator?.nick || order.cancelOperator?.name || order.cancelOperatorUserId || '未知'" />
|
||||
<t-cell title="取消原因" :note="order.cancelReason || '未填写'" />
|
||||
</t-cell-group>
|
||||
<section class="actions" v-entrance-transition>
|
||||
<t-button
|
||||
v-if="canReceive"
|
||||
theme="primary"
|
||||
@click="toPayment"
|
||||
>登记收款</t-button>
|
||||
<t-button
|
||||
v-if="canRefund"
|
||||
theme="danger"
|
||||
@click="toRefund"
|
||||
>登记退款</t-button>
|
||||
<t-button
|
||||
v-if="canConfirmNoRefund"
|
||||
theme="default"
|
||||
@click="toNoRefund"
|
||||
>确认无需退款</t-button>
|
||||
<t-button
|
||||
v-if="canCancel"
|
||||
theme="danger"
|
||||
@click="toCancel"
|
||||
>取消订单</t-button>
|
||||
</section>
|
||||
</template>
|
||||
<t-empty v-else :description="loading ? '正在加载订单' : '订单不存在'" />
|
||||
</div>
|
||||
</div>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<t-form
|
||||
v-if="order.itemList?.length"
|
||||
class="form card product"
|
||||
title="订单明细"
|
||||
theme="card"
|
||||
label-width="0"
|
||||
v-entrance-transition
|
||||
>
|
||||
<t-form-item class="form-item" v-for="item in order.itemList" :key="item.id">
|
||||
<div class="item">
|
||||
<div class="header">
|
||||
<div class="left">
|
||||
<t-image
|
||||
v-if="getProductPhotoURL(item)"
|
||||
:src="getProductPhotoURL(item)"
|
||||
:alt="item.productNameSnapshot || '产品图片'"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="avatar fallback"
|
||||
v-text="(item.productNameSnapshot || '产').slice(0, 1)"
|
||||
/>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="title">
|
||||
<div class="name-gift">
|
||||
<span class="name text-bold" v-text="item.productNameSnapshot || '未命名产品'" />
|
||||
<t-tag v-if="item.gifted" size="small" theme="success" content="赠送" />
|
||||
</div>
|
||||
<t-tag
|
||||
:content="getItemFulfillmentStatus(item).text"
|
||||
:theme="getItemFulfillmentStatus(item).theme"
|
||||
variant="light-outline"
|
||||
/>
|
||||
</div>
|
||||
<div class="description">
|
||||
<strong
|
||||
v-if="item.lineAmount !== null && item.lineAmount !== undefined"
|
||||
class="red"
|
||||
v-text="`¥${formatPackageAmount(item.lineAmount)}`"
|
||||
/>
|
||||
<t-tag v-else size="small" content="套餐权益" />
|
||||
<product-sku-tags
|
||||
:product-name="item.productNameSnapshot"
|
||||
:snapshot="item.skuSpecSnapshot"
|
||||
:fallback="item.specSummarySnapshot || item.skuNameSnapshot"
|
||||
:unit="item.unitSnapshot"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="metric">
|
||||
<strong v-text="getPackageQuantityText(item.quantity)" />
|
||||
<span>订单数量</span>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<strong :class="getAvailableQuantityClass(item)" v-text="getItemQuantityText(item, item.availableBaseQuantity)" />
|
||||
<span>可履约</span>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<strong :class="getAmountClass(Number(item.pendingBaseQuantity || 0), 'red')" v-text="getItemQuantityText(item, item.pendingBaseQuantity)" />
|
||||
<span>待核销</span>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<strong :class="getFulfilledQuantityClass(item)" v-text="getItemQuantityText(item, item.fulfilledBaseQuantity)" />
|
||||
<span>已履约</span>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<strong :class="getRemainingQuantityClass(item)" v-text="getItemQuantityText(item, item.remainingBaseQuantity)" />
|
||||
<span>剩余</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label="履约记录" arrow @click="toFulfillmentList">
|
||||
查看本单所有履约单
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<t-button
|
||||
v-if="canCreateFulfillment && canFulfillByPayment && hasFulfillableItems && order.status === 'ACTIVE'"
|
||||
class="cell-button"
|
||||
theme="primary"
|
||||
content="履约产品"
|
||||
@click="toCreateFulfillment"
|
||||
/>
|
||||
<t-cell-group v-if="!isRecycleOrder" class="finance-panel" title="资金摘要" theme="card">
|
||||
<t-cell title="成交金额">
|
||||
<template #note><span :class="getPaymentAmountClass(order.paymentStatus)" v-text="formatPackageAmount(order.saleAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="已生效收款">
|
||||
<template #note><span :class="getAmountClass(order.paidAmount, 'green')" v-text="formatPackageAmount(order.paidAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="待核销收款">
|
||||
<template #note><span :class="getAmountClass(order.pendingPaidAmount, 'orange')" v-text="formatPackageAmount(order.pendingPaidAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="剩余待收款">
|
||||
<template #note><span :class="getRemainingAmountClass(order.unpaidAmount)" v-text="formatPackageAmount(order.unpaidAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="有效退款">
|
||||
<template #note><span :class="getAmountClass(order.refundedAmount, 'red')" v-text="formatPackageAmount(order.refundedAmount)" /></template>
|
||||
</t-cell>
|
||||
<t-cell title="收款状态" :note="getSalesPaymentStatusText(order.paymentStatus)" />
|
||||
<t-cell v-if="order.paymentStatus === 'PAID'" title="全额实收时间" :note="getPaidAtText(order.paidAt)" />
|
||||
<t-cell title="退款状态" :note="getSalesRefundStatusText(order.refundStatus)" />
|
||||
<t-cell
|
||||
v-if="canReadFund || canReadMyReceive"
|
||||
:title="canReadFund ? '查看全部资金流水' : '查看我的收款申请'"
|
||||
arrow
|
||||
@click="toFundRecords"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<!-- 兑换条款与支付明细在订单详情内展示 -->
|
||||
<recycle-exchange-panel
|
||||
v-if="isRecycleOrder && order.recycleExchangeId"
|
||||
ref="recyclePanel"
|
||||
:exchange-id="order.recycleExchangeId"
|
||||
:order="order"
|
||||
@changed="loadData"
|
||||
@open-rule="toRecycleRule"
|
||||
@open-payments="toRecyclePayments"
|
||||
/>
|
||||
<!-- 展示订单取消信息 -->
|
||||
<t-cell-group v-if="order.status === 'CANCELLED'" class="cancel-info" title="取消记录" theme="card">
|
||||
<t-cell title="取消时间">
|
||||
<template #note>
|
||||
<time-label :timestamp="order.cancelledAt" underline />
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="取消人" :note="order.cancelOperator?.nick || order.cancelOperator?.name || order.cancelOperatorUserId || '未知'" />
|
||||
<t-cell title="取消原因" :note="order.cancelReason || '未填写'" />
|
||||
</t-cell-group>
|
||||
<section class="actions" v-entrance-transition>
|
||||
<t-button
|
||||
v-if="order.status !== 'CANCELLED' && recyclePanel?.canRegister"
|
||||
theme="primary"
|
||||
@click="toRecycleRegister(order.recycleExchangeId || '')"
|
||||
>登记回收</t-button>
|
||||
<t-button
|
||||
v-if="canReceive"
|
||||
theme="primary"
|
||||
@click="toPayment"
|
||||
>登记收款</t-button>
|
||||
<t-button
|
||||
v-if="canRefund"
|
||||
theme="danger"
|
||||
@click="toRefund"
|
||||
>登记退款</t-button>
|
||||
<t-button
|
||||
v-if="canConfirmNoRefund"
|
||||
theme="default"
|
||||
@click="toNoRefund"
|
||||
>确认无需退款</t-button>
|
||||
<t-button
|
||||
v-if="canCancel"
|
||||
theme="danger"
|
||||
@click="toCancel"
|
||||
>取消订单</t-button>
|
||||
</section>
|
||||
</template>
|
||||
<t-empty v-else :description="loading ? '正在加载订单' : '订单不存在'" />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
@@ -237,8 +251,9 @@ import SalesOrderAPI from "@/api/SalesOrderAPI";
|
||||
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
import ProductSkuTags from "@/components/ProductSkuTags.vue";
|
||||
import RecycleExchangePanel from "@/pages/recycle/components/RecycleExchangePanel.vue";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import { convertPackageQuantity, formatPackageAmount, getPackageQuantityText } from "@/utils/package";
|
||||
import { comparePackageQuantity, convertPackageQuantity, formatPackageAmount, getPackageQuantityText } from "@/utils/package";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
|
||||
@@ -251,7 +266,7 @@ import {
|
||||
getStatusTheme
|
||||
} from "@/utils/salesOrder";
|
||||
import { Message } from "@/utils/message";
|
||||
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
|
||||
import { uploadPhotoList } from "@/utils/photo";
|
||||
|
||||
@@ -274,12 +289,22 @@ function resolveId(): string {
|
||||
|
||||
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
|
||||
useExpandToMaster({
|
||||
path: "/management/sales-orders",
|
||||
path: "/product/sales-orders",
|
||||
id: () => resolveId()
|
||||
});
|
||||
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||
const pane = usePane();
|
||||
|
||||
/**
|
||||
* 尝试在右栏压入一层子页(分栏的第三层)。
|
||||
*
|
||||
* 接不住时有三种情况:整页打开详情、窄屏、宿主列表没声明子页槽,
|
||||
* 此时返回 false,调用方退回整页跳转。
|
||||
*/
|
||||
function openSub(view: string): boolean {
|
||||
return pane?.openSub(view) ?? false;
|
||||
}
|
||||
|
||||
function goBack(): void {
|
||||
if (pane) {
|
||||
pane.close();
|
||||
@@ -295,17 +320,27 @@ const isEditing = ref(false);
|
||||
const isSaving = ref(false);
|
||||
const editRemark = ref("");
|
||||
const photoItems = ref<PhotoItem[]>([]);
|
||||
const recyclePanel = ref<InstanceType<typeof RecycleExchangePanel>>();
|
||||
const canReadFund = computed(() => userStore.hasPermissions(permissionCodes.fundRecord.read));
|
||||
const canReadMyReceive = computed(() => userStore.hasPermissions(permissionCodes.fundReceive.create));
|
||||
const canUpdate = computed(() => userStore.hasPermissions(permissionCodes.salesOrder.update));
|
||||
/** 回收兑换订单不产生资金流水,服务端也会拒绝,前端不再暴露收款入口 */
|
||||
const isRecycleOrder = computed(() => order.value?.orderType === "RECYCLE");
|
||||
/** 回收兑换订单的备注与照片由兑换单承载,服务端也会拒绝,前端不暴露编辑入口 */
|
||||
const canUpdate = computed(() => !isRecycleOrder.value && userStore.hasPermissions(permissionCodes.salesOrder.update));
|
||||
const canCreateFulfillment = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.create));
|
||||
const canReceive = computed(() => !!order.value && order.value.status !== "CANCELLED" && order.value.paymentStatus !== "PAID" && userStore.hasPermissions(permissionCodes.fundReceive.create));
|
||||
const hasFulfillableItems = computed(() => {
|
||||
const itemType = order.value?.orderType === "RECYCLE" ? "RECYCLE_ENTITLEMENT" : order.value?.orderType === "PACKAGE" ? "PACKAGE_ENTITLEMENT" : "DIRECT_PRODUCT";
|
||||
return (order.value?.itemList || []).some(item => item.itemType === itemType && 0 < comparePackageQuantity(item.availableBaseQuantity ?? "0", "0"));
|
||||
});
|
||||
const canReceive = computed(() => !!order.value && !isRecycleOrder.value && order.value.status !== "CANCELLED" && order.value.paymentStatus !== "PAID" && userStore.hasPermissions(permissionCodes.fundReceive.create));
|
||||
const canRefund = computed(() => !!order.value && order.value.status === "CANCELLED" && order.value.refundStatus === "PENDING" && userStore.hasPermissions(permissionCodes.fund.refund));
|
||||
const canConfirmNoRefund = computed(() => !!order.value && order.value.status === "CANCELLED" && order.value.refundStatus === "PENDING" && userStore.hasPermissions(permissionCodes.fund.refund));
|
||||
/** 订单和关联兑换单通过同一入口取消 */
|
||||
const canCancel = computed(() => !!order.value
|
||||
&& (order.value.status === "ACTIVE" || order.value.status === "FULFILLED")
|
||||
&& userStore.hasPermissions(permissionCodes.salesOrder.cancel));
|
||||
const canFulfillByPayment = computed(() => order.value?.paymentStatus === "PAID" || userStore.hasRoles(gaoRoleCodes.storeManager));
|
||||
/** 回收订单的「结清」由回收物支付驱动,paymentStatus 已同步,沿用同一判断 */
|
||||
const canFulfillByPayment = computed(() => order.value?.paymentStatus === "PAID" || userStore.hasPermissions(permissionCodes.orderFulfillment.unsettled));
|
||||
|
||||
function toPhotoItems(attachmentList?: readonly Partial<Attachment>[]): PhotoItem[] {
|
||||
return (attachmentList || [])
|
||||
@@ -420,6 +455,13 @@ async function loadData(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshAfterRecyclePayment(): Promise<void> {
|
||||
if (recyclePanel.value) await recyclePanel.value.reload();
|
||||
else await loadData();
|
||||
}
|
||||
|
||||
defineExpose({ refreshAfterRecyclePayment, refreshOrder: loadData });
|
||||
|
||||
function toEdit(): void {
|
||||
if (!order.value || !canUpdate.value) return;
|
||||
editRemark.value = order.value.remark || "";
|
||||
@@ -469,9 +511,31 @@ async function toEventRecord(): Promise<void> {
|
||||
if (order.value?.sourceEventRecord?.id) await router.push(`/management/registration-event-records/${order.value.sourceEventRecord.id}`);
|
||||
}
|
||||
|
||||
async function toRecycleRule(id: string): Promise<void> {
|
||||
// 分栏时换成「订单详情 + 兑换模板」,右栏换了内容,订单还留在主栏
|
||||
if (id && openSub(`recycle-rule:${id}`)) {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
name: "RecycleRuleDetail",
|
||||
params: { id },
|
||||
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
|
||||
});
|
||||
}
|
||||
|
||||
async function toRecyclePayments(id: string): Promise<void> {
|
||||
if (id && openSub(`recycle-payments:${id}`)) return;
|
||||
await router.push({ name: "RecyclePaymentList", params: { id } });
|
||||
}
|
||||
|
||||
async function toRecycleRegister(id: string): Promise<void> {
|
||||
if (!id || openSub(`recycle-register:${id}`)) return;
|
||||
await router.push({ name: "RecyclePaymentCreate", params: { id } });
|
||||
}
|
||||
|
||||
async function toFundRecords(): Promise<void> {
|
||||
if (order.value?.id) await router.push({
|
||||
path: "/management/fund-records",
|
||||
path: "/product/fund-records",
|
||||
query: {
|
||||
salesOrderId: order.value.id,
|
||||
transitionDepth: String(getCurrentRouteDepth() + 1)
|
||||
@@ -480,8 +544,14 @@ async function toFundRecords(): Promise<void> {
|
||||
}
|
||||
|
||||
async function toFulfillmentList(): Promise<void> {
|
||||
if (order.value?.id) await router.push({
|
||||
path: "/management/order-fulfillments",
|
||||
if (!order.value?.id) {
|
||||
return;
|
||||
}
|
||||
if (openSub("fulfillments")) {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
path: "/product/order-fulfillments",
|
||||
query: {
|
||||
salesOrderId: order.value.id,
|
||||
dateType: "all",
|
||||
@@ -491,8 +561,14 @@ async function toFulfillmentList(): Promise<void> {
|
||||
}
|
||||
|
||||
async function toCreateFulfillment(): Promise<void> {
|
||||
if (order.value?.id) await router.push({
|
||||
path: "/management/order-fulfillments/create",
|
||||
if (!order.value?.id) {
|
||||
return;
|
||||
}
|
||||
if (openSub("fulfillment-create")) {
|
||||
return;
|
||||
}
|
||||
await router.push({
|
||||
path: "/product/order-fulfillments/create",
|
||||
query: {
|
||||
salesOrderId: order.value.id,
|
||||
transitionDepth: String(getCurrentRouteDepth() + 1)
|
||||
@@ -501,19 +577,21 @@ async function toCreateFulfillment(): Promise<void> {
|
||||
}
|
||||
|
||||
async function toPayment(): Promise<void> {
|
||||
if (order.value?.id) await router.push(`/management/sales-orders/${order.value.id}/payment`);
|
||||
if (order.value?.id && openSub("payment")) return;
|
||||
if (order.value?.id) await router.push(`/product/sales-orders/${order.value.id}/payment`);
|
||||
}
|
||||
|
||||
async function toRefund(): Promise<void> {
|
||||
if (order.value?.id) await router.push(`/management/sales-orders/${order.value.id}/refund`);
|
||||
if (order.value?.id) await router.push(`/product/sales-orders/${order.value.id}/refund`);
|
||||
}
|
||||
|
||||
async function toNoRefund(): Promise<void> {
|
||||
if (order.value?.id) await router.push(`/management/sales-orders/${order.value.id}/no-refund`);
|
||||
if (order.value?.id) await router.push(`/product/sales-orders/${order.value.id}/no-refund`);
|
||||
}
|
||||
|
||||
async function toCancel(): Promise<void> {
|
||||
if (order.value?.id) await router.push(`/management/sales-orders/${order.value.id}/cancel`);
|
||||
if (!order.value?.id || openSub("cancel")) return;
|
||||
await router.push(`/product/sales-orders/${order.value.id}/cancel`);
|
||||
}
|
||||
|
||||
function getCurrentRouteDepth(): number {
|
||||
@@ -528,15 +606,18 @@ function getCurrentRouteDepth(): number {
|
||||
}
|
||||
|
||||
onMounted(loadData);
|
||||
onActivated(loadData);
|
||||
watch(() => [props.orderId, route.params.id], loadData);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.sales-order-detail {
|
||||
gap: 1rem;
|
||||
padding: 0 0 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.tips {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .8125rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.customer {
|
||||
margin: 0 1rem;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar sales-order-list">
|
||||
<t-navbar fixed :z-index="20" title="销售订单" left-arrow @left-click="$router.back()">
|
||||
<t-navbar fixed :z-index="20" title="交易订单" left-arrow @left-click="$router.back()">
|
||||
<template #right>
|
||||
<navbar-actions :actions="actions" :visible="route.name === 'SalesOrderList'" />
|
||||
</template>
|
||||
@@ -12,6 +12,7 @@
|
||||
:split="isWide"
|
||||
:selected="!!selectedId"
|
||||
:direction="paneDirection"
|
||||
:sub="!!subView"
|
||||
>
|
||||
<template #master>
|
||||
<t-pull-down-refresh
|
||||
@@ -87,7 +88,7 @@
|
||||
:can-fulfill="canCreateFulfillment"
|
||||
:can-cancel="canCancel"
|
||||
:can-refund="canRefund"
|
||||
:can-store-manager="canStoreManager"
|
||||
:can-fulfill-unsettled="canFulfillUnsettled"
|
||||
v-entrance-transition="{ step: 30 }"
|
||||
@click="toDetail(item)"
|
||||
@cancel="toCancel(item)"
|
||||
@@ -96,17 +97,63 @@
|
||||
@refund="toRefund(item)"
|
||||
@confirm-no-refund="toNoRefund(item)"
|
||||
/>
|
||||
<center-tips v-if="!list.length" :content="loading ? '正在加载销售订单' : '暂无销售订单'" />
|
||||
<center-tips v-if="!list.length" :content="loading ? '正在加载交易订单' : '暂无交易订单'" />
|
||||
</div>
|
||||
<center-tips :content="loading ? '正在加载' : noMore ? '已经到底了' : '上拉加载更多'" />
|
||||
</t-pull-down-refresh>
|
||||
</template>
|
||||
<template #detail>
|
||||
<sales-order-cancel v-if="directAction.kind === 'cancel'" :key="selectedId" :order-id="directAction.id" embedded />
|
||||
<sales-order-payment v-else-if="directAction.kind === 'payment'" :key="selectedId" :order-id="directAction.id" embedded />
|
||||
<order-fulfillment-create
|
||||
v-else-if="directAction.kind === 'fulfillment-create'"
|
||||
:key="selectedId"
|
||||
:sales-order-id="directAction.id"
|
||||
embedded
|
||||
@saved="handleFulfillmentSaved"
|
||||
/>
|
||||
<recycle-exchange-create
|
||||
v-else-if="selectedId === recycleCreatePaneId"
|
||||
@created="handleRecycleCreated"
|
||||
/>
|
||||
<sales-order-detail
|
||||
:key="`detail-${selectedId}`"
|
||||
v-else
|
||||
ref="salesOrderDetailRef"
|
||||
:key="`detail-${selectedId}-${detailVersion}`"
|
||||
:order-id="selectedId"
|
||||
/>
|
||||
</template>
|
||||
<!--
|
||||
第三层:订单详情跳到从属页面时,订单留在主栏、右栏换成这一层。
|
||||
子页标识由详情页的 openSub() 发起,格式 `kind:arg`。
|
||||
-->
|
||||
<template #sub>
|
||||
<recycle-rule-detail
|
||||
v-if="subKind === 'recycle-rule'"
|
||||
:key="`rule-${subArg}`"
|
||||
:rule-id="subArg"
|
||||
/>
|
||||
<order-fulfillment-list
|
||||
v-else-if="subKind === 'fulfillments'"
|
||||
key="fulfillments"
|
||||
:sales-order-id="selectedId"
|
||||
embedded
|
||||
/>
|
||||
<order-fulfillment-detail v-else-if="subKind === 'fulfillment-detail'" :fulfillment-id="subArg" />
|
||||
<order-fulfillment-create
|
||||
v-else-if="subKind === 'fulfillment-create'"
|
||||
key="fulfillment-create"
|
||||
:sales-order-id="selectedId"
|
||||
embedded
|
||||
@saved="handleFulfillmentSaved"
|
||||
/>
|
||||
<recycle-payment-list v-else-if="subKind === 'recycle-payments'" :exchange-id="subArg" />
|
||||
<recycle-payment-detail v-else-if="subKind === 'recycle-payment-detail'" :exchange-id="subArg" :payment-id="subView?.split(':')[2] || ''" @changed="refreshRecycleDetail" />
|
||||
<recycle-payment-revoke v-else-if="subKind === 'recycle-payment-revoke'" :exchange-id="subArg" :payment-id="subView?.split(':')[2] || ''" @changed="refreshRecycleDetail" />
|
||||
<recycle-payment-create v-else-if="subKind === 'recycle-register'" :exchange-id="subArg" embedded @saved="handleRecyclePaymentSaved" />
|
||||
<sales-order-cancel v-else-if="subKind === 'cancel'" :order-id="selectedId" embedded />
|
||||
<sales-order-payment v-else-if="subKind === 'payment'" :order-id="selectedId" embedded />
|
||||
</template>
|
||||
</master-detail-page>
|
||||
|
||||
<customer-selector
|
||||
@@ -127,6 +174,17 @@
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import { Toolkit } from "timi-web";
|
||||
import SalesOrderDetail from "@/pages/salesOrder/SalesOrderDetail.vue";
|
||||
import RecycleExchangeCreate from "@/pages/recycle/RecycleExchangeCreate.vue";
|
||||
import RecycleRuleDetail from "@/pages/recycle/RecycleRuleDetail.vue";
|
||||
import RecyclePaymentList from "@/pages/recycle/RecyclePaymentList.vue";
|
||||
import RecyclePaymentDetail from "@/pages/recycle/RecyclePaymentDetail.vue";
|
||||
import RecyclePaymentRevoke from "@/pages/recycle/RecyclePaymentRevoke.vue";
|
||||
import RecyclePaymentCreate from "@/pages/recycle/RecyclePaymentCreate.vue";
|
||||
import SalesOrderCancel from "@/pages/salesOrder/SalesOrderCancel.vue";
|
||||
import SalesOrderPayment from "@/pages/salesOrder/SalesOrderPayment.vue";
|
||||
import OrderFulfillmentCreate from "@/pages/fulfillment/OrderFulfillmentCreate.vue";
|
||||
import OrderFulfillmentDetail from "@/pages/fulfillment/OrderFulfillmentDetail.vue";
|
||||
import OrderFulfillmentList from "@/pages/fulfillment/OrderFulfillmentList.vue";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { onBeforeRouteLeave } from "vue-router";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
@@ -157,7 +215,7 @@ import { buildPresetDateRange, parseDateTime } from "@/utils/date";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { events, isCurrentStoreEvent, type ListDataChangedPayload, listDataEventKeys } from "@/utils/listDataEvents";
|
||||
import { Message } from "@/utils/message";
|
||||
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
|
||||
import SalesOrderFilterPopup from "@/pages/salesOrder/component/SalesOrderFilterPopup.vue";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
@@ -165,25 +223,81 @@ import type { Customer } from "@/types/Customer";
|
||||
defineOptions({ name: "SalesOrderList" });
|
||||
|
||||
|
||||
const SALES_ORDER_FILTER_STORAGE_KEY = "gao-customer-h5:sales-order-filter";
|
||||
// v2:类型筛选新增 RECYCLE,旧缓存里没有它,升版让旧条件失效
|
||||
const SALES_ORDER_FILTER_STORAGE_KEY = "gao-customer-h5:sales-order-filter:v2";
|
||||
const route = useRoute();
|
||||
|
||||
// 选中项、切换方向、关闭逻辑、转屏、query 同步都在这里;订单没有内联编辑视图
|
||||
const { selectedId, paneDirection, isWide, openDetail } = useMasterDetailPane({
|
||||
path: "/management/sales-orders",
|
||||
detail: id => `/management/sales-orders/${id}`
|
||||
const recycleCreatePaneId = "__recycle_create__";
|
||||
const { selectedId, subView, paneDirection, isWide, openDetail, detailVersion } = useMasterDetailPane({
|
||||
path: "/product/sales-orders",
|
||||
detail: id => {
|
||||
const [kind, orderId] = id.split(":");
|
||||
if (kind === "cancel" || kind === "payment") return `/product/sales-orders/${orderId}/${kind}`;
|
||||
if (kind === "fulfillment-create") return `/product/order-fulfillments/create?salesOrderId=${encodeURIComponent(orderId)}`;
|
||||
return id === recycleCreatePaneId
|
||||
? "/product/recycle-exchanges/create?source=sales-orders"
|
||||
: `/product/sales-orders/${id}`;
|
||||
}
|
||||
});
|
||||
|
||||
const directAction = computed(() => {
|
||||
const [kind, id] = (selectedId.value || "").split(":");
|
||||
return { kind, id: id || "" };
|
||||
});
|
||||
|
||||
/** 子页标识形如 `recycle-rule:698f`,冒号前是类型,后面是参数。 */
|
||||
const subKind = computed(() => subView.value?.split(":")[0] || "");
|
||||
const subArg = computed(() => subView.value?.split(":")[1] || "");
|
||||
watch(subView, (next, previous) => {
|
||||
if (previous?.startsWith("fulfillment-detail:") && next === "fulfillments") {
|
||||
paneDirection.value = "back";
|
||||
}
|
||||
if (previous?.startsWith("recycle-payment-detail:") && next?.startsWith("recycle-payments:")) {
|
||||
paneDirection.value = "back";
|
||||
}
|
||||
if (previous?.startsWith("recycle-payment-revoke:") && next?.startsWith("recycle-payment-detail:")) {
|
||||
paneDirection.value = "back";
|
||||
}
|
||||
});
|
||||
const router = useRouter();
|
||||
const salesOrderListRef = ref<ComponentPublicInstance | null>(null);
|
||||
const salesOrderDetailRef = ref<InstanceType<typeof SalesOrderDetail>>();
|
||||
|
||||
async function refreshRecycleDetail(): Promise<void> {
|
||||
await salesOrderDetailRef.value?.refreshAfterRecyclePayment();
|
||||
}
|
||||
|
||||
async function handleRecyclePaymentSaved(paymentId?: string): Promise<void> {
|
||||
const exchangeId = subArg.value;
|
||||
if (paymentId && exchangeId) {
|
||||
paneDirection.value = "forward";
|
||||
subView.value = `recycle-payment-detail:${exchangeId}:${paymentId}`;
|
||||
}
|
||||
await refreshRecycleDetail();
|
||||
}
|
||||
|
||||
async function handleFulfillmentSaved(fulfillmentId?: string): Promise<void> {
|
||||
if (directAction.value.kind === "fulfillment-create") {
|
||||
openDetail(directAction.value.id);
|
||||
return;
|
||||
}
|
||||
if (fulfillmentId) {
|
||||
paneDirection.value = "forward";
|
||||
subView.value = `fulfillment-detail:${fulfillmentId}`;
|
||||
}
|
||||
await salesOrderDetailRef.value?.refreshOrder();
|
||||
}
|
||||
const currentStoreStore = useCurrentStoreStore();
|
||||
const userStore = useUserStore();
|
||||
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.salesOrder.create));
|
||||
const canCreatePackageOrder = computed(() => userStore.hasPermissions(permissionCodes.customerPackage.create));
|
||||
const canCreateRecycleOrder = computed(() => userStore.hasPermissions(permissionCodes.salesOrder.create));
|
||||
const canReceive = computed(() => userStore.hasPermissions(permissionCodes.fundReceive.create));
|
||||
const canCreateFulfillment = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.create));
|
||||
const canCancel = computed(() => userStore.hasPermissions(permissionCodes.salesOrder.cancel));
|
||||
const canRefund = computed(() => userStore.hasPermissions(permissionCodes.fund.refund));
|
||||
const canStoreManager = computed(() => userStore.hasRoles(gaoRoleCodes.storeManager));
|
||||
const canFulfillUnsettled = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.unsettled));
|
||||
let savedPageScrollTop: number | undefined;
|
||||
let shouldReloadOnActivate = false;
|
||||
let eventRefreshPromise: Promise<void> | undefined;
|
||||
@@ -226,14 +340,21 @@ const actions = computed(() => [
|
||||
text: "创建产品订单",
|
||||
icon: "task",
|
||||
theme: "primary" as const,
|
||||
action: () => router.push("/management/sales-orders/create")
|
||||
action: () => router.push("/product/sales-orders/create")
|
||||
}] : []),
|
||||
...(canCreatePackageOrder.value ? [{
|
||||
key: "create-package-order",
|
||||
text: "创建套餐订单",
|
||||
icon: "layers",
|
||||
theme: "primary" as const,
|
||||
action: () => router.push("/management/customer-packages/create")
|
||||
action: () => router.push("/product/customer-packages/create")
|
||||
}] : []),
|
||||
...(canCreateRecycleOrder.value ? [{
|
||||
key: "create-recycle-order",
|
||||
text: "创建回收兑换订单",
|
||||
icon: "swap",
|
||||
theme: "primary" as const,
|
||||
action: () => openDetail(recycleCreatePaneId)
|
||||
}] : [])
|
||||
]);
|
||||
|
||||
@@ -257,7 +378,8 @@ const filterStorageKey = computed(() => `${SALES_ORDER_FILTER_STORAGE_KEY}:${cur
|
||||
let cachedPackageConfigId = "";
|
||||
const orderTypeOptions: Array<{ label: string; value: GaoSalesOrderType }> = [
|
||||
{ label: "套餐订单", value: "PACKAGE" },
|
||||
{ label: "产品订单", value: "DIRECT_PRODUCT" }
|
||||
{ label: "产品订单", value: "DIRECT_PRODUCT" },
|
||||
{ label: "回收兑换订单", value: "RECYCLE" }
|
||||
];
|
||||
const statusOptions: Array<{ label: string; value: GaoSalesOrderStatus }> = [
|
||||
{ label: "进行中", value: "ACTIVE" },
|
||||
@@ -266,9 +388,9 @@ const statusOptions: Array<{ label: string; value: GaoSalesOrderStatus }> = [
|
||||
];
|
||||
const paymentOptions: Array<{ label: string; value: SalesOrderPaymentFilter }> = [
|
||||
{ label: "未收清", value: "PENDING_RECEIVE" },
|
||||
{ label: "未收款", value: "UNPAID" },
|
||||
{ label: "部分收款", value: "PARTIALLY_PAID" },
|
||||
{ label: "已收款", value: "PAID" }
|
||||
{ label: "未结清", value: "UNPAID" },
|
||||
{ label: "部分结清", value: "PARTIALLY_PAID" },
|
||||
{ label: "已结清", value: "PAID" }
|
||||
];
|
||||
const paymentStatusValues: GaoSalesPaymentStatus[] = ["UNPAID", "PARTIALLY_PAID", "PAID"];
|
||||
const refundOptions: Array<{ label: string; value: GaoSalesRefundStatus }> = [
|
||||
@@ -548,7 +670,7 @@ function startEventRefresh(): void {
|
||||
return;
|
||||
}
|
||||
eventRefreshPromise = reloadList(true)
|
||||
.catch(error => Message.error(getErrorMessage(error, "销售订单加载失败")))
|
||||
.catch(error => Message.error(getErrorMessage(error, "交易订单加载失败")))
|
||||
.finally(() => {
|
||||
eventRefreshPromise = undefined;
|
||||
if (!isDisposed && hasPendingEventRefresh) {
|
||||
@@ -573,7 +695,7 @@ async function refresh(): Promise<void> {
|
||||
try {
|
||||
await reloadList();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "销售订单加载失败"));
|
||||
Message.error(getErrorMessage(error, "交易订单加载失败"));
|
||||
} finally {
|
||||
refreshing.value = false;
|
||||
}
|
||||
@@ -583,7 +705,7 @@ async function loadMore(): Promise<void> {
|
||||
try {
|
||||
await fetchList(false);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "销售订单加载失败"));
|
||||
Message.error(getErrorMessage(error, "交易订单加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,7 +730,7 @@ async function confirmFilter(value: SalesOrderListFilter, resetCustomer = false)
|
||||
await reloadList();
|
||||
}
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "销售订单加载失败"));
|
||||
Message.error(getErrorMessage(error, "交易订单加载失败"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,31 +751,44 @@ async function toDetail(item: SalesOrder): Promise<void> {
|
||||
openDetail(item.id || "");
|
||||
}
|
||||
|
||||
function handleRecycleCreated(orderId: string): void {
|
||||
openDetail(orderId);
|
||||
}
|
||||
|
||||
function openOrderAction(item: SalesOrder, view: string): boolean {
|
||||
if (!isWide.value || !item.id) return false;
|
||||
openDetail(`${view}:${item.id}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
async function toPayment(item: SalesOrder): Promise<void> {
|
||||
if (item.id) await router.push(`/management/sales-orders/${item.id}/payment`);
|
||||
if (openOrderAction(item, "payment")) return;
|
||||
if (item.id) await router.push(`/product/sales-orders/${item.id}/payment`);
|
||||
}
|
||||
|
||||
async function toCancel(item: SalesOrder): Promise<void> {
|
||||
if (item.id) await router.push(`/management/sales-orders/${item.id}/cancel`);
|
||||
if (openOrderAction(item, "cancel")) return;
|
||||
if (item.id) await router.push(`/product/sales-orders/${item.id}/cancel`);
|
||||
}
|
||||
|
||||
async function toRefund(item: SalesOrder): Promise<void> {
|
||||
if (item.id) await router.push(`/management/sales-orders/${item.id}/refund`);
|
||||
if (item.id) await router.push(`/product/sales-orders/${item.id}/refund`);
|
||||
}
|
||||
|
||||
async function toNoRefund(item: SalesOrder): Promise<void> {
|
||||
if (item.id) await router.push(`/management/sales-orders/${item.id}/no-refund`);
|
||||
if (item.id) await router.push(`/product/sales-orders/${item.id}/no-refund`);
|
||||
}
|
||||
|
||||
async function toFulfillment(item: SalesOrder): Promise<void> {
|
||||
if (item.id) await router.push({ path: "/management/order-fulfillments/create", query: { salesOrderId: item.id } });
|
||||
if (openOrderAction(item, "fulfillment-create")) return;
|
||||
if (item.id) await router.push({ path: "/product/order-fulfillments/create", query: { salesOrderId: item.id } });
|
||||
}
|
||||
|
||||
const search = Toolkit.debounce(async () => {
|
||||
try {
|
||||
await fetchList(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "销售订单加载失败"));
|
||||
Message.error(getErrorMessage(error, "交易订单加载失败"));
|
||||
}
|
||||
}, false);
|
||||
|
||||
@@ -679,7 +814,7 @@ watch(keyword, async () => {
|
||||
try {
|
||||
await fetchList(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "销售订单加载失败"));
|
||||
Message.error(getErrorMessage(error, "交易订单加载失败"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -727,7 +862,7 @@ onMounted(async () => {
|
||||
await fetchList(true);
|
||||
initialized = true;
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "销售订单加载失败"));
|
||||
Message.error(getErrorMessage(error, "交易订单加载失败"));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -742,7 +877,7 @@ onActivated(async () => {
|
||||
await loadRoutePackage();
|
||||
await fetchList(true);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "销售订单加载失败"));
|
||||
Message.error(getErrorMessage(error, "交易订单加载失败"));
|
||||
}
|
||||
} else {
|
||||
restorePageScrollPosition();
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</t-navbar>
|
||||
<main class="tui-page-content scroll column">
|
||||
<div v-can="permissionCodes.fund.refund" class="sales-order-operation">
|
||||
<t-cell-group v-if="order" title="销售订单" theme="card" v-entrance-transition>
|
||||
<t-cell-group v-if="order" title="交易订单" theme="card" v-entrance-transition>
|
||||
<t-cell title="订单号" :note="order.orderNo || order.id" />
|
||||
<t-cell title="当前退款状态" :note="getSalesRefundStatusText(order.refundStatus)" />
|
||||
</t-cell-group>
|
||||
@@ -127,7 +127,7 @@ async function save(): Promise<void> {
|
||||
await SalesOrderAPI.confirmNoRefund({ salesOrderId: order.value.id, reason: reason.value.trim() });
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, order.value.id);
|
||||
Message.success("已确认无需退款");
|
||||
await router.replace(`/management/sales-orders/${order.value.id}`);
|
||||
await router.replace(`/product/sales-orders/${order.value.id}`);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "确认失败,请刷新后重试"));
|
||||
} finally {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
:z-index="20"
|
||||
title="登记收款"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
@left-click="exit"
|
||||
>
|
||||
<template #right>
|
||||
<t-button
|
||||
@@ -21,7 +21,7 @@
|
||||
<main class="tui-page-content scroll column">
|
||||
<t-cell-group
|
||||
v-if="order"
|
||||
title="销售订单"
|
||||
title="交易订单"
|
||||
theme="card"
|
||||
v-entrance-transition
|
||||
>
|
||||
@@ -90,6 +90,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { usePane } from "timi-tdesign-mobile";
|
||||
import DateTimeNowPicker from "@/components/DateTimeNowPicker.vue";
|
||||
import { useUserStore, type Attachment } from "timi-web-api";
|
||||
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||
@@ -109,6 +110,8 @@ import { uploadPhotoList } from "@/utils/photo";
|
||||
import type { SalesOrder } from "@/types/SalesOrder";
|
||||
|
||||
defineOptions({ name: "SalesOrderPayment" });
|
||||
const props = withDefaults(defineProps<{ orderId?: string; embedded?: boolean }>(), { orderId: "", embedded: false });
|
||||
const pane = usePane();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
@@ -125,6 +128,14 @@ const canDirectVerify = computed(() => userStore.hasRoles(gaoRoleCodes.storeMana
|
||||
&& userStore.hasPermissions(permissionCodes.fundReceive.create)
|
||||
&& userStore.hasPermissions(permissionCodes.fundReceive.verify));
|
||||
|
||||
function exit(): void {
|
||||
if (props.embedded && pane) {
|
||||
pane.close();
|
||||
return;
|
||||
}
|
||||
router.back();
|
||||
}
|
||||
|
||||
function fillUnpaidAmount(): void {
|
||||
amountText.value = formatPackageAmountInput(order.value?.unpaidAmount);
|
||||
}
|
||||
@@ -143,7 +154,7 @@ function buildAttachments(): Partial<Attachment>[] {
|
||||
}
|
||||
|
||||
async function loadData(): Promise<void> {
|
||||
const id = String(route.params.id || "");
|
||||
const id = props.orderId || String(route.params.id || "");
|
||||
if (!id) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
@@ -187,9 +198,13 @@ async function save(): Promise<void> {
|
||||
: await SalesOrderAPI.receivePayment(request);
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, order.value.id);
|
||||
Message.success(directVerify.value ? "收款登记并核销成功" : "收款登记已提交");
|
||||
if (props.embedded && pane) {
|
||||
pane.close(true);
|
||||
return;
|
||||
}
|
||||
await router.replace(record.id && userStore.hasPermissions(permissionCodes.fundReceive.create)
|
||||
? `/management/fund-records/${record.id}`
|
||||
: `/management/sales-orders/${order.value.id}`);
|
||||
? `/product/fund-records/${record.id}`
|
||||
: `/product/sales-orders/${order.value.id}`);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "收款登记失败,重试会复用同一请求号"));
|
||||
} finally {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<div v-can="permissionCodes.fund.refund" class="sales-order-operation">
|
||||
<t-cell-group
|
||||
v-if="order"
|
||||
title="销售订单"
|
||||
title="交易订单"
|
||||
theme="card"
|
||||
v-entrance-transition
|
||||
>
|
||||
@@ -221,7 +221,7 @@ async function save(): Promise<void> {
|
||||
});
|
||||
emitListDataChanged(listDataEventKeys.salesOrderChanged, order.value.id);
|
||||
Message.success("退款登记已提交");
|
||||
await router.replace(`/management/sales-orders/${order.value.id}`);
|
||||
await router.replace(`/product/sales-orders/${order.value.id}`);
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "退款登记失败,重试会复用同一请求号"));
|
||||
} finally {
|
||||
|
||||
@@ -114,7 +114,8 @@ const endDraft = ref("");
|
||||
let resetRequested = false;
|
||||
const orderTypeOptions: Array<{ label: string; value: GaoSalesOrderType }> = [
|
||||
{ label: "套餐订单", value: "PACKAGE" },
|
||||
{ label: "产品订单", value: "DIRECT_PRODUCT" }
|
||||
{ label: "产品订单", value: "DIRECT_PRODUCT" },
|
||||
{ label: "回收兑换订单", value: "RECYCLE" }
|
||||
];
|
||||
const statusOptions: Array<{ label: string; value: GaoSalesOrderStatus }> = [
|
||||
{ label: "进行中", value: "ACTIVE" },
|
||||
@@ -123,10 +124,11 @@ const statusOptions: Array<{ label: string; value: GaoSalesOrderStatus }> = [
|
||||
];
|
||||
|
||||
const paymentOptions: Array<{ label: string; value: SalesOrderPaymentFilter }> = [
|
||||
{ label: "已收款", value: "PAID" },
|
||||
{ label: "部分收款", value: "PARTIALLY_PAID" },
|
||||
{ label: "未收清", value: "PENDING_RECEIVE" },
|
||||
{ label: "未收款", value: "UNPAID" }
|
||||
// 交易订单里既有现金单也有回收单,统一用结清口径
|
||||
{ label: "已结清", value: "PAID" },
|
||||
{ label: "部分结清", value: "PARTIALLY_PAID" },
|
||||
{ label: "待结清", value: "PENDING_RECEIVE" },
|
||||
{ label: "未结清", value: "UNPAID" }
|
||||
];
|
||||
const refundOptions: Array<{ label: string; value: GaoSalesRefundStatus }> = [
|
||||
{ label: "无需退款", value: "NOT_REQUIRED" },
|
||||
@@ -168,7 +170,7 @@ const filterGroups = computed<FilterGroup[]>(() => [
|
||||
},
|
||||
{
|
||||
key: "paymentStatusList",
|
||||
title: "收款状态",
|
||||
title: "结清状态",
|
||||
options: paymentOptions,
|
||||
multiple: true,
|
||||
columns: 2,
|
||||
@@ -187,10 +189,10 @@ const visibleFilterGroups = computed(() => props.filterKey
|
||||
: filterGroups.value);
|
||||
const popupTitle = computed(() => {
|
||||
if (!props.filterKey) {
|
||||
return "筛选销售订单";
|
||||
return "筛选交易订单";
|
||||
}
|
||||
const group = visibleFilterGroups.value[0];
|
||||
return group ? `筛选${group.title}` : "筛选销售订单";
|
||||
return group ? `筛选${group.title}` : "筛选交易订单";
|
||||
});
|
||||
const filterModel = computed<FilterModel>(() => ({
|
||||
date: [draftFilter.value.dateFilterType],
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="资金条件" class="cell roll-note" arrow @click="openFilterPopup('paymentStatusList')">
|
||||
<t-cell title="结清条件" class="cell roll-note" arrow @click="openFilterPopup('paymentStatusList')">
|
||||
<template #note>
|
||||
<div class="tags">
|
||||
<t-tag
|
||||
@@ -52,20 +52,6 @@
|
||||
variant="light-outline"
|
||||
:content="item"
|
||||
/>
|
||||
<t-tag
|
||||
v-for="item in selectedPaymentTags"
|
||||
:key="item"
|
||||
theme="primary"
|
||||
variant="light-outline"
|
||||
:content="item"
|
||||
/>
|
||||
<t-tag
|
||||
v-for="item in selectedPaymentTags"
|
||||
:key="item"
|
||||
theme="primary"
|
||||
variant="light-outline"
|
||||
:content="item"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
@@ -122,7 +108,8 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
const orderTypeOptions: Array<{ label: string; value: GaoSalesOrderType }> = [
|
||||
{ label: "套餐订单", value: "PACKAGE" },
|
||||
{ label: "产品订单", value: "DIRECT_PRODUCT" }
|
||||
{ label: "产品订单", value: "DIRECT_PRODUCT" },
|
||||
{ label: "回收兑换订单", value: "RECYCLE" }
|
||||
];
|
||||
const statusOptions: Array<{ label: string; value: GaoSalesOrderStatus }> = [
|
||||
{ label: "进行中", value: "ACTIVE" },
|
||||
@@ -131,9 +118,9 @@ const statusOptions: Array<{ label: string; value: GaoSalesOrderStatus }> = [
|
||||
];
|
||||
const paymentOptions: Array<{ label: string; value: SalesOrderPaymentFilter }> = [
|
||||
{ label: "未收清", value: "PENDING_RECEIVE" },
|
||||
{ label: "未收款", value: "UNPAID" },
|
||||
{ label: "部分收款", value: "PARTIALLY_PAID" },
|
||||
{ label: "已收款", value: "PAID" }
|
||||
{ label: "未结清", value: "UNPAID" },
|
||||
{ label: "部分结清", value: "PARTIALLY_PAID" },
|
||||
{ label: "已结清", value: "PAID" }
|
||||
];
|
||||
const refundOptions: Array<{ label: string; value: GaoSalesRefundStatus }> = [
|
||||
{ label: "无需退款", value: "NOT_REQUIRED" },
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
/>
|
||||
<t-tag
|
||||
v-else
|
||||
:content="getSalesPaymentStatusText(props.order.paymentStatus)"
|
||||
:content="paymentStatusText"
|
||||
:theme="getPaymentStatusTheme(props.order.paymentStatus)"
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
@@ -65,7 +65,18 @@
|
||||
<t-divider />
|
||||
<div class="time-payment">
|
||||
<time-label class="time gray" :timestamp="props.order.purchasedAt" underline />
|
||||
<div class="amount">
|
||||
<!-- 回收订单展示约定支付的回收物 -->
|
||||
<div v-if="isRecycle" class="amount recycle">
|
||||
<t-tag
|
||||
class="name"
|
||||
size="small"
|
||||
theme="primary"
|
||||
variant="light-outline"
|
||||
:content="props.order.recycleItemName || '未命名回收物'"
|
||||
/>
|
||||
<strong class="value red" v-text="recycleRequiredText" />
|
||||
</div>
|
||||
<div v-else class="amount">
|
||||
<span class="red">¥</span>
|
||||
<strong class="value red" v-text="formatPackageAmount(props.order.saleAmount)" />
|
||||
</div>
|
||||
@@ -143,7 +154,8 @@ import { TimeLabel } from "timi-web";
|
||||
import type { GaoSalesPaymentStatus, SalesOrder } from "@/types/SalesOrder";
|
||||
import { getCustomerPhotoURL } from "@/utils/customer";
|
||||
import { comparePackageQuantity, formatPackageAmount, getPackageQuantityText } from "@/utils/package";
|
||||
import { getSalesOrderStatusText, getSalesOrderTypeText, getSalesPaymentStatusText, getStatusTheme } from "@/utils/salesOrder";
|
||||
import { getOrderSettlementText, getSalesOrderStatusText, getSalesOrderTypeText, getStatusTheme } from "@/utils/salesOrder";
|
||||
import { getRecycleQuantityText } from "@/utils/recycle";
|
||||
import { getProductSkuSnapshotText } from "@/utils/product";
|
||||
|
||||
defineOptions({ name: "SalesOrderListCell" });
|
||||
@@ -155,7 +167,7 @@ const props = defineProps<{
|
||||
canFulfill: boolean;
|
||||
canCancel: boolean;
|
||||
canRefund: boolean;
|
||||
canStoreManager: boolean;
|
||||
canFulfillUnsettled: boolean;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
click: [];
|
||||
@@ -170,6 +182,11 @@ const itemList = computed(() => props.order.itemList || []);
|
||||
const displayItemList = computed(() => props.fulfillableSkuId
|
||||
? itemList.value.filter(item => item.skuId === props.fulfillableSkuId && 0 < comparePackageQuantity(item.availableBaseQuantity ?? "0", "0"))
|
||||
: itemList.value);
|
||||
const isRecycle = computed(() => props.order.orderType === "RECYCLE");
|
||||
/** 交易订单统一用结清口径:回收单由回收物支付驱动,现金单由收款驱动 */
|
||||
const paymentStatusText = computed(() => getOrderSettlementText(props.order.paymentStatus));
|
||||
const recycleRequired = computed(() => Number(props.order.recycleRequiredQuantity ?? 0));
|
||||
const recycleRequiredText = computed(() => getRecycleQuantityText(recycleRequired.value.toFixed(3), props.order.recycleUnit || ""));
|
||||
const customerName = computed(() => props.order.customer?.name || props.order.customer?.code || props.order.customerId || "未知客户");
|
||||
const avatarText = computed(() => customerName.value.slice(0, 1) || "客");
|
||||
const photoURL = computed(() => getCustomerPhotoURL(props.order.customer, 64));
|
||||
@@ -180,9 +197,10 @@ const isCancelled = computed(() => props.order.status === "CANCELLED");
|
||||
const isCancelledPendingRefund = computed(() => isCancelled.value && props.order.refundStatus === "PENDING");
|
||||
const showRefundActions = computed(() => props.canRefund && isCancelledPendingRefund.value);
|
||||
const showMoreActionMenu = computed(() => props.canCancel || showRefundActions.value);
|
||||
const showReceiveAction = computed(() => props.canReceive && !isCancelled.value && props.order.paymentStatus !== "PAID");
|
||||
// 回收订单只能登记回收物支付,资金收款会被服务端拒绝
|
||||
const showReceiveAction = computed(() => props.canReceive && !isRecycle.value && !isCancelled.value && props.order.paymentStatus !== "PAID");
|
||||
const canCancelOrder = computed(() => props.order.status === "ACTIVE" || props.order.status === "FULFILLED");
|
||||
const canFulfillByPayment = computed(() => props.order.paymentStatus === "PAID" || props.canStoreManager);
|
||||
const canFulfillByPayment = computed(() => props.order.paymentStatus === "PAID" || props.canFulfillUnsettled);
|
||||
const showFulfillAction = computed(() => props.canFulfill && canFulfillByPayment.value && props.order.status === "ACTIVE");
|
||||
|
||||
function handleCancel(): void {
|
||||
@@ -360,6 +378,15 @@ function getProductText(item: NonNullable<SalesOrder["itemList"]>[number]): stri
|
||||
align-items: baseline;
|
||||
justify-content: end;
|
||||
|
||||
&.recycle {
|
||||
gap: .25rem;
|
||||
align-items: center;
|
||||
|
||||
.name {
|
||||
margin-top: .25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 1.5rem;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -111,41 +111,41 @@ const entryGroupList: HomeEntryGroup[] = [
|
||||
title: "订单管理",
|
||||
entryList: [
|
||||
{
|
||||
path: "/management/sales-orders/create",
|
||||
path: "/product/sales-orders/create",
|
||||
permission: permissionCodes.salesOrder.create,
|
||||
icon: "task-add",
|
||||
title: "创建产品订单"
|
||||
},
|
||||
{
|
||||
path: "/management/customer-packages/create",
|
||||
path: "/product/customer-packages/create",
|
||||
permission: permissionCodes.customerPackage.create,
|
||||
icon: "layers",
|
||||
title: "创建套餐订单"
|
||||
},
|
||||
{
|
||||
path: "/management/order-fulfillments/quick",
|
||||
path: "/product/order-fulfillments/quick",
|
||||
permission: permissionCodes.orderFulfillment.create,
|
||||
icon: "undertake-delivery",
|
||||
title: "快速履约",
|
||||
quick: true
|
||||
},
|
||||
{
|
||||
path: "/management/sales-orders",
|
||||
path: "/product/sales-orders",
|
||||
permission: permissionCodes.salesOrder.read,
|
||||
icon: "task",
|
||||
title: "销售订单"
|
||||
title: "交易订单"
|
||||
},
|
||||
{
|
||||
path: "/management/points/redemptions",
|
||||
path: "/product/points/redemptions",
|
||||
permission: permissionCodes.pointRedemption.create,
|
||||
icon: "gift",
|
||||
title: "积分兑换"
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-exchanges",
|
||||
permission: permissionCodes.recycleExchange.query,
|
||||
path: "/product/recycle-exchanges/create",
|
||||
permission: permissionCodes.salesOrder.create,
|
||||
icon: "swap",
|
||||
title: "回收兑换"
|
||||
title: "创建回收兑换单"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -64,25 +64,25 @@ const menuGroupList = computed<MenuGroup[]>(() => [
|
||||
items: [
|
||||
{
|
||||
icon: "catalog",
|
||||
path: "/management/product-categories",
|
||||
path: "/product/product-categories",
|
||||
title: "产品分类",
|
||||
visible: userStore.hasPermissions(permissionCodes.productCategory.read)
|
||||
},
|
||||
{
|
||||
icon: "control-platform",
|
||||
path: "/management/products",
|
||||
path: "/product/products",
|
||||
title: "产品库",
|
||||
visible: userStore.hasPermissions(permissionCodes.product.read)
|
||||
},
|
||||
{
|
||||
icon: "wallet",
|
||||
path: "/management/product-stocks",
|
||||
path: "/product/product-stocks",
|
||||
title: "库存",
|
||||
visible: userStore.hasPermissions(permissionCodes.productStock.read)
|
||||
},
|
||||
{
|
||||
icon: "history",
|
||||
path: "/management/product-stock-records",
|
||||
path: "/product/product-stock-records",
|
||||
title: "库存流水",
|
||||
visible: userStore.hasPermissions(permissionCodes.productStock.read)
|
||||
}
|
||||
@@ -92,25 +92,25 @@ const menuGroupList = computed<MenuGroup[]>(() => [
|
||||
items: [
|
||||
{
|
||||
icon: "task",
|
||||
path: "/management/sales-orders",
|
||||
title: "销售订单",
|
||||
path: "/product/sales-orders",
|
||||
title: "交易订单",
|
||||
visible: userStore.hasPermissions(permissionCodes.salesOrder.read)
|
||||
},
|
||||
{
|
||||
icon: "wallet",
|
||||
path: "/management/fund-records",
|
||||
path: "/product/fund-records",
|
||||
title: "资金流水",
|
||||
visible: userStore.hasPermissions(permissionCodes.fundRecord.read)
|
||||
},
|
||||
{
|
||||
icon: "undertake-delivery",
|
||||
path: "/management/order-fulfillments",
|
||||
path: "/product/order-fulfillments",
|
||||
title: "履约记录",
|
||||
visible: userStore.hasPermissions(permissionCodes.orderFulfillment.read)
|
||||
},
|
||||
{
|
||||
icon: "money",
|
||||
path: "/management/consumption-records",
|
||||
path: "/product/consumption-records",
|
||||
title: "消费记录",
|
||||
visible: userStore.hasPermissions(permissionCodes.salesOrder.read)
|
||||
}
|
||||
@@ -120,13 +120,13 @@ const menuGroupList = computed<MenuGroup[]>(() => [
|
||||
items: [
|
||||
{
|
||||
icon: "layers",
|
||||
path: "/management/package-configs",
|
||||
path: "/product/package-configs",
|
||||
title: "套餐配置",
|
||||
visible: userStore.hasPermissions(permissionCodes.packageConfig.read)
|
||||
},
|
||||
{
|
||||
icon: "task",
|
||||
path: "/management/package-orders",
|
||||
path: "/product/package-orders",
|
||||
title: "套餐订单",
|
||||
visible: userStore.hasPermissions(permissionCodes.packageConfig.read)
|
||||
&& userStore.hasPermissions(permissionCodes.salesOrder.read)
|
||||
@@ -137,13 +137,13 @@ const menuGroupList = computed<MenuGroup[]>(() => [
|
||||
items: [
|
||||
{
|
||||
icon: "cart",
|
||||
path: "/management/points/redeem-skus",
|
||||
path: "/product/points/redeem-skus",
|
||||
title: "兑换商品",
|
||||
visible: userStore.hasPermissions(permissionCodes.pointRedeemSku.manage)
|
||||
},
|
||||
{
|
||||
icon: "gift",
|
||||
path: "/management/points/redemptions",
|
||||
path: "/product/points/redemptions",
|
||||
title: "积分兑换",
|
||||
visible: userStore.hasPermissions(permissionCodes.pointRedemption.create)
|
||||
}
|
||||
@@ -152,22 +152,28 @@ const menuGroupList = computed<MenuGroup[]>(() => [
|
||||
{
|
||||
items: [
|
||||
{
|
||||
icon: "swap",
|
||||
path: "/management/recycle-exchanges",
|
||||
title: "回收兑换",
|
||||
visible: userStore.hasPermissions(permissionCodes.recycleExchange.query)
|
||||
icon: "layers",
|
||||
path: "/product/recycle-items",
|
||||
title: "回收物",
|
||||
visible: userStore.hasPermissions(permissionCodes.recycleExchange.configManage)
|
||||
},
|
||||
{
|
||||
icon: "history",
|
||||
path: "/product/recycle-payments",
|
||||
title: "回收流水",
|
||||
visible: userStore.hasPermissions(permissionCodes.fundRecord.read)
|
||||
},
|
||||
{
|
||||
icon: "setting",
|
||||
path: "/management/recycle-items",
|
||||
title: "回收配置",
|
||||
path: "/product/recycle-rules",
|
||||
title: "兑换模板",
|
||||
visible: userStore.hasPermissions(permissionCodes.recycleExchange.configManage)
|
||||
},
|
||||
{
|
||||
icon: "chart-combo",
|
||||
path: "/management/recycle-stats",
|
||||
path: "/product/recycle-stats",
|
||||
title: "回收统计",
|
||||
visible: userStore.hasPermissions(permissionCodes.recycleExchange.query)
|
||||
visible: userStore.hasPermissions(permissionCodes.salesOrder.read)
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -176,13 +182,13 @@ const menuGroupList = computed<MenuGroup[]>(() => [
|
||||
items: [
|
||||
{
|
||||
icon: "chart-analytics",
|
||||
path: "/management/product-data-charts",
|
||||
path: "/product/product-data-charts",
|
||||
title: "产品经营图表",
|
||||
visible: userStore.hasPermissions(permissionCodes.stat.read)
|
||||
},
|
||||
{
|
||||
icon: "chart-combo",
|
||||
path: "/management/order-data-charts",
|
||||
path: "/product/order-data-charts",
|
||||
title: "客户经营图表",
|
||||
visible: userStore.hasPermissions(permissionCodes.stat.read)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { RouteRecordRaw } from "vue-router";
|
||||
|
||||
const chartRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "/management/product-data-charts",
|
||||
path: "/product/product-data-charts",
|
||||
name: "ProductDataCharts",
|
||||
component: () => import("@/pages/product/ProductDataCharts.vue"),
|
||||
meta: {
|
||||
@@ -13,7 +13,7 @@ const chartRoutes: RouteRecordRaw[] = [
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/management/order-data-charts",
|
||||
path: "/product/order-data-charts",
|
||||
name: "OrderDataCharts",
|
||||
component: () => import("@/pages/product/OrderDataCharts.vue"),
|
||||
meta: {
|
||||
|
||||
@@ -6,25 +6,25 @@ function meta(depth = 3): RouteRecordRaw["meta"] {
|
||||
|
||||
export default [
|
||||
{
|
||||
path: "/management/order-fulfillments",
|
||||
path: "/product/order-fulfillments",
|
||||
name: "OrderFulfillmentList",
|
||||
component: () => import("@/pages/fulfillment/OrderFulfillmentList.vue"),
|
||||
meta: meta()
|
||||
},
|
||||
{
|
||||
path: "/management/order-fulfillments/create",
|
||||
path: "/product/order-fulfillments/create",
|
||||
name: "OrderFulfillmentCreate",
|
||||
component: () => import("@/pages/fulfillment/OrderFulfillmentCreate.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/order-fulfillments/quick",
|
||||
path: "/product/order-fulfillments/quick",
|
||||
name: "OrderFulfillmentQuick",
|
||||
component: () => import("@/pages/fulfillment/OrderFulfillmentQuick.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/order-fulfillments/:id",
|
||||
path: "/product/order-fulfillments/:id",
|
||||
name: "OrderFulfillmentDetail",
|
||||
component: () => import("@/pages/fulfillment/OrderFulfillmentDetail.vue"),
|
||||
meta: meta(4)
|
||||
|
||||
@@ -5,11 +5,11 @@ function pageMeta(depth = 3, background = "#F5F5F8"): RouteRecordRaw["meta"] {
|
||||
}
|
||||
|
||||
export default [
|
||||
{ path: "/management/package-configs", name: "PackageConfigList", component: () => import("@/pages/package/PackageConfigList.vue"), meta: pageMeta() },
|
||||
{ path: "/management/package-orders", name: "PackageOrderConfigList", component: () => import("@/pages/package/PackageOrderConfigList.vue"), meta: pageMeta() },
|
||||
{ path: "/management/package-configs/create", name: "PackageConfigCreate", component: () => import("@/pages/package/PackageConfigEdit.vue"), meta: pageMeta(4) },
|
||||
{ path: "/management/package-configs/:id", name: "PackageConfigDetail", component: () => import("@/pages/package/PackageConfigDetail.vue"), meta: pageMeta(4) },
|
||||
{ path: "/management/package-configs/:id/edit", name: "PackageConfigEdit", component: () => import("@/pages/package/PackageConfigEdit.vue"), meta: pageMeta(5) },
|
||||
{ path: "/management/package-configs/:id/purchase", name: "PackagePurchase", component: () => import("@/pages/package/PackagePurchase.vue"), meta: pageMeta(5) },
|
||||
{ path: "/management/customer-packages/create", name: "CustomerPackageCreate", component: () => import("@/pages/package/PackagePurchase.vue"), meta: pageMeta(4) }
|
||||
{ path: "/product/package-configs", name: "PackageConfigList", component: () => import("@/pages/package/PackageConfigList.vue"), meta: pageMeta() },
|
||||
{ path: "/product/package-orders", name: "PackageOrderConfigList", component: () => import("@/pages/package/PackageOrderConfigList.vue"), meta: pageMeta() },
|
||||
{ path: "/product/package-configs/create", name: "PackageConfigCreate", component: () => import("@/pages/package/PackageConfigEdit.vue"), meta: pageMeta(4) },
|
||||
{ path: "/product/package-configs/:id", name: "PackageConfigDetail", component: () => import("@/pages/package/PackageConfigDetail.vue"), meta: pageMeta(4) },
|
||||
{ path: "/product/package-configs/:id/edit", name: "PackageConfigEdit", component: () => import("@/pages/package/PackageConfigEdit.vue"), meta: pageMeta(5) },
|
||||
{ path: "/product/package-configs/:id/purchase", name: "PackagePurchase", component: () => import("@/pages/package/PackagePurchase.vue"), meta: pageMeta(5) },
|
||||
{ path: "/product/customer-packages/create", name: "CustomerPackageCreate", component: () => import("@/pages/package/PackagePurchase.vue"), meta: pageMeta(4) }
|
||||
] as RouteRecordRaw[];
|
||||
|
||||
@@ -2,27 +2,27 @@ import type { RouteRecordRaw } from "vue-router";
|
||||
|
||||
const pointRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "/management/points/redeem-skus", name: "PointRedeemSkuList", component: () => import("@/pages/point/PointRedeemSkuList.vue"),
|
||||
path: "/product/points/redeem-skus", name: "PointRedeemSkuList", component: () => import("@/pages/point/PointRedeemSkuList.vue"),
|
||||
meta: { depth: 3, tabBarVisible: false, bodyBackground: "#F5F5F8", darkBodyBackground: "#10161f" }
|
||||
},
|
||||
{
|
||||
path: "/management/points/redeem-skus/create", name: "PointRedeemSkuCreate", component: () => import("@/pages/point/PointRedeemSkuEdit.vue"),
|
||||
path: "/product/points/redeem-skus/create", name: "PointRedeemSkuCreate", component: () => import("@/pages/point/PointRedeemSkuEdit.vue"),
|
||||
meta: { depth: 4, tabBarVisible: false, bodyBackground: "#F5F5F8", darkBodyBackground: "#10161f" }
|
||||
},
|
||||
{
|
||||
path: "/management/points/redeem-skus/:id/edit", name: "PointRedeemSkuEdit", component: () => import("@/pages/point/PointRedeemSkuEdit.vue"),
|
||||
path: "/product/points/redeem-skus/:id/edit", name: "PointRedeemSkuEdit", component: () => import("@/pages/point/PointRedeemSkuEdit.vue"),
|
||||
meta: { depth: 4, tabBarVisible: false, bodyBackground: "#F5F5F8", darkBodyBackground: "#10161f" }
|
||||
},
|
||||
{
|
||||
path: "/management/points/redemptions", name: "PointRedemptionList", component: () => import("@/pages/point/PointRedemptionList.vue"),
|
||||
path: "/product/points/redemptions", name: "PointRedemptionList", component: () => import("@/pages/point/PointRedemptionList.vue"),
|
||||
meta: { depth: 3, tabBarVisible: false, bodyBackground: "#F5F5F8", darkBodyBackground: "#10161f" }
|
||||
},
|
||||
{
|
||||
path: "/management/points/redemptions/create", name: "PointRedemptionCreate", component: () => import("@/pages/point/PointRedemptionCreate.vue"),
|
||||
path: "/product/points/redemptions/create", name: "PointRedemptionCreate", component: () => import("@/pages/point/PointRedemptionCreate.vue"),
|
||||
meta: { depth: 4, tabBarVisible: false, bodyBackground: "#F5F5F8", darkBodyBackground: "#10161f" }
|
||||
},
|
||||
{
|
||||
path: "/management/points/redemptions/:id", name: "PointRedemptionDetail", component: () => import("@/pages/point/PointRedemptionDetail.vue"),
|
||||
path: "/product/points/redemptions/:id", name: "PointRedemptionDetail", component: () => import("@/pages/point/PointRedemptionDetail.vue"),
|
||||
meta: { depth: 4, tabBarVisible: false, bodyBackground: "#F5F5F8", darkBodyBackground: "#10161f" }
|
||||
},
|
||||
{
|
||||
|
||||
@@ -11,79 +11,85 @@ function pageMeta(depth = 3, background = "#F5F5F8"): RouteRecordRaw["meta"] {
|
||||
|
||||
const productRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "/management/product-categories",
|
||||
path: "/product/product-categories",
|
||||
name: "ProductCategoryList",
|
||||
component: () => import("@/pages/product/ProductCategoryList.vue"),
|
||||
meta: pageMeta()
|
||||
},
|
||||
{
|
||||
path: "/management/product-categories/rank",
|
||||
path: "/product/product-categories/rank",
|
||||
name: "ProductCategoryRank",
|
||||
component: () => import("@/pages/product/ProductCategoryRank.vue"),
|
||||
meta: pageMeta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/products",
|
||||
path: "/product/products",
|
||||
name: "ProductList",
|
||||
component: () => import("@/pages/product/ProductList.vue"),
|
||||
meta: pageMeta()
|
||||
},
|
||||
{
|
||||
path: "/management/products/create",
|
||||
path: "/product/products/create",
|
||||
name: "ProductCreate",
|
||||
component: () => import("@/pages/product/ProductEdit.vue"),
|
||||
meta: pageMeta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/products/:id",
|
||||
path: "/product/products/:id",
|
||||
name: "ProductDetail",
|
||||
component: () => import("@/pages/product/ProductDetail.vue"),
|
||||
meta: pageMeta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/products/:id/edit",
|
||||
path: "/product/products/:id/edit",
|
||||
name: "ProductEdit",
|
||||
component: () => import("@/pages/product/ProductEdit.vue"),
|
||||
meta: pageMeta(5)
|
||||
},
|
||||
{
|
||||
path: "/management/product-stocks",
|
||||
path: "/product/products/:productId/skus/:skuId",
|
||||
name: "ProductSkuDetail",
|
||||
component: () => import("@/pages/product/ProductSkuDetail.vue"),
|
||||
meta: pageMeta(5)
|
||||
},
|
||||
{
|
||||
path: "/product/product-stocks",
|
||||
name: "ProductStockList",
|
||||
component: () => import("@/pages/product/ProductStockList.vue"),
|
||||
meta: pageMeta()
|
||||
},
|
||||
{
|
||||
path: "/management/product-stocks/:productId/skus",
|
||||
path: "/product/product-stocks/:productId/skus",
|
||||
name: "ProductStockSkuList",
|
||||
component: () => import("@/pages/product/ProductStockSkuList.vue"),
|
||||
meta: pageMeta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/product-stocks/batch/select",
|
||||
path: "/product/product-stocks/batch/select",
|
||||
name: "ProductStockBatchSelect",
|
||||
component: () => import("@/pages/product/ProductStockBatchSelect.vue"),
|
||||
meta: pageMeta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/product-stocks/batch/configure",
|
||||
path: "/product/product-stocks/batch/configure",
|
||||
name: "ProductStockBatchConfigure",
|
||||
component: () => import("@/pages/product/ProductStockBatchConfigure.vue"),
|
||||
meta: pageMeta(5)
|
||||
},
|
||||
{
|
||||
path: "/management/product-stock-records",
|
||||
path: "/product/product-stock-records",
|
||||
name: "ProductStockRecordList",
|
||||
component: () => import("@/pages/product/ProductStockRecordList.vue"),
|
||||
meta: pageMeta()
|
||||
},
|
||||
{
|
||||
path: "/management/product-stock-records/:id",
|
||||
path: "/product/product-stock-records/:id",
|
||||
name: "ProductStockRecordDetail",
|
||||
component: () => import("@/pages/product/ProductStockRecordDetail.vue"),
|
||||
meta: pageMeta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/product-stocks/:skuId",
|
||||
path: "/product/product-stocks/:skuId",
|
||||
name: "ProductStockDetail",
|
||||
component: () => import("@/pages/product/ProductStockDetail.vue"),
|
||||
meta: pageMeta(5)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import type { RouteRecordRaw } from "vue-router";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
|
||||
function meta(depth = 3): RouteRecordRaw["meta"] {
|
||||
return { depth, tabBarVisible: false, bodyBackground: "#F5F5F8", darkBodyBackground: "#10161f" };
|
||||
@@ -6,61 +9,129 @@ function meta(depth = 3): RouteRecordRaw["meta"] {
|
||||
|
||||
export default [
|
||||
{
|
||||
path: "/management/recycle-exchanges",
|
||||
name: "RecycleExchangeList",
|
||||
component: () => import("@/pages/recycle/RecycleExchangeList.vue"),
|
||||
path: "/product/recycle-payments",
|
||||
name: "RecyclePaymentAll",
|
||||
component: () => import("@/pages/recycle/RecyclePaymentList.vue"),
|
||||
meta: meta()
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-exchanges/create",
|
||||
path: "/product/recycle-exchanges",
|
||||
name: "RecycleExchangeList",
|
||||
redirect: to => {
|
||||
const detail = typeof to.query.detail === "string" ? to.query.detail : "";
|
||||
if (detail) {
|
||||
return { name: "RecycleExchangeDetail", params: { id: detail } };
|
||||
}
|
||||
return { name: "SalesOrderList", query: { orderType: "RECYCLE", customerId: to.query.customerId } };
|
||||
},
|
||||
meta: meta()
|
||||
},
|
||||
{
|
||||
path: "/product/recycle-exchanges/create",
|
||||
name: "RecycleExchangeCreate",
|
||||
component: () => import("@/pages/recycle/RecycleExchangeCreate.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-exchanges/:id",
|
||||
path: "/product/recycle-exchanges/:id/payments/create",
|
||||
name: "RecyclePaymentCreate",
|
||||
component: () => import("@/pages/recycle/RecyclePaymentCreate.vue"),
|
||||
meta: meta(6)
|
||||
},
|
||||
{
|
||||
path: "/product/recycle-exchanges/:id/payments/:paymentId/revoke",
|
||||
name: "RecyclePaymentRevoke",
|
||||
component: () => import("@/pages/recycle/RecyclePaymentRevoke.vue"),
|
||||
meta: meta(7)
|
||||
},
|
||||
{
|
||||
path: "/product/recycle-exchanges/:id/payments/:paymentId",
|
||||
name: "RecyclePaymentDetail",
|
||||
component: () => import("@/pages/recycle/RecyclePaymentDetail.vue"),
|
||||
meta: meta(6)
|
||||
},
|
||||
{
|
||||
path: "/product/recycle-exchanges/:id/payments",
|
||||
name: "RecyclePaymentList",
|
||||
component: () => import("@/pages/recycle/RecyclePaymentList.vue"),
|
||||
meta: meta(5)
|
||||
},
|
||||
{
|
||||
// 兑换单详情已并入交易订单详情,这里保留旧路径与名称,按销售订单 ID 转发
|
||||
path: "/product/recycle-exchanges/:id",
|
||||
name: "RecycleExchangeDetail",
|
||||
component: () => import("@/pages/recycle/RecycleExchangeDetail.vue"),
|
||||
beforeEnter: async to => {
|
||||
const id = String(to.params.id || "");
|
||||
if (id) {
|
||||
try {
|
||||
const result = await RecycleAPI.detail(id);
|
||||
if (result.exchange?.salesOrderId) {
|
||||
return { name: "SalesOrderDetail", params: { id: result.exchange.salesOrderId }, replace: true };
|
||||
}
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "兑换单加载失败"));
|
||||
}
|
||||
}
|
||||
return { name: "SalesOrderList", query: { orderType: "RECYCLE" }, replace: true };
|
||||
},
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-items",
|
||||
path: "/management/recycle-accounts",
|
||||
name: "RecycleAccount",
|
||||
component: () => import("@/pages/recycle/RecycleAccount.vue"),
|
||||
meta: meta()
|
||||
},
|
||||
{
|
||||
path: "/product/recycle-items",
|
||||
name: "RecycleItemList",
|
||||
component: () => import("@/pages/recycle/RecycleItemList.vue"),
|
||||
meta: meta()
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-items/create",
|
||||
path: "/product/recycle-items/create",
|
||||
name: "RecycleItemCreate",
|
||||
component: () => import("@/pages/recycle/RecycleItemEdit.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-items/:id",
|
||||
name: "RecycleItemEdit",
|
||||
component: () => import("@/pages/recycle/RecycleItemEdit.vue"),
|
||||
path: "/product/recycle-items/:id",
|
||||
name: "RecycleItemDetail",
|
||||
component: () => import("@/pages/recycle/RecycleItemDetail.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-rules",
|
||||
path: "/product/recycle-items/:id/edit",
|
||||
name: "RecycleItemEdit",
|
||||
component: () => import("@/pages/recycle/RecycleItemEdit.vue"),
|
||||
meta: meta(5)
|
||||
},
|
||||
{
|
||||
path: "/product/recycle-rules",
|
||||
name: "RecycleRuleList",
|
||||
component: () => import("@/pages/recycle/RecycleRuleList.vue"),
|
||||
meta: meta()
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-rules/create",
|
||||
path: "/product/recycle-rules/create",
|
||||
name: "RecycleRuleCreate",
|
||||
component: () => import("@/pages/recycle/RecycleRuleEdit.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-rules/:id",
|
||||
name: "RecycleRuleEdit",
|
||||
component: () => import("@/pages/recycle/RecycleRuleEdit.vue"),
|
||||
path: "/product/recycle-rules/:id",
|
||||
name: "RecycleRuleDetail",
|
||||
component: () => import("@/pages/recycle/RecycleRuleDetail.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/recycle-stats",
|
||||
path: "/product/recycle-rules/:id/edit",
|
||||
name: "RecycleRuleEdit",
|
||||
component: () => import("@/pages/recycle/RecycleRuleEdit.vue"),
|
||||
meta: meta(5)
|
||||
},
|
||||
{
|
||||
path: "/product/recycle-stats",
|
||||
name: "RecycleStat",
|
||||
component: () => import("@/pages/recycle/RecycleStat.vue"),
|
||||
meta: meta()
|
||||
|
||||
@@ -5,53 +5,53 @@ function meta(depth = 3, background = "#F5F5F8"): RouteRecordRaw["meta"] {
|
||||
}
|
||||
|
||||
export default [
|
||||
{ path: "/management/sales-orders", name: "SalesOrderList", component: () => import("@/pages/salesOrder/SalesOrderList.vue"), meta: meta() },
|
||||
{ path: "/management/consumption-records", name: "ConsumptionRecordList", component: () => import("@/pages/salesOrder/ConsumptionRecordList.vue"), meta: meta() },
|
||||
{ path: "/product/sales-orders", name: "SalesOrderList", component: () => import("@/pages/salesOrder/SalesOrderList.vue"), meta: meta() },
|
||||
{ path: "/product/consumption-records", name: "ConsumptionRecordList", component: () => import("@/pages/salesOrder/ConsumptionRecordList.vue"), meta: meta() },
|
||||
{
|
||||
path: "/management/sales-orders/create",
|
||||
path: "/product/sales-orders/create",
|
||||
name: "SalesOrderCreate",
|
||||
component: () => import("@/pages/salesOrder/SalesOrderCreate.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/sales-orders/:id",
|
||||
path: "/product/sales-orders/:id",
|
||||
name: "SalesOrderDetail",
|
||||
component: () => import("@/pages/salesOrder/SalesOrderDetail.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/sales-orders/:id/payment",
|
||||
path: "/product/sales-orders/:id/payment",
|
||||
name: "SalesOrderPayment",
|
||||
component: () => import("@/pages/salesOrder/SalesOrderPayment.vue"),
|
||||
meta: meta(5)
|
||||
},
|
||||
{
|
||||
path: "/management/sales-orders/:id/refund",
|
||||
path: "/product/sales-orders/:id/refund",
|
||||
name: "SalesOrderRefund",
|
||||
component: () => import("@/pages/salesOrder/SalesOrderRefund.vue"),
|
||||
meta: meta(5)
|
||||
},
|
||||
{
|
||||
path: "/management/sales-orders/:id/no-refund",
|
||||
path: "/product/sales-orders/:id/no-refund",
|
||||
name: "SalesOrderNoRefund",
|
||||
component: () => import("@/pages/salesOrder/SalesOrderNoRefund.vue"),
|
||||
meta: meta(5)
|
||||
},
|
||||
{
|
||||
path: "/management/sales-orders/:id/cancel",
|
||||
path: "/product/sales-orders/:id/cancel",
|
||||
name: "SalesOrderCancel",
|
||||
component: () => import("@/pages/salesOrder/SalesOrderCancel.vue"),
|
||||
meta: meta(5)
|
||||
},
|
||||
{ path: "/management/fund-records", name: "FundRecordList", component: () => import("@/pages/salesOrder/FundRecordList.vue"), meta: meta() },
|
||||
{ path: "/product/fund-records", name: "FundRecordList", component: () => import("@/pages/salesOrder/FundRecordList.vue"), meta: meta() },
|
||||
{
|
||||
path: "/management/fund-records/:id",
|
||||
path: "/product/fund-records/:id",
|
||||
name: "FundRecordDetail",
|
||||
component: () => import("@/pages/salesOrder/FundRecordDetail.vue"),
|
||||
meta: meta(4)
|
||||
},
|
||||
{
|
||||
path: "/management/fund-records/:id/revoke",
|
||||
path: "/product/fund-records/:id/revoke",
|
||||
name: "FundRecordRevoke",
|
||||
component: () => import("@/pages/salesOrder/FundRecordRevoke.vue"),
|
||||
meta: meta(5)
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useUserStore } from "timi-web-api";
|
||||
|
||||
import EventRecordAPI from "@/api/EventRecordAPI";
|
||||
import FulfillmentAPI from "@/api/FulfillmentAPI";
|
||||
import RecycleAPI from "@/api/RecycleAPI";
|
||||
import SalesOrderAPI from "@/api/SalesOrderAPI";
|
||||
import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
@@ -12,16 +11,13 @@ import { useCurrentStoreStore } from "./currentStoreStore";
|
||||
export const usePendingNoticeStore = defineStore("pendingNotice", () => {
|
||||
const userStore = useUserStore();
|
||||
const currentStoreStore = useCurrentStoreStore();
|
||||
const pendingCounts = reactive({ fulfillment: 0, stock: 0, fund: 0, event: 0, recycle: 0 });
|
||||
const pendingCounts = reactive({ fulfillment: 0, stock: 0, fund: 0, event: 0 });
|
||||
let pendingRequestId = 0;
|
||||
const pendingNoticeList = computed(() => {
|
||||
const notices: { content: string; name: string; query: Record<string, string> }[] = [];
|
||||
if (pendingCounts.fulfillment) {
|
||||
notices.push({ content: `有 ${pendingCounts.fulfillment} 条履约待核销`, name: "OrderFulfillmentList", query: { status: "PENDING" } });
|
||||
}
|
||||
if (pendingCounts.recycle) {
|
||||
notices.push({ content: `有 ${pendingCounts.recycle} 条回收兑换待核销`, name: "RecycleExchangeList", query: { status: "PENDING" } });
|
||||
}
|
||||
if (pendingCounts.fund) {
|
||||
notices.push({ content: `有 ${pendingCounts.fund} 条资金流水待核销`, name: "FundRecordList", query: { status: "PENDING" } });
|
||||
}
|
||||
@@ -50,6 +46,7 @@ export const usePendingNoticeStore = defineStore("pendingNotice", () => {
|
||||
}
|
||||
};
|
||||
if (userStore.hasPermissions(permissionCodes.orderFulfillment.read)) {
|
||||
// 回收兑换订单的领取也是订单履约,统一统计,服务端按权限过滤来源
|
||||
tasks.push(load("fulfillment", () => FulfillmentAPI.list({ index: 0, size: 1, status: "PENDING" })));
|
||||
tasks.push(load("stock", () => FulfillmentAPI.list({ index: 0, size: 1, status: "WAITING_STOCK" })));
|
||||
}
|
||||
@@ -59,9 +56,6 @@ export const usePendingNoticeStore = defineStore("pendingNotice", () => {
|
||||
if (userStore.hasPermissions(permissionCodes.eventRecord.read)) {
|
||||
tasks.push(load("event", () => EventRecordAPI.list({ index: 0, size: 1, verificationStatus: "PENDING" })));
|
||||
}
|
||||
if (userStore.hasPermissions(permissionCodes.recycleExchange.query)) {
|
||||
tasks.push(load("recycle", () => RecycleAPI.page({ index: 0, size: 1, status: "PENDING" })));
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
@@ -69,7 +63,7 @@ export const usePendingNoticeStore = defineStore("pendingNotice", () => {
|
||||
() => [currentStoreStore.currentStoreId, userStore.loginUser.user?.id || userStore.loginUser.id || ""],
|
||||
([, userId]) => {
|
||||
pendingRequestId++;
|
||||
Object.assign(pendingCounts, { fulfillment: 0, stock: 0, fund: 0, event: 0, recycle: 0 });
|
||||
Object.assign(pendingCounts, { fulfillment: 0, stock: 0, fund: 0, event: 0 });
|
||||
if (userId) {
|
||||
void refreshPendingNotices();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ export type OrderFulfillmentItem = {
|
||||
|
||||
export type OrderFulfillment = {
|
||||
salesOrderId?: string;
|
||||
/** 来源订单类型,列表接口 join 返回,用于区分回收兑换来源 */
|
||||
orderType?: string;
|
||||
storeId?: string;
|
||||
customerId?: string;
|
||||
status?: GaoFulfillmentStatus;
|
||||
@@ -62,8 +64,9 @@ export type FulfillmentPage = {
|
||||
size: number;
|
||||
};
|
||||
|
||||
/** 统一履约创建请求。回收兑换订单也是销售订单,一律用 salesOrderId。 */
|
||||
export type OrderFulfillmentCreateRequest = {
|
||||
salesOrderId: string;
|
||||
salesOrderId?: string;
|
||||
requestNo: string;
|
||||
deliveredAt?: number;
|
||||
itemList: GaoOrderFulfillmentItemRequest[];
|
||||
@@ -127,8 +130,9 @@ export type QuickFulfillmentCreateRequest = {
|
||||
remark?: string | null;
|
||||
};
|
||||
|
||||
/** 履约明细请求。回收兑换来源不提供 sourceOrderItemId。 */
|
||||
export type GaoOrderFulfillmentItemRequest = {
|
||||
sourceOrderItemId: string;
|
||||
sourceOrderItemId?: string;
|
||||
skuUnitId: string;
|
||||
quantity: number | string;
|
||||
};
|
||||
|
||||
+247
-103
@@ -1,32 +1,38 @@
|
||||
import type { Attachment, Model, PageResult, User } from "timi-web-api";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { ProductSkuSpecSnapshot, StockRecord } from "@/types/Product";
|
||||
|
||||
/** 回收物与兑换规则的启用状态。配置没有删除,停用使用 INACTIVE。 */
|
||||
/** 回收物与兑换模板的启用状态。配置没有删除,停用使用 INACTIVE。 */
|
||||
export type RecycleStatus = "ACTIVE" | "INACTIVE";
|
||||
|
||||
/** 兑换单状态。 */
|
||||
export type RecycleExchangeStatus = "PENDING" | "VERIFIED" | "CANCELLED" | "REVOKED";
|
||||
/**
|
||||
* 兑换单状态。
|
||||
*
|
||||
* PENDING 待领取,COMPLETED 已完成,CANCELLED 已取消。
|
||||
*/
|
||||
export type RecycleExchangeStatus = "PENDING" | "COMPLETED" | "CANCELLED";
|
||||
|
||||
/** 兑换单操作类型。 */
|
||||
export type RecycleExchangeActionType = "VERIFY" | "CANCEL" | "REVOKE";
|
||||
/** 兑换单操作类型。核销与冲正由回收物支付承载,兑换单只剩取消。 */
|
||||
export type RecycleExchangeActionType = "CANCEL";
|
||||
|
||||
/**
|
||||
* 回收物支付状态。
|
||||
*
|
||||
* 冲正会生成一条新记录,`sourcePaymentId` 指向被冲正的原支付。
|
||||
*/
|
||||
export type RecyclePaymentStatus = "PENDING" | "VERIFIED" | "REJECTED" | "CANCELLED" | "REVOKED";
|
||||
|
||||
/** 回收物配置。回收物不是退货,不校验客户购买记录,也不累计客户余额。 */
|
||||
export type RecycleItem = {
|
||||
storeId?: string;
|
||||
/** 回收物图片附件。 */
|
||||
attachmentList?: Partial<Attachment>[];
|
||||
name: string;
|
||||
/** 回收计量单位,例如「个」「公斤」 */
|
||||
unitName: string;
|
||||
/** 来源产品 ID,仅用于识别,不影响库存 */
|
||||
productId?: string | null;
|
||||
/** 来源 SKU ID,填写时必须同时填写其所属 productId */
|
||||
skuId?: string | null;
|
||||
/** 回收数量是否允许小数。 */
|
||||
allowDecimalQuantity?: boolean;
|
||||
status?: RecycleStatus;
|
||||
remark?: string | null;
|
||||
/** 来源产品名称,服务端回填,仅展示用 */
|
||||
sourceProductName?: string | null;
|
||||
/** 来源 SKU 规格摘要,服务端回填,仅展示用 */
|
||||
sourceSkuName?: string | null;
|
||||
} & Model;
|
||||
|
||||
/** 回收物配置分页与筛选条件。 */
|
||||
@@ -39,24 +45,16 @@ export type RecycleItemPage = {
|
||||
limit: number;
|
||||
};
|
||||
|
||||
/** 回收兑换规则:单份回收数量兑换单份业务单位数量。 */
|
||||
export type RecycleExchangeRule = {
|
||||
storeId?: string;
|
||||
recycleItemId: string;
|
||||
/** 单份规则回收数量 */
|
||||
recycleQuantity: number | string;
|
||||
/** 兑换 SKU ID */
|
||||
/** 兑换模板明细:一条商品在这个模板里兑换多少业务单位。 */
|
||||
export type RecycleRuleItem = {
|
||||
id?: string;
|
||||
ruleId?: string;
|
||||
skuId: string;
|
||||
/** 兑换 SKU 业务单位 ID */
|
||||
skuUnitId: string;
|
||||
/** 单份规则兑换业务单位数量 */
|
||||
/** 单份模板兑换的业务单位数量 */
|
||||
exchangeQuantity: number | string;
|
||||
status?: RecycleStatus;
|
||||
sort?: number;
|
||||
remark?: string | null;
|
||||
/** 以下为服务端回填的展示字段,保存时无需提交 */
|
||||
recycleName?: string | null;
|
||||
recycleUnit?: string | null;
|
||||
/** 以下为服务端回填的展示字段 */
|
||||
productName?: string | null;
|
||||
productType?: string | null;
|
||||
skuCode?: string | null;
|
||||
@@ -65,9 +63,31 @@ export type RecycleExchangeRule = {
|
||||
unitName?: string | null;
|
||||
stockEnabled?: boolean | null;
|
||||
allowDecimalQuantity?: boolean | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 回收兑换模板。
|
||||
*
|
||||
* 模板只是开单的快捷配置,可随时修改或删除;兑换单创建时保存 `ruleSnapshot`,
|
||||
* 不依赖模板继续履约。
|
||||
*/
|
||||
export type RecycleExchangeRule = {
|
||||
storeId?: string;
|
||||
recycleItemId: string;
|
||||
/** 单份模板回收数量 */
|
||||
recycleQuantity: number | string;
|
||||
/** 商品明细,至少一条 */
|
||||
itemList?: RecycleRuleItem[];
|
||||
status?: RecycleStatus;
|
||||
sort?: number;
|
||||
remark?: string | null;
|
||||
/** 以下为服务端回填的展示字段,保存时无需提交 */
|
||||
recycleName?: string | null;
|
||||
recycleUnit?: string | null;
|
||||
recycleItemAttachments?: Partial<Attachment>[];
|
||||
} & Model;
|
||||
|
||||
/** 兑换规则分页与筛选条件。 */
|
||||
/** 兑换模板分页与筛选条件。 */
|
||||
export type RecycleExchangeRulePage = {
|
||||
storeId?: string;
|
||||
status?: RecycleStatus;
|
||||
@@ -79,48 +99,48 @@ export type RecycleExchangeRulePage = {
|
||||
limit: number;
|
||||
};
|
||||
|
||||
/** 保存模板请求。新增不传 id,修改必须提交完整明细。 */
|
||||
export type RecycleRuleRequest = {
|
||||
id?: string;
|
||||
storeId?: string;
|
||||
recycleItemId: string;
|
||||
recycleQuantity: number | string;
|
||||
itemList: RecycleRuleItem[];
|
||||
status: RecycleStatus;
|
||||
sort?: number;
|
||||
remark?: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 兑换单。
|
||||
*
|
||||
* 规则、产品、客户后续变更都不改写单据,页面展示优先使用快照字段。
|
||||
* 兑换单本身只记录回收物与支付条件,商品明细在生成的销售订单里(`salesOrderId`)。
|
||||
*/
|
||||
export type RecycleExchange = {
|
||||
storeId?: string;
|
||||
customerId?: string;
|
||||
requestNo?: string;
|
||||
/** 模板 ID,自由创建时为空 */
|
||||
ruleId?: string;
|
||||
/** 生成的销售订单 ID,商品明细、支付与履约都用它 */
|
||||
salesOrderId?: string;
|
||||
/** 创建时模板快照,自由创建时为空 */
|
||||
ruleSnapshot?: Partial<RecycleExchangeRule> | null;
|
||||
recycleItemId?: string;
|
||||
recycleNameSnapshot?: string;
|
||||
/** 回收物当前图片附件。 */
|
||||
recycleItemAttachments?: Partial<Attachment>[];
|
||||
recycleUnitSnapshot?: string;
|
||||
sourceProductIdSnapshot?: string;
|
||||
sourceSkuIdSnapshot?: string;
|
||||
/** 回收物当前是否允许小数。 */
|
||||
allowDecimalQuantity?: boolean;
|
||||
/** 模板单份回收数量 */
|
||||
ruleRecycleQuantity?: number | string;
|
||||
ruleExchangeQuantity?: number | string;
|
||||
/** 规则倍数,正整数 */
|
||||
/** 模板份数,自由创建时为空 */
|
||||
multiple?: number;
|
||||
/** 预设回收数量 = 规则回收数量 × 倍数 */
|
||||
/** 模板预设回收数量 = 模板回收数量 × 份数 */
|
||||
defaultRecycleQuantity?: number | string;
|
||||
/** 预设兑换数量 = 规则兑换数量 × 倍数 */
|
||||
defaultExchangeQuantity?: number | string;
|
||||
/** 实际回收数量 */
|
||||
/** 约定支付回收物数量 */
|
||||
recycleQuantity?: number | string;
|
||||
/** 实际兑换数量 */
|
||||
exchangeQuantity?: number | string;
|
||||
productIdSnapshot?: string;
|
||||
skuIdSnapshot?: string;
|
||||
skuUnitIdSnapshot?: string;
|
||||
productNameSnapshot?: string;
|
||||
productTypeSnapshot?: string;
|
||||
skuCodeSnapshot?: string;
|
||||
skuNameSnapshot?: string;
|
||||
specSummarySnapshot?: string;
|
||||
skuSpecSnapshot?: ProductSkuSpecSnapshot[];
|
||||
unitSnapshot?: string;
|
||||
baseQuantityPerUnitSnapshot?: number | string;
|
||||
baseQuantity?: number | string;
|
||||
allowDecimalSnapshot?: boolean;
|
||||
/** true 为兑换 SKU 启用库存管理,创建时预占,撤销时释放 */
|
||||
stockEnabledSnapshot?: boolean;
|
||||
status?: RecycleExchangeStatus;
|
||||
operatorUserId?: string;
|
||||
/** 业务发生时间 */
|
||||
@@ -130,7 +150,7 @@ export type RecycleExchange = {
|
||||
operator?: Partial<User>;
|
||||
} & Model;
|
||||
|
||||
/** 兑换单操作记录。核销记录的退回字段为空。 */
|
||||
/** 兑换单操作记录。核销与冲正由回收物支付承载,只有取消。 */
|
||||
export type RecycleExchangeAction = {
|
||||
exchangeId?: string;
|
||||
actionType?: RecycleExchangeActionType;
|
||||
@@ -138,67 +158,191 @@ export type RecycleExchangeAction = {
|
||||
occurredAt?: number;
|
||||
reason?: string | null;
|
||||
remark?: string | null;
|
||||
/** true 为回收物全部退还客户 */
|
||||
recycleReturned?: boolean | null;
|
||||
/** true 为兑换商品已退回门店 */
|
||||
stockReturned?: boolean | null;
|
||||
stockRecordId?: string;
|
||||
sourceStockRecordId?: string;
|
||||
/** 取消后门店保留的回收物数量 */
|
||||
retainedRecycleQuantity?: number | string;
|
||||
operator?: Partial<User>;
|
||||
} & Model;
|
||||
|
||||
/** 兑换单详情。冲正照片按操作记录 ID 从 actionAttachments 读取。 */
|
||||
/** 兑换单详情。取消凭证按操作记录 ID 从 actionAttachments 读取。 */
|
||||
export type RecycleExchangeDetail = {
|
||||
exchange?: RecycleExchange;
|
||||
actionList?: RecycleExchangeAction[];
|
||||
attachmentList?: Attachment[];
|
||||
actionAttachments?: Record<string, Attachment[]>;
|
||||
stockRecordList?: StockRecord[];
|
||||
};
|
||||
|
||||
export type RecycleExchangeCreateRequest = {
|
||||
storeId?: string;
|
||||
customerId: string;
|
||||
ruleId: string;
|
||||
requestNo: string;
|
||||
multiple: number;
|
||||
/** 实际回收数量,不传使用预设值 */
|
||||
recycleQuantity?: string;
|
||||
/** 实际兑换数量,不传使用预设值 */
|
||||
exchangeQuantity?: string;
|
||||
occurredAt?: number;
|
||||
remark?: string | null;
|
||||
attachmentList?: Partial<Attachment>[];
|
||||
};
|
||||
|
||||
/** 兑换单动作请求。门店由服务端按兑换单归属解析,这里不需要也不应该传。 */
|
||||
export type RecycleExchangeActionRequest = {
|
||||
exchangeId: string;
|
||||
requestNo: string;
|
||||
occurredAt?: number;
|
||||
remark?: string | null;
|
||||
/** 冲正必填 */
|
||||
reason?: string;
|
||||
/** 撤销、冲正必填 */
|
||||
recycleReturned?: boolean;
|
||||
/** 库存商品冲正必填,必须为 true */
|
||||
stockReturned?: boolean;
|
||||
/** 库存商品冲正至少一张 PHOTO */
|
||||
attachmentList?: Partial<Attachment>[];
|
||||
};
|
||||
|
||||
export type RecycleExchangePage = {
|
||||
/** 客户回收物额度账户。可用额度 = balance - reserved。 */
|
||||
export type RecycleAccount = {
|
||||
id?: string;
|
||||
storeId?: string;
|
||||
customerId?: string;
|
||||
recycleItemId?: string;
|
||||
/** 额度余额 */
|
||||
balance?: number | string;
|
||||
/** 支付预占 */
|
||||
reserved?: number | string;
|
||||
/** 服务端回填的回收物名称与单位,仅展示用 */
|
||||
recycleName?: string | null;
|
||||
recycleUnit?: string | null;
|
||||
createdAt?: number;
|
||||
updatedAt?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* 额度流水。
|
||||
*
|
||||
* `bizType` 决定来源语义:履约产生、人工调整、支付预占与释放、支付核销、冲正返还。
|
||||
*/
|
||||
export type RecycleLedger = {
|
||||
id?: string;
|
||||
accountId?: string;
|
||||
storeId?: string;
|
||||
customerId?: string;
|
||||
recycleItemId?: string;
|
||||
bizType?: string;
|
||||
bizId?: string | null;
|
||||
requestNo?: string;
|
||||
balanceDelta?: number | string;
|
||||
reservedDelta?: number | string;
|
||||
balanceAfter?: number | string;
|
||||
reservedAfter?: number | string;
|
||||
operatorUserId?: string | null;
|
||||
reason?: string | null;
|
||||
createdAt?: number;
|
||||
};
|
||||
|
||||
/** 人工调整额度请求。 */
|
||||
export type RecycleAccountAdjustRequest = {
|
||||
storeId?: string;
|
||||
customerId: string;
|
||||
recycleItemId: string;
|
||||
requestNo: string;
|
||||
/** 可正可负,不能为零 */
|
||||
quantity: number | string;
|
||||
/** 调整原因,必填 */
|
||||
reason: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 产品回收物产出配置。
|
||||
*
|
||||
* `quantityPerBase` 表示每个 SKU **基础单位**产生多少回收物,最多三位小数。
|
||||
*/
|
||||
export type RecycleProductYield = {
|
||||
id?: string;
|
||||
storeId?: string;
|
||||
skuId?: string;
|
||||
status?: RecycleExchangeStatus;
|
||||
/** 业务时间起点,包含 */
|
||||
beginAt?: number;
|
||||
/** 业务时间终点,包含 */
|
||||
endAt?: number;
|
||||
index: number;
|
||||
size: number;
|
||||
recycleItemId?: string;
|
||||
/** 回收物是否允许小数数量。 */
|
||||
allowDecimalQuantity?: boolean;
|
||||
/** 回收物附件。 */
|
||||
attachmentList?: Partial<Attachment>[];
|
||||
quantityPerBase?: number | string;
|
||||
/** 服务端回填的回收物名称与单位,仅展示用 */
|
||||
recycleName?: string | null;
|
||||
recycleUnit?: string | null;
|
||||
/** 产品维度查询时回填的 SKU 名称与规格摘要,仅展示用 */
|
||||
skuName?: string | null;
|
||||
skuSpecSummary?: string | null;
|
||||
};
|
||||
|
||||
/** 回收物支付。一笔订单可分批提交,已核销数量达到约定数量后结清。 */
|
||||
export type RecyclePayment = {
|
||||
id?: string;
|
||||
storeId?: string;
|
||||
customerId?: string;
|
||||
/** 兑换生成的销售订单 ID */
|
||||
orderId?: string;
|
||||
recycleExchangeId?: string;
|
||||
customer?: Customer;
|
||||
recycleItemId?: string;
|
||||
requestNo?: string;
|
||||
quantity?: number | string;
|
||||
/** 带方向的数量,支付为正、冲正为负,汇总时直接相加 */
|
||||
signedQuantity?: number | string;
|
||||
status?: RecyclePaymentStatus;
|
||||
/** 冲正记录指向被冲正的原支付 */
|
||||
sourcePaymentId?: string | null;
|
||||
operatorUserId?: string;
|
||||
verifierUserId?: string | null;
|
||||
occurredAt?: number;
|
||||
verifiedAt?: number | null;
|
||||
reason?: string | null;
|
||||
/** 冲正时实物是否已退还客户 */
|
||||
returnedToCustomer?: boolean | null;
|
||||
/** 服务端回填的回收物名称与单位,仅展示用 */
|
||||
recycleName?: string | null;
|
||||
recycleUnit?: string | null;
|
||||
attachmentList?: Attachment[];
|
||||
operator?: Partial<User>;
|
||||
verifier?: Partial<User>;
|
||||
} & Model;
|
||||
|
||||
/** 回收物支付请求。创建、核销、拒绝、撤销、冲正共用。 */
|
||||
export type RecyclePaymentRequest = {
|
||||
storeId?: string;
|
||||
orderId?: string;
|
||||
paymentId?: string;
|
||||
requestNo?: string;
|
||||
quantity?: number | string;
|
||||
occurredAt?: number;
|
||||
reason?: string;
|
||||
returnedToCustomer?: boolean;
|
||||
attachmentList?: Partial<Attachment>[];
|
||||
};
|
||||
|
||||
/** 统一交易记录:资金流水与回收物支付混合展示,回收物数量不能当金额用。 */
|
||||
export type OrderTransaction = {
|
||||
type: "FUND" | "RECYCLE_PAYMENT";
|
||||
occurredAt?: number;
|
||||
fundRecord?: Record<string, unknown>;
|
||||
recyclePayment?: RecyclePayment;
|
||||
};
|
||||
|
||||
/** 兑换明细请求:创建兑换单与自由创建时提交的商品行。 */
|
||||
export type RecycleExchangeItemRequest = {
|
||||
skuId: string;
|
||||
skuUnitId: string;
|
||||
quantity: number | string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建兑换单请求。
|
||||
*
|
||||
* 按模板创建传 `ruleId` 与可选 `multiple`;自由创建不传 `ruleId`,必须传
|
||||
* `recycleItemId` 与 `itemList`,且需要调整权限。
|
||||
*/
|
||||
export type RecycleExchangeCreateRequest = {
|
||||
storeId?: string;
|
||||
customerId: string;
|
||||
/** 模板 ID,自由创建时为空 */
|
||||
ruleId?: string;
|
||||
/** 自由创建时的回收物 ID */
|
||||
recycleItemId?: string;
|
||||
/** 兑换明细,按模板创建时可省略 */
|
||||
itemList?: RecycleExchangeItemRequest[];
|
||||
requestNo: string;
|
||||
/** 兑换份数,按模板创建时使用,省略按 1 份处理 */
|
||||
multiple?: number;
|
||||
/** 约定支付回收数量,不传使用模板预设值 */
|
||||
recycleQuantity?: number | string;
|
||||
/**
|
||||
* true 为创建时立即预占并核销全部应付回收物。
|
||||
*
|
||||
* 需要支付创建与核销权限、足够可用额度,并提供回收凭证。
|
||||
*/
|
||||
verifyPayment?: boolean;
|
||||
/** 创建时核销的回收物数量 */
|
||||
paymentQuantity?: number | string;
|
||||
/** 创建时回收的凭证照片 */
|
||||
paymentAttachmentList?: Partial<Attachment>[];
|
||||
/** 创建时完成全部履约和核销 */
|
||||
fulfillAll?: boolean;
|
||||
/** 全部履约的凭证照片 */
|
||||
fulfillmentAttachmentList?: Partial<Attachment>[];
|
||||
occurredAt?: number;
|
||||
remark?: string | null;
|
||||
attachmentList?: Partial<Attachment>[];
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+13
-2
@@ -4,9 +4,9 @@ import type { EventRecord } from "@/types/EventRecord";
|
||||
import type { FulfillmentRevokeRequest, FulfillmentReturnRequest } from "@/types/Fulfillment";
|
||||
import type { ProductSkuSpecSnapshot } from "@/types/Product";
|
||||
|
||||
export type GaoSalesOrderType = "PACKAGE" | "DIRECT_PRODUCT";
|
||||
export type GaoSalesOrderType = "PACKAGE" | "DIRECT_PRODUCT" | "RECYCLE";
|
||||
export type GaoSalesOrderStatus = "ACTIVE" | "FULFILLED" | "CANCELLED";
|
||||
export type GaoSalesOrderItemType = "PACKAGE_ENTITLEMENT" | "DIRECT_PRODUCT";
|
||||
export type GaoSalesOrderItemType = "PACKAGE_ENTITLEMENT" | "DIRECT_PRODUCT" | "RECYCLE_ENTITLEMENT";
|
||||
export type GaoSalesPaymentStatus = "UNPAID" | "PARTIALLY_PAID" | "PAID";
|
||||
export type GaoSalesRefundStatus = "NOT_REQUIRED" | "PENDING" | "REFUNDED";
|
||||
export type FundBizType = "SALES_ORDER";
|
||||
@@ -52,6 +52,17 @@ export type SalesOrder = {
|
||||
paymentStatus?: GaoSalesPaymentStatus;
|
||||
refundStatus?: GaoSalesRefundStatus;
|
||||
saleAmount?: number;
|
||||
/** 回收兑换订单约定支付的回收物与数量,其他订单类型为空 */
|
||||
recycleItemId?: string;
|
||||
recycleRequiredQuantity?: number | string;
|
||||
recycleItemName?: string;
|
||||
recycleUnit?: string;
|
||||
/** 对应兑换单 ID,详情页用于跳转 */
|
||||
recycleExchangeId?: string;
|
||||
/** 已核销回收物数量,列表接口返回 */
|
||||
recycleVerifiedQuantity?: number | string | null;
|
||||
/** 待核销回收物数量,列表接口返回 */
|
||||
recyclePendingQuantity?: number | string | null;
|
||||
pendingPaidAmount?: number;
|
||||
paidAmount?: number;
|
||||
refundedAmount?: number;
|
||||
|
||||
@@ -43,7 +43,7 @@ export function createDefaultSalesOrderFilter(): SalesOrderListFilter {
|
||||
return {
|
||||
dateFilterType: "all",
|
||||
dateRange: ["", ""],
|
||||
orderTypeList: ["PACKAGE", "DIRECT_PRODUCT"],
|
||||
orderTypeList: ["PACKAGE", "DIRECT_PRODUCT", "RECYCLE"],
|
||||
statusList: ["ACTIVE"],
|
||||
paymentStatusList: ["UNPAID", "PARTIALLY_PAID", "PAID"],
|
||||
refundStatusList: ["NOT_REQUIRED", "PENDING", "REFUNDED"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import { getCurrentStoreId } from "@/utils/store";
|
||||
|
||||
export const listDataEventKeys = {
|
||||
productChanged: "gao:list:product-changed",
|
||||
productYieldChanged: "gao:list:product-yield-changed",
|
||||
productStockChanged: "gao:list:product-stock-changed",
|
||||
salesOrderChanged: "gao:list:sales-order-changed"
|
||||
} as const;
|
||||
@@ -16,6 +17,7 @@ export interface ListDataChangedPayload {
|
||||
|
||||
interface ListDataEventMap {
|
||||
[listDataEventKeys.productChanged]: [payload: ListDataChangedPayload];
|
||||
[listDataEventKeys.productYieldChanged]: [payload: ListDataChangedPayload];
|
||||
[listDataEventKeys.productStockChanged]: [payload: ListDataChangedPayload];
|
||||
[listDataEventKeys.salesOrderChanged]: [payload: ListDataChangedPayload];
|
||||
}
|
||||
|
||||
+17
-7
@@ -94,6 +94,7 @@ export const permissionCodes = {
|
||||
},
|
||||
orderFulfillment: {
|
||||
create: "GAO:ORDER_FULFILLMENT:CREATE",
|
||||
unsettled: "GAO:ORDER_FULFILLMENT:UNSETTLED",
|
||||
read: "GAO:ORDER_FULFILLMENT:READ",
|
||||
verify: "GAO:ORDER_FULFILLMENT:VERIFY",
|
||||
return: "GAO:ORDER_FULFILLMENT:RETURN",
|
||||
@@ -106,7 +107,18 @@ export const permissionCodes = {
|
||||
quantityAdjust: "GAO:RECYCLE_EXCHANGE:QUANTITY_ADJUST",
|
||||
verify: "GAO:RECYCLE_EXCHANGE:VERIFY",
|
||||
cancel: "GAO:RECYCLE_EXCHANGE:CANCEL",
|
||||
revoke: "GAO:RECYCLE_EXCHANGE:REVOKE"
|
||||
revoke: "GAO:RECYCLE_EXCHANGE:REVOKE",
|
||||
unsettledFulfillment: "GAO:RECYCLE_EXCHANGE:UNSETTLED_FULFILLMENT"
|
||||
},
|
||||
recycleAccount: {
|
||||
read: "GAO:RECYCLE_ACCOUNT:READ",
|
||||
adjust: "GAO:RECYCLE_ACCOUNT:ADJUST"
|
||||
},
|
||||
recyclePayment: {
|
||||
read: "GAO:RECYCLE_PAYMENT:READ",
|
||||
create: "GAO:RECYCLE_PAYMENT:CREATE",
|
||||
verify: "GAO:RECYCLE_PAYMENT:VERIFY",
|
||||
revoke: "GAO:RECYCLE_PAYMENT:REVOKE"
|
||||
},
|
||||
fundReceive: {
|
||||
create: "GAO:FUND_RECEIVE:CREATE",
|
||||
@@ -247,6 +259,7 @@ export const gaoStoreScopePermissionCodes = [
|
||||
permissionCodes.salesOrder.cancel,
|
||||
permissionCodes.salesOrder.priceOverride,
|
||||
permissionCodes.orderFulfillment.create,
|
||||
permissionCodes.orderFulfillment.unsettled,
|
||||
permissionCodes.orderFulfillment.read,
|
||||
permissionCodes.orderFulfillment.verify,
|
||||
permissionCodes.orderFulfillment.return,
|
||||
@@ -254,12 +267,9 @@ export const gaoStoreScopePermissionCodes = [
|
||||
permissionCodes.fundReceive.create,
|
||||
permissionCodes.fundReceive.verify,
|
||||
permissionCodes.recycleExchange.configManage,
|
||||
permissionCodes.recycleExchange.query,
|
||||
permissionCodes.recycleExchange.create,
|
||||
permissionCodes.recycleExchange.quantityAdjust,
|
||||
permissionCodes.recycleExchange.verify,
|
||||
permissionCodes.recycleExchange.cancel,
|
||||
permissionCodes.recycleExchange.revoke,
|
||||
permissionCodes.recycleExchange.unsettledFulfillment,
|
||||
permissionCodes.recycleAccount.read,
|
||||
permissionCodes.recycleAccount.adjust,
|
||||
permissionCodes.fundRecord.read,
|
||||
permissionCodes.fund.refund,
|
||||
permissionCodes.fund.revoke,
|
||||
|
||||
@@ -38,9 +38,9 @@ export function normalizeProductQuantity(value: number | string): string | undef
|
||||
return fraction ? `${integer}.${fraction}` : integer;
|
||||
}
|
||||
|
||||
/** 根据产品数量规则返回数量控件步长。允许小数时固定步进 0.1。 */
|
||||
/** 根据产品数量规则返回数量控件步长。允许小数时固定步进 0.05。 */
|
||||
export function getProductQuantityStep(sku?: Pick<ProductSku, "allowDecimalQuantity">): number {
|
||||
return sku?.allowDecimalQuantity ? .1 : 1;
|
||||
return sku?.allowDecimalQuantity ? .05 : 1;
|
||||
}
|
||||
|
||||
export function getProductTypeText(type?: ProductType): string {
|
||||
|
||||
+96
-20
@@ -1,4 +1,12 @@
|
||||
import type { RecycleExchange, RecycleExchangeActionType, RecycleExchangeStatus, RecycleStatus } from "@/types/Recycle";
|
||||
import type {
|
||||
RecycleAccount,
|
||||
RecycleExchange,
|
||||
RecycleExchangeActionType,
|
||||
RecycleExchangeStatus,
|
||||
RecyclePayment,
|
||||
RecyclePaymentStatus,
|
||||
RecycleStatus
|
||||
} from "@/types/Recycle";
|
||||
import { comparePackageQuantity, getPackageQuantityText } from "@/utils/package";
|
||||
|
||||
/** 配置状态(回收物、规则)的展示文案。 */
|
||||
@@ -19,15 +27,14 @@ export function getRecycleStatusTheme(status?: RecycleStatus): "success" | "warn
|
||||
/** 兑换单状态文案。 */
|
||||
export function getRecycleExchangeStatusText(status?: RecycleExchangeStatus): string {
|
||||
return ({
|
||||
PENDING: "待核销",
|
||||
VERIFIED: "已核销",
|
||||
CANCELLED: "已撤销",
|
||||
REVOKED: "已冲正"
|
||||
PENDING: "待领取",
|
||||
COMPLETED: "已完成",
|
||||
CANCELLED: "已取消"
|
||||
} as Record<string, string>)[status || ""] || "未知";
|
||||
}
|
||||
|
||||
export function getRecycleExchangeStatusTheme(status?: RecycleExchangeStatus): "success" | "warning" | "danger" | "primary" {
|
||||
if (status === "VERIFIED") {
|
||||
if (status === "COMPLETED") {
|
||||
return "success";
|
||||
}
|
||||
if (status === "PENDING") {
|
||||
@@ -36,26 +43,89 @@ export function getRecycleExchangeStatusTheme(status?: RecycleExchangeStatus): "
|
||||
if (status === "CANCELLED") {
|
||||
return "danger";
|
||||
}
|
||||
// 已冲正用主色,默认灰标签在深色模式下会变成白底不可读
|
||||
// 未知状态用主色,默认灰标签在深色模式下会变成白底不可读
|
||||
return "primary";
|
||||
}
|
||||
|
||||
/** 操作记录类型文案。 */
|
||||
/** 操作记录类型文案。兑换单只剩取消,核销与冲正看回收物支付。 */
|
||||
export function getRecycleActionText(type?: RecycleExchangeActionType): string {
|
||||
return ({ VERIFY: "核销", CANCEL: "撤销", REVOKE: "冲正" } as Record<string, string>)[type || ""] || "未知操作";
|
||||
}
|
||||
|
||||
/** 兑换单可执行的操作,服务端仍会按状态和权限二次校验。 */
|
||||
export function canVerifyExchange(status?: RecycleExchangeStatus): boolean {
|
||||
return status === "PENDING";
|
||||
return ({ CANCEL: "取消" } as Record<string, string>)[type || ""] || "未知操作";
|
||||
}
|
||||
|
||||
/** 待领取与已完成都可以取消,已完成只是商品领完了,回收物归属仍需能修正。 */
|
||||
export function canCancelExchange(status?: RecycleExchangeStatus): boolean {
|
||||
return status === "PENDING";
|
||||
return status === "PENDING" || status === "COMPLETED";
|
||||
}
|
||||
|
||||
export function canRevokeExchange(status?: RecycleExchangeStatus): boolean {
|
||||
return status === "VERIFIED";
|
||||
/** 客户额度的可用数量 = 余额 - 预占。 */
|
||||
export function getRecycleAvailable(account?: RecycleAccount): number {
|
||||
if (!account) {
|
||||
return 0;
|
||||
}
|
||||
const balance = Number(account.balance ?? 0);
|
||||
const reserved = Number(account.reserved ?? 0);
|
||||
if (!Number.isFinite(balance) || !Number.isFinite(reserved)) {
|
||||
return 0;
|
||||
}
|
||||
return Math.max(balance - reserved, 0);
|
||||
}
|
||||
|
||||
/** 额度账户是否还有可用数量。 */
|
||||
export function hasRecycleAvailable(account?: RecycleAccount): boolean {
|
||||
return 0 < getRecycleAvailable(account);
|
||||
}
|
||||
|
||||
/** 回收物支付状态文案。冲正记录单独展示,不覆盖原支付状态。 */
|
||||
export function getRecyclePaymentStatusText(status?: RecyclePaymentStatus): string {
|
||||
return ({
|
||||
PENDING: "待核销",
|
||||
VERIFIED: "已核销",
|
||||
REJECTED: "已拒绝",
|
||||
CANCELLED: "已取消",
|
||||
REVOKED: "已冲正"
|
||||
} as Record<string, string>)[status || ""] || "未知";
|
||||
}
|
||||
|
||||
export function getRecyclePaymentStatusTheme(status?: RecyclePaymentStatus): "success" | "warning" | "danger" | "primary" {
|
||||
if (status === "VERIFIED") {
|
||||
return "success";
|
||||
}
|
||||
if (status === "PENDING") {
|
||||
return "warning";
|
||||
}
|
||||
if (status === "REJECTED" || status === "CANCELLED") {
|
||||
return "danger";
|
||||
}
|
||||
if (status === "REVOKED") {
|
||||
return "primary";
|
||||
}
|
||||
return "primary";
|
||||
}
|
||||
|
||||
/**
|
||||
* 额度流水来源文案。
|
||||
*
|
||||
* 履约产生只代表额度增加,不等于门店收到实物;实际收取看支付核销。
|
||||
*/
|
||||
export function getRecycleLedgerTypeText(bizType?: string): string {
|
||||
return ({
|
||||
FULFILLMENT_YIELD: "履约产生",
|
||||
ADJUST: "人工调整",
|
||||
PAYMENT_RESERVE: "支付预占",
|
||||
PAYMENT_RELEASE: "释放预占",
|
||||
PAYMENT_VERIFY: "支付核销",
|
||||
PAYMENT_REVOKE: "冲正返还"
|
||||
} as Record<string, string>)[bizType || ""] || "未知来源";
|
||||
}
|
||||
|
||||
/** 支付是否还能核销或拒绝。 */
|
||||
export function isPaymentPending(payment?: RecyclePayment): boolean {
|
||||
return payment?.status === "PENDING";
|
||||
}
|
||||
|
||||
/** 支付是否已核销,可作为冲正对象。 */
|
||||
export function isPaymentVerified(payment?: RecyclePayment): boolean {
|
||||
return payment?.status === "VERIFIED" && !payment.sourcePaymentId;
|
||||
}
|
||||
|
||||
/** 拼接「数量 + 单位」,后端 BigDecimal 可能是字符串。 */
|
||||
@@ -83,8 +153,14 @@ export function multiplyRecycleQuantity(value: number | string | null | undefine
|
||||
return fraction ? `${integer}.${fraction}` : integer;
|
||||
}
|
||||
|
||||
/** 实际数量是否被有权限的操作人调整过(与预设值不同)。 */
|
||||
/**
|
||||
* 实际回收数量是否被调整过(与模板预设值不同)。
|
||||
*
|
||||
* 自由创建没有模板,也就不存在「预设值」,不算调整。
|
||||
*/
|
||||
export function isRecycleQuantityAdjusted(exchange: RecycleExchange): boolean {
|
||||
return comparePackageQuantity(exchange.recycleQuantity ?? "0", exchange.defaultRecycleQuantity ?? "0") !== 0
|
||||
|| comparePackageQuantity(exchange.exchangeQuantity ?? "0", exchange.defaultExchangeQuantity ?? "0") !== 0;
|
||||
if (!exchange.ruleId || exchange.defaultRecycleQuantity === undefined || exchange.defaultRecycleQuantity === null) {
|
||||
return false;
|
||||
}
|
||||
return comparePackageQuantity(exchange.recycleQuantity ?? "0", exchange.defaultRecycleQuantity) !== 0;
|
||||
}
|
||||
|
||||
+12
-3
@@ -2,10 +2,10 @@ import type { GaoFulfillmentStatus } from "@/types/Fulfillment";
|
||||
import type { FundBizType, FundOperationType, FundRecordStatus, GaoSalesOrderItemType, GaoSalesOrderStatus, GaoSalesOrderType, GaoSalesPaymentStatus, GaoSalesRefundStatus } from "@/types/SalesOrder";
|
||||
|
||||
export function getFundBizTypeText(type?: FundBizType): string {
|
||||
return type === "SALES_ORDER" ? "销售订单" : "未知";
|
||||
return type === "SALES_ORDER" ? "交易订单" : "未知";
|
||||
}
|
||||
export function getSalesOrderTypeText(type?: GaoSalesOrderType): string {
|
||||
return type === "PACKAGE" ? "套餐订单" : type === "DIRECT_PRODUCT" ? "产品订单" : "未知订单";
|
||||
return ({ PACKAGE: "套餐订单", DIRECT_PRODUCT: "产品订单", RECYCLE: "回收兑换订单" } as Record<string, string>)[type || ""] || "未知订单";
|
||||
}
|
||||
export function getSalesOrderStatusText(status?: GaoSalesOrderStatus): string {
|
||||
return ({ ACTIVE: "进行中", FULFILLED: "已履约", CANCELLED: "已取消" } as Record<string, string>)[status || ""] || "未知";
|
||||
@@ -13,6 +13,15 @@ export function getSalesOrderStatusText(status?: GaoSalesOrderStatus): string {
|
||||
export function getSalesPaymentStatusText(status?: GaoSalesPaymentStatus): string {
|
||||
return ({ UNPAID: "未收款", PARTIALLY_PAID: "部分收款", PAID: "已收款" } as Record<string, string>)[status || ""] || "未知";
|
||||
}
|
||||
/**
|
||||
* 交易订单的结清文案。
|
||||
*
|
||||
* 交易订单里同时有现金单和回收兑换单:现金单看收款、回收单看回收物支付,
|
||||
* 两者都是「结清」语义,统一口径才不会出现一边「已收款」一边「部分结清」。
|
||||
*/
|
||||
export function getOrderSettlementText(status?: GaoSalesPaymentStatus): string {
|
||||
return ({ UNPAID: "未结清", PARTIALLY_PAID: "部分结清", PAID: "已结清" } as Record<string, string>)[status || ""] || "未知";
|
||||
}
|
||||
export function getSalesRefundStatusText(status?: GaoSalesRefundStatus): string {
|
||||
return ({ NOT_REQUIRED: "无需退款", PENDING: "待处理退款", REFUNDED: "已退款" } as Record<string, string>)[status || ""] || "未知";
|
||||
}
|
||||
@@ -23,7 +32,7 @@ export function getFundStatusText(status?: FundRecordStatus): string {
|
||||
return ({ PENDING: "待核销", VERIFIED: "已生效", REJECTED: "已拒绝", CANCELLED: "已撤销" } as Record<string, string>)[status || ""] || "未知";
|
||||
}
|
||||
export function getSalesOrderItemTypeText(type?: GaoSalesOrderItemType): string {
|
||||
return type === "PACKAGE_ENTITLEMENT" ? "套餐权益" : type === "DIRECT_PRODUCT" ? "直接产品" : "未知来源";
|
||||
return ({ PACKAGE_ENTITLEMENT: "套餐权益", DIRECT_PRODUCT: "直接产品", RECYCLE_ENTITLEMENT: "回收兑换权益" } as Record<string, string>)[type || ""] || "未知来源";
|
||||
}
|
||||
export function getFulfillmentStatusText(status?: GaoFulfillmentStatus): string {
|
||||
return ({ WAITING_STOCK: "等待库存", PENDING: "待核销", VERIFIED: "已核销", REJECTED: "已拒绝", CANCELLED: "已撤销", REVOKED: "已冲正", RETURNED: "已退货" } as Record<string, string>)[status || ""] || "未知";
|
||||
|
||||
Reference in New Issue
Block a user