feat(frontend): 商品属性、订单状态与导出任务界面
- 新增商品属性页(分类/品牌/单位)与商品表单的品牌/单位选择 - 新增订单状态页:状态分视图列表、新建/编辑弹窗、明细维护、审核/驳回/取消/作废/恢复/推送仓库等操作 - 导出任务按类型动态渲染筛选表单与任务进度;导出按钮/筛选组件抽为公共组件 - 旧地址 order-split / order-create / order-delivery 重定向到 /order,导航与多标签页适配新页面 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
4343bcdd17
commit
907df04070
@ -6,7 +6,38 @@
|
||||
<title>OMS 管理系统</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<div id="app">
|
||||
<!-- 首屏占位:动态路由(菜单)注册完成前先显示加载中,避免刷新时白屏 -->
|
||||
<div class="app-boot">
|
||||
<span class="app-boot__spinner"></span>
|
||||
<span class="app-boot__text">正在加载…</span>
|
||||
</div>
|
||||
</div>
|
||||
<style>
|
||||
.app-boot {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
color: #909399;
|
||||
font-size: 14px;
|
||||
font-family: system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif;
|
||||
}
|
||||
.app-boot__spinner {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 2px solid #dcdfe6;
|
||||
border-top-color: #409eff;
|
||||
border-radius: 50%;
|
||||
animation: app-boot-spin 0.8s linear infinite;
|
||||
}
|
||||
@keyframes app-boot-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
16
frontend/package-lock.json
generated
16
frontend/package-lock.json
generated
@ -10,6 +10,7 @@
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
"axios": "^1.20.0",
|
||||
"element-china-area-data": "^6.1.0",
|
||||
"element-plus": "^2.9.1",
|
||||
"pinia": "^2.3.1",
|
||||
"vue": "^3.5.13",
|
||||
@ -1270,6 +1271,12 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/china-division": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/china-division/-/china-division-2.7.0.tgz",
|
||||
"integrity": "sha512-4uUPAT+1WfqDh5jytq7omdCmHNk3j+k76zEG/2IqaGcYB90c2SwcixttcypdsZ3T/9tN1TTpBDoeZn+Yw/qBEA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
@ -1341,6 +1348,15 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/element-china-area-data": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/element-china-area-data/-/element-china-area-data-6.1.0.tgz",
|
||||
"integrity": "sha512-IkpcjwQv2A/2AxFiSoaISZ+oMw1rZCPUSOg5sOCwT5jKc96TaawmKZeY81xfxXsO0QbKxU5LLc6AirhG52hUmg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"china-division": "^2.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/element-plus": {
|
||||
"version": "2.14.5",
|
||||
"resolved": "https://registry.npmjs.org/element-plus/-/element-plus-2.14.5.tgz",
|
||||
|
||||
@ -29,6 +29,13 @@ body,
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
/* 页面标题行的右侧操作按钮组(如「新增 + 导出」) */
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* 卡片:头部与内容 */
|
||||
.el-card__header {
|
||||
padding: 10px 12px;
|
||||
|
||||
@ -1,16 +1,45 @@
|
||||
import { get, post } from '@/utils/request'
|
||||
import request from '@/utils/request'
|
||||
|
||||
/** 导出类型:出入库记录 / 商品 / 订单 */
|
||||
export type ExportType = 'stock_record' | 'product' | 'order'
|
||||
/**
|
||||
* 导出类型:由后端注册表定义(见 backend/app/utils/exportDefs.js#EXPORT_TYPES),
|
||||
* 前端不做枚举收窄,新增类型时后端改一处即可
|
||||
*/
|
||||
export type ExportType = string
|
||||
|
||||
/** 筛选字段控件类型:文本 / 下拉 / 日期 / 数字 / 商品选择器 / 店铺选择器 / 仓库选择器 */
|
||||
export type ExportFilterType =
|
||||
| 'text'
|
||||
| 'select'
|
||||
| 'date'
|
||||
| 'number'
|
||||
| 'product'
|
||||
| 'shop'
|
||||
| 'warehouse'
|
||||
|
||||
/** 筛选字段下拉选项 */
|
||||
export interface ExportFilterOption {
|
||||
label: string
|
||||
value: string | number
|
||||
}
|
||||
|
||||
/** 筛选字段定义(后端随导出类型一起下发,前端据此动态渲染提交表单) */
|
||||
export interface ExportFilterDef {
|
||||
key: string
|
||||
label: string
|
||||
type: ExportFilterType
|
||||
options?: ExportFilterOption[]
|
||||
placeholder?: string
|
||||
}
|
||||
|
||||
/** 导出任务状态:0待处理 1处理中 2已完成 3失败 */
|
||||
export type ExportStatus = 0 | 1 | 2 | 3
|
||||
|
||||
/** 导出类型选项(后端返回) */
|
||||
/** 导出类型选项(后端返回,含该类型可传的筛选字段定义) */
|
||||
export interface ExportTypeOption {
|
||||
value: ExportType
|
||||
label: string
|
||||
filters: ExportFilterDef[]
|
||||
}
|
||||
|
||||
/** 导出任务项 */
|
||||
@ -31,26 +60,10 @@ export interface ExportTaskItem {
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 导出筛选条件(按类型可选字段) */
|
||||
export interface ExportFilters {
|
||||
product_id?: number | null
|
||||
warehouse_id?: number | null
|
||||
biz_type?: string
|
||||
direction?: number | string
|
||||
bill_type?: number | string
|
||||
item_type?: string
|
||||
bill_no?: string
|
||||
keyword?: string
|
||||
category_name?: string
|
||||
status?: number | string
|
||||
submit_status?: number | string
|
||||
shop_id?: number | null
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
/** 导出筛选条件(按类型可选,字段集合见后端下发的 ExportFilterDef[]) */
|
||||
export type ExportFilters = Record<string, string | number | boolean | null | undefined>
|
||||
|
||||
/** 导出类型选项 */
|
||||
/** 导出类型选项(含筛选字段定义) */
|
||||
export function getExportTypes() {
|
||||
return get<ExportTypeOption[]>('/export-tasks/types')
|
||||
}
|
||||
|
||||
396
frontend/src/api/orderStatus.ts
Normal file
396
frontend/src/api/orderStatus.ts
Normal file
@ -0,0 +1,396 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 订单(状态分表)
|
||||
*
|
||||
* 订单按状态分表存储,状态同时代表「所在表」:
|
||||
* pending 待审核 / queued 待推送 / exception 异常 / outsourcing 委外中 / delivery 配送
|
||||
* / void 已作废 / canceled 已取消 / history 历史(归档表)。
|
||||
* 流转:待审核 →(审核+锁库存)待推送 →(推送仓库成功)委外中 →(仓库回传确认)配送;推送失败 → 异常。
|
||||
* 列表按状态分视图(左侧 tab),状态流转由后端业务事务推动,前端只提交动作。
|
||||
*/
|
||||
export type OrderStage =
|
||||
| 'pending'
|
||||
| 'queued'
|
||||
| 'exception'
|
||||
| 'outsourcing'
|
||||
| 'delivery'
|
||||
| 'void'
|
||||
| 'canceled'
|
||||
| 'history'
|
||||
|
||||
/** 页面左侧 tab(顺序即状态流转顺序) */
|
||||
export const ORDER_STAGE_TABS: { key: OrderStage; label: string }[] = [
|
||||
{ key: 'pending', label: '待审核' },
|
||||
{ key: 'queued', label: '待推送' },
|
||||
{ key: 'exception', label: '异常' },
|
||||
{ key: 'outsourcing', label: '委外中' },
|
||||
{ key: 'delivery', label: '配送' },
|
||||
{ key: 'void', label: '已作废' },
|
||||
{ key: 'canceled', label: '已取消' },
|
||||
{ key: 'history', label: '历史' },
|
||||
]
|
||||
|
||||
/** 状态展示口径(文案与颜色,与后端 app/lib/orderStatus.js 对齐) */
|
||||
export const ORDER_STAGE_META: Record<
|
||||
OrderStage,
|
||||
{ label: string; tag: '' | 'info' | 'warning' | 'success' | 'danger' }
|
||||
> = {
|
||||
pending: { label: '待审核', tag: 'warning' },
|
||||
queued: { label: '待推送', tag: '' },
|
||||
exception: { label: '异常', tag: 'danger' },
|
||||
outsourcing: { label: '委外中', tag: '' },
|
||||
delivery: { label: '配送', tag: 'success' },
|
||||
void: { label: '已作废', tag: 'info' },
|
||||
canceled: { label: '已取消', tag: 'info' },
|
||||
history: { label: '历史', tag: 'info' },
|
||||
}
|
||||
|
||||
/** 商品明细行(product_info JSON 元素,列表摘要用) */
|
||||
export interface OrderProductLine {
|
||||
item_code: string | null
|
||||
item_name: string | null
|
||||
quantity: number | null
|
||||
price: number | null
|
||||
}
|
||||
|
||||
/** 商品明细(order_status_items:发货单明细与平台明细的超集) */
|
||||
export interface OrderItemLine {
|
||||
id?: number
|
||||
order_id?: number
|
||||
order_line_no?: string
|
||||
item_id?: number | null
|
||||
item_code?: string | null
|
||||
item_name?: string | null
|
||||
plan_qty: number
|
||||
actual_price?: number | null
|
||||
retail_price?: number | null
|
||||
ext_code?: string | null
|
||||
inventory_type?: string
|
||||
source_order_code?: string | null
|
||||
sub_source_order_code?: string | null
|
||||
stock_id?: number | null
|
||||
product_id?: number | null
|
||||
sku_code?: string | null
|
||||
spec?: string | null
|
||||
image?: string | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface OrderStatusItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
order_no: string
|
||||
parent_order_no: string | null
|
||||
shop_id: number | null
|
||||
shop_name?: string | null
|
||||
warehouse_id?: number | null
|
||||
warehouse_code?: string | null
|
||||
warehouse_name?: string | null
|
||||
product_info: OrderProductLine[] | null
|
||||
product_summary?: string
|
||||
product_kind?: number
|
||||
receiver: string | null
|
||||
address: string | null
|
||||
status: OrderStage
|
||||
status_label?: string
|
||||
remark: string | null
|
||||
/** —— 老发货单口径字段(为容纳老表而扩展) —— */
|
||||
order_type?: string | null
|
||||
is_urgency?: string | null
|
||||
invoice_flag?: string | null
|
||||
shop_nick?: string | null
|
||||
buyer_message?: string | null
|
||||
seller_message?: string | null
|
||||
total_amount?: number | string | null
|
||||
item_amount?: number | string | null
|
||||
discount_amount?: number | string | null
|
||||
freight?: number | string | null
|
||||
ar_amount?: number | string | null
|
||||
got_amount?: number | string | null
|
||||
logistics_code?: string | null
|
||||
logistics_name?: string | null
|
||||
express_code?: string | null
|
||||
express_codes?: string[] | null
|
||||
logistics_area_code?: string | null
|
||||
operator_name?: string | null
|
||||
tel?: string | null
|
||||
mobile?: string | null
|
||||
email?: string | null
|
||||
country_code?: string | null
|
||||
province?: string | null
|
||||
city?: string | null
|
||||
area?: string | null
|
||||
town?: string | null
|
||||
detail_address?: string | null
|
||||
zip_code?: string | null
|
||||
oaid?: string | null
|
||||
stock_locked?: number | null
|
||||
wms_status?: string | null
|
||||
wms_order_no?: string | null
|
||||
wms_synced_at?: string | null
|
||||
pushed_at?: string | null
|
||||
wms_push_result?: Record<string, unknown> | null
|
||||
legacy_source?: string | null
|
||||
legacy_order_id?: number | null
|
||||
legacy_status?: number | null
|
||||
item_total?: number | string | null
|
||||
item_kind?: number | null
|
||||
audit_by?: number | null
|
||||
audit_time?: string | null
|
||||
void_at?: string | null
|
||||
void_by?: number | null
|
||||
void_reason?: string | null
|
||||
/** 索引表记录的当前所在表 */
|
||||
current_table?: OrderStage
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
/** 仅历史视图 */
|
||||
archived_at?: string | null
|
||||
transferred_at?: string | null
|
||||
}
|
||||
|
||||
export interface OrderStatusQuery {
|
||||
status: OrderStage
|
||||
page: number
|
||||
pageSize: number
|
||||
order_no?: string
|
||||
parent_order_no?: string
|
||||
shop_id?: number | ''
|
||||
receiver?: string
|
||||
address?: string
|
||||
remark?: string
|
||||
created_from?: string
|
||||
created_to?: string
|
||||
archived_from?: string
|
||||
archived_to?: string
|
||||
}
|
||||
|
||||
export interface OrderStatusFilters {
|
||||
statuses: { value: OrderStage; label: string }[]
|
||||
status_labels: Record<OrderStage, string>
|
||||
active_statuses: OrderStage[]
|
||||
/** 超期自动归档阈值(月) */
|
||||
archive_months: number
|
||||
/** 订单索引表名 */
|
||||
index_table?: string
|
||||
shops: { id: number; name: string }[]
|
||||
warehouses: { id: number; code: string; name: string }[]
|
||||
}
|
||||
|
||||
/** 新建/编辑订单(发货单口径) */
|
||||
export interface OrderStatusPayload {
|
||||
/** 来源订单号(上游/平台订单号;与 order_no 至少传一个) */
|
||||
parent_order_no?: string
|
||||
order_no?: string
|
||||
shop_id?: number | null
|
||||
warehouse_id?: number | null
|
||||
order_type?: string
|
||||
receiver?: string
|
||||
tel?: string
|
||||
mobile?: string
|
||||
email?: string
|
||||
country_code?: string
|
||||
province?: string
|
||||
city?: string
|
||||
area?: string
|
||||
town?: string
|
||||
detail_address?: string
|
||||
zip_code?: string
|
||||
address?: string
|
||||
oaid?: string
|
||||
is_urgency?: string
|
||||
invoice_flag?: string
|
||||
total_amount?: number | null
|
||||
item_amount?: number | null
|
||||
discount_amount?: number | null
|
||||
freight?: number | null
|
||||
ar_amount?: number | null
|
||||
got_amount?: number | null
|
||||
logistics_code?: string
|
||||
logistics_name?: string
|
||||
seller_message?: string
|
||||
buyer_message?: string
|
||||
remark?: string
|
||||
product_info?: OrderProductLine[]
|
||||
/** 商品明细(发货单口径;与 product_info 二选一) */
|
||||
items?: OrderItemLine[]
|
||||
}
|
||||
|
||||
/** 流转结果(审核 / 推送 / 转回待审核 / 取消 / 作废 / 按 id 归档) */
|
||||
export interface OrderStatusTransitionResult {
|
||||
count: number
|
||||
status: OrderStage
|
||||
status_label: string
|
||||
order_nos: string[]
|
||||
/** 单条审核:本次锁定库存的明细行数 */
|
||||
stock_locked?: number
|
||||
/** 批量审核:失败明细 */
|
||||
failed?: number
|
||||
failures?: { id: number; message: string }[]
|
||||
}
|
||||
|
||||
/** 单据级流转结果(驳回 / 恢复:可能换号) */
|
||||
export interface OrderStatusSingleFlowResult {
|
||||
count: number
|
||||
status: OrderStage
|
||||
status_label: string
|
||||
items: { id: number; order_no: string; bill_no_changed: boolean }[]
|
||||
}
|
||||
|
||||
/** 推送仓库结果 */
|
||||
export interface OrderPushWmsResult {
|
||||
id: number
|
||||
attempts: number
|
||||
wms_response?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface OrderPushWmsBatchResult {
|
||||
requested: number
|
||||
processed: number
|
||||
pendingRest: number
|
||||
pushed: number
|
||||
failed: number
|
||||
retry: number
|
||||
skipped: number
|
||||
details: { id: number; ok: boolean; message: string }[]
|
||||
}
|
||||
|
||||
/** 归档结果(不传 ids 时按创建时间超期批量归档) */
|
||||
export interface OrderStatusArchiveResult {
|
||||
count: number
|
||||
status?: OrderStage
|
||||
status_label?: string
|
||||
order_nos?: string[]
|
||||
months?: number
|
||||
threshold?: string
|
||||
by_status?: Record<string, number>
|
||||
}
|
||||
|
||||
/** 订单列表(按 status 定位状态表;principal_id 由请求拦截器注入) */
|
||||
export function getOrderStatusList(params: OrderStatusQuery) {
|
||||
return get<{ list: OrderStatusItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/order-status/list',
|
||||
params as unknown as object,
|
||||
)
|
||||
}
|
||||
|
||||
/** 筛选项数据源:状态枚举 + 当前主体下的店铺/仓库 + 归档阈值 */
|
||||
export function getOrderStatusFilters() {
|
||||
return get<OrderStatusFilters>('/order-status/filters')
|
||||
}
|
||||
|
||||
/** 订单详情(单据头 + 商品明细) */
|
||||
export function getOrderStatusDetail(id: number) {
|
||||
return get<{ order: OrderStatusItem; items: OrderItemLine[] }>(`/order-status/${id}`)
|
||||
}
|
||||
|
||||
/** 新建订单 / 发货单(写入索引表 + 待审核表;带 items 时同时写入明细) */
|
||||
export function createOrderStatus(data: OrderStatusPayload) {
|
||||
return post<{
|
||||
id: number
|
||||
order_no: string
|
||||
status: OrderStage
|
||||
status_label: string
|
||||
item_count: number
|
||||
}>('/order-status', data)
|
||||
}
|
||||
|
||||
/** 编辑订单(仅待审核 / 异常;未传字段保持原值) */
|
||||
export function updateOrderStatus(id: number, data: OrderStatusPayload) {
|
||||
return put<{ id: number; order_no: string }>(`/order-status/${id}`, data)
|
||||
}
|
||||
|
||||
/** 删除订单(仅待审核 / 异常 / 已取消) */
|
||||
export function removeOrderStatus(id: number) {
|
||||
return del<{ count: number; order_nos: string[] }>(`/order-status/${id}`)
|
||||
}
|
||||
|
||||
/** 商品明细(按订单ID) */
|
||||
export function getOrderItems(orderId: number) {
|
||||
return get<{ list: OrderItemLine[]; total: number }>('/order-status/items', { order_id: orderId })
|
||||
}
|
||||
|
||||
/** 保存商品明细(整体替换,仅待审核 / 异常) */
|
||||
export function saveOrderItems(orderId: number, items: OrderItemLine[]) {
|
||||
return post<{ list: OrderItemLine[]; total: number }>('/order-status/items', {
|
||||
order_id: orderId,
|
||||
items,
|
||||
})
|
||||
}
|
||||
|
||||
/** 收件人文本智能识别 */
|
||||
export function parseReceiverText(text: string) {
|
||||
return post<Record<string, string>>('/order-status/parse-receiver', { text })
|
||||
}
|
||||
|
||||
/** 批量审核:待审核 / 异常 → 委外中 */
|
||||
export function auditOrders(ids: number[]) {
|
||||
return post<OrderStatusTransitionResult>('/order-status/audit', { ids })
|
||||
}
|
||||
|
||||
/** 批量推送外部:outcome=success 成功回传(→ 配送)/ failed 推送失败(→ 异常,remark 记录原因) */
|
||||
export function pushOrders(ids: number[], outcome: 'success' | 'failed', remark?: string) {
|
||||
return post<OrderStatusTransitionResult>('/order-status/push', { ids, outcome, remark })
|
||||
}
|
||||
|
||||
/** 异常批量转回待审核 */
|
||||
export function returnOrdersToPending(ids: number[]) {
|
||||
return post<OrderStatusTransitionResult>('/order-status/return-to-pending', { ids })
|
||||
}
|
||||
|
||||
/** 归档:传 ids 归档指定订单;不传则归档创建时间超过 months(默认 3)个月的订单 */
|
||||
export function archiveOrders(data: { ids?: number[]; months?: number }) {
|
||||
return post<OrderStatusArchiveResult>('/order-status/archive', data)
|
||||
}
|
||||
|
||||
/** 驳回(委外中 → 待审核;换号 + 释放锁定库存) */
|
||||
export function rejectOrders(ids: number[]) {
|
||||
return post<OrderStatusSingleFlowResult>('/order-status/reject', { ids })
|
||||
}
|
||||
|
||||
/** 取消(待审核 / 异常 / 委外中 → 已取消;已推送的会先取消外部单据) */
|
||||
export function cancelOrders(ids: number[], remark?: string) {
|
||||
return post<OrderStatusTransitionResult>('/order-status/cancel', { ids, remark })
|
||||
}
|
||||
|
||||
/** 作废(待审核 / 异常 / 委外中 → 已作废;记录作废原因并释放锁定库存) */
|
||||
export function voidOrders(ids: number[], voidReason?: string, remark?: string) {
|
||||
return post<OrderStatusTransitionResult>('/order-status/void', {
|
||||
ids,
|
||||
void_reason: voidReason,
|
||||
remark,
|
||||
})
|
||||
}
|
||||
|
||||
/** 恢复(已取消 / 已作废 → 待审核;曾推送过的自动换号) */
|
||||
export function restoreOrders(ids: number[]) {
|
||||
return post<OrderStatusSingleFlowResult>('/order-status/restore', { ids })
|
||||
}
|
||||
|
||||
/** 推送仓库(WMS deliveryorder.create):单条立即推送 */
|
||||
export function pushOrderToWms(id: number) {
|
||||
return post<OrderPushWmsResult>(`/order-status/${id}/push-wms`, {})
|
||||
}
|
||||
|
||||
/** 推送仓库:批量(顺序限流,超出部分交给定时任务) */
|
||||
export function pushOrdersToWms(ids: number[]) {
|
||||
return post<OrderPushWmsBatchResult>('/order-status/push-wms', { ids })
|
||||
}
|
||||
|
||||
/** 批量切换发货仓库(同步刷新 warehouse_code 快照) */
|
||||
export function changeOrdersWarehouse(ids: number[], warehouseId: number) {
|
||||
return post<{ updated: number; target: { id: number; code: string; name: string } }>(
|
||||
'/order-status/change-warehouse',
|
||||
{ ids, warehouse_id: warehouseId },
|
||||
)
|
||||
}
|
||||
|
||||
/** 批量设置所属店铺(同步刷新 shop_nick 快照) */
|
||||
export function changeOrdersShop(ids: number[], shopId: number) {
|
||||
return post<{ updated: number; target: { id: number; name: string } }>('/order-status/change-shop', {
|
||||
ids,
|
||||
shop_id: shopId,
|
||||
})
|
||||
}
|
||||
@ -17,7 +17,9 @@ export interface ProductItem {
|
||||
item_type: number
|
||||
category_id: number | null
|
||||
category_name: string | null
|
||||
brand_id: number | null
|
||||
brand_name: string | null
|
||||
unit_id: number | null
|
||||
length: number | string | null // 长度,单位 cm
|
||||
width: number | string | null // 宽度,单位 cm
|
||||
height: number | string | null // 高度,单位 cm
|
||||
@ -64,7 +66,9 @@ export interface ProductPayload {
|
||||
item_type?: number
|
||||
category_id?: number | null
|
||||
category_name?: string
|
||||
brand_id?: number | null
|
||||
brand_name?: string
|
||||
unit_id?: number | null
|
||||
sku_property?: string
|
||||
stock_unit?: string
|
||||
length?: number | null // 长度,单位 cm
|
||||
|
||||
57
frontend/src/api/productBrand.ts
Normal file
57
frontend/src/api/productBrand.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 商品品牌(按主体隔离) */
|
||||
export interface ProductBrand {
|
||||
id: number
|
||||
principal_id: number
|
||||
name: string
|
||||
code: string | null
|
||||
status: number
|
||||
sort: number
|
||||
remark: string | null
|
||||
/** 是否系统默认:1系统数据(不可改/删,全部主体可见) 0自定义(按主体隔离) */
|
||||
is_system?: number
|
||||
/** 被商品使用次数(被引用时禁止删除) */
|
||||
used_count?: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 下拉项(仅启用) */
|
||||
export interface ProductAttributeOption {
|
||||
id: number
|
||||
name: string
|
||||
code: string | null
|
||||
}
|
||||
|
||||
export interface ProductBrandPayload {
|
||||
name: string
|
||||
code?: string | null
|
||||
status?: number
|
||||
sort?: number
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
export function getProductBrands(params?: object) {
|
||||
return get<{ list: ProductBrand[]; total: number; page: number; pageSize: number }>(
|
||||
'/product-brands',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 下拉用:仅返回启用商品品牌(按 sort 升序) */
|
||||
export function getProductBrandOptions() {
|
||||
return get<ProductAttributeOption[]>('/product-brands/select')
|
||||
}
|
||||
|
||||
export function createProductBrand(data: ProductBrandPayload) {
|
||||
return post<{ id: number }>('/product-brands', data)
|
||||
}
|
||||
|
||||
export function updateProductBrand(id: number, data: Partial<ProductBrandPayload>) {
|
||||
return put<{ id: number }>(`/product-brands/${id}`, data)
|
||||
}
|
||||
|
||||
export function deleteProductBrand(id: number) {
|
||||
return del<{ id: number }>(`/product-brands/${id}`)
|
||||
}
|
||||
57
frontend/src/api/productCategory.ts
Normal file
57
frontend/src/api/productCategory.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 商品分类(按主体隔离) */
|
||||
export interface ProductCategory {
|
||||
id: number
|
||||
principal_id: number
|
||||
name: string
|
||||
code: string | null
|
||||
status: number
|
||||
sort: number
|
||||
remark: string | null
|
||||
/** 是否系统默认:1系统数据(不可改/删,全部主体可见) 0自定义(按主体隔离) */
|
||||
is_system?: number
|
||||
/** 被商品使用次数(被引用时禁止删除) */
|
||||
used_count?: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 下拉项(仅启用) */
|
||||
export interface ProductAttributeOption {
|
||||
id: number
|
||||
name: string
|
||||
code: string | null
|
||||
}
|
||||
|
||||
export interface ProductCategoryPayload {
|
||||
name: string
|
||||
code?: string | null
|
||||
status?: number
|
||||
sort?: number
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
export function getProductCategories(params?: object) {
|
||||
return get<{ list: ProductCategory[]; total: number; page: number; pageSize: number }>(
|
||||
'/product-categories',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 下拉用:仅返回启用商品分类(按 sort 升序) */
|
||||
export function getProductCategoryOptions() {
|
||||
return get<ProductAttributeOption[]>('/product-categories/select')
|
||||
}
|
||||
|
||||
export function createProductCategory(data: ProductCategoryPayload) {
|
||||
return post<{ id: number }>('/product-categories', data)
|
||||
}
|
||||
|
||||
export function updateProductCategory(id: number, data: Partial<ProductCategoryPayload>) {
|
||||
return put<{ id: number }>(`/product-categories/${id}`, data)
|
||||
}
|
||||
|
||||
export function deleteProductCategory(id: number) {
|
||||
return del<{ id: number }>(`/product-categories/${id}`)
|
||||
}
|
||||
57
frontend/src/api/productUnit.ts
Normal file
57
frontend/src/api/productUnit.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 商品单位(按主体隔离) */
|
||||
export interface ProductUnit {
|
||||
id: number
|
||||
principal_id: number
|
||||
name: string
|
||||
code: string | null
|
||||
status: number
|
||||
sort: number
|
||||
remark: string | null
|
||||
/** 是否系统默认:1系统数据(不可改/删,全部主体可见) 0自定义(按主体隔离) */
|
||||
is_system?: number
|
||||
/** 被商品使用次数(被引用时禁止删除) */
|
||||
used_count?: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 下拉项(仅启用) */
|
||||
export interface ProductAttributeOption {
|
||||
id: number
|
||||
name: string
|
||||
code: string | null
|
||||
}
|
||||
|
||||
export interface ProductUnitPayload {
|
||||
name: string
|
||||
code?: string | null
|
||||
status?: number
|
||||
sort?: number
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
export function getProductUnits(params?: object) {
|
||||
return get<{ list: ProductUnit[]; total: number; page: number; pageSize: number }>(
|
||||
'/product-units',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 下拉用:仅返回启用商品单位(按 sort 升序) */
|
||||
export function getProductUnitOptions() {
|
||||
return get<ProductAttributeOption[]>('/product-units/select')
|
||||
}
|
||||
|
||||
export function createProductUnit(data: ProductUnitPayload) {
|
||||
return post<{ id: number }>('/product-units', data)
|
||||
}
|
||||
|
||||
export function updateProductUnit(id: number, data: Partial<ProductUnitPayload>) {
|
||||
return put<{ id: number }>(`/product-units/${id}`, data)
|
||||
}
|
||||
|
||||
export function deleteProductUnit(id: number) {
|
||||
return del<{ id: number }>(`/product-units/${id}`)
|
||||
}
|
||||
47
frontend/src/components/ExportButton.vue
Normal file
47
frontend/src/components/ExportButton.vue
Normal file
@ -0,0 +1,47 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useExportTasks } from '@/composables/useExportTasks'
|
||||
import type { ExportFilters, ExportType } from '@/api/exportTask'
|
||||
|
||||
/**
|
||||
* 导出按钮(列表页通用)
|
||||
*
|
||||
* 用法:<ExportButton type="product" :filters="exportFilters" />
|
||||
* 点击后按当前页面筛选条件提交导出任务,完成时自动下载(逻辑见 composables/useExportTasks)。
|
||||
*/
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 导出类型(后端注册表 key) */
|
||||
type: ExportType
|
||||
/** 当前页面的筛选条件(字段名需与后端该类型的筛选项一致) */
|
||||
filters?: ExportFilters
|
||||
/** 按钮文案 */
|
||||
label?: string
|
||||
/** 按钮尺寸 */
|
||||
size?: 'large' | 'default' | 'small'
|
||||
/** 是否朴素按钮(列表页次级操作) */
|
||||
plain?: boolean
|
||||
}>(),
|
||||
{
|
||||
filters: () => ({}),
|
||||
label: '导出',
|
||||
size: 'default',
|
||||
plain: false,
|
||||
},
|
||||
)
|
||||
|
||||
const { submitting, submit } = useExportTasks()
|
||||
const text = computed(() => props.label)
|
||||
|
||||
function handleClick() {
|
||||
submit(props.type, props.filters || {})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-button type="success" :size="size" :plain="plain" :loading="submitting" @click="handleClick">
|
||||
<el-icon><Download /></el-icon>
|
||||
<span>{{ text }}</span>
|
||||
</el-button>
|
||||
</template>
|
||||
152
frontend/src/components/ExportFilterField.vue
Normal file
152
frontend/src/components/ExportFilterField.vue
Normal file
@ -0,0 +1,152 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import ProductSelect from '@/components/ProductSelect.vue'
|
||||
import VirtualSelect from '@/components/VirtualSelect.vue'
|
||||
import type { ExportFilterDef } from '@/api/exportTask'
|
||||
import type { ProductSearchItem } from '@/api/product'
|
||||
|
||||
/**
|
||||
* 导出筛选字段控件(按后端下发的筛选定义渲染对应控件)
|
||||
*
|
||||
* - text 文本框 / select 下拉 / date 日期 / number 数字
|
||||
* - product 商品选择器(锁定 product_id,并通过 update:productLabel 回传展示标签)
|
||||
* - shop / warehouse 店铺、仓库虚拟下拉(选项由父组件传入,避免各页重复请求)
|
||||
*/
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 筛选字段定义(后端返回) */
|
||||
field: ExportFilterDef
|
||||
/** 当前值 */
|
||||
modelValue?: string | number | null
|
||||
/** 商品字段已选中但选项未加载时的展示标签 */
|
||||
productLabel?: string
|
||||
/** 店铺下拉选项 */
|
||||
shopOptions?: { label: string; value: number }[]
|
||||
/** 仓库下拉选项 */
|
||||
warehouseOptions?: { label: string; value: number }[]
|
||||
}>(),
|
||||
{
|
||||
modelValue: undefined,
|
||||
productLabel: '',
|
||||
shopOptions: () => [],
|
||||
warehouseOptions: () => [],
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: string | number | null | undefined]
|
||||
'update:productLabel': [value: string]
|
||||
}>()
|
||||
|
||||
/** 通用值(文本 / 下拉 / 日期) */
|
||||
const value = computed({
|
||||
get: () => props.modelValue ?? undefined,
|
||||
set: (v: string | number | null | undefined) => emit('update:modelValue', v),
|
||||
})
|
||||
|
||||
/** 数字值(el-input-number 需要 number) */
|
||||
const numberValue = computed({
|
||||
get: () => (props.modelValue === undefined || props.modelValue === null || props.modelValue === ''
|
||||
? undefined
|
||||
: Number(props.modelValue)),
|
||||
set: (v: number | undefined) => emit('update:modelValue', v),
|
||||
})
|
||||
|
||||
/** 商品ID(ProductSelect 需要 number | null) */
|
||||
const productId = computed({
|
||||
get: () => (props.modelValue === undefined || props.modelValue === null || props.modelValue === ''
|
||||
? null
|
||||
: Number(props.modelValue)),
|
||||
set: (v: number | null) => emit('update:modelValue', v),
|
||||
})
|
||||
|
||||
function onProductSelect(product: ProductSearchItem) {
|
||||
emit('update:modelValue', product.id)
|
||||
emit('update:productLabel', product.item_code ? `${product.item_code} ${product.item_name}` : product.item_name || '')
|
||||
}
|
||||
|
||||
function clearProduct() {
|
||||
emit('update:modelValue', null)
|
||||
emit('update:productLabel', '')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-select
|
||||
v-if="field.type === 'select'"
|
||||
v-model="value"
|
||||
placeholder="全部"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option v-for="o in field.options || []" :key="String(o.value)" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
|
||||
<el-date-picker
|
||||
v-else-if="field.type === 'date'"
|
||||
v-model="value"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
:placeholder="field.placeholder || '选择日期'"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
/>
|
||||
|
||||
<el-input-number
|
||||
v-else-if="field.type === 'number'"
|
||||
v-model="numberValue"
|
||||
:min="0"
|
||||
:controls="false"
|
||||
:placeholder="field.placeholder || ''"
|
||||
style="width: 100%"
|
||||
/>
|
||||
|
||||
<div v-else-if="field.type === 'product'" class="product-filter">
|
||||
<ProductSelect
|
||||
v-model="productId"
|
||||
:model-label="productLabel"
|
||||
:placeholder="field.placeholder || '搜索商品编码/名称锁定商品'"
|
||||
@select="onProductSelect"
|
||||
/>
|
||||
<el-button v-if="productId != null" link type="primary" @click="clearProduct">清除</el-button>
|
||||
</div>
|
||||
|
||||
<VirtualSelect
|
||||
v-else-if="field.type === 'shop'"
|
||||
v-model="value"
|
||||
:options="shopOptions"
|
||||
placeholder="全部"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
/>
|
||||
|
||||
<VirtualSelect
|
||||
v-else-if="field.type === 'warehouse'"
|
||||
v-model="value"
|
||||
:options="warehouseOptions"
|
||||
placeholder="全部"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
/>
|
||||
|
||||
<el-input
|
||||
v-else
|
||||
v-model="value"
|
||||
:placeholder="field.placeholder || ''"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.product-filter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
109
frontend/src/composables/useExportTasks.ts
Normal file
109
frontend/src/composables/useExportTasks.ts
Normal file
@ -0,0 +1,109 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {
|
||||
downloadExport,
|
||||
getExportTask,
|
||||
submitExport,
|
||||
type ExportFilters,
|
||||
type ExportType,
|
||||
} from '@/api/exportTask'
|
||||
|
||||
/**
|
||||
* 导出任务提交与自动下载(全局单例)
|
||||
*
|
||||
* 任意页面提交导出后立即返回任务ID,本模块在后台轮询任务进度,完成后自动触发浏览器下载并提示;
|
||||
* 失败时提示原因。导出任务页的列表只负责展示进度,不再重复下载(避免下载两次)。
|
||||
*/
|
||||
|
||||
/** 轮询间隔(毫秒) */
|
||||
const POLL_INTERVAL = 2000
|
||||
|
||||
/** 待下载的任务ID(有值即代表轮询进行中) */
|
||||
const pendingIds = ref<number[]>([])
|
||||
let timer: number | null = null
|
||||
|
||||
/**
|
||||
* 触发浏览器下载导出文件
|
||||
* @param id 任务ID
|
||||
* @param fileName 文件名(后端返回,缺省按任务ID命名)
|
||||
*/
|
||||
export async function downloadExportFile(id: number, fileName?: string | null) {
|
||||
const blob = await downloadExport(id)
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = fileName || `export_${id}.xlsx`
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
window.URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
function removePending(id: number) {
|
||||
pendingIds.value = pendingIds.value.filter(item => item !== id)
|
||||
}
|
||||
|
||||
/** 轮询一轮:完成的自动下载,失败的提示原因,未完成的留到下一轮 */
|
||||
async function pollOnce() {
|
||||
for (const id of [ ...pendingIds.value ]) {
|
||||
try {
|
||||
const task = await getExportTask(id)
|
||||
if (task.status === 2) {
|
||||
removePending(id)
|
||||
await downloadExportFile(task.id, task.file_name)
|
||||
ElMessage.success(`导出完成(${task.type_label || task.type},共 ${task.total_count} 行),已开始下载`)
|
||||
} else if (task.status === 3) {
|
||||
removePending(id)
|
||||
ElMessage.error(`导出失败:${task.error_message || '未知原因'}`)
|
||||
}
|
||||
} catch {
|
||||
// 单次查询失败(如网络抖动)不打断轮询,下一轮重试
|
||||
}
|
||||
}
|
||||
if (!pendingIds.value.length) stopPolling()
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
if (timer != null) return
|
||||
timer = window.setInterval(() => { pollOnce().catch(() => {}) }, POLL_INTERVAL)
|
||||
pollOnce().catch(() => {})
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
if (timer != null) {
|
||||
window.clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出任务提交(组合式函数)
|
||||
* @return {Object} submitting 提交中标记 / submit 提交方法 / pendingCount 待下载任务数
|
||||
*/
|
||||
export function useExportTasks() {
|
||||
const submitting = ref(false)
|
||||
|
||||
/**
|
||||
* 提交导出任务
|
||||
* @param type 导出类型(后端注册表 key)
|
||||
* @param filters 筛选条件(字段需在该类型声明内,多余字段后端会丢弃)
|
||||
*/
|
||||
async function submit(type: ExportType, filters: ExportFilters = {}) {
|
||||
submitting.value = true
|
||||
try {
|
||||
const res = await submitExport({ type, filters })
|
||||
pendingIds.value = [ ...pendingIds.value, res.id ]
|
||||
startPolling()
|
||||
ElMessage.success('已提交导出任务,处理完成后将自动下载(可在顶栏「导出任务」查看进度)')
|
||||
return res
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
submitting,
|
||||
submit,
|
||||
pendingCount: computed(() => pendingIds.value.length),
|
||||
}
|
||||
}
|
||||
@ -48,6 +48,11 @@ const visibleTabs = computed(() => {
|
||||
return slice
|
||||
})
|
||||
|
||||
// 「更多」下拉里只展示被收起(未渲染在标签条上)的标签
|
||||
const hiddenTabs = computed(() =>
|
||||
tabs.tabs.filter((t) => !visibleTabs.value.some((v) => v.key === t.key)),
|
||||
)
|
||||
|
||||
function estimateWidth(t: { key: string; title: string; affix: boolean }): number {
|
||||
const cached = tabWidths.get(t.key)
|
||||
if (cached) return cached
|
||||
@ -178,12 +183,12 @@ function onPrincipalChange(id: number) {
|
||||
:closable="!tab.affix"
|
||||
/>
|
||||
</el-tabs>
|
||||
<el-dropdown trigger="click">
|
||||
<el-dropdown v-if="hiddenTabs.length" trigger="click">
|
||||
<el-button text size="small" :icon="ArrowDown">更多</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item
|
||||
v-for="tab in tabs.tabs"
|
||||
v-for="tab in hiddenTabs"
|
||||
:key="tab.key"
|
||||
@click="gotoTab(tab)"
|
||||
:style="{ color: tab.key === tabs.active ? 'var(--el-color-primary)' : '' }"
|
||||
@ -415,5 +420,9 @@ function onPrincipalChange(id: number) {
|
||||
font-weight: 600;
|
||||
margin-bottom: -1px;
|
||||
border-bottom: none;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
/* 顶部/两侧柔和阴影,让当前块"浮起"突出;底部下沉与正文无缝相连 */
|
||||
box-shadow: 0 -2px 10px -1px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -5,6 +5,9 @@ import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import pinia from './store'
|
||||
import { getToken } from './utils/request'
|
||||
import { useAuthStore } from './store/auth'
|
||||
import { useMenuStore } from './store/menu'
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
@ -13,6 +16,30 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
}
|
||||
|
||||
app.use(pinia)
|
||||
app.use(router)
|
||||
app.use(ElementPlus)
|
||||
app.mount('#app')
|
||||
|
||||
/**
|
||||
* 启动流程:先把「当前用户信息 + 菜单(动态路由)」准备好,再安装 router 并挂载。
|
||||
*
|
||||
* 业务页路由是按菜单动态注册的:若先 `app.use(router)` 再拉菜单,深链接刷新时
|
||||
* 首次解析匹配不到任何路由(白屏 + `No match found for location with path "..."` 警告)。
|
||||
* 失败不阻断启动:守卫仍会在后续导航里补拉菜单。
|
||||
*/
|
||||
async function bootstrap() {
|
||||
if (getToken()) {
|
||||
try {
|
||||
await useAuthStore().fetchProfile()
|
||||
} catch {
|
||||
// 401 由拦截器处理;无主体时守卫会引导到「创建主体」
|
||||
}
|
||||
try {
|
||||
await useMenuStore().fetchMenus()
|
||||
} catch {
|
||||
// 菜单接口异常时 store 内部已回退默认菜单
|
||||
}
|
||||
}
|
||||
app.use(router)
|
||||
app.mount('#app')
|
||||
}
|
||||
|
||||
void bootstrap()
|
||||
|
||||
@ -24,6 +24,11 @@ const router = createRouter({
|
||||
component: () => import('@/views/ExportTask/Index.vue'),
|
||||
meta: { title: '导出任务' },
|
||||
},
|
||||
// 兼容旧地址:订单页统一为 /order,旧书签/收藏重定向过去
|
||||
{ path: 'order-split', redirect: { path: '/order' } },
|
||||
// 老发货单入口已并入「订单」页(数据已迁入新表,能力均已在新表实现)
|
||||
{ path: 'order-create', redirect: { path: '/order' } },
|
||||
{ path: 'order-delivery', redirect: { path: '/order' } },
|
||||
],
|
||||
},
|
||||
],
|
||||
@ -52,11 +57,11 @@ router.beforeEach(async (to) => {
|
||||
const menuStore = useMenuStore()
|
||||
if (!menuStore.loaded) {
|
||||
await menuStore.fetchMenus()
|
||||
// 动态路由是本次导航期间注册的,深链接刷新时会早于匹配阶段,
|
||||
// 当前 to 尚未匹配到任何路由 → 用新的路由表重新解析当前目标
|
||||
if (to.matched.length === 0) {
|
||||
return to.fullPath
|
||||
}
|
||||
}
|
||||
// 动态路由是运行期注册的,深链接刷新时早于匹配阶段:
|
||||
// 当前 to 尚未匹配到任何路由 → 用新的路由表重新解析当前目标
|
||||
if (to.matched.length === 0) {
|
||||
return to.fullPath
|
||||
}
|
||||
// 已登录但无主体:强制停留在创建主体面板,隐藏其余菜单
|
||||
if (!auth.hasPrincipal && to.path !== '/principal/create') {
|
||||
|
||||
@ -25,14 +25,14 @@ const defaultMenus: MenuItem[] = [
|
||||
{
|
||||
id: 4, parent_id: 0, name: '订单管理', type: 1, icon: 'List', sort: 90, status: 1,
|
||||
children: [
|
||||
{ id: 42, parent_id: 4, name: '创建发货单', type: 2, path: '/order-create', icon: 'Plus', permission: 'orderDelivery:create', component: 'views/Order/Create.vue', sort: 80, status: 1 },
|
||||
{ id: 41, parent_id: 4, name: '订单', type: 2, path: '/order', icon: 'Tickets', permission: 'order:list', component: 'views/Order/Index.vue', sort: 70, status: 1 },
|
||||
{ id: 41, parent_id: 4, name: '订单', type: 2, path: '/order', icon: 'Tickets', permission: 'order:list', component: 'views/Order/Status.vue', sort: 70, status: 1 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 3, parent_id: 0, name: '商品管理', type: 1, icon: 'Goods', sort: 80, status: 1,
|
||||
children: [
|
||||
{ id: 31, parent_id: 3, name: '商品', type: 2, path: '/product', icon: 'Box', permission: 'product:list', component: 'views/Product/Index.vue', sort: 80, status: 1 },
|
||||
{ id: 33, parent_id: 3, name: '商品属性', type: 2, path: '/product-attribute', icon: 'Collection', permission: 'productAttribute:list', component: 'views/ProductAttribute/Index.vue', sort: 90, status: 1 },
|
||||
{ id: 32, parent_id: 3, name: '组合商品', type: 2, path: '/combo-product', icon: 'Files', permission: 'comboProduct:list', component: 'views/ComboProduct/Index.vue', sort: 70, status: 1 },
|
||||
{ id: 52, parent_id: 3, name: '店铺商品', type: 2, path: '/shop-product', icon: 'GoodsFilled', permission: 'shopProduct:list', component: 'views/ShopProduct/Index.vue', sort: 65, status: 1 },
|
||||
],
|
||||
|
||||
@ -15,39 +15,24 @@ export interface TabItem {
|
||||
affix: boolean
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'oms-tabs'
|
||||
/** 旧版本会把标签写入本地存储,这里清理掉遗留数据(标签只在当前会话内有效) */
|
||||
const LEGACY_STORAGE_KEY = 'oms-tabs'
|
||||
const MAX_TABS = 20
|
||||
|
||||
/** 从本地恢复上次会话的标签历史 */
|
||||
function loadTabs(): TabItem[] {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
if (raw) return JSON.parse(raw) as TabItem[]
|
||||
} catch {
|
||||
/* 本地数据损坏时忽略,退回空列表 */
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
export const useTabsStore = defineStore('tabs', () => {
|
||||
const tabs = ref<TabItem[]>([])
|
||||
const active = ref('')
|
||||
|
||||
function persist() {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(tabs.value))
|
||||
} catch {
|
||||
/* 容量超限等异常忽略 */
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化:固定首页标签 + 恢复本地历史,并把当前页面也纳入标签 */
|
||||
/** 初始化:只保留固定首页标签 + 当前页面,不恢复任何历史记录 */
|
||||
function init(current?: RouteLocationNormalized) {
|
||||
try {
|
||||
localStorage.removeItem(LEGACY_STORAGE_KEY)
|
||||
} catch {
|
||||
/* 本地存储不可用时忽略 */
|
||||
}
|
||||
// 仪表盘即首页:固定标签使用「/dashboard」路由,与侧边栏「仪表盘」入口一致,避免重复开标签
|
||||
const home: TabItem = { key: '/dashboard', fullPath: '/dashboard', title: '首页', affix: true }
|
||||
// 过滤掉旧会话遗留的「/」首页标签,防止与仪表盘首页重复
|
||||
const others = loadTabs().filter((t) => t.key !== home.key && t.key !== '/')
|
||||
tabs.value = [home, ...others].slice(0, MAX_TABS)
|
||||
tabs.value = [home]
|
||||
active.value = home.key
|
||||
if (current && current.fullPath !== home.key && current.fullPath !== '/') addTab(current)
|
||||
}
|
||||
@ -67,7 +52,6 @@ export const useTabsStore = defineStore('tabs', () => {
|
||||
tabs.value.push({ key, fullPath: route.fullPath, title, affix: false })
|
||||
}
|
||||
active.value = key
|
||||
persist()
|
||||
}
|
||||
|
||||
/** 关闭指定标签;若关闭的是当前页,自动跳到相邻标签 */
|
||||
@ -81,14 +65,12 @@ export const useTabsStore = defineStore('tabs', () => {
|
||||
if (next) router.push(next.fullPath)
|
||||
else active.value = ''
|
||||
}
|
||||
persist()
|
||||
}
|
||||
|
||||
/** 关闭除指定标签外的全部(保留固定标签) */
|
||||
function closeOthers(key: string) {
|
||||
tabs.value = tabs.value.filter((t) => t.affix || t.key === key)
|
||||
active.value = key
|
||||
persist()
|
||||
}
|
||||
|
||||
/** 关闭全部(保留固定标签) */
|
||||
@ -97,7 +79,6 @@ export const useTabsStore = defineStore('tabs', () => {
|
||||
const first = tabs.value[0]
|
||||
active.value = first?.key ?? ''
|
||||
if (first) router.push(first.fullPath)
|
||||
persist()
|
||||
}
|
||||
|
||||
return { tabs, active, init, addTab, removeTab, closeOthers, closeAll }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
getComboProducts,
|
||||
@ -10,6 +10,7 @@ import {
|
||||
} from '@/api/comboProduct'
|
||||
import { searchProducts, type ProductSearchItem } from '@/api/product'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
|
||||
@ -36,6 +37,12 @@ function reset() {
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件(与列表筛选同源) */
|
||||
const exportFilters = computed(() => ({
|
||||
keyword: query.keyword.trim(),
|
||||
status: query.status,
|
||||
}))
|
||||
|
||||
/** 把明细渲染为「商品名 × 数量」(明细已冗余商品信息) */
|
||||
function itemsText(items: ComboProductItem['items']) {
|
||||
if (!items || !items.length) return '-'
|
||||
@ -221,7 +228,10 @@ onMounted(fetchList)
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>组合商品</span>
|
||||
<el-button type="primary" @click="openCreate">新增组合商品</el-button>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="openCreate">新增组合商品</el-button>
|
||||
<ExportButton type="combo_product" :filters="exportFilters" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@ -1,27 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import ProductSelect from '@/components/ProductSelect.vue'
|
||||
import ExportFilterField from '@/components/ExportFilterField.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
import { downloadExportFile, useExportTasks } from '@/composables/useExportTasks'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { getWarehouseOptions, type WarehouseOption } from '@/api/warehouse'
|
||||
import { getShops, type ShopItem } from '@/api/shop'
|
||||
import {
|
||||
downloadExport,
|
||||
getExportTasks,
|
||||
getExportTypes,
|
||||
submitExport,
|
||||
type ExportFilters,
|
||||
type ExportTaskItem,
|
||||
type ExportType,
|
||||
type ExportTypeOption,
|
||||
} from '@/api/exportTask'
|
||||
|
||||
/**
|
||||
* 导出任务页(全局任务池)
|
||||
* - 提交导出(选类型 + 筛选)→ 立即得到任务ID,定时任务在后台逐个处理并落盘 CSV
|
||||
* - 列表轮询进度;任务「完成」后自动触发浏览器下载(也可手动点「下载」)
|
||||
* - 文件按 年/月/日 分目录存储,记录按当前主体隔离
|
||||
* - 提交导出(选类型 + 筛选)→ 立即得到任务ID,定时任务在后台逐个处理并落盘 XLSX
|
||||
* - 筛选字段由后端类型定义(/export-tasks/types)动态渲染,新增导出类型无需改本页
|
||||
* - 列表轮询进度;任务完成后的自动下载由 composables/useExportTasks 统一处理
|
||||
*/
|
||||
|
||||
const query = reactive({
|
||||
@ -46,22 +45,6 @@ const statusOptions = [
|
||||
{ label: '已完成', value: 2 },
|
||||
{ label: '失败', value: 3 },
|
||||
]
|
||||
const orderStatusOptions = [
|
||||
{ label: '待处理', value: 1 },
|
||||
{ label: '处理中', value: 2 },
|
||||
{ label: '已完成', value: 3 },
|
||||
{ label: '已取消', value: 4 },
|
||||
]
|
||||
const submitStatusOptions = [
|
||||
{ label: '未上交', value: 0 },
|
||||
{ label: '上交中', value: 1 },
|
||||
{ label: '已上交', value: 2 },
|
||||
{ label: '上交失败', value: 3 },
|
||||
]
|
||||
const productStatusOptions = [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
]
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } =
|
||||
useListPage<ExportTaskItem, typeof query>({
|
||||
@ -82,51 +65,52 @@ async function fetchTypes() {
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 提交导出对话框 ---------- */
|
||||
/* ---------- 新建导出对话框(筛选字段由后端类型定义动态渲染) ---------- */
|
||||
const dialogVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const { submitting, submit } = useExportTasks()
|
||||
|
||||
/** 当前导出类型可传的筛选字段 */
|
||||
const currentFilters = computed(
|
||||
() => typeOptions.value.find(o => o.value === form.type)?.filters || [],
|
||||
)
|
||||
|
||||
const form = reactive({
|
||||
type: '' as ExportType | '',
|
||||
keyword: '',
|
||||
dateRange: [] as string[],
|
||||
biz_type: '',
|
||||
direction: '' as string | number,
|
||||
bill_type: '' as string | number,
|
||||
item_type: '',
|
||||
bill_no: '',
|
||||
product_id: null as number | null,
|
||||
product_label: '',
|
||||
status: '' as string | number,
|
||||
submit_status: '' as string | number,
|
||||
type: '',
|
||||
values: {} as Record<string, string | number | null | undefined>,
|
||||
productLabels: {} as Record<string, string>,
|
||||
})
|
||||
|
||||
function openDialog() {
|
||||
form.type = typeOptions.value[0]?.value || 'stock_record'
|
||||
form.keyword = ''
|
||||
form.dateRange = []
|
||||
form.biz_type = ''
|
||||
form.direction = ''
|
||||
form.bill_type = ''
|
||||
form.item_type = ''
|
||||
form.bill_no = ''
|
||||
form.product_id = null
|
||||
form.product_label = ''
|
||||
form.status = ''
|
||||
form.submit_status = ''
|
||||
dialogVisible.value = true
|
||||
/** 店铺 / 仓库下拉选项(打开弹窗时按需加载) */
|
||||
const shopOptions = ref<{ label: string; value: number }[]>([])
|
||||
const warehouseOptions = ref<{ label: string; value: number }[]>([])
|
||||
|
||||
async function loadOptions() {
|
||||
try {
|
||||
const res = await getShops({ page: 1, pageSize: 500 })
|
||||
shopOptions.value = (res.list as ShopItem[]).map(s => ({ label: `${s.code} ${s.name}`, value: s.id }))
|
||||
} catch {
|
||||
shopOptions.value = []
|
||||
}
|
||||
try {
|
||||
const list = (await getWarehouseOptions()) as WarehouseOption[]
|
||||
warehouseOptions.value = list.map(w => ({ label: `${w.code} ${w.name}`, value: w.id }))
|
||||
} catch {
|
||||
warehouseOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function onProductLock(p: { id: number; item_code?: string; item_name?: string } | null) {
|
||||
if (!p) {
|
||||
onProductClear()
|
||||
return
|
||||
}
|
||||
form.product_id = p.id
|
||||
form.product_label = p.item_code ? `${p.item_code} ${p.item_name}` : p.item_name || ''
|
||||
function openDialog() {
|
||||
form.type = typeOptions.value[0]?.value || ''
|
||||
form.values = {}
|
||||
form.productLabels = {}
|
||||
dialogVisible.value = true
|
||||
loadOptions()
|
||||
}
|
||||
function onProductClear() {
|
||||
form.product_id = null
|
||||
form.product_label = ''
|
||||
|
||||
/** 切换类型:清空上一个类型的筛选值 */
|
||||
function onTypeChange() {
|
||||
form.values = {}
|
||||
form.productLabels = {}
|
||||
}
|
||||
|
||||
async function onSubmit() {
|
||||
@ -134,40 +118,19 @@ async function onSubmit() {
|
||||
ElMessage.warning('请选择导出类型')
|
||||
return
|
||||
}
|
||||
const filters: ExportFilters = {}
|
||||
if (form.keyword) filters.keyword = form.keyword.trim()
|
||||
if (form.dateRange.length === 2) {
|
||||
filters.start_time = form.dateRange[0]
|
||||
filters.end_time = form.dateRange[1]
|
||||
}
|
||||
if (form.type === 'stock_record') {
|
||||
if (form.product_id != null) filters.product_id = form.product_id
|
||||
if (form.biz_type) filters.biz_type = form.biz_type
|
||||
if (form.direction !== '') filters.direction = form.direction
|
||||
if (form.bill_type !== '') filters.bill_type = form.bill_type
|
||||
if (form.item_type) filters.item_type = form.item_type
|
||||
if (form.bill_no) filters.bill_no = form.bill_no.trim()
|
||||
} else if (form.type === 'product') {
|
||||
if (form.status !== '') filters.status = form.status
|
||||
} else if (form.type === 'order') {
|
||||
if (form.status !== '') filters.status = form.status
|
||||
if (form.submit_status !== '') filters.submit_status = form.submit_status
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
const res = await submitExport({ type: form.type as ExportType, filters })
|
||||
ElMessage.success('已提交导出任务,处理完成后将自动下载')
|
||||
autoDownloadIds.value.add(res.id)
|
||||
dialogVisible.value = false
|
||||
await refresh()
|
||||
startPolling()
|
||||
} finally {
|
||||
submitting.value = false
|
||||
const filters: Record<string, string | number | null | undefined> = {}
|
||||
for (const field of currentFilters.value) {
|
||||
const value = form.values[field.key]
|
||||
if (value === undefined || value === null || value === '') continue
|
||||
filters[field.key] = value
|
||||
}
|
||||
await submit(form.type, filters)
|
||||
dialogVisible.value = false
|
||||
await refresh()
|
||||
startPolling()
|
||||
}
|
||||
|
||||
/* ---------- 轮询进度 + 完成自动下载 ---------- */
|
||||
const autoDownloadIds = ref<Set<number>>(new Set())
|
||||
/* ---------- 列表进度轮询(完成后自动下载由 useExportTasks 统一处理,此处只刷新进度) ---------- */
|
||||
const pollingTimer = ref<number | null>(null)
|
||||
|
||||
function hasActive(arr: ExportTaskItem[]) {
|
||||
@ -176,15 +139,7 @@ function hasActive(arr: ExportTaskItem[]) {
|
||||
|
||||
async function refresh() {
|
||||
await fetchList()
|
||||
for (const t of list.value) {
|
||||
if (t.status === 2 && autoDownloadIds.value.has(t.id)) {
|
||||
autoDownloadIds.value.delete(t.id)
|
||||
triggerDownload(t.id, t.file_name)
|
||||
}
|
||||
}
|
||||
if (!hasActive(list.value) && autoDownloadIds.value.size === 0) {
|
||||
stopPolling()
|
||||
}
|
||||
if (!hasActive(list.value)) stopPolling()
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
@ -200,15 +155,7 @@ function stopPolling() {
|
||||
|
||||
async function triggerDownload(id: number, fileName?: string | null) {
|
||||
try {
|
||||
const blob = await downloadExport(id)
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = fileName || `export_${id}.xlsx`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(url)
|
||||
await downloadExportFile(id, fileName)
|
||||
} catch {
|
||||
// 错误已由响应拦截器统一提示
|
||||
}
|
||||
@ -302,102 +249,25 @@ onUnmounted(() => stopPolling())
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
|
||||
<!-- 新建导出对话框 -->
|
||||
<!-- 新建导出对话框(筛选字段由所选导出类型的后端定义渲染) -->
|
||||
<el-dialog v-model="dialogVisible" title="新建导出" width="560px" append-to-body>
|
||||
<el-form label-width="90px" size="small">
|
||||
<el-form-item label="导出类型" required>
|
||||
<el-select v-model="form.type" placeholder="请选择" style="width: 100%">
|
||||
<el-select v-model="form.type" placeholder="请选择" style="width: 100%" @change="onTypeChange">
|
||||
<el-option v-for="o in typeOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="关键词">
|
||||
<el-input
|
||||
v-model="form.keyword"
|
||||
:placeholder="form.type === 'order' ? '订单号 / 备注' : '编码 / 名称'"
|
||||
clearable
|
||||
<el-form-item v-for="fd in currentFilters" :key="fd.key" :label="fd.label">
|
||||
<ExportFilterField
|
||||
v-model="form.values[fd.key]"
|
||||
v-model:product-label="form.productLabels[fd.key]"
|
||||
:field="fd"
|
||||
:shop-options="shopOptions"
|
||||
:warehouse-options="warehouseOptions"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<template v-if="form.type === 'stock_record'">
|
||||
<el-form-item label="商品">
|
||||
<div class="product-filter">
|
||||
<ProductSelect
|
||||
v-model="form.product_id"
|
||||
:model-label="form.product_label"
|
||||
placeholder="搜索商品编码/名称锁定商品"
|
||||
@select="onProductLock"
|
||||
/>
|
||||
<el-button v-if="form.product_id != null" link type="primary" @click="onProductClear">清除</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="业务动作">
|
||||
<el-select v-model="form.biz_type" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="出库推送锁定" value="outbound_lock" />
|
||||
<el-option label="出库解锁" value="outbound_unlock" />
|
||||
<el-option label="出库确认扣减" value="outbound_deduct" />
|
||||
<el-option label="出库驳回回补" value="outbound_restore" />
|
||||
<el-option label="入库确认增加" value="inbound_increase" />
|
||||
<el-option label="订单审核锁定" value="order_lock" />
|
||||
<el-option label="订单解锁" value="order_unlock" />
|
||||
<el-option label="订单发货确认扣减" value="order_deduct" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="方向">
|
||||
<el-select v-model="form.direction" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="入库" :value="1" />
|
||||
<el-option label="出库" :value="2" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="单据类型">
|
||||
<el-select v-model="form.bill_type" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="入库单" :value="1" />
|
||||
<el-option label="出库单" :value="2" />
|
||||
<el-option label="发货单" :value="3" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="库存类型">
|
||||
<el-select v-model="form.item_type" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="正品" value="ZC" />
|
||||
<el-option label="残次品" value="CC" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="单据号">
|
||||
<el-input v-model="form.bill_no" placeholder="如 CK_1" clearable />
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<template v-if="form.type === 'product'">
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="form.status" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option v-for="o in productStatusOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<template v-if="form.type === 'order'">
|
||||
<el-form-item label="订单状态">
|
||||
<el-select v-model="form.status" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option v-for="o in orderStatusOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="上交状态">
|
||||
<el-select v-model="form.submit_status" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option v-for="o in submitStatusOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<el-form-item v-if="form.type === 'stock_record' || form.type === 'order'" label="时间区间">
|
||||
<el-date-picker
|
||||
v-model="form.dateRange"
|
||||
type="daterange"
|
||||
value-format="YYYY-MM-DD"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
style="width: 100%"
|
||||
/>
|
||||
<el-form-item v-if="!currentFilters.length">
|
||||
<span class="hint">该类型暂无可选筛选条件,将导出当前主体的全部数据</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
@ -440,11 +310,6 @@ onUnmounted(() => stopPolling())
|
||||
.search-bar {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.product-filter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.table-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
@ -39,6 +39,7 @@ import {
|
||||
} from '@/api/warehouseExpressMapping'
|
||||
import { getExpressCompanyOptions, type ExpressCompanyOption } from '@/api/expressCompany'
|
||||
import SplitLayout from '@/components/SplitLayout.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import FieldValueForm from '@/components/FieldValueForm.vue'
|
||||
@ -83,6 +84,28 @@ function reset() {
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件:仓库列表(关键词模糊匹配仓库编码/名称) */
|
||||
const warehouseExportFilters = computed(() => ({
|
||||
keyword: query.code.trim(),
|
||||
status: query.status,
|
||||
}))
|
||||
|
||||
/** 导出筛选条件:当前仓库的接口配置 / 快递映射 / 调用日志 */
|
||||
const detailExportFilters = computed(() => ({ warehouse_id: currentWarehouse.value?.id ?? null }))
|
||||
|
||||
/** 导出筛选条件:当前仓库的商品 */
|
||||
const productExportFilters = computed(() => ({
|
||||
warehouse_id: currentWarehouse.value?.id ?? null,
|
||||
keyword: productQuery.keyword.trim(),
|
||||
}))
|
||||
|
||||
/** 导出筛选条件:当前仓库已同步商品的库存 */
|
||||
const inventoryExportFilters = computed(() => ({
|
||||
warehouse_id: currentWarehouse.value?.id ?? null,
|
||||
keyword: inventoryQuery.keyword.trim(),
|
||||
pushed: 1,
|
||||
}))
|
||||
|
||||
/* -------------------- 详情 / 接口配置 -------------------- */
|
||||
const activeDetailTab = ref('detail')
|
||||
const detailLoading = ref(false)
|
||||
@ -824,7 +847,10 @@ onMounted(fetchList)
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>外部仓库</span>
|
||||
<el-button type="primary" @click="openCreate">新增仓库</el-button>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="openCreate">新增仓库</el-button>
|
||||
<ExportButton type="warehouse" :filters="warehouseExportFilters" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -956,9 +982,12 @@ onMounted(fetchList)
|
||||
<span class="items-title">
|
||||
接口配置 · {{ currentWarehouse.name }}
|
||||
</span>
|
||||
<el-button type="primary" size="small" class="toolbar-right" @click="openApiCreate">
|
||||
新增配置
|
||||
</el-button>
|
||||
<div class="toolbar-right header-actions">
|
||||
<ExportButton type="warehouse_api" :filters="detailExportFilters" size="small" plain />
|
||||
<el-button type="primary" size="small" @click="openApiCreate">
|
||||
新增配置
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom-table-wrap">
|
||||
<DataTable :loading="configLoading" :data="configList" class="fill-table">
|
||||
@ -1006,9 +1035,17 @@ onMounted(fetchList)
|
||||
<span class="muted toolbar-hint">
|
||||
外部回传的快递编码优先按此处「自定义编码 → 默认快递编码」解析;未配映射时按快递公司字典兜底
|
||||
</span>
|
||||
<el-button type="primary" size="small" class="toolbar-right" @click="openMappingCreate">
|
||||
新增映射
|
||||
</el-button>
|
||||
<div class="toolbar-right header-actions">
|
||||
<ExportButton
|
||||
type="express_mapping"
|
||||
:filters="detailExportFilters"
|
||||
size="small"
|
||||
plain
|
||||
/>
|
||||
<el-button type="primary" size="small" @click="openMappingCreate">
|
||||
新增映射
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom-table-wrap">
|
||||
<DataTable :loading="mappingLoading" :data="mappingList" class="fill-table">
|
||||
@ -1059,6 +1096,7 @@ onMounted(fetchList)
|
||||
@keyup.enter="searchProducts"
|
||||
/>
|
||||
<el-button @click="searchProducts">查询</el-button>
|
||||
<ExportButton type="warehouse_product" :filters="productExportFilters" size="small" plain />
|
||||
</div>
|
||||
<div class="bottom-table-wrap">
|
||||
<DataTable :loading="productLoading" :data="productList" class="fill-table" @selection-change="handleProductSelectionChange">
|
||||
@ -1122,6 +1160,7 @@ onMounted(fetchList)
|
||||
@keyup.enter="searchInventory"
|
||||
/>
|
||||
<el-button @click="searchInventory">查询</el-button>
|
||||
<ExportButton type="warehouse_product" :filters="inventoryExportFilters" size="small" plain />
|
||||
</div>
|
||||
<div class="bottom-table-wrap">
|
||||
<DataTable :loading="inventoryLoading" :data="displayInventoryList" class="fill-table" @selection-change="handleInventorySelectionChange">
|
||||
@ -1177,6 +1216,7 @@ onMounted(fetchList)
|
||||
<div class="items-toolbar">
|
||||
<span class="items-title">调用日志 · {{ currentWarehouse.name }}</span>
|
||||
<el-button size="small" :loading="outboundLoading" @click="fetchOutboundLogs">刷新</el-button>
|
||||
<ExportButton type="api_outbound_log" :filters="detailExportFilters" size="small" plain />
|
||||
</div>
|
||||
<div class="bottom-table-wrap">
|
||||
<DataTable :loading="outboundLoading" :data="outboundLogs" class="fill-table">
|
||||
|
||||
@ -12,6 +12,7 @@ import { getWarehouseOptions, type WarehouseOption } from '@/api/warehouse'
|
||||
import { getExpressCompanyOptions, type ExpressCompanyOption } from '@/api/expressCompany'
|
||||
import { type ProductSearchItem } from '@/api/product'
|
||||
import SplitLayout from '@/components/SplitLayout.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import ProductSelect from '@/components/ProductSelect.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
@ -81,6 +82,13 @@ function reset() {
|
||||
query.inbound_type = ''
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件(与列表筛选同一套条件,字段名与后端 inbound_order 类型对齐) */
|
||||
const exportFilters = computed(() => ({
|
||||
bill_no: query.bill_no.trim(),
|
||||
status: query.status,
|
||||
inbound_type: query.inbound_type,
|
||||
}))
|
||||
function typeLabel(row: InboundOrder) {
|
||||
return TYPE_OPTIONS.find((o) => o.value === row.inbound_type)?.label || String(row.inbound_type)
|
||||
}
|
||||
@ -432,7 +440,10 @@ onMounted(async () => {
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>入库单</span>
|
||||
<el-button type="primary" @click="openCreate">新增入库单</el-button>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="openCreate">新增入库单</el-button>
|
||||
<ExportButton type="inbound_order" :filters="exportFilters" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
876
frontend/src/views/Order/OrderFormDialog.vue
Normal file
876
frontend/src/views/Order/OrderFormDialog.vue
Normal file
@ -0,0 +1,876 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ProductSelect from '@/components/ProductSelect.vue'
|
||||
import { getExpressCompanyOptions, type ExpressCompanyOption } from '@/api/expressCompany'
|
||||
import type { ProductSearchItem } from '@/api/product'
|
||||
import type { DataItem } from 'element-china-area-data'
|
||||
import {
|
||||
createOrderStatus,
|
||||
getOrderStatusDetail,
|
||||
parseReceiverText,
|
||||
updateOrderStatus,
|
||||
type OrderItemLine,
|
||||
type OrderStatusFilters,
|
||||
type OrderStatusPayload,
|
||||
} from '@/api/orderStatus'
|
||||
|
||||
/**
|
||||
* 订单(发货单)新建 / 编辑弹窗
|
||||
*
|
||||
* 字段口径与老「发货单」一致:仓库 / 店铺 / 订单类型 / 收件人 12 项 / 金额 / 留言 / 物流 / 明细;
|
||||
* 订单号留空时由后端生成(有来源订单号 → 「来源订单号-序号」,否则 → FH_{id})。
|
||||
* 编辑模式仅待审核 / 异常可用,明细随表单一并保存(覆盖式)。
|
||||
*/
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
/** 编辑时的订单 id;不传为新建 */
|
||||
orderId?: number | null
|
||||
filters: OrderStatusFilters
|
||||
/** 默认落到哪个单据(新建时用于刷新对应列表) */
|
||||
defaultShopId?: number | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [ value: boolean ]
|
||||
saved: [ payload: { id: number; order_no: string; isEdit: boolean } ]
|
||||
}>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: value => emit('update:modelValue', value),
|
||||
})
|
||||
|
||||
const isEdit = computed(() => Boolean(props.orderId))
|
||||
const submitting = ref(false)
|
||||
const loading = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const ORDER_TYPES = [
|
||||
{ value: 'JYCK', label: 'JYCK 一般交易出库单' },
|
||||
{ value: 'HHCK', label: 'HHCK 换货出库' },
|
||||
{ value: 'BFCK', label: 'BFCK 补发出库' },
|
||||
]
|
||||
|
||||
const form = reactive<OrderStatusPayload & { items: OrderItemLine[] }>({
|
||||
parent_order_no: '',
|
||||
order_no: '',
|
||||
warehouse_id: null,
|
||||
shop_id: null,
|
||||
order_type: 'JYCK',
|
||||
is_urgency: 'N',
|
||||
invoice_flag: 'N',
|
||||
receiver: '',
|
||||
tel: '',
|
||||
mobile: '',
|
||||
email: '',
|
||||
country_code: '',
|
||||
province: '',
|
||||
city: '',
|
||||
area: '',
|
||||
town: '',
|
||||
detail_address: '',
|
||||
zip_code: '',
|
||||
oaid: '',
|
||||
total_amount: null,
|
||||
item_amount: null,
|
||||
discount_amount: null,
|
||||
freight: null,
|
||||
ar_amount: null,
|
||||
got_amount: null,
|
||||
logistics_code: '',
|
||||
logistics_name: '',
|
||||
seller_message: '',
|
||||
buyer_message: '',
|
||||
remark: '',
|
||||
items: [],
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
warehouse_id: [ { required: true, message: '请选择仓库(推送仓库需要仓库编码与接口配置)', trigger: 'change' } ],
|
||||
shop_id: [ { required: true, message: '请选择店铺(推送时 shopNick 取店铺名称匹配快递策略)', trigger: 'change' } ],
|
||||
receiver: [ { required: true, message: '请输入收件人姓名', trigger: 'blur' } ],
|
||||
// 省 / 市 / 区 由三级联动一次写入,校验挂在 province 上即可(city / area 不会再单独为空)
|
||||
province: [ { required: true, message: '请选择省 / 市 / 区', trigger: 'change' } ],
|
||||
town: [ { required: true, message: '请输入街道/镇', trigger: 'blur' } ],
|
||||
logistics_code: [ { required: true, message: '请选择物流公司(推送仓库时随单下发 logisticsCode)', trigger: 'change' } ],
|
||||
}
|
||||
|
||||
/** 明细行默认值 */
|
||||
function emptyLine(): OrderItemLine {
|
||||
return {
|
||||
order_line_no: '',
|
||||
item_id: null,
|
||||
item_code: '',
|
||||
item_name: '',
|
||||
plan_qty: 1,
|
||||
actual_price: 0,
|
||||
retail_price: 0,
|
||||
ext_code: '',
|
||||
inventory_type: 'ZP',
|
||||
}
|
||||
}
|
||||
|
||||
function fillItems(items: OrderItemLine[] | undefined) {
|
||||
form.items = (items || []).map(item => ({
|
||||
...item,
|
||||
plan_qty: Number(item.plan_qty || 0),
|
||||
actual_price: item.actual_price === null || item.actual_price === undefined ? 0 : Number(item.actual_price),
|
||||
}))
|
||||
if (!form.items.length) form.items = [ emptyLine() ]
|
||||
}
|
||||
|
||||
/** 默认仓库:取当前主体仓库列表第一个(与老发货单一致,减少手工选择) */
|
||||
function defaultWarehouseId(): number | null {
|
||||
const list = props.filters.warehouses || []
|
||||
return list.length ? list[0].id : null
|
||||
}
|
||||
|
||||
/** 默认店铺:优先父级入口指定的店铺,否则取店铺列表第一个 */
|
||||
function defaultShopIdOf(): number | null {
|
||||
if (props.defaultShopId) return props.defaultShopId
|
||||
const list = props.filters.shops || []
|
||||
return list.length ? list[0].id : null
|
||||
}
|
||||
|
||||
function reset() {
|
||||
Object.assign(form, {
|
||||
parent_order_no: '',
|
||||
order_no: '',
|
||||
warehouse_id: defaultWarehouseId(),
|
||||
shop_id: defaultShopIdOf(),
|
||||
order_type: 'JYCK',
|
||||
is_urgency: 'N',
|
||||
invoice_flag: 'N',
|
||||
receiver: '',
|
||||
tel: '',
|
||||
mobile: '',
|
||||
email: '',
|
||||
country_code: '',
|
||||
province: '',
|
||||
city: '',
|
||||
area: '',
|
||||
town: '',
|
||||
detail_address: '',
|
||||
zip_code: '',
|
||||
oaid: '',
|
||||
total_amount: null,
|
||||
item_amount: null,
|
||||
discount_amount: null,
|
||||
freight: null,
|
||||
ar_amount: null,
|
||||
got_amount: null,
|
||||
logistics_code: '',
|
||||
logistics_name: '',
|
||||
seller_message: '',
|
||||
buyer_message: '',
|
||||
remark: '',
|
||||
})
|
||||
fillItems([])
|
||||
}
|
||||
|
||||
/** 编辑模式:载入现有单据与明细 */
|
||||
async function loadDetail(id: number) {
|
||||
loading.value = true
|
||||
try {
|
||||
const { order, items } = await getOrderStatusDetail(id)
|
||||
Object.assign(form, {
|
||||
parent_order_no: order.parent_order_no || '',
|
||||
order_no: order.order_no,
|
||||
warehouse_id: order.warehouse_id ?? null,
|
||||
shop_id: order.shop_id ?? null,
|
||||
order_type: order.order_type || 'JYCK',
|
||||
is_urgency: order.is_urgency || 'N',
|
||||
invoice_flag: order.invoice_flag || 'N',
|
||||
receiver: order.receiver || '',
|
||||
tel: order.tel || '',
|
||||
mobile: order.mobile || '',
|
||||
email: order.email || '',
|
||||
country_code: order.country_code || '',
|
||||
province: order.province || '',
|
||||
city: order.city || '',
|
||||
area: order.area || '',
|
||||
town: order.town || '',
|
||||
detail_address: order.detail_address || '',
|
||||
zip_code: order.zip_code || '',
|
||||
oaid: order.oaid || '',
|
||||
total_amount: numOrNull(order.total_amount),
|
||||
item_amount: numOrNull(order.item_amount),
|
||||
discount_amount: numOrNull(order.discount_amount),
|
||||
freight: numOrNull(order.freight),
|
||||
ar_amount: numOrNull(order.ar_amount),
|
||||
got_amount: numOrNull(order.got_amount),
|
||||
logistics_code: order.logistics_code || '',
|
||||
logistics_name: order.logistics_name || '',
|
||||
seller_message: order.seller_message || '',
|
||||
buyer_message: order.buyer_message || '',
|
||||
remark: order.remark || '',
|
||||
})
|
||||
fillItems(items)
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function numOrNull(value: unknown): number | null {
|
||||
if (value === null || value === undefined || value === '') return null
|
||||
const num = Number(value)
|
||||
return Number.isFinite(num) ? num : null
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [ props.modelValue, props.orderId ] as const,
|
||||
async ([ open, id ]) => {
|
||||
if (!open) return
|
||||
reset()
|
||||
if (id) await loadDetail(Number(id))
|
||||
else fillItems([])
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
/* -------------------- 收件人智能识别 -------------------- */
|
||||
const receiverText = ref('')
|
||||
const parsing = ref(false)
|
||||
async function handleParseReceiver() {
|
||||
const text = receiverText.value.trim()
|
||||
if (!text) {
|
||||
ElMessage.warning('请先粘贴包含收件人信息的文本')
|
||||
return
|
||||
}
|
||||
parsing.value = true
|
||||
try {
|
||||
const data = await parseReceiverText(text)
|
||||
// 识别结果按同名字段回填(识别不到的不覆盖已有值)
|
||||
const mapping: Record<string, keyof typeof form> = {
|
||||
name: 'receiver',
|
||||
tel: 'tel',
|
||||
mobile: 'mobile',
|
||||
province: 'province',
|
||||
city: 'city',
|
||||
area: 'area',
|
||||
town: 'town',
|
||||
detailAddress: 'detail_address',
|
||||
detail_address: 'detail_address',
|
||||
zipCode: 'zip_code',
|
||||
zip_code: 'zip_code',
|
||||
email: 'email',
|
||||
}
|
||||
let hit = 0
|
||||
for (const [ key, value ] of Object.entries(data || {})) {
|
||||
const field = mapping[key]
|
||||
if (!field || value === null || value === undefined || value === '') continue
|
||||
;(form as Record<string, unknown>)[field as string] = String(value)
|
||||
hit += 1
|
||||
}
|
||||
ElMessage.success(hit ? `已识别并填充 ${hit} 项收件人信息` : '未识别到可用字段,请手工填写')
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
parsing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- 省 / 市 / 区 三级联动 -------------------- */
|
||||
/** 省市区选项(element-china-area-data 的 pcaTextArr,值即文本,与库内 province/city/area 同口径) */
|
||||
const areaOptions = ref<DataItem[]>([])
|
||||
|
||||
/** 三级路径(由 province/city/area 派生,识别回填 / 编辑回显都能同步) */
|
||||
const areaPath = computed<string[]>(() =>
|
||||
[ form.province, form.city, form.area ].map(part => String(part || '').trim()).filter(Boolean),
|
||||
)
|
||||
|
||||
/** 选完三级后拆分回三个字段(后端仍按 province/city/area 三个列存) */
|
||||
function handleAreaChange(path: string[] | null) {
|
||||
const list = Array.isArray(path) ? path : []
|
||||
form.province = list[0] || ''
|
||||
form.city = list[1] || ''
|
||||
form.area = list[2] || ''
|
||||
}
|
||||
|
||||
/** 当前地区路径是否命中标准行政区划(未命中时下拉显示为空,需提示库内原值) */
|
||||
const areaPathMatched = computed(() => {
|
||||
const path = areaPath.value
|
||||
if (!path.length) return true
|
||||
let level: DataItem[] | undefined = areaOptions.value
|
||||
for (const name of path) {
|
||||
const hit: DataItem | undefined = (level || []).find(option => option.label === name)
|
||||
if (!hit) return false
|
||||
level = hit.children
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
/* -------------------- 物流公司(快递公司字典) -------------------- */
|
||||
const expressCompanies = ref<ExpressCompanyOption[]>([])
|
||||
|
||||
/** 下拉选项:字典项 + 当前值(WMS 可能回传字典外的自定义编码,避免显示为空) */
|
||||
const expressOptions = computed<ExpressCompanyOption[]>(() => {
|
||||
const list = [ ...expressCompanies.value ]
|
||||
const code = String(form.logistics_code || '').trim()
|
||||
if (code && !list.some(company => company.code === code)) {
|
||||
list.unshift({ id: 0, code, name: String(form.logistics_name || code) })
|
||||
}
|
||||
return list
|
||||
})
|
||||
|
||||
/** 选中物流公司后自动带出名称(与老发货单口径一致) */
|
||||
function handleExpressChange(code: string | null) {
|
||||
const company = expressCompanies.value.find(item => item.code === code)
|
||||
form.logistics_name = company ? company.name : ''
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
async open => {
|
||||
if (!open) return
|
||||
try {
|
||||
expressCompanies.value = await getExpressCompanyOptions()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
// 省市区数据较大,按需动态加载(单独 chunk,不进主包)
|
||||
if (!areaOptions.value.length) {
|
||||
try {
|
||||
const { pcaTextArr } = await import('element-china-area-data')
|
||||
areaOptions.value = pcaTextArr as DataItem[]
|
||||
} catch {
|
||||
// 可选依赖加载失败时降级为不做可选(省市区仍有智能识别与手工联动)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
// 筛选项(仓库 / 店铺)异步到达时兜底回填默认值(新建场景)
|
||||
watch(
|
||||
() => props.filters,
|
||||
() => {
|
||||
if (!visible.value || isEdit.value) return
|
||||
if (form.warehouse_id == null) form.warehouse_id = defaultWarehouseId()
|
||||
if (form.shop_id == null) form.shop_id = defaultShopIdOf()
|
||||
},
|
||||
{ deep: true },
|
||||
)
|
||||
|
||||
/* -------------------- 明细 -------------------- */
|
||||
function addLine() {
|
||||
form.items = [ ...form.items, emptyLine() ]
|
||||
}
|
||||
function removeLine(index: number) {
|
||||
const list = [ ...form.items ]
|
||||
list.splice(index, 1)
|
||||
form.items = list.length ? list : [ emptyLine() ]
|
||||
}
|
||||
|
||||
/** 选中商品后带出商品ID / 编码 / 名称(单价与数量由人工填写,与老发货单一致) */
|
||||
function onLineProductSelect(index: number, product: ProductSearchItem) {
|
||||
const line = form.items[index]
|
||||
if (!line) return
|
||||
line.item_id = product.id
|
||||
line.item_code = product.item_code || ''
|
||||
line.item_name = product.item_name || ''
|
||||
}
|
||||
|
||||
function lineAmount(line: OrderItemLine): string {
|
||||
const qty = Number(line.plan_qty || 0)
|
||||
const price = Number(line.actual_price || 0)
|
||||
if (!Number.isFinite(qty) || !Number.isFinite(price)) return '-'
|
||||
return (qty * price).toFixed(2)
|
||||
}
|
||||
|
||||
/** 汇总明细金额(商品总金额 item_amount 的唯一口径:Σ 数量 × 单价) */
|
||||
const itemsAmount = computed(() =>
|
||||
form.items.reduce((sum, line) => sum + Number(line.plan_qty || 0) * Number(line.actual_price || 0), 0),
|
||||
)
|
||||
|
||||
/** 明细是否有实际内容(空行不计):有明细时商品总金额由明细派生,不允许手改 */
|
||||
const hasRealItems = computed(() =>
|
||||
form.items.some(line => String(line.item_code || '').trim() || Number(line.item_id || 0) > 0),
|
||||
)
|
||||
|
||||
/** 商品总金额(两位小数) */
|
||||
const derivedItemAmount = computed(() => Number(itemsAmount.value.toFixed(2)))
|
||||
|
||||
// 明细变化 → 自动回填商品总金额(对齐后端重算口径,避免表头与明细不一致)
|
||||
watch(
|
||||
() => form.items.map(line => `${line.item_code}|${line.plan_qty}|${line.actual_price}`).join(','),
|
||||
() => {
|
||||
if (hasRealItems.value) form.item_amount = derivedItemAmount.value
|
||||
},
|
||||
)
|
||||
|
||||
/** 提交前清理:空行剔除、行号补全、空串转 undefined */
|
||||
function buildPayload(): OrderStatusPayload {
|
||||
const items = form.items
|
||||
.filter(line => (line.item_code && String(line.item_code).trim()) || (line.item_id && line.item_id > 0))
|
||||
.map((line, index) => ({
|
||||
order_line_no: String(line.order_line_no || index + 1),
|
||||
item_id: line.item_id ?? null,
|
||||
item_code: line.item_code ? String(line.item_code).trim() : null,
|
||||
item_name: line.item_name ? String(line.item_name).trim() : null,
|
||||
plan_qty: Number(line.plan_qty || 0),
|
||||
actual_price: line.actual_price === null || line.actual_price === undefined ? 0 : Number(line.actual_price),
|
||||
retail_price: line.retail_price === null || line.retail_price === undefined ? 0 : Number(line.retail_price),
|
||||
ext_code: line.ext_code ? String(line.ext_code).trim() : null,
|
||||
inventory_type: line.inventory_type || 'ZP',
|
||||
}))
|
||||
|
||||
const text = (value: unknown) => {
|
||||
const str = value === null || value === undefined ? '' : String(value).trim()
|
||||
return str === '' ? undefined : str
|
||||
}
|
||||
|
||||
// 金额类:空值不传(后端保留库内既有值 / 默认 0),避免显式 null 触发非空约束
|
||||
const amount = (value: unknown) => {
|
||||
const num = numOrNull(value)
|
||||
return num === null ? undefined : num
|
||||
}
|
||||
|
||||
return {
|
||||
parent_order_no: text(form.parent_order_no),
|
||||
order_no: isEdit.value ? undefined : text(form.order_no),
|
||||
warehouse_id: form.warehouse_id ?? null,
|
||||
shop_id: form.shop_id ?? null,
|
||||
order_type: form.order_type || 'JYCK',
|
||||
is_urgency: form.is_urgency || 'N',
|
||||
invoice_flag: form.invoice_flag || 'N',
|
||||
receiver: text(form.receiver),
|
||||
tel: text(form.tel),
|
||||
mobile: text(form.mobile),
|
||||
email: text(form.email),
|
||||
country_code: text(form.country_code),
|
||||
province: text(form.province),
|
||||
city: text(form.city),
|
||||
area: text(form.area),
|
||||
town: text(form.town),
|
||||
detail_address: text(form.detail_address),
|
||||
zip_code: text(form.zip_code),
|
||||
oaid: text(form.oaid),
|
||||
total_amount: amount(form.total_amount),
|
||||
item_amount: hasRealItems.value ? derivedItemAmount.value : amount(form.item_amount),
|
||||
discount_amount: amount(form.discount_amount),
|
||||
freight: amount(form.freight),
|
||||
ar_amount: amount(form.ar_amount),
|
||||
got_amount: amount(form.got_amount),
|
||||
logistics_code: text(form.logistics_code),
|
||||
logistics_name: text(form.logistics_name),
|
||||
seller_message: text(form.seller_message),
|
||||
buyer_message: text(form.buyer_message),
|
||||
remark: text(form.remark),
|
||||
items: items.length ? items : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async valid => {
|
||||
if (!valid) return
|
||||
// 收件人电话与手机至少填一个(对齐后端与取号硬依赖)
|
||||
if (!String(form.tel || '').trim() && !String(form.mobile || '').trim()) {
|
||||
ElMessage.warning('收件人电话(tel)与手机(mobile)至少填写一个')
|
||||
return
|
||||
}
|
||||
// 新建发货单必须有商品明细(单号、库存锁定与推送仓库均以明细为准)
|
||||
if (!isEdit.value && !hasRealItems.value) {
|
||||
ElMessage.warning('请至少填写一行商品明细(商品编码 + 数量 + 单价)')
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
const payload = buildPayload()
|
||||
if (isEdit.value && props.orderId) {
|
||||
await updateOrderStatus(Number(props.orderId), payload)
|
||||
ElMessage.success('订单已更新')
|
||||
emit('saved', { id: Number(props.orderId), order_no: String(payload.order_no || ''), isEdit: true })
|
||||
} else {
|
||||
const result = await createOrderStatus(payload)
|
||||
ElMessage.success(`已创建订单 ${result.order_no}`)
|
||||
emit('saved', { id: result.id, order_no: result.order_no, isEdit: false })
|
||||
}
|
||||
visible.value = false
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="isEdit ? '编辑订单' : '新建订单(发货单)'"
|
||||
width="980px"
|
||||
top="6vh"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="96px" size="small" scroll-to-error v-loading="loading">
|
||||
<div class="form-body">
|
||||
<el-divider content-position="left">基础信息</el-divider>
|
||||
<el-row :gutter="8">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="来源订单号">
|
||||
<el-input v-model="form.parent_order_no" placeholder="上游 / 平台订单号(可空)" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="订单号">
|
||||
<el-input
|
||||
v-model="form.order_no"
|
||||
:disabled="isEdit"
|
||||
:placeholder="isEdit ? '订单号不可修改(驳回 / 恢复时系统换号)' : '留空自动生成'"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="仓库" prop="warehouse_id">
|
||||
<el-select v-model="form.warehouse_id" placeholder="请选择仓库" clearable filterable style="width: 100%">
|
||||
<el-option
|
||||
v-for="warehouse in props.filters.warehouses"
|
||||
:key="warehouse.id"
|
||||
:label="`${warehouse.name}(${warehouse.code})`"
|
||||
:value="warehouse.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="店铺" prop="shop_id">
|
||||
<el-select v-model="form.shop_id" placeholder="请选择店铺" clearable filterable style="width: 100%">
|
||||
<el-option v-for="shop in props.filters.shops" :key="shop.id" :label="shop.name" :value="shop.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="订单类型">
|
||||
<el-select v-model="form.order_type" style="width: 100%">
|
||||
<el-option v-for="item in ORDER_TYPES" :key="item.value" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="是否紧急">
|
||||
<el-select v-model="form.is_urgency" style="width: 100%">
|
||||
<el-option label="否" value="N" />
|
||||
<el-option label="是" value="Y" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="需要发票">
|
||||
<el-select v-model="form.invoice_flag" style="width: 100%">
|
||||
<el-option label="否" value="N" />
|
||||
<el-option label="是" value="Y" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" placeholder="备注 / 异常原因" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-divider content-position="left">收件人</el-divider>
|
||||
<div class="parse-bar">
|
||||
<el-input
|
||||
v-model="receiverText"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
placeholder="粘贴「姓名 电话 地址」等文本,自动识别并填充下方字段"
|
||||
/>
|
||||
<el-button type="primary" size="small" :loading="parsing" @click="handleParseReceiver">智能识别</el-button>
|
||||
</div>
|
||||
<el-row :gutter="8">
|
||||
<el-col :span="8">
|
||||
<el-form-item label="收件人" prop="receiver">
|
||||
<el-input v-model="form.receiver" placeholder="姓名" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="电话">
|
||||
<el-input v-model="form.tel" placeholder="电话(与手机至少填一个)" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="手机">
|
||||
<el-input v-model="form.mobile" placeholder="手机" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="省/市/区" prop="province">
|
||||
<div class="area-field">
|
||||
<el-cascader
|
||||
:model-value="areaPath"
|
||||
:options="areaOptions"
|
||||
:props="{ expandTrigger: 'hover' }"
|
||||
placeholder="搜索或逐级选择省 / 市 / 区"
|
||||
filterable
|
||||
clearable
|
||||
style="width: 100%"
|
||||
@change="handleAreaChange"
|
||||
/>
|
||||
<span v-if="!areaPathMatched" class="field-hint">
|
||||
库内地区:{{ areaPath.join(' / ') }}(不在标准行政区划内,重新选择将覆盖)
|
||||
</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="街道/镇" prop="town">
|
||||
<el-input v-model="form.town" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="详细地址">
|
||||
<el-input v-model="form.detail_address" placeholder="门牌号 / 楼栋 / 村组等" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-collapse class="more-collapse">
|
||||
<el-collapse-item title="更多收件人字段(选填:邮箱 / 国家编码 / 邮编 / OAID)" name="more-receiver">
|
||||
<el-row :gutter="8">
|
||||
<el-col :span="8">
|
||||
<el-form-item label="邮箱">
|
||||
<el-input v-model="form.email" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="国家编码">
|
||||
<el-input v-model="form.country_code" placeholder="如 CN" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="邮编">
|
||||
<el-input v-model="form.zip_code" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="OAID">
|
||||
<el-input v-model="form.oaid" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
|
||||
<el-divider content-position="left">金额与物流</el-divider>
|
||||
<el-row :gutter="8">
|
||||
<el-col :span="6">
|
||||
<el-form-item label="订单总金额">
|
||||
<el-input-number v-model="form.total_amount" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="商品总金额">
|
||||
<div class="amount-field">
|
||||
<el-input-number
|
||||
v-model="form.item_amount"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
:controls="false"
|
||||
:disabled="hasRealItems"
|
||||
style="width: 100%"
|
||||
/>
|
||||
<span v-if="hasRealItems" class="field-hint">按明细自动计算</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="折扣金额">
|
||||
<el-input-number v-model="form.discount_amount" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="快递费">
|
||||
<el-input-number v-model="form.freight" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="应收金额">
|
||||
<el-input-number v-model="form.ar_amount" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="已收金额">
|
||||
<el-input-number v-model="form.got_amount" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="物流公司" prop="logistics_code">
|
||||
<el-select
|
||||
v-model="form.logistics_code"
|
||||
placeholder="请选择快递公司"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@change="handleExpressChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="company in expressOptions"
|
||||
:key="company.code"
|
||||
:label="`${company.name}(${company.code})`"
|
||||
:value="company.code"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-collapse class="more-collapse">
|
||||
<el-collapse-item title="更多(选填:卖家留言 / 买家留言)" name="more-amount">
|
||||
<el-row :gutter="8">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="卖家留言">
|
||||
<el-input v-model="form.seller_message" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="买家留言">
|
||||
<el-input v-model="form.buyer_message" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
|
||||
<el-divider content-position="left">商品明细</el-divider>
|
||||
<DataTable :data="form.items" :stripe="true">
|
||||
<el-table-column label="行号" width="70">
|
||||
<template #default="{ row, $index }">
|
||||
<el-input v-model="row.order_line_no" size="small" :placeholder="String($index + 1)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品" min-width="220">
|
||||
<template #default="{ row, $index }">
|
||||
<ProductSelect
|
||||
v-model="row.item_id"
|
||||
:model-label="[ row.item_code, row.item_name ].filter(Boolean).join(' ')"
|
||||
@select="(p: ProductSearchItem) => onLineProductSelect($index, p)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品编码" width="140">
|
||||
<template #default="{ row }">
|
||||
<el-input v-model="row.item_code" size="small" placeholder="选商品后自动带出" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品名称" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<el-input v-model="row.item_name" size="small" placeholder="选商品后自动带出" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="数量" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-input-number v-model="row.plan_qty" :min="0" :precision="3" :controls="false" size="small" style="width: 100%" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单价" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-input-number v-model="row.actual_price" :min="0" :precision="2" :controls="false" size="small" style="width: 100%" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="库存类型" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-select v-model="row.inventory_type" size="small">
|
||||
<el-option label="正品" value="ZP" />
|
||||
<el-option label="残次" value="CC" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="外部编码" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-input v-model="row.ext_code" size="small" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="金额" width="90" align="right">
|
||||
<template #default="{ row }">{{ lineAmount(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="70">
|
||||
<template #default="{ $index }">
|
||||
<el-button link type="danger" size="small" @click="removeLine($index)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
<div class="items-footer">
|
||||
<el-button size="small" @click="addLine">添加商品行</el-button>
|
||||
<span class="items-total">明细金额合计:{{ itemsAmount.toFixed(2) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" size="small" :loading="submitting" @click="submit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.form-body {
|
||||
max-height: 66vh;
|
||||
overflow-y: auto;
|
||||
padding-right: 4px;
|
||||
}
|
||||
.form-body :deep(.el-divider) {
|
||||
margin: 4px 0 14px;
|
||||
}
|
||||
.form-body :deep(.el-divider__text) {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.more-collapse {
|
||||
border-top: none;
|
||||
}
|
||||
.more-collapse :deep(.el-collapse-item__header) {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
border-bottom: none;
|
||||
}
|
||||
.more-collapse :deep(.el-collapse-item__wrap) {
|
||||
border-bottom: none;
|
||||
}
|
||||
.parse-bar {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.parse-bar .el-button {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
.items-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.items-total {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.amount-field {
|
||||
width: 100%;
|
||||
}
|
||||
.area-field {
|
||||
width: 100%;
|
||||
}
|
||||
.field-hint {
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
:deep(.el-descriptions__label) {
|
||||
width: 110px;
|
||||
}
|
||||
</style>
|
||||
63
frontend/src/views/Order/Status.vue
Normal file
63
frontend/src/views/Order/Status.vue
Normal file
@ -0,0 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import OrderStatusPanel from './StatusPanel.vue'
|
||||
import { ORDER_STAGE_TABS, type OrderStage } from '@/api/orderStatus'
|
||||
|
||||
/**
|
||||
* 订单
|
||||
*
|
||||
* 订单按状态分表存储,页面按状态分视图管理:
|
||||
* 左侧 tab 切换 5 个视图(待审核 / 异常 / 委外中 / 配送 / 历史),
|
||||
* 历史为归档表且只读;tab 懒加载,首次切到才请求列表。
|
||||
*/
|
||||
const active = ref<OrderStage>('pending')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card class="order-card">
|
||||
<template #header>
|
||||
<div class="page-header">订单</div>
|
||||
</template>
|
||||
|
||||
<el-tabs v-model="active" tab-position="left" class="order-tabs">
|
||||
<el-tab-pane
|
||||
v-for="t in ORDER_STAGE_TABS"
|
||||
:key="t.key"
|
||||
:name="t.key"
|
||||
:label="t.label"
|
||||
lazy
|
||||
>
|
||||
<OrderStatusPanel :status="t.key" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
font-weight: 600;
|
||||
}
|
||||
.order-card {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.order-card :deep(.el-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.order-card :deep(.el-tabs.order-tabs) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
}
|
||||
.order-card :deep(.el-tabs--left .el-tabs__header) {
|
||||
margin-right: 12px;
|
||||
}
|
||||
.order-card :deep(.el-tabs--left .el-tabs__content),
|
||||
.order-card :deep(.el-tab-pane) {
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
925
frontend/src/views/Order/StatusPanel.vue
Normal file
925
frontend/src/views/Order/StatusPanel.vue
Normal file
@ -0,0 +1,925 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import OrderFormDialog from './OrderFormDialog.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import {
|
||||
ORDER_STAGE_META,
|
||||
archiveOrders,
|
||||
auditOrders,
|
||||
cancelOrders,
|
||||
changeOrdersShop,
|
||||
changeOrdersWarehouse,
|
||||
getOrderStatusDetail,
|
||||
getOrderStatusFilters,
|
||||
getOrderStatusList,
|
||||
pushOrderToWms,
|
||||
pushOrders,
|
||||
pushOrdersToWms,
|
||||
rejectOrders,
|
||||
removeOrderStatus,
|
||||
restoreOrders,
|
||||
returnOrdersToPending,
|
||||
voidOrders,
|
||||
type OrderItemLine,
|
||||
type OrderStage,
|
||||
type OrderStatusFilters,
|
||||
type OrderStatusItem,
|
||||
} from '@/api/orderStatus'
|
||||
|
||||
/**
|
||||
* 订单面板(按状态分视图)
|
||||
*
|
||||
* 八个视图(待审核 / 待推送 / 异常 / 委外中 / 配送 / 已作废 / 已取消 / 历史)共用本面板,数据源为对应状态表;
|
||||
* 批量与行内动作按场景分布:
|
||||
* - 待审核:审核(锁定库存 → 待推送)/ 切换仓库 / 设置店铺 / 取消 / 作废 / 编辑 / 删除
|
||||
* - 待推送:推送仓库(WMS deliveryorder.create)/ 驳回(换号+释放库存)/ 取消 / 作废 / 切换仓库 / 设置店铺 / 手工标记推送结果
|
||||
* - 异常:转回待审核 / 直接审核 / 设置店铺 / 取消 / 作废 / 编辑 / 删除
|
||||
* - 委外中(已推送成功):只读流转(取消 / 设置店铺)——**不再提供推送仓库操作**
|
||||
* - 配送 / 历史:只读(配送可归档)
|
||||
* - 已作废 / 已取消:可恢复(曾推送过的自动换号);已取消可删除
|
||||
*/
|
||||
const props = defineProps<{ status: OrderStage }>()
|
||||
|
||||
const isHistory = computed(() => props.status === 'history')
|
||||
/** 异常视图:状态恒为「异常」,列表不再重复展示状态列,并把异常原因提到前面标红 */
|
||||
const isException = computed(() => props.status === 'exception')
|
||||
const stageMeta = computed(() => ORDER_STAGE_META[props.status])
|
||||
|
||||
/* -------------------- 筛选条件(默认一行简单条件,可展开为完整条件) -------------------- */
|
||||
const expanded = ref(false)
|
||||
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
order_no: '',
|
||||
parent_order_no: '',
|
||||
shop_id: '' as number | '',
|
||||
receiver: '',
|
||||
address: '',
|
||||
remark: '',
|
||||
createdRange: [] as string[],
|
||||
archivedRange: [] as string[],
|
||||
})
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } =
|
||||
useListPage<OrderStatusItem, typeof query>({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = {
|
||||
status: props.status,
|
||||
page: query.page,
|
||||
pageSize: query.pageSize,
|
||||
}
|
||||
if (query.order_no) params.order_no = query.order_no.trim()
|
||||
if (query.parent_order_no) params.parent_order_no = query.parent_order_no.trim()
|
||||
if (query.shop_id !== '') params.shop_id = query.shop_id
|
||||
if (query.receiver) params.receiver = query.receiver.trim()
|
||||
if (query.address) params.address = query.address.trim()
|
||||
if (query.remark) params.remark = query.remark.trim()
|
||||
if (query.createdRange.length === 2) {
|
||||
params.created_from = query.createdRange[0]
|
||||
params.created_to = query.createdRange[1]
|
||||
}
|
||||
if (query.archivedRange.length === 2) {
|
||||
params.archived_from = query.archivedRange[0]
|
||||
params.archived_to = query.archivedRange[1]
|
||||
}
|
||||
return getOrderStatusList(params as never)
|
||||
},
|
||||
})
|
||||
|
||||
/** 无条件重置(含展开区的完整条件) */
|
||||
function reset() {
|
||||
query.order_no = ''
|
||||
query.parent_order_no = ''
|
||||
query.shop_id = ''
|
||||
query.receiver = ''
|
||||
query.address = ''
|
||||
query.remark = ''
|
||||
query.createdRange = []
|
||||
query.archivedRange = []
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件(当前视图状态 + 当前筛选条件) */
|
||||
const exportFilters = computed(() => ({
|
||||
order_stage: props.status,
|
||||
order_no: query.order_no.trim(),
|
||||
parent_order_no: query.parent_order_no.trim(),
|
||||
receiver: query.receiver.trim(),
|
||||
address: query.address.trim(),
|
||||
remark: query.remark.trim(),
|
||||
shop_id: query.shop_id,
|
||||
created_from: query.createdRange[0],
|
||||
created_to: query.createdRange[1],
|
||||
archived_from: query.archivedRange[0],
|
||||
archived_to: query.archivedRange[1],
|
||||
}))
|
||||
|
||||
/* -------------------- 筛选项数据源(状态枚举 / 店铺 / 归档阈值) -------------------- */
|
||||
const filters = ref<OrderStatusFilters>({
|
||||
statuses: [],
|
||||
status_labels: {} as OrderStatusFilters['status_labels'],
|
||||
active_statuses: [],
|
||||
archive_months: 3,
|
||||
shops: [],
|
||||
warehouses: [],
|
||||
})
|
||||
async function fetchFilters() {
|
||||
try {
|
||||
filters.value = await getOrderStatusFilters()
|
||||
} catch {
|
||||
// 拦截器已提示,保留默认值
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- 勾选与批量操作 -------------------- */
|
||||
const selectedIds = ref<number[]>([])
|
||||
function onSelectionChange(rows: OrderStatusItem[]) {
|
||||
selectedIds.value = rows.map(row => row.id)
|
||||
}
|
||||
|
||||
type BatchKey =
|
||||
| 'audit'
|
||||
| 'return'
|
||||
| 'push_wms'
|
||||
| 'push_success'
|
||||
| 'push_failed'
|
||||
| 'reject'
|
||||
| 'cancel'
|
||||
| 'void'
|
||||
| 'restore'
|
||||
| 'change_warehouse'
|
||||
| 'change_shop'
|
||||
|
||||
/** 批量操作按场景分布在各视图 */
|
||||
const BATCH_ACTIONS: Record<OrderStage, { key: BatchKey; label: string; type: string }[]> = {
|
||||
pending: [
|
||||
{ key: 'audit', label: '批量审核(→ 待推送)', type: 'primary' },
|
||||
{ key: 'change_warehouse', label: '切换仓库', type: 'default' },
|
||||
{ key: 'change_shop', label: '设置店铺', type: 'default' },
|
||||
{ key: 'cancel', label: '取消', type: 'warning' },
|
||||
{ key: 'void', label: '作废', type: 'danger' },
|
||||
],
|
||||
queued: [
|
||||
{ key: 'push_wms', label: '推送仓库', type: 'success' },
|
||||
{ key: 'reject', label: '驳回(换号)', type: 'warning' },
|
||||
{ key: 'change_warehouse', label: '切换仓库', type: 'default' },
|
||||
{ key: 'change_shop', label: '设置店铺', type: 'default' },
|
||||
{ key: 'cancel', label: '取消', type: 'warning' },
|
||||
{ key: 'void', label: '作废', type: 'danger' },
|
||||
{ key: 'push_success', label: '手工标记推送成功', type: 'default' },
|
||||
{ key: 'push_failed', label: '手工标记推送失败', type: 'default' },
|
||||
],
|
||||
exception: [
|
||||
{ key: 'return', label: '批量转回待审核', type: 'warning' },
|
||||
{ key: 'audit', label: '批量审核(直接 → 待推送)', type: 'primary' },
|
||||
{ key: 'change_warehouse', label: '切换仓库', type: 'default' },
|
||||
{ key: 'change_shop', label: '设置店铺', type: 'default' },
|
||||
{ key: 'cancel', label: '取消', type: 'warning' },
|
||||
{ key: 'void', label: '作废', type: 'danger' },
|
||||
],
|
||||
outsourcing: [
|
||||
{ key: 'change_shop', label: '设置店铺', type: 'default' },
|
||||
{ key: 'cancel', label: '取消(同步取消仓库单)', type: 'warning' },
|
||||
],
|
||||
delivery: [],
|
||||
void: [{ key: 'restore', label: '恢复(→ 待审核)', type: 'primary' }],
|
||||
canceled: [{ key: 'restore', label: '恢复(→ 待审核)', type: 'primary' }],
|
||||
history: [],
|
||||
}
|
||||
const batchActions = computed(() => BATCH_ACTIONS[props.status] || [])
|
||||
|
||||
/** 批量操作确认文案 */
|
||||
function confirmText(key: BatchKey, count: number): string {
|
||||
const map: Record<BatchKey, string> = {
|
||||
audit: `确认对选中的 ${count} 条订单执行「审核」?审核即锁定库存并进入「${ORDER_STAGE_META.queued.label}」。`,
|
||||
return: `确认将选中的 ${count} 条订单「转回待审核」?转回后需重新审核。`,
|
||||
push_wms: `确认将选中的 ${count} 条订单「推送仓库」?推送成功进入「${ORDER_STAGE_META.outsourcing.label}」,等仓库回传确认后进入「${ORDER_STAGE_META.delivery.label}」。`,
|
||||
push_success: `确认将选中的 ${count} 条订单手工标记为「推送成功」?将进入「${ORDER_STAGE_META.outsourcing.label}」视图。`,
|
||||
push_failed: `确认将选中的 ${count} 条订单手工标记为「推送失败」?将转入「${ORDER_STAGE_META.exception.label}」并释放锁定库存。`,
|
||||
reject: `确认驳回选中的 ${count} 条订单?驳回会自动换号(避免重推被仓库判重)并释放锁定库存,回到「${ORDER_STAGE_META.pending.label}」。`,
|
||||
cancel: `确认取消选中的 ${count} 条订单?已推送成功的会先取消仓库单据,成功后释放锁定库存。`,
|
||||
void: `确认作废选中的 ${count} 条订单?作废记录人与原因、释放锁定库存,不可恢复也禁止删除。`,
|
||||
restore: '确认将选中的订单恢复到「待审核」?曾推送过的单据会自动换号。',
|
||||
change_warehouse: '确认切换选中订单的发货仓库?',
|
||||
change_shop: '确认设置选中订单的所属店铺?',
|
||||
}
|
||||
return map[key]
|
||||
}
|
||||
|
||||
/** 切换仓库/设置店铺使用的目标下拉(弹窗内选择) */
|
||||
async function pickWarehouse(current?: number | null): Promise<number | null> {
|
||||
const list = filters.value.warehouses || []
|
||||
if (!list.length) {
|
||||
ElMessage.warning('当前主体下没有仓库,请先到「仓库管理」创建')
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const { value } = await ElMessageBox.prompt('请输入目标仓库名称或编码关键词后选择', '切换仓库', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPlaceholder: `可选:${list.map(w => `${w.name}(${w.code})`).join(' / ')}`,
|
||||
inputValidator: (text: string) => {
|
||||
const keyword = String(text || '').trim()
|
||||
return list.some(w => w.name.includes(keyword) || w.code.includes(keyword))
|
||||
? true
|
||||
: '请输入列表中的仓库名称或编码'
|
||||
},
|
||||
})
|
||||
const keyword = String(value).trim()
|
||||
const hit = list.find(w => w.name.includes(keyword) || w.code.includes(keyword))
|
||||
return hit ? hit.id : (current ?? null)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function pickShop(): Promise<number | null> {
|
||||
const list = filters.value.shops || []
|
||||
if (!list.length) {
|
||||
ElMessage.warning('当前主体下没有店铺,请先到「店铺管理」创建')
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const { value } = await ElMessageBox.prompt('请输入目标店铺名称关键词', '设置所属店铺', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPlaceholder: `可选:${list.map(s => s.name).join(' / ')}`,
|
||||
inputValidator: (text: string) => {
|
||||
const keyword = String(text || '').trim()
|
||||
return list.some(s => s.name.includes(keyword)) ? true : '请输入列表中的店铺名称'
|
||||
},
|
||||
})
|
||||
const keyword = String(value).trim()
|
||||
const hit = list.find(s => s.name.includes(keyword))
|
||||
return hit ? hit.id : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/** 批量操作入口 */
|
||||
async function handleBatch(key: BatchKey) {
|
||||
const ids = [ ...selectedIds.value ]
|
||||
if (!ids.length) {
|
||||
ElMessage.warning('请先勾选要操作的订单')
|
||||
return
|
||||
}
|
||||
try {
|
||||
// 需额外入参的动作先收集参数,再统一确认
|
||||
if (key === 'change_warehouse') {
|
||||
const warehouseId = await pickWarehouse()
|
||||
if (!warehouseId) return
|
||||
const result = await changeOrdersWarehouse(ids, warehouseId)
|
||||
ElMessage.success(`已切换仓库:${result.target.name}`)
|
||||
selectedIds.value = []
|
||||
await fetchList()
|
||||
return
|
||||
}
|
||||
if (key === 'change_shop') {
|
||||
const shopId = await pickShop()
|
||||
if (!shopId) return
|
||||
const result = await changeOrdersShop(ids, shopId)
|
||||
ElMessage.success(`已设置店铺:${result.target.name}`)
|
||||
selectedIds.value = []
|
||||
await fetchList()
|
||||
return
|
||||
}
|
||||
|
||||
let tip = ''
|
||||
if (key === 'push_failed') {
|
||||
const { value } = await ElMessageBox.prompt(confirmText(key, ids.length), '手工标记推送失败', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPlaceholder: '请填写推送失败原因(写入订单备注)',
|
||||
inputValidator: (text: string) => (text && text.trim() ? true : '请填写推送失败原因'),
|
||||
})
|
||||
tip = String(value).trim()
|
||||
} else if (key === 'void') {
|
||||
const { value } = await ElMessageBox.prompt(confirmText(key, ids.length), '作废订单', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPlaceholder: '请填写作废原因(可不填)',
|
||||
})
|
||||
tip = String(value || '').trim()
|
||||
} else if (key === 'cancel') {
|
||||
const { value } = await ElMessageBox.prompt(confirmText(key, ids.length), '取消订单', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPlaceholder: '请填写取消原因(可不填)',
|
||||
})
|
||||
tip = String(value || '').trim()
|
||||
} else {
|
||||
await ElMessageBox.confirm(confirmText(key, ids.length), '批量操作', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
}
|
||||
|
||||
if (key === 'audit') {
|
||||
const result = await auditOrders(ids)
|
||||
if (result.failures?.length) {
|
||||
ElMessage.warning(`已审核 ${result.count} 条,${result.failed} 条失败(如:${result.failures[0].message})`)
|
||||
} else {
|
||||
ElMessage.success(`已审核 ${result.count} 条,当前状态「${result.status_label}」`)
|
||||
}
|
||||
} else if (key === 'return') {
|
||||
const result = await returnOrdersToPending(ids)
|
||||
ElMessage.success(`已处理 ${result.count} 条,当前状态「${result.status_label}」`)
|
||||
} else if (key === 'push_wms') {
|
||||
const result = await pushOrdersToWms(ids)
|
||||
ElMessage.success(
|
||||
`推送完成:成功 ${result.pushed},失败 ${result.failed},待重试 ${result.retry},跳过 ${result.skipped}` +
|
||||
(result.pendingRest ? `(剩余 ${result.pendingRest} 条由定时任务继续推送)` : ''),
|
||||
)
|
||||
} else if (key === 'push_success') {
|
||||
const result = await pushOrders(ids, 'success')
|
||||
ElMessage.success(`已处理 ${result.count} 条,当前状态「${result.status_label}」`)
|
||||
} else if (key === 'push_failed') {
|
||||
const result = await pushOrders(ids, 'failed', tip || '推送外部失败')
|
||||
ElMessage.success(`已处理 ${result.count} 条,当前状态「${result.status_label}」`)
|
||||
} else if (key === 'reject') {
|
||||
const result = await rejectOrders(ids)
|
||||
const renamed = result.items.filter(item => item.bill_no_changed).length
|
||||
ElMessage.success(`已驳回 ${result.count} 条${renamed ? `,其中 ${renamed} 条已换号` : ''}`)
|
||||
} else if (key === 'cancel') {
|
||||
const result = await cancelOrders(ids, tip || undefined)
|
||||
ElMessage.success(`已取消 ${result.count} 条,当前状态「${result.status_label}」`)
|
||||
} else if (key === 'void') {
|
||||
const result = await voidOrders(ids, tip || undefined)
|
||||
ElMessage.success(`已作废 ${result.count} 条,当前状态「${result.status_label}」`)
|
||||
} else if (key === 'restore') {
|
||||
const result = await restoreOrders(ids)
|
||||
const renamed = result.items.filter(item => item.bill_no_changed).length
|
||||
ElMessage.success(`已恢复 ${result.count} 条${renamed ? `,其中 ${renamed} 条已换号` : ''}`)
|
||||
}
|
||||
selectedIds.value = []
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 用户取消 或 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
/** 手工归档创建时间超期的订单(默认 3 个月,定时任务亦会自动执行) */
|
||||
async function handleArchiveExpired() {
|
||||
const months = filters.value.archive_months || 3
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确认归档创建时间超过 ${months} 个月的订单?归档后迁入历史表(只读),并记录归档时间与转入时间。`,
|
||||
'归档超期订单',
|
||||
{ type: 'warning', confirmButtonText: '确定', cancelButtonText: '取消' },
|
||||
)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const result = await archiveOrders({ months })
|
||||
ElMessage.success(`已归档 ${result.count} 条`)
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- 详情(单据头 + 明细,实时取详情接口) -------------------- */
|
||||
const detailVisible = ref(false)
|
||||
const detailLoading = ref(false)
|
||||
const detailRow = ref<OrderStatusItem | null>(null)
|
||||
const detailProducts = ref<OrderItemLine[]>([])
|
||||
|
||||
async function openDetail(row: OrderStatusItem) {
|
||||
detailRow.value = row
|
||||
detailProducts.value = []
|
||||
detailVisible.value = true
|
||||
detailLoading.value = true
|
||||
try {
|
||||
const { order, items } = await getOrderStatusDetail(row.id)
|
||||
detailRow.value = order
|
||||
detailProducts.value = items
|
||||
} catch {
|
||||
// 拦截器已提示,退化为列表行展示
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- 新建 / 编辑(发货单口径表单) -------------------- */
|
||||
const formVisible = ref(false)
|
||||
const formOrderId = ref<number | null>(null)
|
||||
|
||||
function openCreate() {
|
||||
formOrderId.value = null
|
||||
formVisible.value = true
|
||||
}
|
||||
function openEdit(row: OrderStatusItem) {
|
||||
formOrderId.value = row.id
|
||||
formVisible.value = true
|
||||
}
|
||||
async function handleFormSaved() {
|
||||
if (formOrderId.value) {
|
||||
selectedIds.value = []
|
||||
await fetchList()
|
||||
} else if (props.status === 'pending') {
|
||||
await fetchList()
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- 行内动作 -------------------- */
|
||||
type RowActionKey =
|
||||
| 'detail'
|
||||
| 'edit'
|
||||
| 'audit'
|
||||
| 'push_wms'
|
||||
| 'reject'
|
||||
| 'cancel'
|
||||
| 'void'
|
||||
| 'restore'
|
||||
| 'remove'
|
||||
| 'archive'
|
||||
|
||||
const AUTO_ACTIONS: Record<OrderStage, RowActionKey[]> = {
|
||||
pending: [ 'edit', 'audit', 'cancel', 'void', 'remove' ],
|
||||
queued: [ 'push_wms', 'reject', 'cancel', 'void' ],
|
||||
exception: [ 'edit', 'audit', 'cancel', 'void', 'remove' ],
|
||||
outsourcing: [ 'cancel' ],
|
||||
delivery: [ 'archive' ],
|
||||
void: [ 'restore' ],
|
||||
canceled: [ 'restore', 'remove' ],
|
||||
history: [],
|
||||
}
|
||||
const rowActions = computed(() => AUTO_ACTIONS[props.status] || [])
|
||||
|
||||
/** 行内动作文案 */
|
||||
const ROW_ACTION_LABEL: Record<RowActionKey, string> = {
|
||||
detail: '查看',
|
||||
edit: '编辑',
|
||||
audit: '审核',
|
||||
push_wms: '推送仓库',
|
||||
reject: '驳回',
|
||||
cancel: '取消',
|
||||
void: '作废',
|
||||
restore: '恢复',
|
||||
remove: '删除',
|
||||
archive: '归档',
|
||||
}
|
||||
|
||||
/** 单条动作:确认后调用对应接口 */
|
||||
async function handleRowAction(row: OrderStatusItem, key: RowActionKey) {
|
||||
const ids = [ row.id ]
|
||||
try {
|
||||
if (key === 'edit') {
|
||||
openEdit(row)
|
||||
return
|
||||
}
|
||||
if (key === 'audit') {
|
||||
await ElMessageBox.confirm(`确认审核订单 ${row.order_no}?审核即锁定库存并进入「待推送」。`, '审核', { type: 'warning' })
|
||||
const result = await auditOrders(ids)
|
||||
ElMessage.success(`已审核 ${row.order_no},锁定 ${result.stock_locked ?? 0} 行库存,已进入「${result.status_label}」`)
|
||||
} else if (key === 'push_wms') {
|
||||
await ElMessageBox.confirm(`确认把订单 ${row.order_no} 推送到仓库?`, '推送仓库', { type: 'warning' })
|
||||
const result = await pushOrderToWms(row.id)
|
||||
ElMessage.success(`已推送 ${row.order_no}(第 ${result.attempts} 次尝试),已进入「委外中」`)
|
||||
} else if (key === 'reject') {
|
||||
await ElMessageBox.confirm(
|
||||
`确认驳回订单 ${row.order_no}?驳回会换号(避免重推被仓库判重)并释放锁定库存。`,
|
||||
'驳回',
|
||||
{ type: 'warning' },
|
||||
)
|
||||
const result = await rejectOrders(ids)
|
||||
const item = result.items[0]
|
||||
ElMessage.success(item.bill_no_changed ? `已驳回并换号:${item.order_no}` : '已驳回')
|
||||
} else if (key === 'cancel') {
|
||||
const { value } = await ElMessageBox.prompt(`确认取消订单 ${row.order_no}?`, '取消订单', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPlaceholder: '请填写取消原因(可不填)',
|
||||
})
|
||||
await cancelOrders(ids, String(value || '').trim() || undefined)
|
||||
ElMessage.success(`已取消 ${row.order_no}`)
|
||||
} else if (key === 'void') {
|
||||
const { value } = await ElMessageBox.prompt(
|
||||
`确认作废订单 ${row.order_no}?作废后不可恢复也禁止删除。`,
|
||||
'作废订单',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPlaceholder: '请填写作废原因(可不填)',
|
||||
},
|
||||
)
|
||||
await voidOrders(ids, String(value || '').trim() || undefined)
|
||||
ElMessage.success(`已作废 ${row.order_no}`)
|
||||
} else if (key === 'restore') {
|
||||
await ElMessageBox.confirm(`确认把订单 ${row.order_no} 恢复到「待审核」?曾推送过的会自动换号。`, '恢复', {
|
||||
type: 'warning',
|
||||
})
|
||||
const result = await restoreOrders(ids)
|
||||
const item = result.items[0]
|
||||
ElMessage.success(item.bill_no_changed ? `已恢复并换号:${item.order_no}` : `已恢复 ${row.order_no}`)
|
||||
} else if (key === 'remove') {
|
||||
await ElMessageBox.confirm(`确认删除订单 ${row.order_no}?删除后不可恢复(已审核及之后禁止删除)。`, '删除订单', {
|
||||
type: 'warning',
|
||||
})
|
||||
await removeOrderStatus(row.id)
|
||||
ElMessage.success(`已删除 ${row.order_no}`)
|
||||
} else if (key === 'archive') {
|
||||
await ElMessageBox.confirm(`确认把订单 ${row.order_no} 归档到历史?归档后只读。`, '归档', { type: 'warning' })
|
||||
await archiveOrders({ ids })
|
||||
ElMessage.success(`已归档 ${row.order_no}`)
|
||||
}
|
||||
selectedIds.value = []
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 用户取消 或 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
/** 数量/单价展示:数字去掉多余小数 */
|
||||
function fmtNum(value: unknown): string {
|
||||
if (value === null || value === undefined || value === '') return '-'
|
||||
const num = Number(value)
|
||||
return Number.isFinite(num) ? String(Number(num.toFixed(2))) : String(value)
|
||||
}
|
||||
|
||||
/** 行金额 = 数量 × 单价 */
|
||||
function lineAmount(line: OrderItemLine): string {
|
||||
const qty = Number(line.plan_qty || 0)
|
||||
const price = Number(line.actual_price || 0)
|
||||
if (!Number.isFinite(qty) || !Number.isFinite(price)) return '-'
|
||||
return (qty * price).toFixed(2)
|
||||
}
|
||||
|
||||
/** 收件人展示:姓名 + 电话/手机 */
|
||||
function receiverText(row: OrderStatusItem): string {
|
||||
const phone = row.mobile || row.tel || ''
|
||||
return phone ? `${row.receiver || '-'}(${phone})` : row.receiver || '-'
|
||||
}
|
||||
|
||||
/**
|
||||
* 运单号(多包裹时逐个展示):优先 express_codes(回调写入的多运单号集合),回退单值 express_code
|
||||
* @param row 订单行
|
||||
* @return 运单号数组(无则空数组)
|
||||
*/
|
||||
function expressCodesOf(row: OrderStatusItem): string[] {
|
||||
const codes = (row.express_codes || []).filter(code => code && String(code).trim())
|
||||
if (codes.length) return codes.map(code => String(code))
|
||||
return row.express_code ? [ String(row.express_code) ] : []
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchFilters()
|
||||
await fetchList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="panel">
|
||||
<!-- 批量操作区(按场景分布在各视图) + 新建/归档入口 -->
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-left">
|
||||
<el-tag :type="stageMeta.tag" size="small" effect="plain">{{ stageMeta.label }}</el-tag>
|
||||
<el-button
|
||||
v-for="action in batchActions"
|
||||
:key="action.key"
|
||||
:type="action.type as never"
|
||||
size="small"
|
||||
:disabled="!selectedIds.length"
|
||||
@click="handleBatch(action.key)"
|
||||
>
|
||||
{{ action.label }}
|
||||
</el-button>
|
||||
<span v-if="!batchActions.length" class="toolbar-hint">该视图只读(可查看详情)</span>
|
||||
<span v-else-if="selectedIds.length" class="toolbar-hint">已选 {{ selectedIds.length }} 条</span>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
<ExportButton type="order" :filters="exportFilters" size="small" plain />
|
||||
<el-button v-if="props.status === 'pending'" type="primary" size="small" @click="openCreate">
|
||||
新建订单(发货单)
|
||||
</el-button>
|
||||
<el-button v-if="isHistory" size="small" @click="handleArchiveExpired">
|
||||
归档超期订单(>{{ filters.archive_months }} 个月)
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 筛选:默认一行简单条件 -->
|
||||
<el-form :inline="true" size="small" class="filter-bar" @submit.prevent>
|
||||
<el-form-item label="订单号">
|
||||
<el-input v-model="query.order_no" placeholder="支持模糊匹配" clearable style="width: 160px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item label="创建时间">
|
||||
<el-date-picker
|
||||
v-model="query.createdRange"
|
||||
type="daterange"
|
||||
value-format="YYYY-MM-DD"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
style="width: 230px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
<el-link type="primary" :underline="false" class="expand-link" @click="expanded = !expanded">
|
||||
{{ expanded ? '收起' : '展开' }}
|
||||
</el-link>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 展开后的完整条件 -->
|
||||
<el-form v-if="expanded" :inline="true" size="small" class="filter-bar filter-extra" @submit.prevent>
|
||||
<el-form-item label="来源订单号">
|
||||
<el-input v-model="query.parent_order_no" placeholder="上游 / 平台订单号" clearable style="width: 160px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item label="店铺">
|
||||
<el-select v-model="query.shop_id" placeholder="全部" clearable style="width: 160px">
|
||||
<el-option v-for="shop in filters.shops" :key="shop.id" :label="shop.name" :value="shop.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="收货人">
|
||||
<el-input v-model="query.receiver" placeholder="收货人" clearable style="width: 130px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item label="收货地址">
|
||||
<el-input v-model="query.address" placeholder="地址关键词" clearable style="width: 180px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注/异常原因">
|
||||
<el-input v-model="query.remark" placeholder="备注或异常原因" clearable style="width: 160px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="isHistory" label="归档时间">
|
||||
<el-date-picker
|
||||
v-model="query.archivedRange"
|
||||
type="daterange"
|
||||
value-format="YYYY-MM-DD"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
style="width: 230px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 列表 -->
|
||||
<div class="table-wrap">
|
||||
<DataTable
|
||||
:loading="loading"
|
||||
:data="list"
|
||||
row-key="id"
|
||||
class="fill-table"
|
||||
@selection-change="onSelectionChange"
|
||||
>
|
||||
<el-table-column type="selection" width="42" :reserve-selection="false" />
|
||||
<el-table-column prop="order_no" label="订单号" width="150" show-overflow-tooltip />
|
||||
<el-table-column v-if="isException" label="异常原因" min-width="260" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.remark" type="danger" effect="plain" size="small" class="fail-tag">
|
||||
{{ row.remark }}
|
||||
</el-tag>
|
||||
<span v-else class="muted">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="parent_order_no" label="来源订单号" width="140" show-overflow-tooltip />
|
||||
<el-table-column label="店铺" width="120" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.shop_name || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品明细" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.product_summary || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="仓库" width="130" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.warehouse_name || row.warehouse_code || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="收货人" width="140" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ receiverText(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="address" label="收货地址" min-width="180" show-overflow-tooltip />
|
||||
<el-table-column v-if="!isException" label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="stageMeta.tag">{{ row.status_label || stageMeta.label }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="物流公司" width="130" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.logistics_name || row.logistics_code || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="运单号" width="170" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<template v-if="expressCodesOf(row).length">
|
||||
<div v-for="code in expressCodesOf(row)" :key="code">{{ code }}</div>
|
||||
</template>
|
||||
<template v-else>-</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="库存/仓库单" width="140" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="Number(row.stock_locked) === 1" size="small" type="warning" effect="plain">已锁库存</el-tag>
|
||||
<span v-else-if="row.wms_order_no">WMS {{ row.wms_order_no }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="!isException" prop="remark" label="备注 / 异常原因" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column label="创建时间" width="150">
|
||||
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="isHistory" label="归档时间" width="150">
|
||||
<template #default="{ row }">{{ formatDateTime(row.archived_at) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="isHistory" label="转入时间" width="150">
|
||||
<template #default="{ row }">{{ formatDateTime(row.transferred_at) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" :width="rowActions.length > 3 ? 220 : 150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="openDetail(row)">查看</el-button>
|
||||
<el-button
|
||||
v-for="action in rowActions"
|
||||
:key="action"
|
||||
link
|
||||
size="small"
|
||||
:type="action === 'remove' || action === 'void' ? 'danger' : 'primary'"
|
||||
@click="handleRowAction(row, action)"
|
||||
>
|
||||
{{ ROW_ACTION_LABEL[action] }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
</div>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
|
||||
<!-- 详情(单据头 + 明细,实时取自详情接口) -->
|
||||
<el-drawer v-model="detailVisible" :title="`订单 ${detailRow?.order_no || ''}`" size="720px">
|
||||
<template v-if="detailRow">
|
||||
<el-descriptions v-loading="detailLoading" :column="2" border size="small">
|
||||
<el-descriptions-item label="订单号">{{ detailRow.order_no }}</el-descriptions-item>
|
||||
<el-descriptions-item label="来源订单号">{{ detailRow.parent_order_no || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag size="small" :type="ORDER_STAGE_META[detailRow.status]?.tag">
|
||||
{{ detailRow.status_label || ORDER_STAGE_META[detailRow.status]?.label }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="所在表">{{ detailRow.current_table || detailRow.status }}</el-descriptions-item>
|
||||
<el-descriptions-item label="仓库">
|
||||
{{ detailRow.warehouse_name || detailRow.warehouse_code || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="店铺">{{ detailRow.shop_name || detailRow.shop_nick || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="订单类型">{{ detailRow.order_type || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="订单ID(索引表)">{{ detailRow.id }}</el-descriptions-item>
|
||||
<el-descriptions-item label="收件人">{{ detailRow.receiver || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="电话 / 手机">
|
||||
{{ detailRow.mobile || detailRow.tel || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="收货地址" :span="2">
|
||||
{{ [ detailRow.province, detailRow.city, detailRow.area, detailRow.town, detailRow.detail_address ].filter(Boolean).join('') || detailRow.address || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="商品总数量">{{ fmtNum(detailRow.item_total) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="商品种类">{{ detailRow.item_kind ?? 0 }} 种</el-descriptions-item>
|
||||
<el-descriptions-item label="订单总金额">{{ fmtNum(detailRow.total_amount) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="商品金额">{{ fmtNum(detailRow.item_amount) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="快递费">{{ fmtNum(detailRow.freight) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="已收金额">{{ fmtNum(detailRow.got_amount) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="物流公司">
|
||||
{{ detailRow.logistics_name || detailRow.logistics_code || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="运单号">
|
||||
<template v-if="expressCodesOf(detailRow).length">
|
||||
<div v-for="code in expressCodesOf(detailRow)" :key="code">{{ code }}</div>
|
||||
</template>
|
||||
<template v-else>-</template>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="库存锁定">
|
||||
<el-tag size="small" :type="Number(detailRow.stock_locked) === 1 ? 'warning' : 'info'" effect="plain">
|
||||
{{ Number(detailRow.stock_locked) === 1 ? '已锁定' : '未锁定' }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="仓库单号">{{ detailRow.wms_order_no || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="审核人 / 时间">
|
||||
{{ detailRow.operator_name || detailRow.audit_by || '-' }} / {{ formatDateTime(detailRow.audit_time) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="推送时间">{{ formatDateTime(detailRow.pushed_at) }}</el-descriptions-item>
|
||||
<template v-if="detailRow.void_at">
|
||||
<el-descriptions-item label="作废时间">{{ formatDateTime(detailRow.void_at) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="作废原因">{{ detailRow.void_reason || '-' }}</el-descriptions-item>
|
||||
</template>
|
||||
<el-descriptions-item label="卖家留言" :span="2">{{ detailRow.seller_message || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="备注 / 异常原因" :span="2">{{ detailRow.remark || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间">{{ formatDateTime(detailRow.created_at) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="更新时间">{{ formatDateTime(detailRow.updated_at) }}</el-descriptions-item>
|
||||
<template v-if="isHistory">
|
||||
<el-descriptions-item label="归档时间">{{ formatDateTime(detailRow.archived_at) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="转入时间">{{ formatDateTime(detailRow.transferred_at) }}</el-descriptions-item>
|
||||
</template>
|
||||
</el-descriptions>
|
||||
|
||||
<el-divider content-position="left">商品明细({{ detailProducts.length }} 行)</el-divider>
|
||||
<DataTable :data="detailProducts" :stripe="true">
|
||||
<el-table-column prop="order_line_no" label="行号" width="70" />
|
||||
<el-table-column prop="item_code" label="商品编码" width="150" show-overflow-tooltip />
|
||||
<el-table-column prop="item_name" label="商品名称" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column label="数量" width="80" align="right">
|
||||
<template #default="{ row }">{{ fmtNum(row.plan_qty) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单价" width="80" align="right">
|
||||
<template #default="{ row }">{{ fmtNum(row.actual_price) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="金额" width="90" align="right">
|
||||
<template #default="{ row }">{{ lineAmount(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="库存类型" width="90">
|
||||
<template #default="{ row }">{{ row.inventory_type === 'CC' ? '残次' : '正品' }}</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
</template>
|
||||
</el-drawer>
|
||||
|
||||
<!-- 新建 / 编辑(发货单口径:仓库 / 店铺 / 收件人 12 项 / 金额 / 留言 / 明细) -->
|
||||
<OrderFormDialog
|
||||
v-model="formVisible"
|
||||
:order-id="formOrderId"
|
||||
:filters="filters"
|
||||
@saved="handleFormSaved"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
.toolbar {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.toolbar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.toolbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.toolbar-hint {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.filter-bar {
|
||||
flex: 0 0 auto;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.filter-extra {
|
||||
padding-top: 2px;
|
||||
}
|
||||
.expand-link {
|
||||
margin-left: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.table-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
/* 异常原因:标红 tag,超长省略(悬浮 tooltip 看全文) */
|
||||
.fail-tag {
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.muted {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.add-line {
|
||||
margin-top: 8px;
|
||||
}
|
||||
.compact-form :deep(.el-form-item) {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.compact-form :deep(.el-divider) {
|
||||
margin: 6px 0 8px;
|
||||
}
|
||||
</style>
|
||||
@ -13,6 +13,7 @@ import { getShops, type ShopItem } from '@/api/shop'
|
||||
import { getExpressCompanyOptions, type ExpressCompanyOption } from '@/api/expressCompany'
|
||||
import { type ProductSearchItem } from '@/api/product'
|
||||
import SplitLayout from '@/components/SplitLayout.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import VirtualSelect from '@/components/VirtualSelect.vue'
|
||||
@ -77,6 +78,13 @@ function reset() {
|
||||
query.outbound_type = ''
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件(与列表筛选同一套条件,字段名与后端 outbound_order 类型对齐) */
|
||||
const exportFilters = computed(() => ({
|
||||
bill_no: query.bill_no.trim(),
|
||||
status: query.status,
|
||||
outbound_type: query.outbound_type,
|
||||
}))
|
||||
function typeLabel(row: OutboundOrder) {
|
||||
return TYPE_OPTIONS.find((o) => o.value === row.outbound_type)?.label || String(row.outbound_type)
|
||||
}
|
||||
@ -480,7 +488,10 @@ onMounted(async () => {
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>出库单</span>
|
||||
<el-button type="primary" @click="openCreate">新增出库单</el-button>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="openCreate">新增出库单</el-button>
|
||||
<ExportButton type="outbound_order" :filters="exportFilters" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { getPrincipals, createPrincipal, type PrincipalPayload } from '@/api/principal'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
@ -24,6 +25,11 @@ function reset() {
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件(主体列表按当前账号已绑定的主体导出) */
|
||||
const exportFilters = computed(() => ({
|
||||
keyword: query.keyword.trim(),
|
||||
}))
|
||||
|
||||
// 新建主体弹窗
|
||||
const dialogVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
@ -77,7 +83,10 @@ onMounted(fetchList)
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>主体管理</span>
|
||||
<el-button type="primary" @click="openCreate">新建主体</el-button>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="openCreate">新建主体</el-button>
|
||||
<ExportButton type="principal" :filters="exportFilters" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
type PrincipalUserItem,
|
||||
} from '@/api/principalUser'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import ImageUploader from '@/components/ImageUploader.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
@ -56,6 +57,12 @@ function reset() {
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件(与列表筛选同源) */
|
||||
const exportFilters = computed(() => ({
|
||||
role: query.role,
|
||||
status: query.status,
|
||||
}))
|
||||
|
||||
// 邀请用户
|
||||
const inviteVisible = ref(false)
|
||||
const inviteSubmitting = ref(false)
|
||||
@ -208,7 +215,10 @@ onMounted(fetchList)
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>账号</span>
|
||||
<el-button type="primary" @click="openInvite">邀请用户</el-button>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="openInvite">邀请用户</el-button>
|
||||
<ExportButton type="principal_user" :filters="exportFilters" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
getProducts,
|
||||
@ -8,17 +9,37 @@ import {
|
||||
deleteProduct,
|
||||
type ProductItem,
|
||||
} from '@/api/product'
|
||||
import {
|
||||
getProductCategoryOptions,
|
||||
createProductCategory,
|
||||
type ProductAttributeOption as CategoryOption,
|
||||
} from '@/api/productCategory'
|
||||
import {
|
||||
getProductBrandOptions,
|
||||
createProductBrand,
|
||||
type ProductAttributeOption as BrandOption,
|
||||
} from '@/api/productBrand'
|
||||
import {
|
||||
getProductUnitOptions,
|
||||
createProductUnit,
|
||||
type ProductAttributeOption as UnitOption,
|
||||
} from '@/api/productUnit'
|
||||
import ImageUploader from '@/components/ImageUploader.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
import { mediaUrl } from '@/utils/media'
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
keyword: '',
|
||||
category_name: '',
|
||||
brand_name: '',
|
||||
stock_unit: '',
|
||||
status: '' as string | number,
|
||||
})
|
||||
|
||||
@ -28,6 +49,8 @@ const { loading, list, total, elapsed, fetchList, search, handlePageChange, hand
|
||||
const params: Record<string, unknown> = { ...query }
|
||||
if (!params.keyword) delete params.keyword
|
||||
if (!params.category_name) delete params.category_name
|
||||
if (!params.brand_name) delete params.brand_name
|
||||
if (!params.stock_unit) delete params.stock_unit
|
||||
if (params.status === '') delete params.status
|
||||
return getProducts(params)
|
||||
},
|
||||
@ -36,10 +59,110 @@ const { loading, list, total, elapsed, fetchList, search, handlePageChange, hand
|
||||
function reset() {
|
||||
query.keyword = ''
|
||||
query.category_name = ''
|
||||
query.brand_name = ''
|
||||
query.stock_unit = ''
|
||||
query.status = ''
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件(与列表筛选同一套条件,字段名与后端 product 类型对齐) */
|
||||
const exportFilters = computed(() => ({
|
||||
keyword: query.keyword.trim(),
|
||||
category_name: query.category_name,
|
||||
brand_name: query.brand_name,
|
||||
stock_unit: query.stock_unit,
|
||||
status: query.status,
|
||||
}))
|
||||
|
||||
/** 从路由 query 带入筛选条件(如由商品属性页「使用商品数」跳转而来) */
|
||||
function applyRouteQuery() {
|
||||
const q = route.query || {}
|
||||
if (typeof q.category_name === 'string') query.category_name = q.category_name
|
||||
if (typeof q.brand_name === 'string') query.brand_name = q.brand_name
|
||||
if (typeof q.stock_unit === 'string') query.stock_unit = q.stock_unit
|
||||
}
|
||||
|
||||
/* -------------------- 属性下拉(分类/品牌/单位) -------------------- */
|
||||
const categoryOptions = ref<CategoryOption[]>([])
|
||||
const brandOptions = ref<BrandOption[]>([])
|
||||
const unitOptions = ref<UnitOption[]>([])
|
||||
|
||||
async function loadAttributeOptions() {
|
||||
try {
|
||||
const [ c, b, u ] = await Promise.all([
|
||||
getProductCategoryOptions(),
|
||||
getProductBrandOptions(),
|
||||
getProductUnitOptions(),
|
||||
])
|
||||
categoryOptions.value = c
|
||||
brandOptions.value = b
|
||||
unitOptions.value = u
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
/** 选中属性后回填 id + 文本(文本冗余存储,便于列表展示/兼容外部系统) */
|
||||
function onCategoryChange(id: number | null) {
|
||||
form.category_id = id
|
||||
form.category_name = categoryOptions.value.find(o => o.id === id)?.name || ''
|
||||
}
|
||||
function onBrandChange(id: number | null) {
|
||||
form.brand_id = id
|
||||
form.brand_name = brandOptions.value.find(o => o.id === id)?.name || ''
|
||||
}
|
||||
function onUnitChange(id: number | null) {
|
||||
form.unit_id = id
|
||||
form.stock_unit = unitOptions.value.find(o => o.id === id)?.name || ''
|
||||
}
|
||||
|
||||
/* -------------------- 快速新增属性(分类/品牌/单位) -------------------- */
|
||||
type QuickAddType = 'category' | 'brand' | 'unit'
|
||||
const quickAddVisible = ref(false)
|
||||
const quickAddType = ref<QuickAddType | null>(null)
|
||||
const quickAddName = ref('')
|
||||
const quickAdding = ref(false)
|
||||
const quickAddLabelMap: Record<QuickAddType, string> = {
|
||||
category: '分类',
|
||||
brand: '品牌',
|
||||
unit: '单位',
|
||||
}
|
||||
|
||||
function openQuickAdd(type: QuickAddType) {
|
||||
quickAddType.value = type
|
||||
quickAddName.value = ''
|
||||
quickAddVisible.value = true
|
||||
}
|
||||
|
||||
async function submitQuickAdd() {
|
||||
const type = quickAddType.value
|
||||
const name = quickAddName.value.trim()
|
||||
if (!type || !name) {
|
||||
ElMessage.warning('请输入名称')
|
||||
return
|
||||
}
|
||||
quickAdding.value = true
|
||||
try {
|
||||
let res: { id: number }
|
||||
if (type === 'category') res = await createProductCategory({ name })
|
||||
else if (type === 'brand') res = await createProductBrand({ name })
|
||||
else res = await createProductUnit({ name })
|
||||
|
||||
await loadAttributeOptions()
|
||||
// 自动选中新建项并回填名称
|
||||
if (type === 'category') onCategoryChange(res.id)
|
||||
else if (type === 'brand') onBrandChange(res.id)
|
||||
else onUnitChange(res.id)
|
||||
|
||||
ElMessage.success('已添加')
|
||||
quickAddVisible.value = false
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
quickAdding.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- 新增 / 编辑 -------------------- */
|
||||
const drawerVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
@ -53,7 +176,9 @@ const form = reactive({
|
||||
item_type: 1,
|
||||
category_id: null as number | null,
|
||||
category_name: '',
|
||||
brand_id: null as number | null,
|
||||
brand_name: '',
|
||||
unit_id: null as number | null,
|
||||
sku_property: '',
|
||||
stock_unit: '',
|
||||
length: null as number | null,
|
||||
@ -82,7 +207,9 @@ const EMPTY_FORM = {
|
||||
item_type: 1,
|
||||
category_id: null,
|
||||
category_name: '',
|
||||
brand_id: null,
|
||||
brand_name: '',
|
||||
unit_id: null,
|
||||
sku_property: '',
|
||||
stock_unit: '',
|
||||
length: null,
|
||||
@ -128,7 +255,9 @@ function openEdit(row: ProductItem) {
|
||||
item_type: row.item_type,
|
||||
category_id: row.category_id,
|
||||
category_name: row.category_name || '',
|
||||
brand_id: row.brand_id,
|
||||
brand_name: row.brand_name || '',
|
||||
unit_id: row.unit_id,
|
||||
sku_property: row.sku_property || '',
|
||||
stock_unit: row.stock_unit || '',
|
||||
length: toNumberOrNull(row.length),
|
||||
@ -226,7 +355,11 @@ async function handleDelete(row: ProductItem) {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(fetchList)
|
||||
onMounted(async () => {
|
||||
await loadAttributeOptions()
|
||||
applyRouteQuery()
|
||||
await fetchList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -234,7 +367,10 @@ onMounted(fetchList)
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>商品</span>
|
||||
<el-button type="primary" @click="openCreate">新增商品</el-button>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="openCreate">新增商品</el-button>
|
||||
<ExportButton type="product" :filters="exportFilters" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -248,12 +384,37 @@ onMounted(fetchList)
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="分类名称">
|
||||
<el-input
|
||||
<el-select
|
||||
v-model="query.category_name"
|
||||
placeholder="精确匹配"
|
||||
clearable
|
||||
@keyup.enter="search"
|
||||
/>
|
||||
filterable
|
||||
style="width: 160px"
|
||||
>
|
||||
<el-option v-for="o in categoryOptions" :key="o.id" :label="o.name" :value="o.name" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="品牌">
|
||||
<el-select
|
||||
v-model="query.brand_name"
|
||||
placeholder="精确匹配"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 160px"
|
||||
>
|
||||
<el-option v-for="o in brandOptions" :key="o.id" :label="o.name" :value="o.name" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="单位">
|
||||
<el-select
|
||||
v-model="query.stock_unit"
|
||||
placeholder="精确匹配"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 140px"
|
||||
>
|
||||
<el-option v-for="o in unitOptions" :key="o.id" :label="o.name" :value="o.name" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 140px">
|
||||
@ -354,17 +515,53 @@ onMounted(fetchList)
|
||||
<el-form-item label="条码" prop="barcode">
|
||||
<el-input v-model="form.barcode" placeholder="选填,商品条码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类名称" prop="category_name">
|
||||
<el-input v-model="form.category_name" placeholder="选填" />
|
||||
<el-form-item label="分类" prop="category_name">
|
||||
<div class="select-with-add">
|
||||
<el-select
|
||||
v-model="form.category_id"
|
||||
placeholder="选填(也可在商品属性中维护)"
|
||||
clearable
|
||||
filterable
|
||||
style="flex: 1"
|
||||
@change="onCategoryChange"
|
||||
>
|
||||
<el-option v-for="o in categoryOptions" :key="o.id" :label="o.name" :value="o.id" />
|
||||
</el-select>
|
||||
<el-button title="快速新增分类" @click="openQuickAdd('category')">+</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="SKU规格" prop="sku_property">
|
||||
<el-input v-model="form.sku_property" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="库存单位" prop="stock_unit">
|
||||
<el-input v-model="form.stock_unit" placeholder="如 件 / 箱" />
|
||||
<el-form-item label="单位" prop="stock_unit">
|
||||
<div class="select-with-add">
|
||||
<el-select
|
||||
v-model="form.unit_id"
|
||||
placeholder="选填(也可在商品属性中维护)"
|
||||
clearable
|
||||
filterable
|
||||
style="flex: 1"
|
||||
@change="onUnitChange"
|
||||
>
|
||||
<el-option v-for="o in unitOptions" :key="o.id" :label="o.name" :value="o.id" />
|
||||
</el-select>
|
||||
<el-button title="快速新增单位" @click="openQuickAdd('unit')">+</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="品牌名称" prop="brand_name">
|
||||
<el-input v-model="form.brand_name" placeholder="选填" />
|
||||
<el-form-item label="品牌" prop="brand_name">
|
||||
<div class="select-with-add">
|
||||
<el-select
|
||||
v-model="form.brand_id"
|
||||
placeholder="选填(也可在商品属性中维护)"
|
||||
clearable
|
||||
filterable
|
||||
style="flex: 1"
|
||||
@change="onBrandChange"
|
||||
>
|
||||
<el-option v-for="o in brandOptions" :key="o.id" :label="o.name" :value="o.id" />
|
||||
</el-select>
|
||||
<el-button title="快速新增品牌" @click="openQuickAdd('brand')">+</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="标价" prop="tag_price">
|
||||
<el-input-number
|
||||
@ -445,6 +642,29 @@ onMounted(fetchList)
|
||||
<el-button type="primary" :loading="submitting" @click="submitForm">保存</el-button>
|
||||
</template>
|
||||
</el-drawer>
|
||||
|
||||
<el-dialog
|
||||
v-model="quickAddVisible"
|
||||
:title="`快速新增${quickAddType ? quickAddLabelMap[quickAddType] : ''}`"
|
||||
width="420px"
|
||||
append-to-body
|
||||
>
|
||||
<el-form label-width="72px" @submit.prevent>
|
||||
<el-form-item :label="quickAddType ? quickAddLabelMap[quickAddType] : '名称'">
|
||||
<el-input
|
||||
v-model="quickAddName"
|
||||
placeholder="请输入名称"
|
||||
maxlength="50"
|
||||
show-word-limit
|
||||
@keyup.enter="submitQuickAdd"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="quickAddVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="quickAdding" @click="submitQuickAdd">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
@ -463,4 +683,16 @@ onMounted(fetchList)
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
.select-with-add {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
.select-with-add .el-button {
|
||||
flex: 0 0 auto;
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
}
|
||||
</style>
|
||||
|
||||
51
frontend/src/views/ProductAttribute/Index.vue
Normal file
51
frontend/src/views/ProductAttribute/Index.vue
Normal file
@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import ProductAttributePanel from './ProductAttributePanel.vue'
|
||||
import type { AttrType } from './ProductAttributePanel.vue'
|
||||
|
||||
const active = ref<AttrType>('category')
|
||||
|
||||
const tabs: { key: AttrType; label: string }[] = [
|
||||
{ key: 'category', label: '商品分类' },
|
||||
{ key: 'brand', label: '商品品牌' },
|
||||
{ key: 'unit', label: '商品单位' },
|
||||
]
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card class="attr-card">
|
||||
<template #header>
|
||||
<div class="page-header">商品属性</div>
|
||||
</template>
|
||||
<el-tabs v-model="active" tab-position="left" class="attr-tabs">
|
||||
<el-tab-pane v-for="t in tabs" :key="t.key" :name="t.key" :label="t.label">
|
||||
<ProductAttributePanel :type="t.key" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
font-weight: 600;
|
||||
}
|
||||
.attr-card {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.attr-card :deep(.el-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.attr-card :deep(.el-tabs.attr-tabs) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
}
|
||||
.attr-card :deep(.el-tabs--left .el-tabs__header) {
|
||||
margin-right: 16px;
|
||||
}
|
||||
</style>
|
||||
350
frontend/src/views/ProductAttribute/ProductAttributePanel.vue
Normal file
350
frontend/src/views/ProductAttribute/ProductAttributePanel.vue
Normal file
@ -0,0 +1,350 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
import {
|
||||
getProductCategories,
|
||||
createProductCategory,
|
||||
updateProductCategory,
|
||||
deleteProductCategory,
|
||||
} from '@/api/productCategory'
|
||||
import {
|
||||
getProductBrands,
|
||||
createProductBrand,
|
||||
updateProductBrand,
|
||||
deleteProductBrand,
|
||||
} from '@/api/productBrand'
|
||||
import {
|
||||
getProductUnits,
|
||||
createProductUnit,
|
||||
updateProductUnit,
|
||||
deleteProductUnit,
|
||||
} from '@/api/productUnit'
|
||||
|
||||
export type AttrType = 'category' | 'brand' | 'unit'
|
||||
|
||||
const props = defineProps<{ type: AttrType }>()
|
||||
|
||||
/** 单个属性行(三类字段一致) */
|
||||
interface AttrRow {
|
||||
id: number
|
||||
principal_id: number
|
||||
name: string
|
||||
code: string | null
|
||||
status: number
|
||||
sort: number
|
||||
remark: string | null
|
||||
/** 是否系统默认:1系统数据(不可改/删) 0自定义(按主体隔离) */
|
||||
is_system?: number
|
||||
used_count?: number
|
||||
}
|
||||
|
||||
const meta = {
|
||||
category: {
|
||||
title: '商品分类',
|
||||
nameLabel: '分类名称',
|
||||
codeLabel: '分类编码',
|
||||
placeholder: '如 服装 / 数码 / 食品',
|
||||
list: getProductCategories,
|
||||
create: createProductCategory,
|
||||
update: updateProductCategory,
|
||||
remove: deleteProductCategory,
|
||||
},
|
||||
brand: {
|
||||
title: '商品品牌',
|
||||
nameLabel: '品牌名称',
|
||||
codeLabel: '品牌编码',
|
||||
placeholder: '如 苹果 / 华为 / 小米',
|
||||
list: getProductBrands,
|
||||
create: createProductBrand,
|
||||
update: updateProductBrand,
|
||||
remove: deleteProductBrand,
|
||||
},
|
||||
unit: {
|
||||
title: '商品单位',
|
||||
nameLabel: '单位名称',
|
||||
codeLabel: '单位编码',
|
||||
placeholder: '如 件 / 箱 / 千克 / 台',
|
||||
list: getProductUnits,
|
||||
create: createProductUnit,
|
||||
update: updateProductUnit,
|
||||
remove: deleteProductUnit,
|
||||
},
|
||||
} as const
|
||||
|
||||
const cur = meta[props.type]
|
||||
const api = cur
|
||||
|
||||
/** 导出类型(三张同构表对应三个导出类型) */
|
||||
const EXPORT_TYPE: Record<AttrType, string> = {
|
||||
category: 'product_category',
|
||||
brand: 'product_brand',
|
||||
unit: 'product_unit',
|
||||
}
|
||||
|
||||
/** 导出筛选条件(与列表筛选同源) */
|
||||
const exportFilters = computed(() => ({
|
||||
keyword: query.keyword.trim(),
|
||||
status: query.status,
|
||||
}))
|
||||
const exportType = computed(() => EXPORT_TYPE[props.type])
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
/** 点击「使用商品数」跳转到商品页,并把查询条件设为仅该属性 */
|
||||
function goProductsByAttr(row: AttrRow) {
|
||||
if (!(row.used_count && row.used_count > 0)) return
|
||||
const queryMap: Record<AttrType, Record<string, string>> = {
|
||||
category: { category_name: row.name },
|
||||
brand: { brand_name: row.name },
|
||||
unit: { stock_unit: row.name },
|
||||
}
|
||||
router.push({ path: '/product', query: queryMap[props.type] })
|
||||
}
|
||||
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
keyword: '',
|
||||
status: '' as string | number,
|
||||
})
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = { ...query }
|
||||
if (!params.keyword) delete params.keyword
|
||||
if (params.status === '') delete params.status
|
||||
return api.list(params)
|
||||
},
|
||||
})
|
||||
|
||||
function reset() {
|
||||
query.keyword = ''
|
||||
query.status = ''
|
||||
search()
|
||||
}
|
||||
|
||||
/* -------------------- 新增 / 编辑 -------------------- */
|
||||
const drawerVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const editId = ref<number | null>(null)
|
||||
const form = reactive({
|
||||
name: '',
|
||||
code: '',
|
||||
status: 1,
|
||||
sort: 0,
|
||||
remark: '',
|
||||
})
|
||||
const EMPTY_FORM = { name: '', code: '', status: 1, sort: 0, remark: '' }
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: `请输入${cur.nameLabel}`, trigger: 'blur' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
editId.value = null
|
||||
Object.assign(form, EMPTY_FORM)
|
||||
drawerVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: AttrRow) {
|
||||
editId.value = row.id
|
||||
Object.assign(form, {
|
||||
name: row.name,
|
||||
code: row.code || '',
|
||||
status: row.status,
|
||||
sort: Number(row.sort) || 0,
|
||||
remark: row.remark || '',
|
||||
})
|
||||
drawerVisible.value = true
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const payload = { ...form }
|
||||
if (editId.value == null) {
|
||||
await api.create(payload)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await api.update(editId.value, payload)
|
||||
ElMessage.success('保存成功')
|
||||
}
|
||||
drawerVisible.value = false
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function handleDelete(row: AttrRow) {
|
||||
if (row.is_system === 1) {
|
||||
ElMessage.warning('系统默认数据不可删除')
|
||||
return
|
||||
}
|
||||
if (row.used_count && row.used_count > 0) {
|
||||
ElMessage.warning(`该${cur.title}已被 ${row.used_count} 个商品使用,禁止删除`)
|
||||
return
|
||||
}
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除${cur.title}「${row.name}」?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await api.remove(row.id)
|
||||
ElMessage.success('已删除')
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(fetchList)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="attr-panel">
|
||||
<el-form :inline="true" class="search-bar">
|
||||
<el-form-item :label="`${cur.nameLabel}关键词`">
|
||||
<el-input v-model="query.keyword" :placeholder="`匹配名称或编码`" clearable @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 120px">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item class="add-btn">
|
||||
<el-button type="success" @click="openCreate">新增{{ cur.title }}</el-button>
|
||||
<ExportButton :type="exportType" :filters="exportFilters" plain />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div class="table-wrap">
|
||||
<DataTable :loading="loading" :data="list" height="100%">
|
||||
<el-table-column prop="code" :label="cur.codeLabel" width="130" />
|
||||
<el-table-column prop="name" :label="cur.nameLabel" min-width="140" />
|
||||
<el-table-column label="使用商品数" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-if="(row.used_count || 0) > 0"
|
||||
link
|
||||
type="warning"
|
||||
@click="goProductsByAttr(row)"
|
||||
>{{ row.used_count }}</el-button>
|
||||
<span v-else>0</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="类型" width="80" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.is_system === 1" type="warning">系统</el-tag>
|
||||
<el-tag v-else type="info">自定义</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="sort" label="排序" width="80" align="center" />
|
||||
<el-table-column prop="remark" label="备注" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" :disabled="row.is_system === 1" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
:disabled="(row.used_count || 0) > 0 || row.is_system === 1"
|
||||
@click="handleDelete(row)"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
</div>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
|
||||
<el-drawer
|
||||
v-model="drawerVisible"
|
||||
:title="editId == null ? `新增${cur.title}` : `编辑${cur.title}`"
|
||||
direction="rtl"
|
||||
size="460px"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item :label="cur.nameLabel" prop="name">
|
||||
<el-input v-model="form.name" :placeholder="cur.placeholder" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="cur.codeLabel">
|
||||
<el-input v-model="form.code" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="form.status" style="width: 100%">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序">
|
||||
<el-input-number v-model="form.sort" :min="0" :precision="0" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="drawerVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitForm">保存</el-button>
|
||||
</template>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.attr-panel {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.add-btn {
|
||||
float: right;
|
||||
}
|
||||
.table-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
:deep(.el-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
getShops,
|
||||
@ -11,6 +11,7 @@ import {
|
||||
type ShopDetail,
|
||||
} from '@/api/shop'
|
||||
import SplitLayout from '@/components/SplitLayout.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
@ -56,6 +57,13 @@ function reset() {
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件(与列表筛选同源) */
|
||||
const exportFilters = computed(() => ({
|
||||
keyword: query.keyword.trim(),
|
||||
platform: query.platform,
|
||||
status: query.status,
|
||||
}))
|
||||
|
||||
/* -------------------- 详情 -------------------- */
|
||||
const activeDetailTab = ref('detail')
|
||||
const detailLoading = ref(false)
|
||||
@ -177,7 +185,10 @@ onMounted(fetchList)
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>店铺</span>
|
||||
<el-button type="primary" @click="openCreate">新增店铺</el-button>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="openCreate">新增店铺</el-button>
|
||||
<ExportButton type="shop" :filters="exportFilters" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import { getShops, type ShopItem } from '@/api/shop'
|
||||
import { getProducts, type ProductItem } from '@/api/product'
|
||||
import { getComboProducts, type ComboProductItem } from '@/api/comboProduct'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
import VirtualSelect from '@/components/VirtualSelect.vue'
|
||||
@ -59,6 +60,14 @@ function reset() {
|
||||
search()
|
||||
}
|
||||
|
||||
/** 导出筛选条件(与列表筛选同源) */
|
||||
const exportFilters = computed(() => ({
|
||||
shop_id: query.shop_id,
|
||||
bind_type: query.bind_type,
|
||||
status: query.status,
|
||||
keyword: query.keyword.trim(),
|
||||
}))
|
||||
|
||||
/* -------------------- 编辑 -------------------- */
|
||||
const dialogVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
@ -233,6 +242,9 @@ onMounted(async () => {
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>店铺商品</span>
|
||||
<div class="header-actions">
|
||||
<ExportButton type="shop_product" :filters="exportFilters" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ExportButton from '@/components/ExportButton.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import ProductSelect from '@/components/ProductSelect.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
@ -73,6 +74,18 @@ const { loading, list, total, elapsed, fetchList, search, handlePageChange, hand
|
||||
},
|
||||
})
|
||||
|
||||
/** 导出筛选条件(与列表筛选同一套条件,字段名与后端 stock_record 类型对齐) */
|
||||
const exportFilters = computed(() => ({
|
||||
product_id: query.product_id,
|
||||
keyword: query.keyword.trim(),
|
||||
bill_no: query.bill_no.trim(),
|
||||
biz_type: query.biz_type,
|
||||
direction: query.direction,
|
||||
bill_type: query.bill_type,
|
||||
start_time: query.dateRange[0],
|
||||
end_time: query.dateRange[1],
|
||||
}))
|
||||
|
||||
/** 业务动作下拉(后端返回枚举,避免文案漂移) */
|
||||
const bizTypes = ref<StockRecordBizType[]>([])
|
||||
async function fetchBizTypes() {
|
||||
@ -138,7 +151,10 @@ onMounted(() => {
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>出入库记录</span>
|
||||
<span class="hint">库存流水:出库推送锁定 / 解锁 / 确认扣减,入库确认增加</span>
|
||||
<div class="header-actions">
|
||||
<span class="hint">库存流水:出库推送锁定 / 解锁 / 确认扣减,入库确认增加</span>
|
||||
<ExportButton type="stock_record" :filters="exportFilters" plain />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user