yin 60a7db4085 refactor(frontend): 业务弹窗统一为 task-panel 面板,统一确认框样式
新增统一弹窗外壳与样式:
- 新增 TaskPanelDialog.vue(自绘标题+副标题 / 可滚动内容区 / 底部提示+操作区),
  默认点遮罩不关闭,内容区 max-height 内部滚动
- 新增 styles/task-panel.css 并在 main.ts 引入:section 分组、栅格字段行
  (88px 标签 + 控件)、提示条、表格区、底部按钮区(small / gap 6)
- 新增 ReasonPromptDialog.vue:替换 ElMessageBox.prompt,用于作废 / 取消 /
  手工标记推送失败等需填原因的操作,支持必填校验、多行、按钮类型与提示

页面改造(el-dialog / el-drawer → TaskPanelDialog + task-panel 栅格):
- 订单、发货单、状态面板、订单同步、入库单(列表/新建)、出库单(列表/新建)、
  库存单据、导出任务、导出按钮、商品查询、单据选择、商品(新增/编辑/批量导入,
  抽屉改弹窗)、店铺、店铺商品、组合商品、自定义快递、外接 API、
  外接打印平台/快递接口、组织(集团设置/下属公司)、权限角色组、主体、主体用户、
  商品属性、用户资料

交互与样式统一:
- ElMessageBox.confirm 统一挂 customClass="app-confirm-box"(App.vue 中定义按钮
  高度/内边距/间距),状态面板封装 ElMessageBox 别名统一注入
- 侧边栏 BasicLayout:加 contain: layout、菜单内部 overflow 滚动、
  关闭子菜单折叠过渡,避免展开时逐帧重排扩散到主内容区
2026-11-19 18:00:54 +08:00

1983 lines
76 KiB
Vue
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
import {
getWarehouses,
getWarehouse,
getWarehouseProducts,
createWarehouse,
updateWarehouse,
deleteWarehouse,
type WarehouseItem,
type WarehouseDetail,
type WarehouseProductItem,
type WarehouseProductWmsInventory,
pushWarehouseProducts,
getWarehouseProductWmsInventory,
syncWarehouseInventory,
} from '@/api/warehouse'
import {
getWarehouseApis,
createWarehouseApi,
updateWarehouseApi,
deleteWarehouseApi,
testWarehouseApi,
getWarehouseApiFields,
getWarehouseApiFieldValues,
updateWarehouseApiFieldValues,
type WarehouseApiItem,
type WarehouseApiFieldDef,
type WarehouseApiFieldGroup,
} from '@/api/warehouseApi'
import { getOutboundLogs, type OutboundLogItem } from '@/api/outboundLog'
import { getCallbackLogs, type CallbackLogItem } from '@/api/callbackLog'
import {
getWarehouseExpressMappings,
createWarehouseExpressMapping,
updateWarehouseExpressMapping,
deleteWarehouseExpressMapping,
type WarehouseExpressMappingItem,
} from '@/api/warehouseExpressMapping'
import { getExpressCompanyOptions, type ExpressCompanyOption } from '@/api/expressCompany'
import { getPrincipalSubsidiaryOptions } from '@/api/principalSubsidiary'
import { getAccessContext } from '@/api/access'
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'
import TaskPanelDialog from '@/components/TaskPanelDialog.vue'
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
import { formatDateTime } from '@/utils/datetime'
/** 仓库自身的类型 */
const WAREHOUSE_TYPE_OPTIONS = [
{ label: 'WMS', value: 'wms' },
{ label: 'ERP', value: 'erp' },
{ label: '其他', value: 'other' },
]
const WAREHOUSE_TYPE_LABELS: Record<string, string> = { wms: 'WMS', erp: 'ERP', other: '其他' }
function warehouseTypeLabel(type?: string | null) {
return type ? WAREHOUSE_TYPE_LABELS[type] || type : '-'
}
/**
* 仓库接口的接口类型:系统当前只对接「天豹云WMS」(类奇门JSON接口)
* 下拉选择后自动带出基础地址,不需要手工填写
*/
const API_TYPE_OPTIONS = [
{ label: '天豹云WMS', value: 'qimen', base_url: 'https://qimen.wms.gztbyc.com/openapi' },
]
const API_TYPE_QIMEN = API_TYPE_OPTIONS[0].value
const API_TYPE_DEFAULT_BASE_URL = API_TYPE_OPTIONS[0].base_url
/**
* 接口类型编码 → 展示名
* @param {string} [type] 接口类型编码
* @return {string} 展示名
*/
function apiTypeLabel(type?: string | null) {
return API_TYPE_OPTIONS.find(item => item.value === type)?.label || API_TYPE_OPTIONS[0].label
}
/* -------------------- 仓库列表 -------------------- */
const query = reactive({
page: 1,
pageSize: DEFAULT_PAGE_SIZE,
code: '',
subsidiary_id: '' as string | number,
status: '' as string | number,
})
/** 货主下拉(组织架构 → 下属公司) */
const subsidiaryOptions = ref<{ id: number; name: string }[]>([])
async function loadSubsidiaryOptions() {
try {
// mine=1:所在公司权限下只返回自己所属公司
subsidiaryOptions.value = await getPrincipalSubsidiaryOptions({ mine: 1 })
} catch {
subsidiaryOptions.value = []
}
}
/**
* 所在公司权限(货主):仅开放「推送商品 / 同步库存 / 查询库存」,
* 仓库维护、接口配置、快递映射、调用日志等入口一律隐藏
*/
const isCompanyScope = ref(false)
async function fetchAccessContext() {
try {
const ctx = await getAccessContext()
isCompanyScope.value = !ctx.is_group
if (isCompanyScope.value && activeDetailTab.value !== 'products' && activeDetailTab.value !== 'inventory') {
activeDetailTab.value = 'products'
}
} catch {
isCompanyScope.value = false
}
}
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
query,
fetcher: () => {
const params: Record<string, unknown> = { ...query }
if (!params.code) delete params.code
if (params.subsidiary_id === '') delete params.subsidiary_id
if (params.status === '') delete params.status
return getWarehouses(params)
},
})
function reset() {
query.code = ''
query.subsidiary_id = ''
query.status = ''
search()
}
/** 导出筛选条件:仓库列表(关键词模糊匹配仓库编码/名称) */
const warehouseExportFilters = computed(() => ({
keyword: query.code.trim(),
subsidiary_id: query.subsidiary_id,
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)
const currentWarehouse = ref<WarehouseDetail | null>(null)
const configLoading = ref(false)
const configList = ref<WarehouseApiItem[]>([])
/** 已加载接口配置的仓库ID,避免切换标签页时重复请求 */
const configLoadedId = ref<number | null>(null)
/** 拉取仓库详情(基本信息 + 关联统计) */
async function fetchDetail(id: number) {
detailLoading.value = true
try {
currentWarehouse.value = await getWarehouse(id)
} catch {
// 拦截器已提示
} finally {
detailLoading.value = false
}
}
/** 拉取当前仓库的接口配置列表 */
async function fetchConfigs() {
const warehouseId = currentWarehouse.value?.id
if (!warehouseId) return
configLoading.value = true
try {
const res = await getWarehouseApis({ warehouse_id: warehouseId, page: 1, pageSize: 200 })
// 请求期间若已切换仓库,丢弃过期结果
if (currentWarehouse.value?.id !== warehouseId) return
configList.value = res.list
configLoadedId.value = warehouseId
} catch {
configList.value = []
} finally {
configLoading.value = false
}
}
/** 切换展示的仓库:重置接口配置与商品缓存并回到明细标签页 */
async function switchWarehouse(id: number) {
if (currentWarehouse.value?.id === id) return
configLoadedId.value = null
configList.value = []
mappingLoadedId.value = null
mappingList.value = []
resetProductState()
resetOutboundState()
resetInventoryState()
// 所在公司权限直接进商品页(其余标签页已隐藏)
activeDetailTab.value = isCompanyScope.value ? 'products' : 'detail'
await fetchDetail(id)
if (isCompanyScope.value && productLoadedId.value !== id) await fetchProducts()
}
function handleRowClick(row: WarehouseItem) {
switchWarehouse(row.id)
}
/** 表格中的「接口配置」入口:选中仓库并切到接口配置标签页 */
async function openConfigTab(row: WarehouseItem) {
await switchWarehouse(row.id)
activeDetailTab.value = 'config'
if (configLoadedId.value !== row.id) await fetchConfigs()
}
function handleDetailTabChange(name: string | number) {
// 所在公司权限仅开放商品/库存两个标签页
if (isCompanyScope.value && name !== 'products' && name !== 'inventory') {
activeDetailTab.value = 'products'
return
}
if (name === 'config' && configLoadedId.value !== currentWarehouse.value?.id) fetchConfigs()
if (name === 'express' && mappingLoadedId.value !== currentWarehouse.value?.id) fetchMappings()
if (name === 'products' && productLoadedId.value !== currentWarehouse.value?.id) fetchProducts()
if (name === 'inventory' && inventoryLoadedId.value !== currentWarehouse.value?.id) fetchInventory()
if (name === 'logs' && outboundLoadedId.value !== currentWarehouse.value?.id) fetchOutboundLogs()
if (name === 'callback_logs' && callbackLoadedId.value !== currentWarehouse.value?.id) fetchCallbackLogs()
}
/* -------------------- 快递映射(按仓库:外部自定义编码 → 默认快递编码) -------------------- */
const mappingLoading = ref(false)
const mappingList = ref<WarehouseExpressMappingItem[]>([])
/** 已加载快递映射的仓库ID,避免切换标签页时重复请求 */
const mappingLoadedId = ref<number | null>(null)
/** 快递公司字典(供「默认快递」下拉) */
const expressCompanies = ref<ExpressCompanyOption[]>([])
/** 拉取当前仓库的快递映射列表 */
async function fetchMappings() {
const warehouseId = currentWarehouse.value?.id
if (!warehouseId) return
mappingLoading.value = true
try {
const res = await getWarehouseExpressMappings({ warehouse_id: warehouseId, page: 1, pageSize: 200 })
// 请求期间若已切换仓库,丢弃过期结果
if (currentWarehouse.value?.id !== warehouseId) return
mappingList.value = res.list
mappingLoadedId.value = warehouseId
} catch {
mappingList.value = []
} finally {
mappingLoading.value = false
}
}
async function ensureExpressCompanies() {
if (expressCompanies.value.length) return
try { expressCompanies.value = await getExpressCompanyOptions() } catch { expressCompanies.value = [] }
}
const mappingDialogVisible = ref(false)
const mappingSubmitting = ref(false)
const mappingFormRef = ref<FormInstance>()
const mappingEditId = ref<number | null>(null)
const mappingForm = reactive({
express_code: '',
custom_code: '',
status: 1,
remark: '',
})
const mappingRules: FormRules = {
express_code: [{ required: true, message: '请选择默认快递', trigger: 'change' }],
custom_code: [{ required: true, message: '请填写自定义编码', trigger: 'blur' }],
}
function openMappingCreate() {
mappingEditId.value = null
Object.assign(mappingForm, { express_code: '', custom_code: '', status: 1, remark: '' })
ensureExpressCompanies()
mappingDialogVisible.value = true
}
function openMappingEdit(row: WarehouseExpressMappingItem) {
mappingEditId.value = row.id
Object.assign(mappingForm, {
express_code: row.express_code,
custom_code: row.custom_code,
status: row.status,
remark: row.remark || '',
})
ensureExpressCompanies()
mappingDialogVisible.value = true
}
async function submitMappingForm() {
if (!mappingFormRef.value) return
await mappingFormRef.value.validate(async (valid) => {
if (!valid) return
const warehouseId = currentWarehouse.value?.id
if (!warehouseId) return
mappingSubmitting.value = true
try {
const payload = {
warehouse_id: warehouseId,
express_code: mappingForm.express_code,
custom_code: mappingForm.custom_code.trim().toUpperCase(),
status: mappingForm.status,
remark: mappingForm.remark || null,
}
if (mappingEditId.value == null) {
await createWarehouseExpressMapping(payload)
ElMessage.success('新增成功')
} else {
await updateWarehouseExpressMapping(mappingEditId.value, payload)
ElMessage.success('保存成功')
}
mappingDialogVisible.value = false
await fetchMappings()
} catch {
// 拦截器已提示
} finally {
mappingSubmitting.value = false
}
})
}
async function handleMappingDelete(row: WarehouseExpressMappingItem) {
try {
await ElMessageBox.confirm(
`确定删除自定义编码「${row.custom_code}」的映射吗?删除后该编码将只能按快递公司字典兑底解析。`,
'删除映射',
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消', customClass: 'app-confirm-box' },
)
} catch {
return
}
try {
await deleteWarehouseExpressMapping(row.id)
ElMessage.success('已删除')
await fetchMappings()
} catch {
// 拦截器已提示
}
}
/* -------------------- 仓库 新增 / 编辑 -------------------- */
const dialogVisible = ref(false)
const submitting = ref(false)
const formRef = ref<FormInstance>()
const editId = ref<number | null>(null)
const form = reactive({
code: '',
name: '',
subsidiary_id: null as number | null,
type: 'wms',
status: 1,
remark: '',
})
const rules: FormRules = {
name: [{ required: true, message: '请输入仓库名称', trigger: 'blur' }],
subsidiary_id: [{ required: true, message: '请选择货主', trigger: 'change' }],
}
function openCreate() {
editId.value = null
form.code = ''
form.name = ''
form.subsidiary_id = null
form.type = 'wms'
form.status = 1
form.remark = ''
dialogVisible.value = true
}
function openEdit(row: WarehouseItem) {
editId.value = row.id
form.code = row.code
form.name = row.name
form.subsidiary_id = row.subsidiary_id ?? null
form.type = row.type || ''
form.status = row.status
form.remark = row.remark || ''
dialogVisible.value = true
}
async function submitForm() {
if (!formRef.value) return
await formRef.value.validate(async (valid) => {
if (!valid) return
submitting.value = true
try {
const payload = {
name: form.name,
subsidiary_id: Number(form.subsidiary_id),
type: form.type || null,
status: form.status,
remark: form.remark,
}
if (editId.value == null) {
await createWarehouse(payload)
ElMessage.success('新增成功')
} else {
await updateWarehouse(editId.value, payload)
ElMessage.success('保存成功')
// 详情面板正展示该仓库时同步刷新
if (currentWarehouse.value && currentWarehouse.value.id === editId.value) {
await fetchDetail(editId.value)
}
}
dialogVisible.value = false
await fetchList()
} catch {
// 拦截器已提示
} finally {
submitting.value = false
}
})
}
async function handleDelete(row: WarehouseItem) {
try {
await ElMessageBox.confirm(`确认删除仓库「${row.name}」及其接口配置、商品推送绑定?`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消',
customClass: 'app-confirm-box',
})
} catch {
return
}
try {
await deleteWarehouse(row.id)
ElMessage.success('已删除')
if (currentWarehouse.value && currentWarehouse.value.id === row.id) {
currentWarehouse.value = null
configList.value = []
configLoadedId.value = null
}
await fetchList()
} catch {
// 拦截器已提示
}
}
/* -------------------- 接口配置 新增 / 编辑(含配置项) -------------------- */
const apiDialogVisible = ref(false)
const apiSubmitting = ref(false)
const apiFormRef = ref<FormInstance>()
const apiEditId = ref<number | null>(null)
const apiForm = reactive({
name: '',
/** 接口类型(天豹云WMS = qimen);切换类型自动带出基础地址 */
type: API_TYPE_QIMEN,
base_url: '',
app_key: '',
app_secret: '',
/** 对外通用回调地址(只读展示,由后端按 app_key 生成) */
callback_url: '',
status: 1,
remark: '',
})
/**
* 切换接口类型:自动带出该类型的默认基础地址(用户已手工改过的不覆盖)
* @return {void}
*/
function onApiTypeChange() {
const preset = API_TYPE_OPTIONS.find(item => item.value === apiForm.type)
if (!preset) return
const current = String(apiForm.base_url || '').trim()
const isPresetOfOthers = API_TYPE_OPTIONS.some(item => item.base_url === current)
if (!current || isPresetOfOthers) apiForm.base_url = preset.base_url
}
const apiRules: FormRules = {
name: [{ required: true, message: '请输入配置名称', trigger: 'blur' }],
}
/** 配置项定义(分组 + 字段清单,后端硬编码 app/lib/warehouseApiFields.js) */
const configFieldDefs = ref<WarehouseApiFieldDef[]>([])
const configFieldGroups = ref<WarehouseApiFieldGroup[]>([])
/** 配置项值:{ 字段key: 值 },与接口配置基础信息在同一个弹窗内维护 */
const configFieldValues = ref<Record<string, unknown>>({})
/** 校验用模型:接口配置基础信息 + 配置项值(配置项按字段 key 落在同一表单模型里) */
const apiFormModel = computed(() => ({ ...apiForm, ...configFieldValues.value }))
/** 拉取配置项定义(只在首次打开时请求,之后复用) */
async function ensureConfigSchema() {
if (configFieldDefs.value.length) return
const schema = await getWarehouseApiFields()
configFieldDefs.value = schema.fields || []
configFieldGroups.value = schema.groups || []
}
/** 配置项表单的初始值:取后端硬编码默认值(新增时使用) */
function defaultConfigFieldValues(): Record<string, unknown> {
const values: Record<string, unknown> = {}
for (const def of configFieldDefs.value) values[def.key] = def.defaultValue ?? null
return values
}
/** 提交前把 json 配置项的文本还原为对象 */
function collectConfigFieldValues(): Record<string, unknown> {
const values: Record<string, unknown> = { ...configFieldValues.value }
for (const def of configFieldDefs.value) {
const value = values[def.key]
if (def.type === 'json' && typeof value === 'string' && value.trim()) {
values[def.key] = JSON.parse(value)
}
}
return values
}
async function openApiCreate() {
apiEditId.value = null
apiForm.name = ''
// 默认就用天豹云WMS,基础地址随类型带出,用户不用手填
apiForm.type = API_TYPE_QIMEN
apiForm.base_url = API_TYPE_DEFAULT_BASE_URL
apiForm.app_key = ''
apiForm.app_secret = ''
apiForm.callback_url = ''
apiForm.status = 1
apiForm.remark = ''
try {
await ensureConfigSchema()
} catch {
return
}
configFieldValues.value = defaultConfigFieldValues()
apiDialogVisible.value = true
}
async function openApiEdit(row: WarehouseApiItem) {
apiEditId.value = row.id
apiForm.name = row.name
apiForm.type = row.type || API_TYPE_QIMEN
apiForm.base_url = row.base_url || API_TYPE_DEFAULT_BASE_URL
apiForm.app_key = row.app_key || ''
apiForm.app_secret = row.app_secret || ''
apiForm.callback_url = row.callback_url || ''
apiForm.status = row.status
apiForm.remark = row.remark || ''
try {
await ensureConfigSchema()
const result = await getWarehouseApiFieldValues(row.id)
configFieldValues.value = { ...(result.values || {}) }
} catch {
return
}
apiDialogVisible.value = true
}
async function submitApiForm() {
if (!apiFormRef.value || !currentWarehouse.value) return
await apiFormRef.value.validate(async (valid) => {
if (!valid) return
apiSubmitting.value = true
try {
const payload = {
warehouse_id: currentWarehouse.value!.id,
name: apiForm.name,
type: apiForm.type || API_TYPE_QIMEN,
// 基础地址不在表单里展示,按接口类型预设写入(老配置保留库里已有值)
base_url: apiForm.base_url || API_TYPE_DEFAULT_BASE_URL,
app_key: apiForm.app_key,
app_secret: apiForm.app_secret,
status: apiForm.status,
remark: apiForm.remark,
}
const isCreate = apiEditId.value == null
let apiId = apiEditId.value
if (isCreate) {
const created = await createWarehouseApi(payload)
apiId = created.id
} else {
await updateWarehouseApi(apiId!, payload)
}
// 配置项值单独接口整体覆盖保存(未填写的项不落库,读取时按硬编码默认值兜底)
const values = collectConfigFieldValues()
const hasValue = Object.values(values).some(v => v !== null && v !== undefined && v !== '')
if (apiId && hasValue) await updateWarehouseApiFieldValues(apiId, values)
ElMessage.success(isCreate ? '新增成功' : '保存成功')
apiDialogVisible.value = false
const warehouseId = currentWarehouse.value!.id
await fetchConfigs()
await fetchList()
if (currentWarehouse.value?.id === warehouseId) await fetchDetail(warehouseId)
} catch {
// 拦截器已提示
} finally {
apiSubmitting.value = false
}
})
}
/* -------------------- 仓库商品(是否已推送到该仓库) -------------------- */
const productQuery = reactive({ page: 1, pageSize: DEFAULT_PAGE_SIZE, keyword: '' })
/** 已加载商品列表的仓库ID,避免切换标签页时重复请求 */
const productLoadedId = ref<number | null>(null)
const {
loading: productLoading,
list: productList,
total: productTotal,
elapsed: productElapsed,
fetchList: fetchProductList,
search: searchProducts,
handlePageChange: handleProductPageChange,
handleSizeChange: handleProductSizeChange,
} = useListPage<WarehouseProductItem, typeof productQuery>({
query: productQuery,
fetcher: () => {
const warehouseId = currentWarehouse.value!.id
const params: Record<string, unknown> = { page: productQuery.page, pageSize: productQuery.pageSize }
if (productQuery.keyword) params.keyword = productQuery.keyword
return getWarehouseProducts(warehouseId, params)
},
})
/** 拉取当前仓库的商品列表并记录已加载的仓库 */
async function fetchProducts() {
const warehouseId = currentWarehouse.value?.id
if (!warehouseId) return
await fetchProductList()
// 请求期间若已切换仓库,丢弃过期结果
if (currentWarehouse.value?.id !== warehouseId) return
productLoadedId.value = warehouseId
}
/** 切换仓库时清空商品列表缓存,回到第一页并清空关键词 */
function resetProductState() {
productLoadedId.value = null
productQuery.page = 1
productQuery.keyword = ''
productList.value = []
productTotal.value = 0
}
/* -------------------- WMS 库存查询(外部商品数量) -------------------- */
/** product_id -> WMS 库存信息(点击「查询WMS库存」后填充) */
const wmsInventoryMap = ref<WarehouseProductWmsInventory>({})
const queryingWms = ref(false)
/* -------------------- 仓库库存(仅已同步商品,勾选查询 WMS 库存) -------------------- */
const inventoryQuery = reactive({ page: 1, pageSize: DEFAULT_PAGE_SIZE, keyword: '' })
/** 已加载库存列表的仓库ID,避免切换标签页时重复请求 */
const inventoryLoadedId = ref<number | null>(null)
/** 库存标签页:已勾选的商品行 */
const selectedInventory = ref<WarehouseProductItem[]>([])
const {
loading: inventoryLoading,
list: inventoryList,
total: inventoryTotal,
elapsed: inventoryElapsed,
fetchList: fetchInventoryList,
search: searchInventory,
handlePageChange: handleInventoryPageChange,
handleSizeChange: handleInventorySizeChange,
} = useListPage<WarehouseProductItem, typeof inventoryQuery>({
query: inventoryQuery,
fetcher: () => {
const warehouseId = currentWarehouse.value!.id
const params: Record<string, unknown> = { page: inventoryQuery.page, pageSize: inventoryQuery.pageSize, pushed: 1 }
if (inventoryQuery.keyword) params.keyword = inventoryQuery.keyword
return getWarehouseProducts(warehouseId, params)
},
})
/** 拉取当前仓库已同步商品的库存列表并记录已加载的仓库 */
async function fetchInventory() {
const warehouseId = currentWarehouse.value?.id
if (!warehouseId) return
await fetchInventoryList()
// 请求期间若已切换仓库,丢弃过期结果
if (currentWarehouse.value?.id !== warehouseId) return
inventoryLoadedId.value = warehouseId
}
/** 切换仓库时清空库存列表缓存,回到第一页并清空关键词与勾选 */
function resetInventoryState() {
inventoryLoadedId.value = null
inventoryQuery.page = 1
inventoryQuery.keyword = ''
inventoryList.value = []
inventoryTotal.value = 0
selectedInventory.value = []
}
function handleInventorySelectionChange(rows: WarehouseProductItem[]) {
selectedInventory.value = rows
}
/** 勾选后查询这些商品的 WMS 库存数量(外部商品数量) */
async function handleQueryInventorySelected() {
const warehouseId = currentWarehouse.value?.id
if (!warehouseId || !selectedInventory.value.length) return
queryingWms.value = true
try {
const res = await getWarehouseProductWmsInventory(
warehouseId,
selectedInventory.value.map(p => p.id),
)
wmsInventoryMap.value = { ...wmsInventoryMap.value, ...(res.inventories || {}) }
const count = Object.keys(res.inventories || {}).length
ElMessage.success(`WMS 库存查询完成,命中 ${count} 个商品`)
} catch (err: any) {
const msg = err?.response?.data?.message || err?.message || '查询失败'
ElMessage.error(`WMS 库存查询失败:${msg}`)
} finally {
queryingWms.value = false
}
}
/** 仅显示差异(系统数量 ≠ 外部WMS数量)的开关 */
const onlyDiff = ref(false)
/** 库存同步(覆盖本地数量)进行中 */
const syncing = ref(false)
/** 差异数值的着色:0 灰、WMS 多(>0) 绿、系统多(<0) 红 */
function diffStyle(val: number) {
if (!val) return {}
return { color: val > 0 ? '#67c23a' : '#f56c6c', fontWeight: 600 }
}
/** 库存列表(客户端按「仅显示差异」过滤;差异需已查询到 WMS 库存) */
const displayInventoryList = computed(() => {
if (!onlyDiff.value) return inventoryList.value
return inventoryList.value.filter(p => {
const wms = wmsInventoryMap.value[p.id]
if (!wms) return false
const goodDiff = Number(wms.good_quantity) - Number(p.good_quantity)
const defectDiff = Number(wms.defect_quantity) - Number(p.defect_quantity)
return goodDiff !== 0 || defectDiff !== 0
})
})
/** 覆盖本地数量:用外部 WMS 库存覆盖系统库存,差异以完成的出入库单平衡 */
async function handleSyncInventory() {
const warehouseId = currentWarehouse.value?.id
if (!warehouseId) return
// 仅处理已查询到 WMS 库存的勾选项
const toSync = selectedInventory.value.filter(p => wmsInventoryMap.value[p.id] != null)
if (!toSync.length) {
ElMessage.warning('请先勾选商品并点击「查询选中库存」获取 WMS 库存后再同步')
return
}
try {
await ElMessageBox.confirm(
'同步后,库存差异将会以出入库单的形式平衡库存。确认同步?',
'同步覆盖本地数量',
{ confirmButtonText: '确认同步', cancelButtonText: '取消', type: 'warning', customClass: 'app-confirm-box' },
)
} catch {
return
}
syncing.value = true
try {
const items = toSync.map(p => {
const wms = wmsInventoryMap.value[p.id]
return {
product_id: p.id,
wms_good_quantity: wms.good_quantity,
wms_defect_quantity: wms.defect_quantity,
}
})
const res = await syncWarehouseInventory(warehouseId, items)
const { inbound_count, outbound_count, skipped, invalid_count } = res
const parts = [`生成入库单 ${inbound_count} 个、出库单 ${outbound_count} 个`]
if (skipped > 0) parts.push(`${skipped} 个商品数量一致无需同步`)
if (invalid_count > 0) parts.push(`${invalid_count} 个商品不属于该仓库货主已忽略`)
ElMessage.success(`同步完成:${parts.join(',')}`)
selectedInventory.value = []
await fetchInventory()
} catch (err: any) {
const msg = err?.response?.data?.message || err?.message || '同步失败'
ElMessage.error(`库存同步失败:${msg}`)
} finally {
syncing.value = false
}
}
/* -------------------- 对外 API 调用日志(OMS → 外部 WMS) -------------------- */
const outboundQuery = reactive({ page: 1, pageSize: DEFAULT_PAGE_SIZE })
/** 已加载调用日志的仓库ID,避免切换标签页时重复请求 */
const outboundLoadedId = ref<number | null>(null)
const {
loading: outboundLoading,
list: outboundLogs,
total: outboundTotal,
elapsed: outboundElapsed,
fetchList: fetchOutboundList,
handlePageChange: handleOutboundPageChange,
handleSizeChange: handleOutboundSizeChange,
} = useListPage<OutboundLogItem, typeof outboundQuery>({
query: outboundQuery,
fetcher: () => {
const warehouseId = currentWarehouse.value!.id
return getOutboundLogs({ warehouse_id: warehouseId, page: outboundQuery.page, pageSize: outboundQuery.pageSize })
},
})
/** 拉取当前仓库的对外调用日志并记录已加载的仓库 */
async function fetchOutboundLogs() {
const warehouseId = currentWarehouse.value?.id
if (!warehouseId) return
await fetchOutboundList()
// 请求期间若已切换仓库,丢弃过期结果
if (currentWarehouse.value?.id !== warehouseId) return
outboundLoadedId.value = warehouseId
}
/** 切换仓库时清空调用日志/回调日志缓存 */
function resetOutboundState() {
outboundLoadedId.value = null
outboundQuery.page = 1
outboundLogs.value = []
outboundTotal.value = 0
resetCallbackState()
}
/* -------------------- 对外回调日志(外部系统 → OMS /openapi) -------------------- */
const callbackQuery = reactive({ page: 1, pageSize: DEFAULT_PAGE_SIZE })
/** 已加载回调日志的仓库ID,避免切换标签页时重复请求 */
const callbackLoadedId = ref<number | null>(null)
const {
loading: callbackLoading,
list: callbackLogs,
total: callbackTotal,
elapsed: callbackElapsed,
fetchList: fetchCallbackList,
handlePageChange: handleCallbackPageChange,
handleSizeChange: handleCallbackSizeChange,
} = useListPage<CallbackLogItem, typeof callbackQuery>({
query: callbackQuery,
fetcher: () => {
const warehouseId = currentWarehouse.value!.id
return getCallbackLogs({ warehouse_id: warehouseId, page: callbackQuery.page, pageSize: callbackQuery.pageSize })
},
})
/** 拉取当前仓库的回调日志并记录已加载的仓库 */
async function fetchCallbackLogs() {
const warehouseId = currentWarehouse.value?.id
if (!warehouseId) return
await fetchCallbackList()
if (currentWarehouse.value?.id !== warehouseId) return
callbackLoadedId.value = warehouseId
}
/** 切换仓库时清空回调日志缓存 */
function resetCallbackState() {
callbackLoadedId.value = null
callbackQuery.page = 1
callbackLogs.value = []
callbackTotal.value = 0
}
/** 商品标签页:已勾选的商品行 */
const selectedProducts = ref<WarehouseProductItem[]>([])
function handleProductSelectionChange(rows: WarehouseProductItem[]) {
selectedProducts.value = rows
}
/** 将勾选的商品推送到当前仓库的 WMS */
const pushing = ref(false)
async function handlePushProducts() {
const warehouseId = currentWarehouse.value?.id
if (!warehouseId || !selectedProducts.value.length) return
const ids = selectedProducts.value.map(p => p.id)
try {
pushing.value = true
const res = await pushWarehouseProducts(warehouseId, ids)
const { success, failed } = res
ElMessage.success(`推送完成:成功 ${success} 条,失败 ${failed} 条`)
if (failed > 0) {
const firstFail = res.results.find(r => !r.success)
if (firstFail) ElMessage.warning(`失败示例:${firstFail.item_code || firstFail.product_id} - ${firstFail.message}`)
}
selectedProducts.value = []
await fetchProducts()
} catch {
// 错误已由响应拦截器统一提示
} finally {
pushing.value = false
}
}
async function handleApiDelete(row: WarehouseApiItem) {
try {
await ElMessageBox.confirm(`确认删除接口配置「${row.name}」?`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消',
customClass: 'app-confirm-box',
})
} catch {
return
}
try {
await deleteWarehouseApi(row.id)
ElMessage.success('已删除')
const warehouseId = currentWarehouse.value?.id
await fetchConfigs()
await fetchList()
if (warehouseId && currentWarehouse.value?.id === warehouseId) await fetchDetail(warehouseId)
} catch {
// 拦截器已提示
}
}
/** 测试接口连通性(WMS 心跳 index.ping) */
const testingId = ref<number | null>(null)
async function handleApiTest(row: WarehouseApiItem) {
if (testingId.value) return
testingId.value = row.id
try {
const res = await testWarehouseApi(row.id)
if (res.ok) {
const tip = res.message ? `(${res.message})` : ''
ElMessage.success(`连接成功${tip}`)
} else {
ElMessage.error(`连接失败:${res.error || res.message || 'WMS 返回异常'}`)
}
} catch {
// 拦截器已提示
} finally {
testingId.value = null
}
}
/** 复制对外回调地址(供外部系统配置回调使用) */
async function copyText(text?: string | null) {
if (!text) return
try {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(text)
} else {
const el = document.createElement('textarea')
el.value = text
el.style.position = 'fixed'
el.style.opacity = '0'
document.body.appendChild(el)
el.select()
document.execCommand('copy')
document.body.removeChild(el)
}
ElMessage.success('已复制')
} catch {
ElMessage.error('复制失败,请手动复制')
}
}
onMounted(async () => {
await Promise.all([ loadSubsidiaryOptions(), fetchAccessContext() ])
await fetchList()
})
</script>
<template>
<el-card class="warehouse-card">
<template #header>
<div class="page-header">
<span>外部仓库</span>
<div class="header-actions">
<template v-if="!isCompanyScope">
<el-button type="primary" @click="openCreate">新增仓库</el-button>
<ExportButton type="warehouse" :filters="warehouseExportFilters" />
</template>
</div>
</div>
</template>
<SplitLayout :first-size="420" storage-key="external-api-split" :show-second="!!currentWarehouse">
<template #first>
<el-form :inline="true" class="search-bar">
<el-form-item label="仓库编码">
<el-input v-model="query.code" placeholder="仓库编码" clearable @keyup.enter="search" />
</el-form-item>
<el-form-item label="货主">
<el-select
v-model="query.subsidiary_id"
placeholder="全部"
clearable
filterable
style="width: 150px"
@change="search"
>
<el-option v-for="s in subsidiaryOptions" :key="s.id" :label="s.name" :value="s.id" />
</el-select>
</el-form-item>
<el-form-item label="状态">
<el-select v-model="query.status" placeholder="全部" clearable style="width: 140px">
<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>
<div class="top-table-wrap">
<DataTable
:loading="loading"
:data="list"
highlight-current-row
height="100%"
@row-click="handleRowClick"
>
<el-table-column prop="code" label="仓库编码" width="180" />
<el-table-column prop="name" label="仓库名称" min-width="160" />
<el-table-column label="货主" width="140" show-overflow-tooltip>
<template #default="{ row }">{{ row.subsidiary_name || '-' }}</template>
</el-table-column>
<el-table-column label="类型" width="100">
<template #default="{ row }">{{ warehouseTypeLabel(row.type) }}</template>
</el-table-column>
<el-table-column label="接口配置" width="100" align="center" v-if="!isCompanyScope">
<template #default="{ row }">{{ (row.apis || []).length }}</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 prop="remark" label="备注" min-width="140" show-overflow-tooltip />
<el-table-column label="操作" width="200" fixed="right" v-if="!isCompanyScope">
<template #default="{ row }">
<el-button link type="primary" @click.stop="openEdit(row)">编辑</el-button>
<el-button link type="success" @click.stop="openConfigTab(row)">接口配置</el-button>
<el-button link type="danger" @click.stop="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"
/>
</template>
<template #second>
<el-tabs
v-model="activeDetailTab"
type="border-card"
class="detail-tabs"
@tab-change="handleDetailTabChange"
>
<el-tab-pane label="明细" name="detail">
<div v-loading="detailLoading" class="detail-body">
<template v-if="currentWarehouse">
<div class="detail-toolbar">
<span class="detail-title">仓库详情 · {{ currentWarehouse.name }}</span>
<el-tag :type="currentWarehouse.status === 1 ? 'success' : 'info'">
{{ currentWarehouse.status === 1 ? '启用' : '禁用' }}
</el-tag>
<el-button
v-if="!isCompanyScope"
size="small"
class="detail-edit"
@click="openEdit(currentWarehouse)"
>
编辑
</el-button>
</div>
<el-descriptions :column="3" border size="small" title="基本信息">
<el-descriptions-item label="仓库编码">{{ currentWarehouse.code }}</el-descriptions-item>
<el-descriptions-item label="仓库名称">{{ currentWarehouse.name }}</el-descriptions-item>
<el-descriptions-item label="货主">
{{ currentWarehouse.subsidiary_name || '-' }}
</el-descriptions-item>
<el-descriptions-item label="仓库类型">
{{ warehouseTypeLabel(currentWarehouse.type) }}
</el-descriptions-item>
<el-descriptions-item label="状态">
{{ currentWarehouse.status === 1 ? '启用' : '禁用' }}
</el-descriptions-item>
<el-descriptions-item label="创建时间">
{{ formatDateTime(currentWarehouse.created_at) }}
</el-descriptions-item>
<el-descriptions-item label="更新时间">
{{ formatDateTime(currentWarehouse.updated_at) }}
</el-descriptions-item>
<el-descriptions-item label="备注" :span="3">
{{ currentWarehouse.remark || '-' }}
</el-descriptions-item>
</el-descriptions>
<el-descriptions v-if="!isCompanyScope" :column="3" border size="small" title="关联统计" class="stat-block">
<el-descriptions-item label="接口配置数">
{{ currentWarehouse.stats?.api_count ?? 0 }}
</el-descriptions-item>
<el-descriptions-item label="启用接口配置">
{{ currentWarehouse.stats?.api_enabled_count ?? 0 }}
</el-descriptions-item>
<el-descriptions-item label="入库单数">
{{ currentWarehouse.stats?.inbound_order_count ?? 0 }}
</el-descriptions-item>
<el-descriptions-item label="出库单数">
{{ currentWarehouse.stats?.outbound_order_count ?? 0 }}
</el-descriptions-item>
</el-descriptions>
</template>
<el-empty v-else description="请点击上方仓库查看详情" />
</div>
</el-tab-pane>
<el-tab-pane v-if="!isCompanyScope" label="接口配置" name="config">
<div class="detail-body is-config">
<template v-if="currentWarehouse">
<div class="items-toolbar">
<span class="items-title">
接口配置 · {{ currentWarehouse.name }}
</span>
<div class="toolbar-right header-actions">
<ExportButton type="warehouse_api" :filters="detailExportFilters" size="small" plain />
<el-button
type="primary"
size="small"
:disabled="configList.length > 0"
:title="configList.length > 0 ? '每个仓库只能配置一个接口' : ''"
@click="openApiCreate"
>
新增配置
</el-button>
</div>
</div>
<el-alert
v-if="configList.length > 0"
type="info"
:closable="false"
show-icon
class="config-once-tip"
title="每个仓库只能配置一个接口;如需更换对接方,请先删除现有配置再新增"
/>
<div class="bottom-table-wrap">
<DataTable :loading="configLoading" :data="configList" height="100%">
<el-table-column prop="name" label="配置名称" min-width="140" />
<el-table-column label="接口类型" width="150">
<template #default="{ row }">{{ apiTypeLabel(row.type) }}</template>
</el-table-column>
<el-table-column prop="app_key" label="应用Key" min-width="140" show-overflow-tooltip />
<el-table-column label="对外回调地址" min-width="280">
<template #default="{ row }">
<div v-if="row.callback_url" class="callback-cell">
<span class="callback-url" :title="row.callback_url">{{ row.callback_url }}</span>
<el-button link type="primary" @click="copyText(row.callback_url)">复制</el-button>
</div>
<span v-else class="muted">-</span>
</template>
</el-table-column>
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
{{ row.status === 1 ? '启用' : '禁用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="220" fixed="right">
<template #default="{ row }">
<el-button link type="success" :loading="testingId === row.id" @click="handleApiTest(row)">测试连接</el-button>
<el-button link type="primary" @click="openApiEdit(row)">编辑</el-button>
<el-button link type="danger" @click="handleApiDelete(row)">删除</el-button>
</template>
</el-table-column>
</DataTable>
</div>
</template>
<el-empty v-else description="请点击上方仓库查看接口配置" />
</div>
</el-tab-pane>
<el-tab-pane v-if="!isCompanyScope" label="快递映射" name="express">
<div class="detail-body is-config">
<template v-if="currentWarehouse">
<div class="items-toolbar">
<span class="items-title">快递映射 · {{ currentWarehouse.name }}</span>
<span class="muted toolbar-hint">
外部回传的快递编码优先按此处「自定义编码 → 默认快递编码」解析;未配映射时按快递公司字典兜底
</span>
<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" height="100%">
<el-table-column label="快递名称" min-width="150">
<template #default="{ row }">{{ row.express_name || '-' }}</template>
</el-table-column>
<el-table-column prop="express_code" label="默认快递编码" width="140" />
<el-table-column prop="custom_code" label="自定义编码" width="160" />
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
{{ row.status === 1 ? '启用' : '禁用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="140" show-overflow-tooltip />
<el-table-column label="操作" width="130" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="openMappingEdit(row)">编辑</el-button>
<el-button link type="danger" @click="handleMappingDelete(row)">删除</el-button>
</template>
</el-table-column>
</DataTable>
</div>
</template>
<el-empty v-else description="请点击上方仓库查看快递映射" />
</div>
</el-tab-pane>
<el-tab-pane label="商品" name="products">
<div class="detail-body is-config">
<template v-if="currentWarehouse">
<div class="items-toolbar">
<span class="items-title">商品 · {{ currentWarehouse.name }}</span>
<el-button
type="primary"
size="small"
:disabled="!selectedProducts.length || pushing"
:loading="pushing"
@click="handlePushProducts"
>
推送选中到仓库
</el-button>
<el-input
v-model="productQuery.keyword"
placeholder="商品编码 / 名称 / 条码"
clearable
class="toolbar-search"
@keyup.enter="searchProducts"
/>
<el-button size="small" @click="searchProducts">查询</el-button>
<ExportButton
v-if="!isCompanyScope"
type="warehouse_product"
:filters="productExportFilters"
size="small"
plain
/>
</div>
<div class="bottom-table-wrap">
<DataTable :loading="productLoading" :data="productList" height="100%" @selection-change="handleProductSelectionChange">
<el-table-column type="selection" width="45" />
<el-table-column prop="item_code" label="商品编码" min-width="130" />
<el-table-column prop="item_name" label="商品名称" min-width="180" show-overflow-tooltip />
<el-table-column prop="sku_property" label="规格" min-width="120" show-overflow-tooltip />
<el-table-column prop="barcode" label="条码" min-width="130" show-overflow-tooltip />
<el-table-column label="推送状态" width="110">
<template #default="{ row }">
<el-tag :type="row.pushed ? 'success' : 'info'" size="small">
{{ row.pushed ? '已推送' : '未推送' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="pushed_at" label="推送时间" width="180">
<template #default="{ row }">{{ formatDateTime(row.pushed_at) }}</template>
</el-table-column>
</DataTable>
</div>
<ListPager
:total="productTotal"
:elapsed="productElapsed"
:page="productQuery.page"
:page-size="productQuery.pageSize"
@page-change="handleProductPageChange"
@size-change="handleProductSizeChange"
/>
</template>
<el-empty v-else description="请点击上方仓库查看商品" />
</div>
</el-tab-pane>
<el-tab-pane label="库存" name="inventory">
<div class="detail-body is-config">
<template v-if="currentWarehouse">
<div class="items-toolbar">
<!-- 所在公司权限:仅保留查询库存与同步覆盖,导出等维护入口不展示 -->
<span class="items-title">库存 · {{ currentWarehouse.name }}</span>
<el-button
type="success"
size="small"
:disabled="!selectedInventory.length || queryingWms"
:loading="queryingWms"
@click="handleQueryInventorySelected"
>
查询选中库存
</el-button>
<el-button
type="warning"
size="small"
:disabled="!selectedInventory.length || syncing"
:loading="syncing"
@click="handleSyncInventory"
>
同步覆盖本地数量
</el-button>
<el-checkbox v-model="onlyDiff" style="margin-left: 12px">仅显示差异</el-checkbox>
<el-input
v-model="inventoryQuery.keyword"
placeholder="商品编码 / 名称 / 条码"
clearable
class="toolbar-search"
@keyup.enter="searchInventory"
/>
<el-button size="small" @click="searchInventory">查询</el-button>
<ExportButton
v-if="!isCompanyScope"
type="warehouse_product"
:filters="inventoryExportFilters"
size="small"
plain
/>
</div>
<div class="bottom-table-wrap">
<DataTable :loading="inventoryLoading" :data="displayInventoryList" height="100%" @selection-change="handleInventorySelectionChange">
<el-table-column type="selection" width="45" />
<el-table-column prop="item_code" label="商品编码" min-width="130" />
<el-table-column prop="item_name" label="商品名称" min-width="180" show-overflow-tooltip />
<el-table-column prop="sku_property" label="规格" min-width="120" show-overflow-tooltip />
<el-table-column prop="barcode" label="条码" min-width="130" show-overflow-tooltip />
<el-table-column prop="good_quantity" label="正品数量" width="100" />
<el-table-column label="委外仓正品数量" width="130">
<template #default="{ row }">
<span v-if="wmsInventoryMap[row.id]" class="wms-qty">{{ wmsInventoryMap[row.id].good_quantity }}</span>
<span v-else class="muted">未查询</span>
</template>
</el-table-column>
<el-table-column label="正品差异数量" width="120">
<template #default="{ row }">
<span v-if="wmsInventoryMap[row.id]" :style="diffStyle(wmsInventoryMap[row.id].good_quantity - row.good_quantity)">{{ wmsInventoryMap[row.id].good_quantity - row.good_quantity }}</span>
<span v-else class="muted">-</span>
</template>
</el-table-column>
<el-table-column prop="defect_quantity" label="残次品数量" width="100" />
<el-table-column label="委外仓残次品数量" width="130">
<template #default="{ row }">
<span v-if="wmsInventoryMap[row.id]" class="wms-qty">{{ wmsInventoryMap[row.id].defect_quantity }}</span>
<span v-else class="muted">未查询</span>
</template>
</el-table-column>
<el-table-column label="残次品差异数量" width="120">
<template #default="{ row }">
<span v-if="wmsInventoryMap[row.id]" :style="diffStyle(wmsInventoryMap[row.id].defect_quantity - row.defect_quantity)">{{ wmsInventoryMap[row.id].defect_quantity - row.defect_quantity }}</span>
<span v-else class="muted">-</span>
</template>
</el-table-column>
</DataTable>
</div>
<ListPager
:total="inventoryTotal"
:elapsed="inventoryElapsed"
:page="inventoryQuery.page"
:page-size="inventoryQuery.pageSize"
@page-change="handleInventoryPageChange"
@size-change="handleInventorySizeChange"
/>
</template>
<el-empty v-else description="请点击上方仓库查看库存" />
</div>
</el-tab-pane>
<el-tab-pane v-if="!isCompanyScope" label="调用日志" name="logs">
<div class="detail-body is-config">
<template v-if="currentWarehouse">
<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" height="100%">
<el-table-column type="expand">
<template #default="{ row }">
<div class="log-detail">
<div><b>请求地址:</b><span class="break-all">{{ row.url }}</span></div>
<div><b>请求报文:</b><pre class="log-pre">{{ row.request_body || '-' }}</pre></div>
<div><b>响应报文:</b><pre class="log-pre">{{ row.response_body || row.error || '-' }}</pre></div>
</div>
</template>
</el-table-column>
<el-table-column prop="method" label="方法" min-width="200" show-overflow-tooltip />
<el-table-column label="结果" width="130">
<template #default="{ row }">
<el-tag :type="row.is_success ? 'success' : 'danger'" size="small">
{{ row.is_success ? '成功' : '失败' }}
</el-tag>
<span v-if="row.response_status" class="muted"> · HTTP {{ row.response_status }}</span>
</template>
</el-table-column>
<el-table-column prop="business_code" label="业务码" width="100" />
<el-table-column prop="business_message" label="业务提示" min-width="160" show-overflow-tooltip />
<el-table-column prop="duration" label="耗时" width="90">
<template #default="{ row }">{{ row.duration }} ms</template>
</el-table-column>
<el-table-column prop="created_at" label="时间" width="180">
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
</el-table-column>
</DataTable>
</div>
<ListPager
:total="outboundTotal"
:elapsed="outboundElapsed"
:page="outboundQuery.page"
:page-size="outboundQuery.pageSize"
@page-change="handleOutboundPageChange"
@size-change="handleOutboundSizeChange"
/>
</template>
<el-empty v-else description="请点击上方仓库查看调用日志" />
</div>
</el-tab-pane>
<el-tab-pane v-if="!isCompanyScope" label="回调日志" name="callback_logs">
<div class="detail-body is-config">
<template v-if="currentWarehouse">
<div class="items-toolbar">
<span class="items-title">回调日志 · {{ currentWarehouse.name }}</span>
<el-button size="small" :loading="callbackLoading" @click="fetchCallbackLogs">刷新</el-button>
<ExportButton type="callback_log" :filters="detailExportFilters" size="small" plain />
</div>
<div class="bottom-table-wrap">
<DataTable :loading="callbackLoading" :data="callbackLogs" height="100%">
<el-table-column type="expand">
<template #default="{ row }">
<div class="log-detail">
<div><b>请求参数:</b><pre class="log-pre">{{ row.request_query || '-' }}</pre></div>
<div><b>请求报文:</b><pre class="log-pre">{{ row.request_body || '-' }}</pre></div>
<div><b>返回报文:</b><pre class="log-pre">{{ row.response_body || '-' }}</pre></div>
<div v-if="row.error"><b>异常信息:</b><span class="break-all">{{ row.error }}</span></div>
<div><b>来源IP:</b>{{ row.ip || '-' }} <b>app_key:</b>{{ row.app_key || '-' }}</div>
</div>
</template>
</el-table-column>
<el-table-column prop="method" label="回调方法" min-width="200" show-overflow-tooltip />
<el-table-column label="结果" width="150">
<template #default="{ row }">
<el-tag :type="row.is_success ? 'success' : 'danger'" size="small">
{{ row.is_success ? '成功' : '失败' }}
</el-tag>
<span v-if="row.http_status" class="muted"> · HTTP {{ row.http_status }}</span>
</template>
</el-table-column>
<el-table-column prop="message" label="提示 / 失败原因" min-width="200" show-overflow-tooltip />
<el-table-column prop="duration" label="耗时" width="90">
<template #default="{ row }">{{ row.duration == null ? '-' : `${row.duration} ms` }}</template>
</el-table-column>
<el-table-column prop="created_at" label="时间" width="180">
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
</el-table-column>
</DataTable>
</div>
<ListPager
:total="callbackTotal"
:elapsed="callbackElapsed"
:page="callbackQuery.page"
:page-size="callbackQuery.pageSize"
@page-change="handleCallbackPageChange"
@size-change="handleCallbackSizeChange"
/>
</template>
<el-empty v-else description="请点击上方仓库查看回调日志" />
</div>
</el-tab-pane>
</el-tabs>
</template>
</SplitLayout>
<!-- 仓库 新增 / 编辑(仅基础信息) -->
<TaskPanelDialog
v-model="dialogVisible"
:title="editId == null ? '新增仓库' : '编辑仓库'"
:subtitle="editId == null ? '保存后自动生成仓库编码,可继续配置对接接口' : '仓库编码创建后不可修改'"
width="min(560px, 92vw)"
body-max-height="60vh"
>
<el-form
ref="formRef"
:model="form"
:rules="rules"
class="task-panel__form"
scroll-to-error
@submit.prevent
>
<p v-if="editId == null" class="task-panel__form-tip">
仓库编码由系统自动生成(前缀 WH),无需填写。
</p>
<div class="task-panel__grid task-panel__grid--single">
<div v-if="editId != null" class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">仓库编码</span>
<div class="task-panel__field-form">
<el-input v-model="form.code" disabled />
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label is-required">仓库名称</span>
<div class="task-panel__field-form">
<el-form-item prop="name">
<el-input v-model="form.name" placeholder="如 上海中心仓" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label is-required">货主</span>
<div class="task-panel__field-form">
<el-form-item prop="subsidiary_id">
<el-select v-model="form.subsidiary_id" placeholder="请选择货主(下属公司)" filterable style="width: 100%">
<el-option v-for="s in subsidiaryOptions" :key="s.id" :label="s.name" :value="s.id" />
</el-select>
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">仓库类型</span>
<div class="task-panel__field-form">
<el-form-item prop="type">
<el-select v-model="form.type" clearable placeholder="请选择" style="width: 100%">
<el-option v-for="t in WAREHOUSE_TYPE_OPTIONS" :key="t.value" :label="t.label" :value="t.value" />
</el-select>
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">状态</span>
<div class="task-panel__field-form">
<el-form-item 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>
</div>
</div>
<div class="task-panel__field task-panel__field--input task-panel__field--textarea">
<span class="task-panel__field-label">备注</span>
<div class="task-panel__field-form">
<el-form-item prop="remark">
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" />
</el-form-item>
</div>
</div>
</div>
</el-form>
<template #hint>
{{ editId == null ? '仓库编码保存后自动生成' : `仓库编码:${form.code || '-'}` }}
</template>
<template #actions>
<el-button size="small" @click="dialogVisible = false">取消</el-button>
<el-button size="small" type="primary" :loading="submitting" @click="submitForm">保存</el-button>
</template>
</TaskPanelDialog>
<!-- 接口配置 新增 / 编辑:基础信息 + 配置项(分组硬编码,配置项值单独接口整体覆盖保存) -->
<TaskPanelDialog
v-model="apiDialogVisible"
:title="apiEditId == null ? '新增接口配置' : '编辑接口配置'"
subtitle="基础地址随接口类型自动带出;每个仓库只能配置一个接口"
width="min(880px, 96vw)"
body-max-height="60vh"
>
<el-form
ref="apiFormRef"
:model="apiFormModel"
:rules="apiRules"
label-position="top"
class="task-panel__form"
scroll-to-error
@submit.prevent
>
<div class="task-panel__grid">
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label is-required">配置名称</span>
<div class="task-panel__field-form">
<el-form-item prop="name">
<el-input v-model="apiForm.name" placeholder="如 出库推送接口" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">接口类型</span>
<div class="task-panel__field-form">
<el-select v-model="apiForm.type" style="width: 100%" @change="onApiTypeChange">
<el-option
v-for="opt in API_TYPE_OPTIONS"
:key="opt.value"
:label="opt.label"
:value="opt.value"
/>
</el-select>
</div>
</div>
<!-- 基础地址由接口类型自动带出,表单里不展示(保存时按类型预设写入) -->
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">应用Key</span>
<div class="task-panel__field-form">
<el-form-item prop="app_key">
<el-input v-model="apiForm.app_key" placeholder="选填" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">应用密钥</span>
<div class="task-panel__field-form">
<el-form-item prop="app_secret">
<el-input v-model="apiForm.app_secret" type="password" show-password placeholder="选填" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--full task-panel__field--control">
<span class="task-panel__field-label">回调地址</span>
<div class="task-panel__field-form task-panel__field-form--row">
<span v-if="apiForm.callback_url" class="callback-url" :title="apiForm.callback_url">
{{ apiForm.callback_url }}
</span>
<span v-else class="task-panel__field-hint">保存后展示</span>
<el-button
v-if="apiForm.callback_url"
size="small"
link
type="primary"
@click="copyText(apiForm.callback_url)"
>
复制
</el-button>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">状态</span>
<div class="task-panel__field-form">
<el-form-item prop="status">
<el-select v-model="apiForm.status" style="width: 100%">
<el-option label="启用" :value="1" />
<el-option label="禁用" :value="0" />
</el-select>
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--full task-panel__field--input task-panel__field--textarea">
<span class="task-panel__field-label">备注</span>
<div class="task-panel__field-form">
<el-form-item prop="remark">
<el-input v-model="apiForm.remark" type="textarea" :rows="2" placeholder="选填" />
</el-form-item>
</div>
</div>
</div>
<p class="task-panel__form-tip">
外部系统(WMS/第三方)以 POST 调用回调地址通知 OMS,query 需携带 method / app_key / timestamp / sign,报文为业务 JSON。
</p>
<div class="task-panel__section">配置项</div>
<div class="config-fields">
<FieldValueForm v-model="configFieldValues" :groups="configFieldGroups" :fields="configFieldDefs" />
</div>
</el-form>
<template #hint>
{{ apiEditId == null ? '保存后按配置项推送,可随时修改' : '配置项保存后整体覆盖' }}
</template>
<template #actions>
<el-button size="small" @click="apiDialogVisible = false">取消</el-button>
<el-button size="small" type="primary" :loading="apiSubmitting" @click="submitApiForm">保存</el-button>
</template>
</TaskPanelDialog>
<!-- 快递映射 新增 / 编辑:自定义编码(外部传入)→ 默认快递编码(快递公司字典) -->
<TaskPanelDialog
v-model="mappingDialogVisible"
:title="mappingEditId == null ? '新增快递映射' : '编辑快递映射'"
subtitle="外部回传的快递编码按「自定义编码 → 默认快递编码」解析"
width="min(560px, 92vw)"
body-max-height="60vh"
>
<el-form
ref="mappingFormRef"
:model="mappingForm"
:rules="mappingRules"
class="task-panel__form"
scroll-to-error
@submit.prevent
>
<div class="task-panel__grid task-panel__grid--single">
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label is-required">默认快递</span>
<div class="task-panel__field-form">
<el-form-item prop="express_code">
<el-select
v-model="mappingForm.express_code"
filterable
placeholder="请选择快递公司(OMS 默认编码)"
style="width: 100%"
>
<el-option
v-for="c in expressCompanies"
:key="c.code"
:label="`${c.name}(${c.code})`"
:value="c.code"
/>
</el-select>
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label is-required">自定义编码</span>
<div class="task-panel__field-form">
<el-form-item prop="custom_code">
<el-input v-model="mappingForm.custom_code" placeholder="外部传入的快递编码,如 SF.KY / KYSF" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--control">
<span class="task-panel__field-label">状态</span>
<div class="task-panel__field-form">
<el-radio-group v-model="mappingForm.status">
<el-radio :value="1">启用</el-radio>
<el-radio :value="0">禁用</el-radio>
</el-radio-group>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">备注</span>
<div class="task-panel__field-form">
<el-input v-model="mappingForm.remark" placeholder="选填" />
</div>
</div>
</div>
</el-form>
<template #hint>未配映射的编码按快递公司字典允许兜底解析</template>
<template #actions>
<el-button size="small" @click="mappingDialogVisible = false">取消</el-button>
<el-button size="small" type="primary" :loading="mappingSubmitting" @click="submitMappingForm">保存</el-button>
</template>
</TaskPanelDialog>
</el-card>
</template>
<style scoped>
.warehouse-card {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.warehouse-card :deep(.el-card__body) {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 10px 12px;
}
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
font-weight: 600;
}
.search-bar {
margin-bottom: 12px;
}
.top-table-wrap {
flex: 1;
min-height: 0;
overflow: hidden;
}
.hint {
color: var(--el-text-color-secondary);
font-size: 13px;
}
/* 接口配置:配置项由 FieldValueForm 按分组渲染,分组标题/字段标签对齐面板风格 */
.config-fields :deep(.field-group .group-title) {
padding: 0;
margin: 0 0 4px;
border-bottom: none;
font-size: 12px;
font-weight: 500;
color: var(--el-text-color-regular);
}
.config-fields :deep(.field-group + .field-group) {
margin-top: 12px;
}
.config-fields :deep(.group-hint) {
margin: 0 0 6px;
}
.config-fields :deep(.el-form-item) {
margin-bottom: 10px;
}
.config-fields :deep(.el-form-item__label) {
font-size: 12px;
color: var(--el-text-color-regular);
padding-bottom: 4px;
}
.detail-tabs {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.detail-tabs :deep(.el-tabs__content) {
flex: 1;
min-height: 0;
overflow: hidden;
}
.detail-tabs :deep(.el-tab-pane) {
height: 100%;
display: flex;
flex-direction: column;
min-height: 0;
}
.detail-body {
flex: 1;
min-height: 0;
overflow: auto;
padding-right: 4px;
}
/* 接口配置:内部由表格撑满,交由表格自身滚动 */
.detail-body.is-config {
display: flex;
flex-direction: column;
overflow: hidden;
}
.detail-toolbar {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
}
.detail-title {
font-weight: 600;
}
.detail-edit {
margin-left: auto;
}
.stat-block {
margin-top: 16px;
}
.items-toolbar {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
min-height: 32px;
}
.config-once-tip {
margin-bottom: 8px;
}
.items-toolbar .el-button {
height: 28px;
padding: 0 12px;
font-size: 13px;
}
.items-toolbar .el-input {
height: 28px;
}
.items-toolbar .el-input .el-input__inner {
height: 28px;
}
.items-title {
font-weight: 600;
}
.toolbar-right {
margin-left: auto;
}
/* 工具栏说明文案(与按钮同行,过长时自动换行) */
.toolbar-hint {
margin-left: 12px;
font-size: 12px;
line-height: 1.4;
}
/* 调用日志:展开详情与辅助样式 */
.log-detail {
padding: 4px 12px;
font-size: 12px;
line-height: 1.6;
}
.log-detail .break-all {
word-break: break-all;
}
.log-pre {
margin: 4px 0 0;
max-height: 260px;
overflow: auto;
white-space: pre-wrap;
word-break: break-all;
background: var(--el-fill-color-light, #f5f7fa);
border-radius: 4px;
padding: 8px;
}
.muted {
color: var(--el-text-color-secondary, #909399);
font-size: 12px;
}
/* 接口配置:对外回调地址(单行省略 + 复制) */
.callback-cell {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
}
.callback-url {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
}
/* 商品标签页:WMS 库存列辅助样式 */
.wms-qty {
font-weight: 600;
}
.wms-sub {
color: var(--el-text-color-secondary, #909399);
font-size: 12px;
}
/* 商品标签页的关键词搜索框:靠右排列,紧跟查询按钮 */
.toolbar-search {
width: 220px;
margin-left: auto;
}
.bottom-table-wrap {
flex: 1;
min-height: 0;
overflow: hidden;
}
</style>