Merge pull request 'v1.2.0' (#7) from dev into master
Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "gao-customer-h5",
|
"name": "gao-customer-h5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --host",
|
"dev": "vite --host",
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
import { axios } from "timi-web-api";
|
||||||
|
import type {
|
||||||
|
RecycleExchange,
|
||||||
|
RecycleExchangeActionRequest,
|
||||||
|
RecycleExchangeCreateRequest,
|
||||||
|
RecycleExchangeDetail,
|
||||||
|
RecycleExchangePage,
|
||||||
|
RecycleExchangeRule,
|
||||||
|
RecycleExchangeRulePage,
|
||||||
|
RecycleExchangeStatRow,
|
||||||
|
RecycleItem,
|
||||||
|
RecycleItemPage,
|
||||||
|
RecyclePageResult,
|
||||||
|
RecycleStatRow
|
||||||
|
} from "@/types/Recycle";
|
||||||
|
import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents";
|
||||||
|
import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store";
|
||||||
|
|
||||||
|
const CONFIG_URI = "/gao/recycle/config";
|
||||||
|
const EXCHANGE_URI = "/gao/recycle/exchange";
|
||||||
|
const STAT_URI = "/gao/recycle/stat";
|
||||||
|
|
||||||
|
/** 配置接口的 storeId 走查询参数,可省略时由后端按登录用户门店范围解析。 */
|
||||||
|
function configParams(page: RecycleItemPage | RecycleExchangeRulePage): Record<string, string | number | undefined> {
|
||||||
|
return {
|
||||||
|
storeId: page.storeId || getCurrentStoreId() || undefined,
|
||||||
|
status: page.status,
|
||||||
|
keyword: page.keyword || undefined,
|
||||||
|
recycleItemId: "recycleItemId" in page ? page.recycleItemId : undefined,
|
||||||
|
skuId: "skuId" in page ? page.skuId : undefined,
|
||||||
|
offset: page.offset,
|
||||||
|
limit: page.limit
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 兑换单状态变化会改变待核销数量,通知顶部的待处理提示重新取数。 */
|
||||||
|
function notifyPendingNoticeChanged(result: RecycleExchange): RecycleExchange {
|
||||||
|
pendingNoticeEvents.emit("changed", getCurrentStoreId());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 配置 ----------
|
||||||
|
|
||||||
|
/** 回收物配置列表,包含启用和停用项,支持按名称与状态筛选。 */
|
||||||
|
async function itemList(page: RecycleItemPage): Promise<RecyclePageResult<RecycleItem>> {
|
||||||
|
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 }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 保存回收物配置:新增不传 id,修改必须提交完整配置。 */
|
||||||
|
async function itemSave(item: RecycleItem): Promise<RecycleItem> {
|
||||||
|
return await axios.post(`${CONFIG_URI}/item/save`, withCurrentStoreId(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 规则列表,返回全部状态,按 sort 升序、创建时间倒序。 */
|
||||||
|
async function ruleList(page: RecycleExchangeRulePage): Promise<RecyclePageResult<RecycleExchangeRule>> {
|
||||||
|
return await axios.post(`${CONFIG_URI}/rules`, undefined, { params: configParams(page) });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 启用规则列表,创建兑换单时使用。回收物或产品后来停用时仍可能出现,以服务端校验为准。 */
|
||||||
|
async function activeRuleList(page: RecycleExchangeRulePage): Promise<RecyclePageResult<RecycleExchangeRule>> {
|
||||||
|
return await axios.post(`${CONFIG_URI}/rules/active`, undefined, { params: configParams(page) });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 兑换规则详情,回填回收物、产品、SKU 与业务单位名称。 */
|
||||||
|
async function ruleDetail(id: string): Promise<RecycleExchangeRule> {
|
||||||
|
return await axios.post(`${CONFIG_URI}/rule/detail`, undefined, {
|
||||||
|
params: { storeId: getCurrentStoreId() || undefined, id }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 保存规则配置:新增不传 id,修改必须提交完整配置。 */
|
||||||
|
async function ruleSave(rule: RecycleExchangeRule): Promise<RecycleExchangeRule> {
|
||||||
|
return await axios.post(`${CONFIG_URI}/rule/save`, withCurrentStoreId(rule));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 兑换单 ----------
|
||||||
|
|
||||||
|
/** 创建兑换单。requestNo 为幂等号,重试必须原样复用。 */
|
||||||
|
async function create(request: RecycleExchangeCreateRequest): Promise<RecycleExchange> {
|
||||||
|
const result = await axios.post(`${EXCHANGE_URI}/create`, withCurrentStoreId(request));
|
||||||
|
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 } });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核销待核销单。成功返回的兑换单状态可能已被并发操作改变,页面应重新查询详情。
|
||||||
|
* 门店由服务端按兑换单自身归属解析,请求不需要带 storeId。
|
||||||
|
*/
|
||||||
|
async function verify(request: RecycleExchangeActionRequest): Promise<RecycleExchange> {
|
||||||
|
const result = await axios.post(`${EXCHANGE_URI}/verify`, request);
|
||||||
|
return notifyPendingNoticeChanged(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 撤销待核销单,recycleReturned 决定回收物是否全部退还客户。门店同理由服务端取。 */
|
||||||
|
async function cancel(request: RecycleExchangeActionRequest): Promise<RecycleExchange> {
|
||||||
|
const result = await axios.post(`${EXCHANGE_URI}/cancel`, request);
|
||||||
|
return notifyPendingNoticeChanged(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 冲正已核销单。库存商品必须 stockReturned 且至少一张 PHOTO。门店同理由服务端取。 */
|
||||||
|
async function revoke(request: RecycleExchangeActionRequest): Promise<RecycleExchange> {
|
||||||
|
const result = await axios.post(`${EXCHANGE_URI}/revoke`, request);
|
||||||
|
return notifyPendingNoticeChanged(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 统计 ----------
|
||||||
|
|
||||||
|
/** 回收统计,时间区间为 [startAt, endAt)。 */
|
||||||
|
async function statRecycle(startAt: number, endAt: number): Promise<RecycleStatRow[]> {
|
||||||
|
return await axios.post(`${STAT_URI}/recycle`, undefined, {
|
||||||
|
params: {
|
||||||
|
storeId: getCurrentStoreId() || undefined,
|
||||||
|
startAt,
|
||||||
|
endAt
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 兑换统计,时间区间为 [startAt, endAt)。 */
|
||||||
|
async function statExchange(startAt: number, endAt: number): Promise<RecycleExchangeStatRow[]> {
|
||||||
|
return await axios.post(`${STAT_URI}/exchange`, undefined, {
|
||||||
|
params: {
|
||||||
|
storeId: getCurrentStoreId() || undefined,
|
||||||
|
startAt,
|
||||||
|
endAt
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
itemList,
|
||||||
|
itemDetail,
|
||||||
|
itemSave,
|
||||||
|
ruleList,
|
||||||
|
activeRuleList,
|
||||||
|
ruleDetail,
|
||||||
|
ruleSave,
|
||||||
|
create,
|
||||||
|
page,
|
||||||
|
detail,
|
||||||
|
verify,
|
||||||
|
cancel,
|
||||||
|
revoke,
|
||||||
|
statRecycle,
|
||||||
|
statExchange
|
||||||
|
};
|
||||||
@@ -22,10 +22,22 @@ html.theme-dark {
|
|||||||
--td-bg-color-page: #10161f;
|
--td-bg-color-page: #10161f;
|
||||||
--td-bg-color-container: #1a2230;
|
--td-bg-color-container: #1a2230;
|
||||||
--td-bg-color-container-hover: #222c3c;
|
--td-bg-color-container-hover: #222c3c;
|
||||||
|
--td-bg-color-container-active: #222c3c;
|
||||||
|
// 次级容器与组件底色:t-tag[theme=default] 的浅色底直接取 secondarycontainer,
|
||||||
|
// 不补就会退化到 gray-color-1(#f3f3f3),在深色页面里是一块白底
|
||||||
|
--td-bg-color-secondarycontainer: #222c3c;
|
||||||
|
--td-bg-color-secondarycontainer-active: #2a3646;
|
||||||
|
--td-bg-color-component: #2a3646;
|
||||||
|
--td-bg-color-component-active: #33414f;
|
||||||
|
--td-bg-color-component-disabled: #1f2836;
|
||||||
|
--td-border-level-1-color: rgba(255, 255, 255, .08);
|
||||||
|
--td-border-level-2-color: rgba(255, 255, 255, .16);
|
||||||
|
--td-component-stroke: rgba(255, 255, 255, .08);
|
||||||
--td-component-border: rgba(255, 255, 255, .12);
|
--td-component-border: rgba(255, 255, 255, .12);
|
||||||
--td-text-color-primary: rgba(255, 255, 255, .9);
|
--td-text-color-primary: rgba(255, 255, 255, .9);
|
||||||
--td-text-color-secondary: rgba(255, 255, 255, .55);
|
--td-text-color-secondary: rgba(255, 255, 255, .55);
|
||||||
--td-text-color-placeholder: rgba(255, 255, 255, .35);
|
--td-text-color-placeholder: rgba(255, 255, 255, .35);
|
||||||
|
--td-text-color-disabled: rgba(255, 255, 255, .25);
|
||||||
|
|
||||||
// 导航激活项在深色下需要压深,否则浅色胶囊压在深底上太刺眼
|
// 导航激活项在深色下需要压深,否则浅色胶囊压在深底上太刺眼
|
||||||
--tui-rail-active-background: rgba(15, 118, 110, .22);
|
--tui-rail-active-background: rgba(15, 118, 110, .22);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
busy: false,
|
busy: false,
|
||||||
items: () => [],
|
items: () => [],
|
||||||
readonly: false,
|
readonly: false,
|
||||||
required: false,
|
required: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
@toggle="toggleSku"
|
@toggle="toggleSku"
|
||||||
@check="toggleProduct"
|
@check="toggleProduct"
|
||||||
/>
|
/>
|
||||||
<center-tips v-else :content="loading ? '正在加载可售产品' : emptyProductText" />
|
<center-tips v-else :content="loading ? (props.productScope === 'all' ? '正在加载产品' : '正在加载可售产品') : emptyProductText" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</bottom-popup>
|
</bottom-popup>
|
||||||
@@ -46,12 +46,14 @@ interface Props {
|
|||||||
modelValue?: ProductSkuSelectionValue;
|
modelValue?: ProductSkuSelectionValue;
|
||||||
visible?: boolean;
|
visible?: boolean;
|
||||||
selectionMode?: ProductSkuSelectionMode;
|
selectionMode?: ProductSkuSelectionMode;
|
||||||
|
/** sellable 只列可售产品;all 连停售产品一起列,用于来源产品这类仅作识别的场景 */
|
||||||
|
productScope?: "sellable" | "all";
|
||||||
selectableProductIdList?: string[];
|
selectableProductIdList?: string[];
|
||||||
selectableSkuIdList?: string[];
|
selectableSkuIdList?: string[];
|
||||||
selectedSkuIdList?: string[];
|
selectedSkuIdList?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), { selectionMode: "single" });
|
const props = withDefaults(defineProps<Props>(), { selectionMode: "single", productScope: "sellable" });
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
"update:modelValue": [value: Props["modelValue"]];
|
"update:modelValue": [value: Props["modelValue"]];
|
||||||
"update:visible": [value: boolean];
|
"update:visible": [value: boolean];
|
||||||
@@ -93,7 +95,9 @@ const visibleProductList = computed(() => {
|
|||||||
return productList.value.filter(item => (!selectableProductIdSet.value || selectableProductIdSet.value.has(item.id || ""))
|
return productList.value.filter(item => (!selectableProductIdSet.value || selectableProductIdSet.value.has(item.id || ""))
|
||||||
&& (!text || `${item.name}${item.code}`.toLocaleLowerCase().includes(text)));
|
&& (!text || `${item.name}${item.code}`.toLocaleLowerCase().includes(text)));
|
||||||
});
|
});
|
||||||
const emptyProductText = computed(() => props.selectableProductIdList?.length === 0 ? "客户暂无已购可履约产品" : "暂无可售产品");
|
const emptyProductText = computed(() => props.selectableProductIdList?.length === 0
|
||||||
|
? "客户暂无已购可履约产品"
|
||||||
|
: (props.productScope === "all" ? "暂无产品" : "暂无可售产品"));
|
||||||
const selectorItemList = computed<ProductSkuSelectorItem[]>(() => visibleProductList.value.map((summary, index) => {
|
const selectorItemList = computed<ProductSkuSelectorItem[]>(() => visibleProductList.value.map((summary, index) => {
|
||||||
const key = getProductKey(summary, index);
|
const key = getProductKey(summary, index);
|
||||||
const product = productDetailMap.value[key] || (summary.skuList?.length ? summary : undefined);
|
const product = productDetailMap.value[key] || (summary.skuList?.length ? summary : undefined);
|
||||||
@@ -132,9 +136,11 @@ watch(popupVisible, async visible => {
|
|||||||
}
|
}
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
productList.value = await ProductAPI.sellableList({ index: 0, size: 1000 });
|
productList.value = props.productScope === "all"
|
||||||
|
? (await ProductAPI.list({ index: 0, size: 1000 })).list || []
|
||||||
|
: await ProductAPI.sellableList({ index: 0, size: 1000 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Message.error(getErrorMessage(error, "可售产品加载失败"));
|
Message.error(getErrorMessage(error, props.productScope === "all" ? "产品加载失败" : "可售产品加载失败"));
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,514 @@
|
|||||||
|
<template>
|
||||||
|
<div class="tui-page-layout tui-navbar">
|
||||||
|
<t-navbar
|
||||||
|
fixed
|
||||||
|
:z-index="20"
|
||||||
|
title="回收兑换"
|
||||||
|
left-arrow
|
||||||
|
@left-click="$router.back()"
|
||||||
|
>
|
||||||
|
<template #right>
|
||||||
|
<t-button
|
||||||
|
:loading="saving"
|
||||||
|
theme="primary"
|
||||||
|
variant="text"
|
||||||
|
size="small"
|
||||||
|
content="提交"
|
||||||
|
@click="save"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</t-navbar>
|
||||||
|
<main class="tui-page-content scroll column">
|
||||||
|
<div v-can="permissionCodes.recycleExchange.create" class="recycle-exchange-create">
|
||||||
|
<t-form class="form card" label-width="7.5rem" v-entrance-transition>
|
||||||
|
<t-form-item label="客户" required-mark>
|
||||||
|
<t-input
|
||||||
|
:model-value="customerName || '请选择客户'"
|
||||||
|
class="customer"
|
||||||
|
readonly
|
||||||
|
borderless
|
||||||
|
placeholder="选择客户"
|
||||||
|
@click="customerVisible = 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
|
||||||
|
theme="primary"
|
||||||
|
variant="outline"
|
||||||
|
size="extra-small"
|
||||||
|
content="选择"
|
||||||
|
@click.stop="customerVisible = true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</t-input>
|
||||||
|
</t-form-item>
|
||||||
|
<customer-profile-card
|
||||||
|
v-if="customer"
|
||||||
|
class="customer-profile"
|
||||||
|
:customer="customer"
|
||||||
|
v-entrance-transition
|
||||||
|
/>
|
||||||
|
<t-form-item label="兑换规则" required-mark content-align="right" arrow @click="openRulePicker">
|
||||||
|
<span class="clip-text" v-text="ruleDisplayText" />
|
||||||
|
</t-form-item>
|
||||||
|
<t-form-item label="倍数" required-mark>
|
||||||
|
<t-stepper
|
||||||
|
v-model="multiple"
|
||||||
|
size="large"
|
||||||
|
:min="1"
|
||||||
|
:max="9999"
|
||||||
|
:step="1"
|
||||||
|
integer
|
||||||
|
theme="outline"
|
||||||
|
/>
|
||||||
|
</t-form-item>
|
||||||
|
<t-form-item label="预设数量" content-align="right">
|
||||||
|
<span v-text="defaultQuantityText" />
|
||||||
|
</t-form-item>
|
||||||
|
<template v-if="canAdjust">
|
||||||
|
<t-form-item label="实际回收">
|
||||||
|
<t-input
|
||||||
|
v-model.trim="recycleQuantityText"
|
||||||
|
type="number"
|
||||||
|
align="right"
|
||||||
|
borderless
|
||||||
|
:placeholder="defaultRecycleQuantity"
|
||||||
|
/>
|
||||||
|
</t-form-item>
|
||||||
|
<t-form-item label="实际兑换">
|
||||||
|
<t-input
|
||||||
|
v-model.trim="exchangeQuantityText"
|
||||||
|
type="number"
|
||||||
|
align="right"
|
||||||
|
borderless
|
||||||
|
:placeholder="defaultExchangeQuantity"
|
||||||
|
/>
|
||||||
|
</t-form-item>
|
||||||
|
<t-form-item label-width="0">
|
||||||
|
<div class="adjust-tips">
|
||||||
|
<span class="tips" v-text="selectedRule ? adjustTipText : '选择兑换规则后可调整实际数量'" />
|
||||||
|
<t-button
|
||||||
|
v-if="selectedRule"
|
||||||
|
size="extra-small"
|
||||||
|
theme="primary"
|
||||||
|
variant="text"
|
||||||
|
content="恢复预设"
|
||||||
|
@click="resetQuantity"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</t-form-item>
|
||||||
|
</template>
|
||||||
|
<t-form-item label="兑换时间" content-align="right">
|
||||||
|
<date-time-now-picker v-model="occurredAtText" title="兑换时间" />
|
||||||
|
</t-form-item>
|
||||||
|
<t-form-item label="备注">
|
||||||
|
<t-textarea v-model.trim="remark" borderless autosize maxlength="500" placeholder="可不填" />
|
||||||
|
</t-form-item>
|
||||||
|
<div class="photo-wrap">
|
||||||
|
<attachment-selector
|
||||||
|
v-model:items="photoItems"
|
||||||
|
:upload="uploadPhotoList"
|
||||||
|
title="兑换凭证照片"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</t-form>
|
||||||
|
<div class="tips footer-tips" v-text="footerTipText" />
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
<customer-selector
|
||||||
|
v-model="customerId"
|
||||||
|
v-model:visible="customerVisible"
|
||||||
|
:enable-scan="false"
|
||||||
|
@change="handleCustomerChange"
|
||||||
|
/>
|
||||||
|
<bottom-popup
|
||||||
|
v-model="ruleVisible"
|
||||||
|
title="选择兑换规则"
|
||||||
|
height="70vh"
|
||||||
|
right-button-text=""
|
||||||
|
@left-button-click="ruleVisible = false"
|
||||||
|
>
|
||||||
|
<div class="rule-picker">
|
||||||
|
<t-cell
|
||||||
|
v-for="item in ruleList"
|
||||||
|
:key="item.id"
|
||||||
|
class="item"
|
||||||
|
:class="{ active: item.id === selectedRule?.id }"
|
||||||
|
@click="selectRule(item)"
|
||||||
|
>
|
||||||
|
<template #title>
|
||||||
|
<span class="clip-text" v-text="getRuleTitle(item)" />
|
||||||
|
</template>
|
||||||
|
<template #note>
|
||||||
|
<span v-text="getRuleRatioText(item)" />
|
||||||
|
</template>
|
||||||
|
<template #description>
|
||||||
|
<div class="description">
|
||||||
|
<span v-text="getRuleProductText(item)" />
|
||||||
|
<t-tag
|
||||||
|
v-if="isStockEnabled(item)"
|
||||||
|
size="small"
|
||||||
|
theme="warning"
|
||||||
|
variant="light-outline"
|
||||||
|
content="占用库存"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</t-cell>
|
||||||
|
<center-tips v-if="!ruleList.length" :content="ruleLoading ? '正在加载兑换规则' : '暂无启用的兑换规则'" />
|
||||||
|
</div>
|
||||||
|
</bottom-popup>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { BottomPopup } 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 CustomerProfileCard from "@/components/CustomerProfileCard.vue";
|
||||||
|
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||||
|
import DateTimeNowPicker from "@/components/DateTimeNowPicker.vue";
|
||||||
|
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
||||||
|
import type { Customer } from "@/types/Customer";
|
||||||
|
import type { PhotoItem } from "@/types/Photo";
|
||||||
|
import type { RecycleExchangeRule } from "@/types/Recycle";
|
||||||
|
import { parseDateTime } from "@/utils/date";
|
||||||
|
import { getErrorMessage } from "@/utils/error";
|
||||||
|
import { Message } from "@/utils/message";
|
||||||
|
import { normalizePackageQuantity } from "@/utils/package";
|
||||||
|
import { permissionCodes } from "@/utils/permission";
|
||||||
|
import { multiplyRecycleQuantity, getRecycleQuantityText } from "@/utils/recycle";
|
||||||
|
import { uploadPhotoList } from "@/utils/photo";
|
||||||
|
|
||||||
|
defineOptions({ name: "RecycleExchangeCreate" });
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
|
// ---------- 客户 ----------
|
||||||
|
|
||||||
|
const customerId = ref("");
|
||||||
|
const customer = ref<Customer>();
|
||||||
|
const customerVisible = ref(false);
|
||||||
|
const customerName = computed(() => customer.value?.name || customer.value?.code || "");
|
||||||
|
|
||||||
|
async function handleCustomerChange(value: string | string[]): Promise<void> {
|
||||||
|
const id = Array.isArray(value) ? String(value[0] || "") : value;
|
||||||
|
customerId.value = id;
|
||||||
|
if (!id) {
|
||||||
|
customer.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
customer.value = await CustomerAPI.detail(id);
|
||||||
|
} catch (error) {
|
||||||
|
customer.value = undefined;
|
||||||
|
Message.error(getErrorMessage(error, "客户资料加载失败"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearCustomer(): void {
|
||||||
|
customerId.value = "";
|
||||||
|
customer.value = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 规则 ----------
|
||||||
|
|
||||||
|
const ruleVisible = ref(false);
|
||||||
|
const ruleLoading = ref(false);
|
||||||
|
const ruleList = ref<RecycleExchangeRule[]>([]);
|
||||||
|
const selectedRule = ref<RecycleExchangeRule>();
|
||||||
|
const multiple = ref(1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规则行只回显「回收物 兑换 兑换物」,具体数量由下方「预设数量」表达。
|
||||||
|
*
|
||||||
|
* 带上产品名是为了区分比例相同但兑换不同产品的规则。
|
||||||
|
*/
|
||||||
|
const ruleDisplayText = computed(() => {
|
||||||
|
const rule = selectedRule.value;
|
||||||
|
if (!rule) {
|
||||||
|
return "请选择兑换规则";
|
||||||
|
}
|
||||||
|
const title = getRuleTitle(rule);
|
||||||
|
const productText = rule.productName || rule.skuName || "";
|
||||||
|
return productText ? `${title} 兑换 ${productText}` : title;
|
||||||
|
});
|
||||||
|
const defaultRecycleQuantity = computed(() => multiplyRecycleQuantity(selectedRule.value?.recycleQuantity, multiple.value));
|
||||||
|
const defaultExchangeQuantity = computed(() => multiplyRecycleQuantity(selectedRule.value?.exchangeQuantity, multiple.value));
|
||||||
|
const recycleUnitName = computed(() => selectedRule.value?.recycleUnit || "");
|
||||||
|
const exchangeUnitName = computed(() => selectedRule.value?.unitName || "");
|
||||||
|
const defaultQuantityText = computed(() => (selectedRule.value
|
||||||
|
? `${getRecycleQuantityText(defaultRecycleQuantity.value, recycleUnitName.value)} 兑换 ${getRecycleQuantityText(defaultExchangeQuantity.value, exchangeUnitName.value)}`
|
||||||
|
: "-"));
|
||||||
|
|
||||||
|
/** 规则自带回收物、产品与单位名称,选择弹层不需要再回查配置和产品库。 */
|
||||||
|
function getRuleTitle(rule: RecycleExchangeRule): string {
|
||||||
|
return rule.recycleName || getRuleProductText(rule) || "兑换规则";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 单份规则的兑换比例,弹层里产品名另起一行显示,这里不带。 */
|
||||||
|
function getRuleRatioText(rule: RecycleExchangeRule): string {
|
||||||
|
const recycleText = getRecycleQuantityText(multiplyRecycleQuantity(rule.recycleQuantity, 1), rule.recycleUnit);
|
||||||
|
const exchangeText = getRecycleQuantityText(multiplyRecycleQuantity(rule.exchangeQuantity, 1), rule.unitName);
|
||||||
|
return `${recycleText} 兑换 ${exchangeText}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRuleProductText(rule: RecycleExchangeRule): string {
|
||||||
|
const productName = rule.productName || "";
|
||||||
|
const skuText = rule.specSummary || rule.skuName || "";
|
||||||
|
if (!productName) {
|
||||||
|
return skuText;
|
||||||
|
}
|
||||||
|
return skuText && skuText !== productName ? `${productName}(${skuText})` : productName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 启用规则列表可能超过一页,创建时一次取完,避免规则被分页截断。 */
|
||||||
|
async function loadRules(): Promise<void> {
|
||||||
|
ruleLoading.value = true;
|
||||||
|
try {
|
||||||
|
const rules: RecycleExchangeRule[] = [];
|
||||||
|
let offset = 0;
|
||||||
|
const limit = 100;
|
||||||
|
let total = 0;
|
||||||
|
do {
|
||||||
|
const page = await RecycleAPI.activeRuleList({ offset, limit });
|
||||||
|
const rows = page.list || [];
|
||||||
|
rules.push(...rows);
|
||||||
|
total = page.total || 0;
|
||||||
|
offset += rows.length;
|
||||||
|
if (!rows.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (offset < total);
|
||||||
|
ruleList.value = rules;
|
||||||
|
} catch (error) {
|
||||||
|
Message.error(getErrorMessage(error, "启用兑换规则加载失败"));
|
||||||
|
} finally {
|
||||||
|
ruleLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openRulePicker(): Promise<void> {
|
||||||
|
ruleVisible.value = true;
|
||||||
|
if (!ruleList.value.length && !ruleLoading.value) {
|
||||||
|
await loadRules();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 换规则或改倍数都要把实际数量重置回预设;没选规则时留空,让占位提示生效。 */
|
||||||
|
function selectRule(rule: RecycleExchangeRule): void {
|
||||||
|
selectedRule.value = rule;
|
||||||
|
ruleVisible.value = false;
|
||||||
|
resetQuantity();
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetQuantity(): void {
|
||||||
|
if (!selectedRule.value) {
|
||||||
|
recycleQuantityText.value = "";
|
||||||
|
exchangeQuantityText.value = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
recycleQuantityText.value = defaultRecycleQuantity.value;
|
||||||
|
exchangeQuantityText.value = defaultExchangeQuantity.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 库存占用标记同样由规则自带,避免再查一次产品库。 */
|
||||||
|
function isStockEnabled(rule?: RecycleExchangeRule): boolean {
|
||||||
|
return rule?.stockEnabled === true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 数量调整 ----------
|
||||||
|
|
||||||
|
const canAdjust = computed(() => userStore.hasPermissions(permissionCodes.recycleExchange.quantityAdjust));
|
||||||
|
const recycleQuantityText = ref("");
|
||||||
|
const exchangeQuantityText = ref("");
|
||||||
|
const adjustTipText = computed(() => {
|
||||||
|
const recycleText = getRecycleQuantityText(defaultRecycleQuantity.value, recycleUnitName.value);
|
||||||
|
const exchangeText = getRecycleQuantityText(defaultExchangeQuantity.value, exchangeUnitName.value);
|
||||||
|
return `有数量调整权限时可修改实际数量,预设为 ${recycleText} 兑换 ${exchangeText}。`;
|
||||||
|
});
|
||||||
|
|
||||||
|
watch([() => selectedRule.value?.id, multiple], () => {
|
||||||
|
resetQuantity();
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---------- 其它字段 ----------
|
||||||
|
|
||||||
|
const occurredAtText = ref("");
|
||||||
|
const remark = ref("");
|
||||||
|
const photoItems = ref<PhotoItem[]>([]);
|
||||||
|
const requestNo = ref("");
|
||||||
|
const saving = ref(false);
|
||||||
|
const footerTipText = "创建即登记收到回收物,兑换凭证照片必传。管理库存的兑换物会在创建时预占库存,库存不足则创建失败。";
|
||||||
|
|
||||||
|
function buildAttachments(): Array<{ tempFileId: string; attachType: "PHOTO" }> {
|
||||||
|
return photoItems.value.flatMap(item => item.tempFileId ? [{
|
||||||
|
tempFileId: item.tempFileId,
|
||||||
|
attachType: "PHOTO" as const
|
||||||
|
}] : []);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildOccurredAt(): number | undefined {
|
||||||
|
return occurredAtText.value ? Time.toTimestamp(parseDateTime(occurredAtText.value, false)) : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交内容一变就要换请求号,服务端按请求号 + 内容摘要去重
|
||||||
|
watch([customerId, () => selectedRule.value?.id, multiple, recycleQuantityText, exchangeQuantityText, occurredAtText, remark, photoItems], () => {
|
||||||
|
requestNo.value = "";
|
||||||
|
}, { deep: true });
|
||||||
|
|
||||||
|
async function save(): Promise<void> {
|
||||||
|
if (saving.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!customerId.value) {
|
||||||
|
Message.warning("请选择客户");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!selectedRule.value?.id) {
|
||||||
|
Message.warning("请选择兑换规则");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const multipleValue = Number(multiple.value);
|
||||||
|
if (!Number.isSafeInteger(multipleValue) || multipleValue < 1) {
|
||||||
|
Message.warning("倍数必须为正整数");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let recycleQuantity: string | undefined;
|
||||||
|
let exchangeQuantity: string | undefined;
|
||||||
|
if (canAdjust.value) {
|
||||||
|
recycleQuantity = normalizePackageQuantity(recycleQuantityText.value || defaultRecycleQuantity.value);
|
||||||
|
exchangeQuantity = normalizePackageQuantity(exchangeQuantityText.value || defaultExchangeQuantity.value);
|
||||||
|
if (!recycleQuantity || !exchangeQuantity || recycleQuantity === "0" || exchangeQuantity === "0") {
|
||||||
|
Message.warning("实际回收数量和兑换数量必须为大于 0 的数字,最多 3 位小数");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!photoItems.value.length) {
|
||||||
|
Message.warning("请上传兑换凭证照片");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!requestNo.value) {
|
||||||
|
requestNo.value = window.crypto.randomUUID();
|
||||||
|
}
|
||||||
|
saving.value = true;
|
||||||
|
try {
|
||||||
|
const result = await RecycleAPI.create({
|
||||||
|
customerId: customerId.value,
|
||||||
|
ruleId: selectedRule.value.id,
|
||||||
|
requestNo: requestNo.value,
|
||||||
|
multiple: multipleValue,
|
||||||
|
// 只有确实调整过才提交实际数量,无调整权限时一律不传
|
||||||
|
recycleQuantity: recycleQuantity === defaultRecycleQuantity.value ? undefined : recycleQuantity,
|
||||||
|
exchangeQuantity: exchangeQuantity === defaultExchangeQuantity.value ? undefined : exchangeQuantity,
|
||||||
|
occurredAt: buildOccurredAt(),
|
||||||
|
remark: remark.value || null,
|
||||||
|
attachmentList: buildAttachments()
|
||||||
|
});
|
||||||
|
Message.success("兑换单已创建");
|
||||||
|
const id = result.id || "";
|
||||||
|
if (id) {
|
||||||
|
await router.replace({ name: "RecycleExchangeDetail", params: { id } });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await router.replace({ name: "RecycleExchangeList" });
|
||||||
|
} catch (error) {
|
||||||
|
Message.error(getErrorMessage(error, "兑换单创建失败,重试会复用同一请求号"));
|
||||||
|
} finally {
|
||||||
|
saving.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await loadRules();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="less">
|
||||||
|
.recycle-exchange-create {
|
||||||
|
padding: 0 0 2rem;
|
||||||
|
|
||||||
|
.form {
|
||||||
|
|
||||||
|
.customer {
|
||||||
|
|
||||||
|
.customer-actions {
|
||||||
|
gap: .5rem;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-profile {
|
||||||
|
margin: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.adjust-tips {
|
||||||
|
gap: .5rem;
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
.tips {
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
font-size: .8125rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.photo-wrap {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-tips {
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
font-size: .8125rem;
|
||||||
|
line-height: 1.6;
|
||||||
|
padding: .75rem 2rem 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.rule-picker {
|
||||||
|
|
||||||
|
.item {
|
||||||
|
padding: .75rem 1rem;
|
||||||
|
border-radius: 1rem;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background: var(--td-brand-color-1, rgba(0, 82, 217, .08));
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
gap: .5rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(html.theme-dark) {
|
||||||
|
.rule-picker {
|
||||||
|
|
||||||
|
.item.active {
|
||||||
|
background: rgba(15, 118, 110, .22);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,498 @@
|
|||||||
|
<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>
|
||||||
@@ -0,0 +1,517 @@
|
|||||||
|
<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,289 @@
|
|||||||
|
<template>
|
||||||
|
<div class="tui-page-layout tui-navbar">
|
||||||
|
<t-navbar
|
||||||
|
fixed
|
||||||
|
:z-index="20"
|
||||||
|
:title="isCreate ? '新增回收物' : '编辑回收物'"
|
||||||
|
left-arrow
|
||||||
|
@left-click="exit()"
|
||||||
|
>
|
||||||
|
<template #right>
|
||||||
|
<t-button
|
||||||
|
:loading="saving"
|
||||||
|
theme="primary"
|
||||||
|
variant="text"
|
||||||
|
size="small"
|
||||||
|
content="保存"
|
||||||
|
@click="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"
|
||||||
|
/>
|
||||||
|
</t-popup>
|
||||||
|
<product-select-popup
|
||||||
|
v-model="selection"
|
||||||
|
v-model:visible="productPopupVisible"
|
||||||
|
product-scope="all"
|
||||||
|
@select="handleProductSelection"
|
||||||
|
/>
|
||||||
|
</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 { 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 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();
|
||||||
|
|
||||||
|
function exit(saved = false): void {
|
||||||
|
if (pane) {
|
||||||
|
pane.close(saved);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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>
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
<template>
|
||||||
|
<div class="tui-page-layout tui-navbar recycle-item-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.configManage"
|
||||||
|
class="list"
|
||||||
|
:split="isWide"
|
||||||
|
:selected="!!selectedId"
|
||||||
|
:direction="paneDirection"
|
||||||
|
>
|
||||||
|
<template #master>
|
||||||
|
<t-pull-down-refresh
|
||||||
|
class="pull-refresh"
|
||||||
|
v-model="refreshing"
|
||||||
|
:refresh-timeout="30000"
|
||||||
|
@refresh="reload"
|
||||||
|
@scrolltolower="loadMore"
|
||||||
|
>
|
||||||
|
<div class="filters glass">
|
||||||
|
<t-input
|
||||||
|
v-model.trim="keyword"
|
||||||
|
class="keyword"
|
||||||
|
type="search"
|
||||||
|
borderless
|
||||||
|
clearable
|
||||||
|
placeholder="搜索回收物名称"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<t-cell-group v-if="list.length" theme="card">
|
||||||
|
<t-cell
|
||||||
|
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="(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>
|
||||||
|
<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>
|
||||||
|
</template>
|
||||||
|
</t-cell>
|
||||||
|
</t-cell-group>
|
||||||
|
<center-tips v-else :content="loading ? '正在加载回收物' : '暂无回收物配置'" />
|
||||||
|
<center-tips :content="loading ? '正在加载' : noMore ? `共 ${total} 条配置` : '上拉加载更多'" />
|
||||||
|
</t-pull-down-refresh>
|
||||||
|
</template>
|
||||||
|
<template #detail>
|
||||||
|
<recycle-item-edit
|
||||||
|
:key="`item-${selectedId}`"
|
||||||
|
:item-id="selectedId"
|
||||||
|
@saved="reload"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</master-detail-page>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||||
|
import { Toolkit } from "timi-web";
|
||||||
|
import RecycleAPI from "@/api/RecycleAPI";
|
||||||
|
import RecycleItemEdit from "@/pages/recycle/RecycleItemEdit.vue";
|
||||||
|
import type { NavbarAction } from "@/types/NavbarAction";
|
||||||
|
import type { RecycleItem } from "@/types/Recycle";
|
||||||
|
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 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 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;
|
||||||
|
|
||||||
|
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 result = await RecycleAPI.itemList({
|
||||||
|
offset: pageIndex.value * pageSize,
|
||||||
|
limit: pageSize,
|
||||||
|
keyword: keyword.value.trim() || undefined
|
||||||
|
});
|
||||||
|
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 reload(): 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, "回收物配置加载失败"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(" · ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 跳转 ----------
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
onUnmounted(() => {
|
||||||
|
reloadByKeyword.cancel();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="less">
|
||||||
|
.recycle-item-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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,400 @@
|
|||||||
|
<template>
|
||||||
|
<div class="tui-page-layout tui-navbar">
|
||||||
|
<t-navbar
|
||||||
|
fixed
|
||||||
|
:z-index="20"
|
||||||
|
:title="isCreate ? '新增兑换规则' : '编辑兑换规则'"
|
||||||
|
left-arrow
|
||||||
|
@left-click="exit()"
|
||||||
|
>
|
||||||
|
<template #right>
|
||||||
|
<t-button
|
||||||
|
:loading="saving"
|
||||||
|
theme="primary"
|
||||||
|
variant="text"
|
||||||
|
size="small"
|
||||||
|
content="保存"
|
||||||
|
@click="save()"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</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-item>
|
||||||
|
<t-form-item label="单份回收数量" required-mark>
|
||||||
|
<t-input
|
||||||
|
v-model.trim="form.recycleQuantity"
|
||||||
|
type="number"
|
||||||
|
align="right"
|
||||||
|
borderless
|
||||||
|
:placeholder="`按${recycleUnitName || '回收单位'}填写`"
|
||||||
|
/>
|
||||||
|
</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>
|
||||||
|
<t-form-item v-if="skuDisplayText || unitDisplayText" label="产品 SKU" content-align="right">
|
||||||
|
<product-sku-tags :fallback="skuDisplayText" :unit="unitDisplayText" />
|
||||||
|
</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>
|
||||||
|
<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="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>
|
||||||
|
<product-select-popup
|
||||||
|
v-model="selection"
|
||||||
|
v-model:visible="productPopupVisible"
|
||||||
|
@select="handleProductSelection"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { BottomPopup, 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 { RecycleItem, 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";
|
||||||
|
|
||||||
|
defineOptions({ name: "RecycleRuleEdit" });
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<{
|
||||||
|
/** 指定规则 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
|
||||||
|
ruleId?: string;
|
||||||
|
}>(), {
|
||||||
|
ruleId: ""
|
||||||
|
});
|
||||||
|
const emit = defineEmits<{
|
||||||
|
saved: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const router = useRouter();
|
||||||
|
const currentId = computed(() => props.ruleId || String(route.params.id || ""));
|
||||||
|
const isCreate = computed(() => !currentId.value);
|
||||||
|
|
||||||
|
useExpandToMaster({
|
||||||
|
path: "/management/recycle-rules",
|
||||||
|
id: () => currentId.value
|
||||||
|
});
|
||||||
|
/** 非空说明当前被内联在主从分栏的右栏里 */
|
||||||
|
const pane = usePane();
|
||||||
|
|
||||||
|
function exit(saved = false): void {
|
||||||
|
if (pane) {
|
||||||
|
pane.close(saved);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void router.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 表单 ----------
|
||||||
|
|
||||||
|
const form = reactive({
|
||||||
|
id: "",
|
||||||
|
recycleItemId: "",
|
||||||
|
recycleQuantity: "",
|
||||||
|
exchangeQuantity: "",
|
||||||
|
status: "ACTIVE" as RecycleStatus,
|
||||||
|
sortText: "",
|
||||||
|
remark: ""
|
||||||
|
});
|
||||||
|
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 均已启用,且所选业务单位允许销售。规则停用不影响已创建的兑换单。";
|
||||||
|
|
||||||
|
function openItemPicker(): void {
|
||||||
|
itemPickerVisible.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 loadItems(): Promise<void> {
|
||||||
|
itemLoading.value = true;
|
||||||
|
const loadedList: RecycleItem[] = [];
|
||||||
|
let offset = 0;
|
||||||
|
const limit = 100;
|
||||||
|
let total = 0;
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
const page = await RecycleAPI.itemList({ offset, limit });
|
||||||
|
const rows = page.list || [];
|
||||||
|
loadedList.push(...rows);
|
||||||
|
total = page.total || 0;
|
||||||
|
offset += rows.length;
|
||||||
|
if (!rows.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (offset < total);
|
||||||
|
itemList.value = loadedList;
|
||||||
|
} finally {
|
||||||
|
itemLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(): Promise<void> {
|
||||||
|
const id = currentId.value;
|
||||||
|
try {
|
||||||
|
await loadItems();
|
||||||
|
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 || "";
|
||||||
|
} catch (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;
|
||||||
|
if (saving.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!form.recycleItemId || !skuId || !skuUnitId) {
|
||||||
|
Message.warning("请选择回收物和兑换产品业务单位");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!recycleQuantity || !exchangeQuantity || recycleQuantity === "0" || exchangeQuantity === "0") {
|
||||||
|
Message.warning("单份回收数量和兑换数量必须为大于 0 的数字,最多 3 位小数");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const sort = form.sortText ? Number(form.sortText) : 0;
|
||||||
|
if (!Number.isSafeInteger(sort)) {
|
||||||
|
Message.warning("排序值必须为整数");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
saving.value = true;
|
||||||
|
try {
|
||||||
|
await RecycleAPI.ruleSave({
|
||||||
|
id: form.id || undefined,
|
||||||
|
recycleItemId: form.recycleItemId,
|
||||||
|
recycleQuantity,
|
||||||
|
skuId,
|
||||||
|
skuUnitId,
|
||||||
|
exchangeQuantity,
|
||||||
|
status: status || form.status,
|
||||||
|
sort,
|
||||||
|
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.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 {
|
||||||
|
|
||||||
|
.tips {
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
font-size: .8125rem;
|
||||||
|
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>
|
||||||
@@ -0,0 +1,265 @@
|
|||||||
|
<template>
|
||||||
|
<div class="tui-page-layout tui-navbar recycle-rule-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.configManage"
|
||||||
|
class="list"
|
||||||
|
:split="isWide"
|
||||||
|
:selected="!!selectedId"
|
||||||
|
:direction="paneDirection"
|
||||||
|
>
|
||||||
|
<template #master>
|
||||||
|
<t-pull-down-refresh
|
||||||
|
class="pull-refresh"
|
||||||
|
v-model="refreshing"
|
||||||
|
:refresh-timeout="30000"
|
||||||
|
@refresh="reload"
|
||||||
|
@scrolltolower="loadMore"
|
||||||
|
>
|
||||||
|
<div class="filters glass">
|
||||||
|
<t-input
|
||||||
|
v-model.trim="keyword"
|
||||||
|
class="keyword"
|
||||||
|
type="search"
|
||||||
|
borderless
|
||||||
|
clearable
|
||||||
|
placeholder="搜索回收物或兑换产品"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<t-cell-group v-if="list.length" theme="card">
|
||||||
|
<t-cell
|
||||||
|
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)" />
|
||||||
|
</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-cell-group>
|
||||||
|
<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"
|
||||||
|
@saved="reload"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</master-detail-page>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||||
|
import { Toolkit } from "timi-web";
|
||||||
|
import RecycleAPI from "@/api/RecycleAPI";
|
||||||
|
import RecycleRuleEdit from "@/pages/recycle/RecycleRuleEdit.vue";
|
||||||
|
import type { NavbarAction } from "@/types/NavbarAction";
|
||||||
|
import type { RecycleExchangeRule } from "@/types/Recycle";
|
||||||
|
import { getErrorMessage } from "@/utils/error";
|
||||||
|
import { Message } from "@/utils/message";
|
||||||
|
import { permissionCodes } from "@/utils/permission";
|
||||||
|
import { getRecycleQuantityText, getRecycleStatusText, getRecycleStatusTheme } from "@/utils/recycle";
|
||||||
|
|
||||||
|
defineOptions({ name: "RecycleRuleList" });
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const { selectedId, isWide, paneDirection, openDetail } = useMasterDetailPane({
|
||||||
|
path: "/management/recycle-rules",
|
||||||
|
detail: id => `/management/recycle-rules/${id}`
|
||||||
|
});
|
||||||
|
|
||||||
|
const actions = computed<NavbarAction[]>(() => [
|
||||||
|
{
|
||||||
|
key: "create",
|
||||||
|
text: "新增规则",
|
||||||
|
icon: "add",
|
||||||
|
theme: "primary",
|
||||||
|
action: toCreate
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "items",
|
||||||
|
text: "回收物配置",
|
||||||
|
icon: "catalog",
|
||||||
|
theme: "primary",
|
||||||
|
action: toItemList
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
// ---------- 列表 ----------
|
||||||
|
|
||||||
|
const list = ref<RecycleExchangeRule[]>([]);
|
||||||
|
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;
|
||||||
|
|
||||||
|
/** 回收物、产品、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 getExchangeText(rule: RecycleExchangeRule): string {
|
||||||
|
const productName = rule.productName || "";
|
||||||
|
const skuText = rule.specSummary || rule.skuName || "";
|
||||||
|
if (!productName) {
|
||||||
|
return skuText;
|
||||||
|
}
|
||||||
|
return skuText && skuText !== productName ? `${productName}(${skuText})` : productName;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 result = await RecycleAPI.ruleList({
|
||||||
|
offset: pageIndex.value * pageSize,
|
||||||
|
limit: pageSize,
|
||||||
|
keyword: keyword.value.trim() || undefined
|
||||||
|
});
|
||||||
|
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 reload(): 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, "兑换规则加载失败"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const reloadByKeyword = Toolkit.debounce(async () => {
|
||||||
|
await reload();
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
// ---------- 跳转 ----------
|
||||||
|
|
||||||
|
function toEdit(item: RecycleExchangeRule): void {
|
||||||
|
openDetail(item.id || "");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toCreate(): Promise<void> {
|
||||||
|
await router.push({ name: "RecycleRuleCreate" });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toItemList(): Promise<void> {
|
||||||
|
await router.push({ name: "RecycleItemList" });
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(reload);
|
||||||
|
watch(keyword, () => {
|
||||||
|
reloadByKeyword();
|
||||||
|
});
|
||||||
|
onUnmounted(() => {
|
||||||
|
reloadByKeyword.cancel();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(html.theme-dark) {
|
||||||
|
.recycle-rule-list {
|
||||||
|
|
||||||
|
.fallback {
|
||||||
|
color: #ccfbf1;
|
||||||
|
background: #115e59;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,437 @@
|
|||||||
|
<template>
|
||||||
|
<div class="tui-page-layout tui-navbar recycle-stat">
|
||||||
|
<t-navbar
|
||||||
|
fixed
|
||||||
|
:z-index="20"
|
||||||
|
title="回收兑换统计"
|
||||||
|
left-arrow
|
||||||
|
@left-click="$router.back()"
|
||||||
|
>
|
||||||
|
<template #right>
|
||||||
|
<t-button
|
||||||
|
:loading="loading"
|
||||||
|
theme="primary"
|
||||||
|
variant="text"
|
||||||
|
size="small"
|
||||||
|
content="刷新"
|
||||||
|
@click="load"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</t-navbar>
|
||||||
|
<main class="tui-page-content scroll column">
|
||||||
|
<div v-can="permissionCodes.recycleExchange.query" 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">
|
||||||
|
<t-cell title="开始日期" :note="customRange[0] || '-'" arrow @click="openStartPicker" />
|
||||||
|
<t-cell title="结束日期" :note="customRange[1] || '-'" arrow @click="openEndPicker" />
|
||||||
|
</template>
|
||||||
|
<t-cell title="统计范围" :note="rangeText" />
|
||||||
|
</t-cell-group>
|
||||||
|
<section class="panel" v-entrance-transition>
|
||||||
|
<div class="panel-head">
|
||||||
|
<div class="title">回收统计</div>
|
||||||
|
<div class="range" v-text="rangeText" />
|
||||||
|
</div>
|
||||||
|
<div class="rows">
|
||||||
|
<div v-for="row in recycleStatList" :key="`${row.recycleItemId}-${row.recycleName}-${row.recycleUnit}`" class="row">
|
||||||
|
<div class="name">
|
||||||
|
<span class="clip-text" v-text="row.recycleName || '未命名回收物'" />
|
||||||
|
<span v-if="row.recycleUnit" class="unit" v-text="`(${row.recycleUnit})`" />
|
||||||
|
</div>
|
||||||
|
<div class="values">
|
||||||
|
<span class="value" v-text="`收到 ${quantityText(row.receivedQuantity)}`" />
|
||||||
|
<span class="value" v-text="`退回 ${quantityText(row.returnedQuantity)}`" />
|
||||||
|
<span class="value net" v-text="`净 ${quantityText(row.netQuantity)}`" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<center-tips v-if="!recycleStatList.length" :content="loading ? '正在统计' : '所选区间没有回收记录'" />
|
||||||
|
</div>
|
||||||
|
<div class="panel-total">
|
||||||
|
<span v-text="`合计收到 ${quantityText(recycleTotals.received)}`" />
|
||||||
|
<span v-text="`合计退回 ${quantityText(recycleTotals.returned)}`" />
|
||||||
|
<span class="net" v-text="`净回收 ${quantityText(recycleTotals.net)}`" />
|
||||||
|
</div>
|
||||||
|
<div class="panel-tip" v-text="'收到量按兑换单业务时间归集,退回量按撤销或冲正业务时间归集,跨期退回可能让净值为负。'" />
|
||||||
|
</section>
|
||||||
|
<section class="panel" v-entrance-transition>
|
||||||
|
<div class="panel-head">
|
||||||
|
<div class="title">兑换统计</div>
|
||||||
|
<div class="range" v-text="rangeText" />
|
||||||
|
</div>
|
||||||
|
<div class="rows">
|
||||||
|
<div v-for="row in exchangeStatList" :key="`${row.skuId}-${row.skuUnitId}-${row.productName}`" class="row">
|
||||||
|
<div class="name">
|
||||||
|
<span class="clip-text" v-text="row.productName || '未命名产品'" />
|
||||||
|
<span v-if="row.unit" class="unit" v-text="`(${row.unit})`" />
|
||||||
|
</div>
|
||||||
|
<div class="values">
|
||||||
|
<span class="value" v-text="`创建 ${quantityText(row.createdQuantity)}`" />
|
||||||
|
<span class="value" v-text="`核销 ${quantityText(row.verifiedQuantity)}`" />
|
||||||
|
<span class="value net" v-text="`冲正 ${quantityText(row.revokedQuantity)}`" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<center-tips v-if="!exchangeStatList.length" :content="loading ? '正在统计' : '所选区间没有兑换记录'" />
|
||||||
|
</div>
|
||||||
|
<div class="panel-total">
|
||||||
|
<span v-text="`合计创建 ${quantityText(exchangeTotals.created)}`" />
|
||||||
|
<span v-text="`合计核销 ${quantityText(exchangeTotals.verified)}`" />
|
||||||
|
<span class="net" v-text="`合计冲正 ${quantityText(exchangeTotals.revoked)}`" />
|
||||||
|
</div>
|
||||||
|
<div class="panel-tip" v-text="'数量按业务单位统计,兑换不计入销售金额、收款或销售订单数量。'" />
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
<t-popup v-model="rangePickerVisible" placement="bottom">
|
||||||
|
<t-picker
|
||||||
|
v-model="rangeDraft"
|
||||||
|
:columns="rangeColumns"
|
||||||
|
title="统计区间"
|
||||||
|
@cancel="rangePickerVisible = false"
|
||||||
|
@confirm="confirmRange"
|
||||||
|
/>
|
||||||
|
</t-popup>
|
||||||
|
<t-popup v-model="startPickerVisible" placement="bottom">
|
||||||
|
<t-date-time-picker
|
||||||
|
v-if="startPickerVisible"
|
||||||
|
v-model="startDraft"
|
||||||
|
format="YYYY-MM-DD"
|
||||||
|
:mode="['date']"
|
||||||
|
title="开始日期"
|
||||||
|
@cancel="startPickerVisible = false"
|
||||||
|
@confirm="confirmStart"
|
||||||
|
/>
|
||||||
|
</t-popup>
|
||||||
|
<t-popup v-model="endPickerVisible" placement="bottom">
|
||||||
|
<t-date-time-picker
|
||||||
|
v-if="endPickerVisible"
|
||||||
|
v-model="endDraft"
|
||||||
|
format="YYYY-MM-DD"
|
||||||
|
:mode="['date']"
|
||||||
|
title="结束日期"
|
||||||
|
@cancel="endPickerVisible = false"
|
||||||
|
@confirm="confirmEnd"
|
||||||
|
/>
|
||||||
|
</t-popup>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { Time } from "timi-web";
|
||||||
|
import RecycleAPI from "@/api/RecycleAPI";
|
||||||
|
import type { RecycleExchangeStatRow, RecycleStatRow } from "@/types/Recycle";
|
||||||
|
import { getErrorMessage } from "@/utils/error";
|
||||||
|
import { Message } from "@/utils/message";
|
||||||
|
import { addPackageQuantity, getPackageQuantityText } from "@/utils/package";
|
||||||
|
import { permissionCodes } from "@/utils/permission";
|
||||||
|
|
||||||
|
defineOptions({ name: "RecycleStat" });
|
||||||
|
|
||||||
|
type RangeType = "today" | "thisWeek" | "thisMonth" | "lastMonth" | "custom";
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const rangeType = ref<RangeType>("thisMonth");
|
||||||
|
const customRange = ref<[string, string]>(["", ""]);
|
||||||
|
const rangePickerVisible = ref(false);
|
||||||
|
const rangeDraft = ref<Array<string | number>>(["thisMonth"]);
|
||||||
|
const startDraft = ref("");
|
||||||
|
const endDraft = ref("");
|
||||||
|
const startPickerVisible = ref(false);
|
||||||
|
const endPickerVisible = ref(false);
|
||||||
|
const recycleStatList = ref<RecycleStatRow[]>([]);
|
||||||
|
const exchangeStatList = ref<RecycleExchangeStatRow[]>([]);
|
||||||
|
const rangeOptions: Array<{ label: string; value: RangeType }> = [
|
||||||
|
{ label: "今天", value: "today" },
|
||||||
|
{ label: "本周", value: "thisWeek" },
|
||||||
|
{ label: "本月", value: "thisMonth" },
|
||||||
|
{ label: "上个月", value: "lastMonth" },
|
||||||
|
{ label: "自定义", value: "custom" }
|
||||||
|
];
|
||||||
|
const rangeColumns = rangeOptions.map(item => ({ label: item.label, value: item.value }));
|
||||||
|
const rangeLabel = computed(() => rangeOptions.find(item => item.value === rangeType.value)?.label || "时间范围");
|
||||||
|
const isCustom = computed(() => rangeType.value === "custom");
|
||||||
|
const activeRange = computed(() => (isCustom.value ? customRange.value : buildPresetRange(rangeType.value)));
|
||||||
|
const rangeText = computed(() => {
|
||||||
|
const [begin, end] = activeRange.value;
|
||||||
|
if (!begin || !end) {
|
||||||
|
return "未选择区间";
|
||||||
|
}
|
||||||
|
// 接口区间右开,展示时把结束日回退一天,避免显示成次日
|
||||||
|
const endDate = new Date(`${end} 00:00:00`);
|
||||||
|
endDate.setDate(endDate.getDate() - 1);
|
||||||
|
return `${begin} 至 ${Time.toDate(endDate)}`;
|
||||||
|
});
|
||||||
|
const recycleTotals = computed(() => sumRecycle(recycleStatList.value));
|
||||||
|
const exchangeTotals = computed(() => sumExchange(exchangeStatList.value));
|
||||||
|
|
||||||
|
// ---------- 区间 ----------
|
||||||
|
|
||||||
|
function toDateText(date: Date): string {
|
||||||
|
return Time.toDate(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
function startOfDay(date: Date): Date {
|
||||||
|
const value = new Date(date);
|
||||||
|
value.setHours(0, 0, 0, 0);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 统计接口的结束时间是开区间,所有预设都换算成「次日零点」。 */
|
||||||
|
function buildPresetRange(type: RangeType): [string, string] {
|
||||||
|
const now = new Date();
|
||||||
|
const today = startOfDay(now);
|
||||||
|
const tomorrow = new Date(today);
|
||||||
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||||
|
if (type === "today") {
|
||||||
|
return [toDateText(today), toDateText(tomorrow)];
|
||||||
|
}
|
||||||
|
if (type === "thisWeek") {
|
||||||
|
const day = today.getDay() || 7;
|
||||||
|
const monday = new Date(today);
|
||||||
|
monday.setDate(monday.getDate() - day + 1);
|
||||||
|
return [toDateText(monday), toDateText(tomorrow)];
|
||||||
|
}
|
||||||
|
if (type === "lastMonth") {
|
||||||
|
const begin = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
||||||
|
const end = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||||
|
return [toDateText(begin), toDateText(end)];
|
||||||
|
}
|
||||||
|
const begin = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||||
|
return [toDateText(begin), toDateText(tomorrow)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildTimestamps(): [number, number] | undefined {
|
||||||
|
const [begin, end] = activeRange.value;
|
||||||
|
if (!begin || !end) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const startAt = Time.toTimestamp(new Date(`${begin} 00:00:00`));
|
||||||
|
const endAt = Time.toTimestamp(new Date(`${end} 00:00:00`));
|
||||||
|
if (!(startAt < endAt)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return [startAt, endAt];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 统计 ----------
|
||||||
|
|
||||||
|
function quantityText(value?: number | string | null): string {
|
||||||
|
return getPackageQuantityText(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sumRecycle(rows: RecycleStatRow[]): { received: string; returned: string; net: string } {
|
||||||
|
let received = "0";
|
||||||
|
let returned = "0";
|
||||||
|
let net = "0";
|
||||||
|
for (const row of rows) {
|
||||||
|
received = addPackageQuantity(received, row.receivedQuantity ?? "0") || received;
|
||||||
|
returned = addPackageQuantity(returned, row.returnedQuantity ?? "0") || returned;
|
||||||
|
net = addPackageQuantity(net, row.netQuantity ?? "0") || net;
|
||||||
|
}
|
||||||
|
return { received, returned, net };
|
||||||
|
}
|
||||||
|
|
||||||
|
function sumExchange(rows: RecycleExchangeStatRow[]): { created: string; verified: string; revoked: string } {
|
||||||
|
let created = "0";
|
||||||
|
let verified = "0";
|
||||||
|
let revoked = "0";
|
||||||
|
for (const row of rows) {
|
||||||
|
created = addPackageQuantity(created, row.createdQuantity ?? "0") || created;
|
||||||
|
verified = addPackageQuantity(verified, row.verifiedQuantity ?? "0") || verified;
|
||||||
|
revoked = addPackageQuantity(revoked, row.revokedQuantity ?? "0") || revoked;
|
||||||
|
}
|
||||||
|
return { created, verified, revoked };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(): Promise<void> {
|
||||||
|
const timestamps = buildTimestamps();
|
||||||
|
if (!timestamps) {
|
||||||
|
recycleStatList.value = [];
|
||||||
|
exchangeStatList.value = [];
|
||||||
|
if (isCustom.value) {
|
||||||
|
Message.warning("自定义区间需要开始日期早于结束日期");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const [startAt, endAt] = timestamps;
|
||||||
|
const [recycleResult, exchangeResult] = await Promise.all([
|
||||||
|
RecycleAPI.statRecycle(startAt, endAt),
|
||||||
|
RecycleAPI.statExchange(startAt, endAt)
|
||||||
|
]);
|
||||||
|
recycleStatList.value = recycleResult || [];
|
||||||
|
exchangeStatList.value = exchangeResult || [];
|
||||||
|
} catch (error) {
|
||||||
|
Message.error(getErrorMessage(error, "回收兑换统计加载失败"));
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 区间交互 ----------
|
||||||
|
|
||||||
|
async function confirmRange(value: Array<string | number>): Promise<void> {
|
||||||
|
rangeType.value = String(value[0] || rangeDraft.value[0] || "thisMonth") as RangeType;
|
||||||
|
rangePickerVisible.value = false;
|
||||||
|
if (isCustom.value && (!customRange.value[0] || !customRange.value[1])) {
|
||||||
|
const [begin, end] = buildPresetRange("thisMonth");
|
||||||
|
// 自定义初始值取本月区间,结束日要回退成可选的日期
|
||||||
|
customRange.value = [begin, toDateText(new Date(`${end} 00:00:00`))];
|
||||||
|
}
|
||||||
|
await load();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openStartPicker(): void {
|
||||||
|
startDraft.value = customRange.value[0] || Time.toDate(new Date());
|
||||||
|
startPickerVisible.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEndPicker(): void {
|
||||||
|
endDraft.value = customRange.value[1] || Time.toDate(new Date());
|
||||||
|
endPickerVisible.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmStart(value?: string | number): Promise<void> {
|
||||||
|
startPickerVisible.value = false;
|
||||||
|
customRange.value = [String(value || startDraft.value), customRange.value[1]];
|
||||||
|
await load();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmEnd(value?: string | number): Promise<void> {
|
||||||
|
endPickerVisible.value = false;
|
||||||
|
customRange.value = [customRange.value[0], String(value || endDraft.value)];
|
||||||
|
await load();
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(load);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="less">
|
||||||
|
.recycle-stat {
|
||||||
|
|
||||||
|
.stat-body {
|
||||||
|
gap: 1rem;
|
||||||
|
display: flex;
|
||||||
|
padding: 0 1rem 2rem;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.range-card {
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
:deep(.t-cell__title) {
|
||||||
|
flex: 0 0 5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.t-cell__note) {
|
||||||
|
flex: 1 1 0;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: right;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
padding: 1rem 1rem .75rem;
|
||||||
|
background: var(--td-bg-color-container);
|
||||||
|
border-radius: 1rem;
|
||||||
|
|
||||||
|
.panel-head {
|
||||||
|
gap: .5rem;
|
||||||
|
display: flex;
|
||||||
|
padding-bottom: .75rem;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.range {
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
font-size: .75rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.rows {
|
||||||
|
gap: .5rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.row {
|
||||||
|
gap: .5rem;
|
||||||
|
display: flex;
|
||||||
|
padding: .5rem 0;
|
||||||
|
flex-direction: column;
|
||||||
|
border-bottom: 1px solid var(--td-component-border);
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
display: flex;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: .875rem;
|
||||||
|
align-items: baseline;
|
||||||
|
|
||||||
|
// clip-text 默认 flex:1 会把单位推到最右,这里让它跟随名称
|
||||||
|
.clip-text {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unit {
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
flex: 0 0 auto;
|
||||||
|
font-size: .75rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.values {
|
||||||
|
gap: .75rem;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
font-size: .75rem;
|
||||||
|
|
||||||
|
.value {
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.net {
|
||||||
|
color: var(--td-text-color-primary);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-total {
|
||||||
|
gap: .75rem;
|
||||||
|
display: flex;
|
||||||
|
margin-top: .5rem;
|
||||||
|
font-size: .75rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
padding-top: .75rem;
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
border-top: 1px solid var(--td-component-border);
|
||||||
|
|
||||||
|
.net {
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-tip {
|
||||||
|
color: var(--td-text-color-placeholder);
|
||||||
|
font-size: .75rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
padding-top: .5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
<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>
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
<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>
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
</t-button>
|
</t-button>
|
||||||
<template v-else-if="updateStage === 'downloading'">
|
<template v-else-if="updateStage === 'downloading'">
|
||||||
<t-progress class="progress" stroke-width=".5rem" :percentage="percent" />
|
<t-progress class="progress" stroke-width=".5rem" :percentage="percent" />
|
||||||
<t-button theme="primary" size="large" block disabled>
|
<t-button class="cell-button" theme="primary" size="large" disabled>
|
||||||
<span v-text="`下载中 ${percent}%`" />
|
<span v-text="`下载中 ${percent}%`" />
|
||||||
</t-button>
|
</t-button>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -140,6 +140,12 @@ const entryGroupList: HomeEntryGroup[] = [
|
|||||||
permission: permissionCodes.pointRedemption.create,
|
permission: permissionCodes.pointRedemption.create,
|
||||||
icon: "gift",
|
icon: "gift",
|
||||||
title: "积分兑换"
|
title: "积分兑换"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/management/recycle-exchanges",
|
||||||
|
permission: permissionCodes.recycleExchange.query,
|
||||||
|
icon: "swap",
|
||||||
|
title: "回收兑换"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,6 +149,28 @@ const menuGroupList = computed<MenuGroup[]>(() => [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
icon: "swap",
|
||||||
|
path: "/management/recycle-exchanges",
|
||||||
|
title: "回收兑换",
|
||||||
|
visible: userStore.hasPermissions(permissionCodes.recycleExchange.query)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "setting",
|
||||||
|
path: "/management/recycle-items",
|
||||||
|
title: "回收配置",
|
||||||
|
visible: userStore.hasPermissions(permissionCodes.recycleExchange.configManage)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "chart-combo",
|
||||||
|
path: "/management/recycle-stats",
|
||||||
|
title: "回收统计",
|
||||||
|
visible: userStore.hasPermissions(permissionCodes.recycleExchange.query)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: "analysis",
|
key: "analysis",
|
||||||
items: [
|
items: [
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import followUpReminderRoutes from "@/router/routes/followUpReminderRoutes";
|
|||||||
import productRoutes from "@/router/routes/productRoutes";
|
import productRoutes from "@/router/routes/productRoutes";
|
||||||
import salesOrderRoutes from "@/router/routes/salesOrderRoutes";
|
import salesOrderRoutes from "@/router/routes/salesOrderRoutes";
|
||||||
import fulfillmentRoutes from "@/router/routes/fulfillmentRoutes";
|
import fulfillmentRoutes from "@/router/routes/fulfillmentRoutes";
|
||||||
|
import recycleRoutes from "@/router/routes/recycleRoutes";
|
||||||
import dataExportRoutes from "@/router/routes/dataExportRoutes";
|
import dataExportRoutes from "@/router/routes/dataExportRoutes";
|
||||||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||||||
import { useGlobalUIStore } from "@/store/globalUI";
|
import { useGlobalUIStore } from "@/store/globalUI";
|
||||||
@@ -37,6 +38,7 @@ const detailRoutes = [
|
|||||||
...productRoutes,
|
...productRoutes,
|
||||||
...salesOrderRoutes,
|
...salesOrderRoutes,
|
||||||
...fulfillmentRoutes,
|
...fulfillmentRoutes,
|
||||||
|
...recycleRoutes,
|
||||||
...dataExportRoutes
|
...dataExportRoutes
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import type { RouteRecordRaw } from "vue-router";
|
||||||
|
|
||||||
|
function meta(depth = 3): RouteRecordRaw["meta"] {
|
||||||
|
return { depth, tabBarVisible: false, bodyBackground: "#F5F5F8", darkBodyBackground: "#10161f" };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
path: "/management/recycle-exchanges",
|
||||||
|
name: "RecycleExchangeList",
|
||||||
|
component: () => import("@/pages/recycle/RecycleExchangeList.vue"),
|
||||||
|
meta: meta()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/management/recycle-exchanges/create",
|
||||||
|
name: "RecycleExchangeCreate",
|
||||||
|
component: () => import("@/pages/recycle/RecycleExchangeCreate.vue"),
|
||||||
|
meta: meta(4)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/management/recycle-exchanges/:id",
|
||||||
|
name: "RecycleExchangeDetail",
|
||||||
|
component: () => import("@/pages/recycle/RecycleExchangeDetail.vue"),
|
||||||
|
meta: meta(4)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/management/recycle-items",
|
||||||
|
name: "RecycleItemList",
|
||||||
|
component: () => import("@/pages/recycle/RecycleItemList.vue"),
|
||||||
|
meta: meta()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/management/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"),
|
||||||
|
meta: meta(4)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/management/recycle-rules",
|
||||||
|
name: "RecycleRuleList",
|
||||||
|
component: () => import("@/pages/recycle/RecycleRuleList.vue"),
|
||||||
|
meta: meta()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/management/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"),
|
||||||
|
meta: meta(4)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/management/recycle-stats",
|
||||||
|
name: "RecycleStat",
|
||||||
|
component: () => import("@/pages/recycle/RecycleStat.vue"),
|
||||||
|
meta: meta()
|
||||||
|
}
|
||||||
|
] as RouteRecordRaw[];
|
||||||
@@ -2,6 +2,7 @@ import { useUserStore } from "timi-web-api";
|
|||||||
|
|
||||||
import EventRecordAPI from "@/api/EventRecordAPI";
|
import EventRecordAPI from "@/api/EventRecordAPI";
|
||||||
import FulfillmentAPI from "@/api/FulfillmentAPI";
|
import FulfillmentAPI from "@/api/FulfillmentAPI";
|
||||||
|
import RecycleAPI from "@/api/RecycleAPI";
|
||||||
import SalesOrderAPI from "@/api/SalesOrderAPI";
|
import SalesOrderAPI from "@/api/SalesOrderAPI";
|
||||||
import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents";
|
import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents";
|
||||||
import { permissionCodes } from "@/utils/permission";
|
import { permissionCodes } from "@/utils/permission";
|
||||||
@@ -11,13 +12,16 @@ import { useCurrentStoreStore } from "./currentStoreStore";
|
|||||||
export const usePendingNoticeStore = defineStore("pendingNotice", () => {
|
export const usePendingNoticeStore = defineStore("pendingNotice", () => {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const currentStoreStore = useCurrentStoreStore();
|
const currentStoreStore = useCurrentStoreStore();
|
||||||
const pendingCounts = reactive({ fulfillment: 0, stock: 0, fund: 0, event: 0 });
|
const pendingCounts = reactive({ fulfillment: 0, stock: 0, fund: 0, event: 0, recycle: 0 });
|
||||||
let pendingRequestId = 0;
|
let pendingRequestId = 0;
|
||||||
const pendingNoticeList = computed(() => {
|
const pendingNoticeList = computed(() => {
|
||||||
const notices: { content: string; name: string; query: Record<string, string> }[] = [];
|
const notices: { content: string; name: string; query: Record<string, string> }[] = [];
|
||||||
if (pendingCounts.fulfillment) {
|
if (pendingCounts.fulfillment) {
|
||||||
notices.push({ content: `有 ${pendingCounts.fulfillment} 条履约待核销`, name: "OrderFulfillmentList", query: { status: "PENDING" } });
|
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) {
|
if (pendingCounts.fund) {
|
||||||
notices.push({ content: `有 ${pendingCounts.fund} 条资金流水待核销`, name: "FundRecordList", query: { status: "PENDING" } });
|
notices.push({ content: `有 ${pendingCounts.fund} 条资金流水待核销`, name: "FundRecordList", query: { status: "PENDING" } });
|
||||||
}
|
}
|
||||||
@@ -55,6 +59,9 @@ export const usePendingNoticeStore = defineStore("pendingNotice", () => {
|
|||||||
if (userStore.hasPermissions(permissionCodes.eventRecord.read)) {
|
if (userStore.hasPermissions(permissionCodes.eventRecord.read)) {
|
||||||
tasks.push(load("event", () => EventRecordAPI.list({ index: 0, size: 1, verificationStatus: "PENDING" })));
|
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);
|
await Promise.all(tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +69,7 @@ export const usePendingNoticeStore = defineStore("pendingNotice", () => {
|
|||||||
() => [currentStoreStore.currentStoreId, userStore.loginUser.user?.id || userStore.loginUser.id || ""],
|
() => [currentStoreStore.currentStoreId, userStore.loginUser.user?.id || userStore.loginUser.id || ""],
|
||||||
([, userId]) => {
|
([, userId]) => {
|
||||||
pendingRequestId++;
|
pendingRequestId++;
|
||||||
Object.assign(pendingCounts, { fulfillment: 0, stock: 0, fund: 0, event: 0 });
|
Object.assign(pendingCounts, { fulfillment: 0, stock: 0, fund: 0, event: 0, recycle: 0 });
|
||||||
if (userId) {
|
if (userId) {
|
||||||
void refreshPendingNotices();
|
void refreshPendingNotices();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,232 @@
|
|||||||
|
import type { Attachment, Model, PageResult, User } from "timi-web-api";
|
||||||
|
import type { Customer } from "@/types/Customer";
|
||||||
|
import type { ProductSkuSpecSnapshot, StockRecord } from "@/types/Product";
|
||||||
|
|
||||||
|
/** 回收物与兑换规则的启用状态。配置没有删除,停用使用 INACTIVE。 */
|
||||||
|
export type RecycleStatus = "ACTIVE" | "INACTIVE";
|
||||||
|
|
||||||
|
/** 兑换单状态。 */
|
||||||
|
export type RecycleExchangeStatus = "PENDING" | "VERIFIED" | "CANCELLED" | "REVOKED";
|
||||||
|
|
||||||
|
/** 兑换单操作类型。 */
|
||||||
|
export type RecycleExchangeActionType = "VERIFY" | "CANCEL" | "REVOKE";
|
||||||
|
|
||||||
|
/** 回收物配置。回收物不是退货,不校验客户购买记录,也不累计客户余额。 */
|
||||||
|
export type RecycleItem = {
|
||||||
|
storeId?: string;
|
||||||
|
name: string;
|
||||||
|
/** 回收计量单位,例如「个」「公斤」 */
|
||||||
|
unitName: string;
|
||||||
|
/** 来源产品 ID,仅用于识别,不影响库存 */
|
||||||
|
productId?: string | null;
|
||||||
|
/** 来源 SKU ID,填写时必须同时填写其所属 productId */
|
||||||
|
skuId?: string | null;
|
||||||
|
status?: RecycleStatus;
|
||||||
|
remark?: string | null;
|
||||||
|
/** 来源产品名称,服务端回填,仅展示用 */
|
||||||
|
sourceProductName?: string | null;
|
||||||
|
/** 来源 SKU 规格摘要,服务端回填,仅展示用 */
|
||||||
|
sourceSkuName?: string | null;
|
||||||
|
} & Model;
|
||||||
|
|
||||||
|
/** 回收物配置分页与筛选条件。 */
|
||||||
|
export type RecycleItemPage = {
|
||||||
|
storeId?: string;
|
||||||
|
status?: RecycleStatus;
|
||||||
|
/** 名称关键字 */
|
||||||
|
keyword?: string;
|
||||||
|
offset: number;
|
||||||
|
limit: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 回收兑换规则:单份回收数量兑换单份业务单位数量。 */
|
||||||
|
export type RecycleExchangeRule = {
|
||||||
|
storeId?: string;
|
||||||
|
recycleItemId: string;
|
||||||
|
/** 单份规则回收数量 */
|
||||||
|
recycleQuantity: number | string;
|
||||||
|
/** 兑换 SKU ID */
|
||||||
|
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;
|
||||||
|
skuName?: string | null;
|
||||||
|
specSummary?: string | null;
|
||||||
|
unitName?: string | null;
|
||||||
|
stockEnabled?: boolean | null;
|
||||||
|
allowDecimalQuantity?: boolean | null;
|
||||||
|
} & Model;
|
||||||
|
|
||||||
|
/** 兑换规则分页与筛选条件。 */
|
||||||
|
export type RecycleExchangeRulePage = {
|
||||||
|
storeId?: string;
|
||||||
|
status?: RecycleStatus;
|
||||||
|
recycleItemId?: string;
|
||||||
|
skuId?: string;
|
||||||
|
/** 回收物名称关键字 */
|
||||||
|
keyword?: string;
|
||||||
|
offset: number;
|
||||||
|
limit: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 兑换单。
|
||||||
|
*
|
||||||
|
* 规则、产品、客户后续变更都不改写单据,页面展示优先使用快照字段。
|
||||||
|
*/
|
||||||
|
export type RecycleExchange = {
|
||||||
|
storeId?: string;
|
||||||
|
customerId?: string;
|
||||||
|
requestNo?: string;
|
||||||
|
ruleId?: string;
|
||||||
|
recycleItemId?: string;
|
||||||
|
recycleNameSnapshot?: string;
|
||||||
|
recycleUnitSnapshot?: string;
|
||||||
|
sourceProductIdSnapshot?: string;
|
||||||
|
sourceSkuIdSnapshot?: string;
|
||||||
|
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;
|
||||||
|
/** 业务发生时间 */
|
||||||
|
occurredAt?: number;
|
||||||
|
remark?: string | null;
|
||||||
|
customer?: Customer;
|
||||||
|
operator?: Partial<User>;
|
||||||
|
} & Model;
|
||||||
|
|
||||||
|
/** 兑换单操作记录。核销记录的退回字段为空。 */
|
||||||
|
export type RecycleExchangeAction = {
|
||||||
|
exchangeId?: string;
|
||||||
|
actionType?: RecycleExchangeActionType;
|
||||||
|
operatorUserId?: string;
|
||||||
|
occurredAt?: number;
|
||||||
|
reason?: string | null;
|
||||||
|
remark?: string | null;
|
||||||
|
/** true 为回收物全部退还客户 */
|
||||||
|
recycleReturned?: boolean | null;
|
||||||
|
/** true 为兑换商品已退回门店 */
|
||||||
|
stockReturned?: boolean | null;
|
||||||
|
stockRecordId?: string;
|
||||||
|
sourceStockRecordId?: string;
|
||||||
|
operator?: Partial<User>;
|
||||||
|
} & Model;
|
||||||
|
|
||||||
|
/** 兑换单详情。冲正照片按操作记录 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 = {
|
||||||
|
storeId?: string;
|
||||||
|
customerId?: string;
|
||||||
|
recycleItemId?: string;
|
||||||
|
skuId?: string;
|
||||||
|
status?: RecycleExchangeStatus;
|
||||||
|
/** 业务时间起点,包含 */
|
||||||
|
beginAt?: number;
|
||||||
|
/** 业务时间终点,包含 */
|
||||||
|
endAt?: number;
|
||||||
|
index: number;
|
||||||
|
size: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置列表分页结果。
|
||||||
|
*
|
||||||
|
* 后端返回的 pages 按本次列表长度计算,末页可能不准,分页一律用 total 推算。
|
||||||
|
*/
|
||||||
|
export type RecyclePageResult<T> = PageResult<T> & {
|
||||||
|
pages?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 回收统计行。同一回收物名称或单位变化后可能出现多行。 */
|
||||||
|
export type RecycleStatRow = {
|
||||||
|
recycleItemId?: string;
|
||||||
|
recycleName?: string;
|
||||||
|
recycleUnit?: string;
|
||||||
|
receivedQuantity?: number | string;
|
||||||
|
returnedQuantity?: number | string;
|
||||||
|
netQuantity?: number | string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 兑换统计行。三项数量按创建、核销、冲正的业务时间分别归集。 */
|
||||||
|
export type RecycleExchangeStatRow = {
|
||||||
|
skuId?: string;
|
||||||
|
skuUnitId?: string;
|
||||||
|
productName?: string;
|
||||||
|
unit?: string;
|
||||||
|
createdQuantity?: number | string;
|
||||||
|
verifiedQuantity?: number | string;
|
||||||
|
revokedQuantity?: number | string;
|
||||||
|
};
|
||||||
@@ -99,6 +99,15 @@ export const permissionCodes = {
|
|||||||
return: "GAO:ORDER_FULFILLMENT:RETURN",
|
return: "GAO:ORDER_FULFILLMENT:RETURN",
|
||||||
revoke: "GAO:ORDER_FULFILLMENT:REVOKE"
|
revoke: "GAO:ORDER_FULFILLMENT:REVOKE"
|
||||||
},
|
},
|
||||||
|
recycleExchange: {
|
||||||
|
configManage: "GAO:RECYCLE_EXCHANGE:CONFIG_MANAGE",
|
||||||
|
query: "GAO:RECYCLE_EXCHANGE:QUERY",
|
||||||
|
create: "GAO:RECYCLE_EXCHANGE:CREATE",
|
||||||
|
quantityAdjust: "GAO:RECYCLE_EXCHANGE:QUANTITY_ADJUST",
|
||||||
|
verify: "GAO:RECYCLE_EXCHANGE:VERIFY",
|
||||||
|
cancel: "GAO:RECYCLE_EXCHANGE:CANCEL",
|
||||||
|
revoke: "GAO:RECYCLE_EXCHANGE:REVOKE"
|
||||||
|
},
|
||||||
fundReceive: {
|
fundReceive: {
|
||||||
create: "GAO:FUND_RECEIVE:CREATE",
|
create: "GAO:FUND_RECEIVE:CREATE",
|
||||||
verify: "GAO:FUND_RECEIVE:VERIFY"
|
verify: "GAO:FUND_RECEIVE:VERIFY"
|
||||||
@@ -244,6 +253,13 @@ export const gaoStoreScopePermissionCodes = [
|
|||||||
permissionCodes.orderFulfillment.revoke,
|
permissionCodes.orderFulfillment.revoke,
|
||||||
permissionCodes.fundReceive.create,
|
permissionCodes.fundReceive.create,
|
||||||
permissionCodes.fundReceive.verify,
|
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.fundRecord.read,
|
permissionCodes.fundRecord.read,
|
||||||
permissionCodes.fund.refund,
|
permissionCodes.fund.refund,
|
||||||
permissionCodes.fund.revoke,
|
permissionCodes.fund.revoke,
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import type { RecycleExchange, RecycleExchangeActionType, RecycleExchangeStatus, RecycleStatus } from "@/types/Recycle";
|
||||||
|
import { comparePackageQuantity, getPackageQuantityText } from "@/utils/package";
|
||||||
|
|
||||||
|
/** 配置状态(回收物、规则)的展示文案。 */
|
||||||
|
export function getRecycleStatusText(status?: RecycleStatus): string {
|
||||||
|
return ({ ACTIVE: "启用", INACTIVE: "停用" } as Record<string, string>)[status || ""] || "未知";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRecycleStatusTheme(status?: RecycleStatus): "success" | "warning" | "default" {
|
||||||
|
if (status === "ACTIVE") {
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
if (status === "INACTIVE") {
|
||||||
|
return "warning";
|
||||||
|
}
|
||||||
|
return "default";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 兑换单状态文案。 */
|
||||||
|
export function getRecycleExchangeStatusText(status?: RecycleExchangeStatus): string {
|
||||||
|
return ({
|
||||||
|
PENDING: "待核销",
|
||||||
|
VERIFIED: "已核销",
|
||||||
|
CANCELLED: "已撤销",
|
||||||
|
REVOKED: "已冲正"
|
||||||
|
} as Record<string, string>)[status || ""] || "未知";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRecycleExchangeStatusTheme(status?: RecycleExchangeStatus): "success" | "warning" | "danger" | "primary" {
|
||||||
|
if (status === "VERIFIED") {
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
if (status === "PENDING") {
|
||||||
|
return "warning";
|
||||||
|
}
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canCancelExchange(status?: RecycleExchangeStatus): boolean {
|
||||||
|
return status === "PENDING";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canRevokeExchange(status?: RecycleExchangeStatus): boolean {
|
||||||
|
return status === "VERIFIED";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 拼接「数量 + 单位」,后端 BigDecimal 可能是字符串。 */
|
||||||
|
export function getRecycleQuantityText(value: number | string | null | undefined, unit?: string | null): string {
|
||||||
|
const quantityText = getPackageQuantityText(value);
|
||||||
|
return unit ? `${quantityText} ${unit}` : quantityText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按整数倍数放大规则数量。
|
||||||
|
*
|
||||||
|
* 用 BigInt 做定点乘法,避免 0.5 × 3 这类组合出现二进制浮点尾数。
|
||||||
|
* 倍数可能来自 TDesign Stepper,它的 formatNumber 返回字符串(如 "2"、"2.0"),
|
||||||
|
* 所以必须先转数字,不能直接对入参用 Number.isFinite。
|
||||||
|
*/
|
||||||
|
export function multiplyRecycleQuantity(value: number | string | null | undefined, multiple: number | string | null | undefined): string {
|
||||||
|
const quantityText = getPackageQuantityText(value);
|
||||||
|
const [integerText, fractionText = ""] = quantityText.split(".");
|
||||||
|
const multipleValue = Number(multiple);
|
||||||
|
const multiplier = Number.isFinite(multipleValue) && 0 < multipleValue ? Math.trunc(multipleValue) : 0;
|
||||||
|
const digits = BigInt(`${integerText}${fractionText}`) * BigInt(multiplier);
|
||||||
|
const padded = digits.toString().padStart(fractionText.length + 1, "0");
|
||||||
|
const integer = fractionText.length ? padded.slice(0, -fractionText.length) : padded;
|
||||||
|
const fraction = fractionText.length ? padded.slice(-fractionText.length).replace(/0+$/, "") : "";
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user