This commit is contained in:
liufumingren 2026-07-11 10:11:18 +08:00
parent d1ef9e502d
commit 51416d367e
6 changed files with 1058 additions and 25 deletions

View File

@ -97,6 +97,23 @@ export function searchInventoryReport(
} as any)
}
/** 货主侧库存报表查询 */
export function searchStoreReport(
data?: StorageReportSearchBody
): Promise<StorageReportSearchResult> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.report.searchStore',
v,
timestamp: new Date().getTime()
},
data: data ?? {},
isSystemApi: true
} as any)
}
export function exportInventoryReport(
data?: StorageReportExportBody
): Promise<StorageReportExportTaskResponse> {
@ -113,6 +130,23 @@ export function exportInventoryReport(
} as any)
}
/** 货主侧库存报表导出 */
export function exportStoreReport(
data?: StorageReportExportBody
): Promise<StorageReportExportTaskResponse> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.report.exportStore',
v,
timestamp: new Date().getTime()
},
data: data ?? {},
isSystemApi: true
} as any)
}
export function getExportTaskProgress(
data: StorageReportExportTaskProgressParams
): Promise<StorageReportExportTaskProgressResponse> {

View File

@ -27,6 +27,8 @@ export const componentMap: Record<string, any> = {
'storage/management/replenishmentDemand/index': () => import('@/views/storage/management/replenishmentDemand/index.vue'),
'storage/receiving': () => import('@/views/storage/receiving/index.vue'),
'storage/report': () => import('@/views/storage/report/index.vue'),
/** 货主侧库存报表 */
'store/report': () => import('@/views/storage/report/store.vue'),
'storage/entry': () => import('@/views/storage/entry/index.vue'),
'storage/inventory': () => import('@/views/storage/inventory/index.vue'),
'storage/stockout': () => import('@/views/storage/stockout/index.vue'),

View File

@ -16,6 +16,7 @@
<el-button size="small" @click="loadList">
<el-icon><Refresh /></el-icon> 刷新
</el-button>
<el-button size="small" plain @click="tableRef?.openColumnConfig?.()">字段设置</el-button>
</div>
<div class="toolbar-right">
<el-select
@ -58,20 +59,42 @@
<span>可用库存 <b>{{ summary.total_available ?? 0 }}</b></span>
</div>
<div class="upper-wrapper">
<upper-table
<div class="split-stack" ref="splitStackRef">
<div class="upper-wrapper" :style="upperPaneStyle">
<upper-table
ref="tableRef"
default-align="center"
:enable-column-config="true"
table-id="external-stock-list"
:data="list"
:columns="columns"
:loading="loading"
:pagination="pagination"
:show-actions="true"
@current-change="handleRowClick"
@page-change="handlePageChange"
@page-size-change="handleSizeChange"
@sort-change="handleSortChange"
>
<template #column-id="{ row }">
<span class="sku-text">{{ row.id ?? '—' }}</span>
</template>
<template #column-images="{ row }">
<el-image
v-if="row.images && row.images.length"
:src="row.images[0]"
:preview-src-list="row.images"
fit="cover"
preview-teleported
class="table-thumb"
/>
<span v-else style="color:#909399">—</span>
</template>
<template #column-actions="{ row }">
<el-button link type="primary" size="small" @click.stop="openEdit(row)">编辑</el-button>
</template>
<template #column-warehouse_name="{ row }">
<span>{{ row['store_stock.warehouse.company_name'] || '—' }}</span>
<span>{{ row['warehouse_remask'] || '—' }}</span>
</template>
<template #column-available_qty="{ row }">
<span>{{ row.available_quantity ?? '—' }}</span>
@ -100,11 +123,20 @@
</upper-table>
</div>
<div class="lower-level" v-if="selectedRow">
<div
class="pane-resizer"
title="拖动调整列表与详情区域高度"
@mousedown="beginSplitDrag"
/>
<div class="lower-level" v-if="selectedRow" :style="lowerPaneStyle">
<div class="detail-header">
<el-tabs v-model="activeTab" class="detail-tab">
<el-tab-pane label="基本信息" name="info" />
<el-tab-pane label="商品图片" name="images" />
<el-tab-pane label="库存信息" name="storage" />
<el-tab-pane label="外部绑定" name="erpStock" />
<el-tab-pane label="日志" name="log" />
</el-tabs>
</div>
@ -127,7 +159,7 @@
</template>
<span v-else>—</span>
</el-descriptions-item>
<el-descriptions-item label="SN管理">
<el-descriptions-item label="序列号管理">
<el-tag size="small" :type="selectedRow.is_sn_mgmt === 'Y' ? 'success' : 'info'">
{{ selectedRow.is_sn_mgmt === 'Y' ? '是' : '否' }}
</el-tag>
@ -147,8 +179,35 @@
<el-descriptions-item label="更新时间">{{ selectedRow.update_at_display || '—' }}</el-descriptions-item>
</el-descriptions>
<!-- 商品图片 -->
<div v-else-if="activeTab === 'images'" class="image-gallery" v-loading="imageLoading">
<template v-if="imageList.length">
<el-image
v-for="(img, idx) in imageList"
:key="idx"
:src="img.url"
:preview-src-list="imageList.map(i => i.url)"
:initial-index="idx"
fit="cover"
preview-teleported
class="gallery-image"
/>
</template>
<el-empty v-else description="暂无商品图片" :image-size="60" />
</div>
<!-- 外部商品绑定 -->
<div v-else-if="activeTab === 'erpStock'" class="erp-stock-wrapper">
<ErpStock :id="selectedRow.id" />
</div>
<!-- 日志 -->
<div v-else-if="activeTab === 'log'" class="log-wrapper">
<Log :id="selectedRow.id" />
</div>
<el-descriptions v-else-if="activeTab === 'storage'" :column="2" border size="small">
<el-descriptions-item label="仓库名称">{{ selectedRow['store_stock.warehouse.company_name'] || '—' }}</el-descriptions-item>
<el-descriptions-item label="仓库名称">{{ selectedRow['warehouse_remask'] || '—' }}</el-descriptions-item>
<el-descriptions-item label="货主备注">{{ selectedRow['store_stock.store_remask'] || '—' }}</el-descriptions-item>
<el-descriptions-item label="总库存">{{ selectedRow.quantity ?? '—' }}</el-descriptions-item>
<el-descriptions-item label="锁定库存">{{ selectedRow.locked_quantity ?? '—' }}</el-descriptions-item>
@ -157,41 +216,137 @@
</el-descriptions>
</div>
</div>
<div class="lower-level empty" v-else>
<div class="lower-level empty" v-else :style="lowerPaneStyle">
<el-empty description="请选择数据查看详情" :image-size="60" />
</div>
</div><!-- .split-stack -->
</div>
<!-- 编辑弹窗 -->
<el-dialog v-model="editVisible" title="编辑商品" width="520px" :close-on-click-modal="false">
<el-form ref="editFormRef" :model="editForm" label-width="90px" size="small">
<el-form-item label="商品名称">
<el-input v-model="editForm.item_name" placeholder="请输入商品名称" clearable />
</el-form-item>
<el-form-item label="商品编码">
<el-input v-model="editForm.item_code" placeholder="请输入商品编码" clearable />
</el-form-item>
<el-form-item label="商家编码">
<el-input v-model="editForm.goods_code" placeholder="请输入商家编码" clearable />
</el-form-item>
<el-form-item label="品牌">
<el-input v-model="editForm.brand_name" placeholder="请输入品牌" clearable />
</el-form-item>
<el-form-item label="库存单位">
<el-input v-model="editForm.stock_unit" placeholder="请输入库存单位" clearable />
</el-form-item>
<el-form-item label="条码">
<el-input v-model="editForm.barcodeInput" placeholder="多个条码用逗号分隔" clearable />
</el-form-item>
</el-form>
<template #footer>
<el-button size="small" @click="editVisible = false">取消</el-button>
<el-button size="small" type="primary" :loading="editSaving" @click="handleEditSave">保存</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { ref, reactive, onMounted, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { Search, Refresh } from '@element-plus/icons-vue'
import { stockWarehouseExternalList } from '@/api/stock/stock'
import { loadWarehouses } from '@/api/index/index'
import { stockWarehouseExternalList, saveWarehouseStock, type StockWarehouseListSort } from '@/api/stock/stock'
import { loadWarehouses, getImages } from '@/api/index/index'
import ScanBox from '@/components/ScanBox/index.vue'
import UpperTable from '@/components/UpperTable/index.vue'
import ErpStock from '@/views/stock/stock/component/erpStock.vue'
import Log from '@/views/stock/stock/component/log.vue'
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
// ─── 列表列配置 ─────────────────────────────────────────────────────────────
const columns = [
{ prop: 'id', label: 'SKU', width: 80 },
{ prop: 'images', label: '商品图片', width: 80 },
{ prop: 'item_code', label: '商品编码', minWidth: 130 },
{ prop: 'item_name', label: '商品名称', minWidth: 150 },
{ prop: 'item_name', label: '商品名称', minWidth: 150, sortable: true },
{ prop: 'goods_code', label: '商家编码', width: 120 },
{ prop: 'barcodes', label: '条码', minWidth: 150, formatter: (row: any) => row.barcodes?.length ? row.barcodes.join(' | ') : '—' },
{ prop: 'brand_name', label: '品牌', width: 100 },
{ prop: 'stock_unit', label: '库存单位', width: 90 },
{ prop: 'warehouse_name', label: '所属仓库', minWidth: 140 },
{ prop: 'quantity', label: '总库存', width: 90 },
{ prop: 'locked_quantity', label: '锁定库存', width: 90 },
{ prop: 'available_qty', label: '可用库存', width: 90 },
{ prop: 'quantity', label: '总库存', width: 90, sortable: true },
{ prop: 'locked_quantity', label: '锁定库存', width: 90, sortable: true },
{ prop: 'available_qty', label: '可用库存', width: 90, sortable: true },
{ prop: 'lock_rate_display', label: '锁定率', width: 90 },
{ prop: 'is_sn_mgmt', label: 'SN管理', width: 80 },
{ prop: 'is_batch_mgmt', label: '批次管理', width: 80 },
{ prop: 'update_at_display', label: '更新时间', width: 160 }
{ prop: 'update_at_display', label: '更新时间', width: 160, sortable: true }
]
// ─── 筛选字段配置 ─────────────────────────────────────────────────────────
const availableFields = [
{
label: '商品名称',
value: 'item_name',
type: 'text'
},
{
label: '品牌',
value: 'brand_name',
type: 'text'
},
{
label: '货物编码',
value: 'goods_code',
type: 'text'
},
{
label: '外部商品绑定',
value: 'has_bound_item',
type: 'select',
options: [
{ label: '全部', value: undefined },
{ label: '是', value: 'Y' },
{ label: '否', value: 'N' }
]
},
{
label: 'SKU',
value: 'id',
type: 'text'
},
{
label: '条码',
value: 'barcode',
type: 'text'
},
{
label: '库存数量',
value: 'quantity',
type: 'text'
},
{
label: 'ABC分类',
value: 'level',
type: 'select',
options: [
{ label: '全部', value: undefined },
{ label: 'A', value: 'A' },
{ label: 'B', value: 'B' },
{ label: 'C', value: 'C' }
]
},
{
label: '是否图片',
value: 'is_images',
type: 'select',
options: [
{ label: '全部', value: undefined },
{ label: '是', value: 'Y' },
{ label: '否', value: 'N' }
]
},
{
label: 'SN管理',
value: 'is_sn_mgmt',
@ -203,7 +358,7 @@ const availableFields = [
]
},
{
label: '效期管理',
label: '保质期管理',
value: 'is_shelf_life_mgmt',
type: 'select',
options: [
@ -237,17 +392,27 @@ const activeTab = ref('info')
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
const queryForm = reactive({ keyword: '', warehouse_id: undefined as number | string | undefined })
const currentCondition = ref<any>({})
const currentSort = reactive({ prop: '', order: '' })
const summary = ref<any>(null)
// ─── 上下分栏拖动 ──────────────────────────────────────────────────────────
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } = useVerticalSplitPane({
defaultLowerPercent: 35,
minLowerPercent: 15,
maxLowerPercent: 70
})
// ─── 仓库列表 ──────────────────────────────────────────────────────────────
const warehouseList = ref<any[]>([])
async function loadWarehouseList() {
try {
const res = await loadWarehouses() as any
if (res?.data) {
warehouseList.value = res.data.list || res.data || []
}
const raw = res?.warehouses || res?.data?.list || res?.data || []
warehouseList.value = raw.map((item: any) => ({
warehouse_id: item.value ?? item.warehouse_id ?? item.id,
warehouse_name: item.label || item.warehouse_name || item.company_name || String(item.value ?? '')
}))
} catch {
// 仓库列表加载失败不影响主流程
}
@ -273,10 +438,18 @@ async function loadList() {
params.where.keyword = queryForm.keyword
}
const sort: StockWarehouseListSort | undefined = currentSort.prop
? {
sortField: currentSort.prop,
sortOrder: currentSort.order === 'ascending' ? 'ASC' : 'DESC'
}
: undefined
const res = await stockWarehouseExternalList({
warehouse_id: queryForm.warehouse_id,
pagination: params.pagination,
where: params.where
where: params.where,
sort
}) as any
if (res?.data) {
const payload = res.data
@ -343,6 +516,93 @@ function handleSizeChange(size: number) {
function handleRowClick(row: any) {
selectedRow.value = row
loadImages(row)
}
// ─── 商品图片 ──────────────────────────────────────────────────────────────
const imageList = ref<{ url: string; name: string }[]>([])
const imageLoading = ref(false)
async function loadImages(row: any) {
if (!row?.id) {
imageList.value = []
return
}
imageLoading.value = true
try {
const res: any = await getImages({ type: 'stock', id: row.id })
const raw = res?.data || res || []
imageList.value = (Array.isArray(raw) ? raw : []).map((img: any) => ({
url: img?.file?.file_url || img?.url || '',
name: img?.file?.file_name || img?.name || ''
}))
} catch {
imageList.value = []
} finally {
imageLoading.value = false
}
}
function handleSortChange({ prop, order }: any) {
currentSort.prop = prop
currentSort.order = order
pagination.currentPage = 1
loadList()
}
// ─── 编辑弹窗 ──────────────────────────────────────────────────────────────
const editVisible = ref(false)
const editSaving = ref(false)
const editFormRef = ref<any>(null)
const editingRow = ref<any>(null)
const editForm = reactive({
item_name: '',
item_code: '',
goods_code: '',
brand_name: '',
stock_unit: '',
barcodeInput: ''
})
function openEdit(row: any) {
editingRow.value = row
editForm.item_name = row.item_name || ''
editForm.item_code = row.item_code || ''
editForm.goods_code = row.goods_code || ''
editForm.brand_name = row.brand_name || ''
editForm.stock_unit = row.stock_unit || ''
editForm.barcodeInput = (row.barcodes || []).join(',')
editVisible.value = true
}
async function handleEditSave() {
if (!editingRow.value?.id) return
editSaving.value = true
try {
const barcodes = editForm.barcodeInput
? editForm.barcodeInput.split(',').map((s: string) => s.trim()).filter(Boolean)
: []
const res: any = await saveWarehouseStock({
id: editingRow.value.id,
item_name: editForm.item_name,
item_code: editForm.item_code,
goods_code: editForm.goods_code,
brand_name: editForm.brand_name,
stock_unit: editForm.stock_unit,
barcodes
})
if (res?.flag === 'success' || res?.code === 200) {
ElMessage.success('保存成功')
editVisible.value = false
loadList()
} else {
ElMessage.error(res?.message || '保存失败')
}
} catch {
ElMessage.error('保存失败')
} finally {
editSaving.value = false
}
}
// ─── 初始化 ────────────────────────────────────────────────────────────────
@ -392,6 +652,28 @@ onMounted(() => {
overflow: hidden;
}
.split-stack {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
.pane-resizer {
flex: 0 0 6px;
min-height: 6px;
background: #e4e7ed;
cursor: row-resize;
flex-shrink: 0;
position: relative;
z-index: 2;
&:hover {
background: #dcdfe6;
}
}
}
.summary-bar {
display: flex;
align-items: center;
@ -414,13 +696,26 @@ onMounted(() => {
}
}
.table-thumb {
width: 48px;
height: 48px;
border-radius: 4px;
border: 1px solid #ebeef5;
cursor: pointer;
vertical-align: middle;
}
.sku-text {
font-family: 'Courier New', monospace;
font-size: 12px;
}
.lower-level {
margin-top: 8px;
border: 1px solid #ebeef5;
border-radius: 4px;
flex-shrink: 0;
display: flex;
flex-direction: column;
overflow: hidden;
&.empty {
border: none;
@ -435,7 +730,22 @@ onMounted(() => {
.detail-container {
padding: 12px;
overflow: auto;
max-height: 260px;
flex: 1;
min-height: 0;
.image-gallery {
display: flex;
flex-wrap: wrap;
gap: 8px;
.gallery-image {
width: 100px;
height: 100px;
border-radius: 4px;
border: 1px solid #ebeef5;
cursor: pointer;
}
}
}
}
}

View File

@ -0,0 +1,644 @@
<template>
<div class="storage-report-container" :style="{ height: containerHeight }">
<scan-box
ref="scanBox"
:width="reportScanBoxConfig.width"
:tree-props="reportScanBoxConfig.treeProps"
:auto-submit="reportScanBoxConfig.autoSubmit"
:preset-tree="presetTree"
:available-fields="availableFieldsRef"
@condition-change="handleConditionChange"
@reset="handleConditionReset"
@condition-clear="handleConditionClear"
/>
<div class="main-content">
<div class="toolbar">
<div class="toolbar-left">
<el-button size="small" type="primary" @click="loadData">刷新</el-button>
<ExportModeDropdown :loading="exportLoading" @action="handleExportAction" />
<el-button size="small" @click="openColumnConfigPanel">字段设置</el-button>
<el-button size="small" @click="toggleDetailVisible">{{ detailVisible ? '隐藏详情' : '显示详情' }}</el-button>
<!-- <span class="toolbar-title">库存报表</span>
<el-tag size="small" type="info">共 {{ pagination.total }} 条</el-tag> -->
<template v-if="pagination.total > 0">
<el-tag size="small" effect="plain">入库合计 {{ formatNumber(sumInbound) }}</el-tag>
<el-tag size="small" effect="plain">出库合计 {{ formatNumber(sumOutbound) }}</el-tag>
</template>
</div>
<div class="toolbar-right">
<el-select
v-model="selectedWarehouseId"
placeholder="全部仓库"
clearable
filterable
size="small"
style="width: 200px"
@change="handleWarehouseChange"
>
<el-option
v-for="wh in warehouseList"
:key="wh.warehouse_id"
:label="wh.warehouse_name"
:value="wh.warehouse_id"
/>
</el-select>
</div>
</div>
<div class="split-stack" ref="splitStackRef">
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
<upper-table
ref="upperTable"
row-key="__rid"
title="报表明细"
default-align="center"
table-id="storage-report-list"
:enable-column-config="true"
:data="list"
:columns="columns"
:table-size="tableSize"
:pagination="pagination"
:show-index="true"
:loading="loading"
:query-time="queryTime"
@current-change="handleRowClick"
@sort-change="handleSortChange"
@page-change="handlePageChange"
@page-size-change="handlePageSizeChange"
@refresh="loadData"
>
<template #empty>
<div class="empty-tip">暂无数据,可在左侧调整筛选条件</div>
</template>
</upper-table>
</div>
<template v-if="detailVisible">
<div
class="pane-resizer"
title="拖动调整列表与详情区域高度"
@mousedown="beginSplitDrag"
/>
<div v-if="selectedRow" class="lower-level" :class="tableSize" :style="lowerPaneStyle">
<!-- <div class="detail-header">
<span class="detail-title">行明细</span>
<span class="detail-sub">字段与接口 <code>data.list[]</code> 单条对象一致</span>
</div> -->
<div class="detail-container">
<el-descriptions :column="2" border size="small">
<el-descriptions-item
v-for="key in detailKeys"
:key="key"
:label="fieldLabel(key)"
:span="isWideKey(key) ? 2 : 1"
>
{{ detailValue(key) }}
</el-descriptions-item>
</el-descriptions>
</div>
</div>
<div v-else class="no-selection" :style="lowerPaneStyle">
<div class="empty-tip">在表格中点击一行可查看该行完整字段</div>
</div>
</template>
</div>
</div>
<AsyncExportProgressDialog
v-model:visible="exportDialogVisible"
title="库存报表导出进度"
:loading="exportLoading"
:progress-percent="exportProgressPercent"
:progress-status="exportProgressStatus"
:status-label="exportStatusLabel"
:task-id="exportTaskProgress.taskId"
:message="exportTaskProgress.message"
:error="exportTaskProgress.error"
:update-time="exportTaskProgress.updateTime"
/>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import dayjs from 'dayjs'
import ScanBox from '@/components/ScanBox/index.vue'
import UpperTable from '@/components/UpperTable/index.vue'
import ExportModeDropdown from '@/components/ExportModeDropdown.vue'
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
import {
exportStoreReport,
getExportTaskProgress,
searchStoreReport,
type StorageReportExportBody,
type StorageReportSearchBody
} from '@/api/storage.report/report'
import * as indexApi from '@/api/index/index'
import { loadWarehouses } from '@/api/index/index'
import {
buildReportTableColumns,
formatReportCell,
formatReportDateTime,
formatReportNumber,
normalizeScanConditionToReportWhere,
reportFieldLabels,
reportScanBoxAvailableFields,
reportScanBoxConfig,
sortReportDetailKeys
} from './report-config'
import { useSettingsStore } from '@/stores/modules/settings'
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
const scanBox = ref<any>(null)
const upperTable = ref<any>(null)
const presetTree = ref<any[]>([])
const availableFieldsRef = reactive(
JSON.parse(JSON.stringify(reportScanBoxAvailableFields)).filter((f: any) => f.value !== 'store_id')
)
const settingsStore = useSettingsStore()
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
const containerHeight = computed(() =>
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
)
const {
splitStackRef,
beginSplitDrag,
lowerPaneStyle,
upperPaneStyle
} = useVerticalSplitPane({ defaultLowerPercent: 40 })
const upperPaneFullStyle = computed(() => ({
flex: '1 1 auto',
minHeight: '0',
overflow: 'hidden'
}))
const detailVisible = ref(true)
function toggleDetailVisible() {
detailVisible.value = !detailVisible.value
}
function openColumnConfigPanel() {
upperTable.value?.openColumnConfig?.()
}
const tableSize = ref<'small' | 'default' | 'large'>('small')
const loading = ref(false)
const queryTime = ref(0)
const {
exportLoading,
exportDialogVisible,
exportTaskProgress,
exportProgressPercent,
exportProgressStatus,
exportStatusLabel,
submitExportTaskWithMode,
resumeExportTaskFromStorage,
hasPendingExportTask
} = useAsyncExportTask({
storageKey: 'storage.report.export.taskId',
submitExport: (payload) => exportStoreReport(payload as StorageReportExportBody),
queryProgress: (params) => getExportTaskProgress(params)
})
const fullList = ref<any[]>([])
const list = ref<any[]>([])
const columns = ref(buildReportTableColumns([]))
const pagination = reactive({
currentPage: 1,
pageSize: 20,
total: 0
})
const currentSort = reactive<{ prop: string; order: '' | 'ascending' | 'descending' }>({
prop: '',
order: ''
})
const selectedRid = ref<string | null>(null)
const currentConditionRaw = ref<any>({})
const selectedWarehouseId = ref<string | number | null>(null)
const warehouseList = ref<any[]>([])
const selectedRow = computed(() => fullList.value.find((r) => r.__rid === selectedRid.value) || null)
const detailKeys = computed(() => {
if (!selectedRow.value) return []
const keys = Object.keys(selectedRow.value).filter((k) => k !== '__rid')
return sortReportDetailKeys(keys)
})
const sumInbound = computed(() =>
fullList.value.reduce((a, r) => a + Number((r as any).inbound_total ?? 0), 0)
)
const sumOutbound = computed(() =>
fullList.value.reduce((a, r) => a + Number((r as any).outbound_total ?? 0), 0)
)
function formatNumber(n: number) {
return Number.isFinite(n) ? n.toLocaleString('zh-CN') : '--'
}
function fieldLabel(key: string) {
return reportFieldLabels[key] || key
}
function detailValue(key: string) {
if (!selectedRow.value) return '--'
const v = (selectedRow.value as any)[key]
if (key === 'start_time' || key === 'end_time') return formatReportDateTime(v)
if (key === 'stock_id') return formatReportCell(v)
if (
key === 'begin_total' ||
key === 'end_total' ||
key === 'inbound_total' ||
key === 'outbound_total' ||
key === 'store_id' ||
key === 'space_id'
) {
return formatReportNumber(v)
}
return formatReportCell(v)
}
function isWideKey(key: string) {
return detailValue(key).length > 80
}
function extractReportList(res: any): any[] {
if (!res) return []
if (res.data != null && Array.isArray(res.data.list)) return res.data.list
if (Array.isArray(res.list)) return res.list
return []
}
function withRowIds(rows: any[]) {
return rows.map((row, idx) => ({
...row,
__rid: `r-${idx}-${row.stock_id ?? ''}-${row.store_id ?? ''}-${row.item_code ?? ''}`
}))
}
function applyClientPage() {
const total = fullList.value.length
pagination.total = total
const start = (pagination.currentPage - 1) * pagination.pageSize
list.value = fullList.value.slice(start, start + pagination.pageSize)
}
const SORTABLE_FIELDS = new Set(['begin_total', 'inbound_total', 'outbound_total', 'end_total'])
function buildSortPayload(): StorageReportSearchBody['sort'] | undefined {
if (!SORTABLE_FIELDS.has(currentSort.prop)) return undefined
if (!currentSort.order) return undefined
const sortOrder = currentSort.order === 'ascending' ? 'ASC' : 'DESC'
return {
sortField: currentSort.prop as any,
sort_field: currentSort.prop as any,
sortOrder,
sort_order: sortOrder
}
}
function buildReportQueryPayload(): StorageReportSearchBody {
const where = normalizeScanConditionToReportWhere(currentConditionRaw.value)
if (selectedWarehouseId.value) {
where.warehouse_id = selectedWarehouseId.value
}
const sort = buildSortPayload()
const body: StorageReportSearchBody = {}
if (Object.keys(where).length > 0) {
body.where = where
}
if (sort) {
body.sort = sort
}
return body
}
async function handleExportWaybill() {
if (hasPendingExportTask()) {
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
resumeExportTaskFromStorage()
return
}
await submitExportTaskWithMode(buildReportQueryPayload() as Record<string, unknown>, 'waybill')
}
async function handleExportItem() {
if (hasPendingExportTask()) {
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
resumeExportTaskFromStorage()
return
}
await submitExportTaskWithMode(buildReportQueryPayload() as Record<string, unknown>, 'item')
}
function handleExportAction(action: string) {
if (action === 'handleExportItem') {
void handleExportItem()
return
}
void handleExportWaybill()
}
async function loadFilterData() {
try {
const presetRes: any = await indexApi.fastWhereTree('stock')
if (presetRes && presetRes.code === 200) {
presetTree.value = presetRes.presetTree || []
}
} catch (e) {
console.error('加载筛选配置失败', e)
}
}
function handleConditionChange(condition: any) {
currentConditionRaw.value = condition
pagination.currentPage = 1
loadData()
}
function handleWarehouseChange() {
pagination.currentPage = 1
loadData()
}
function handleConditionClear() {
currentConditionRaw.value = {}
pagination.currentPage = 1
loadData()
}
function handleConditionReset() {
currentConditionRaw.value = {}
pagination.currentPage = 1
if (scanBox.value?.reset) {
scanBox.value.reset()
} else if (scanBox.value?.clear) {
scanBox.value.clear()
}
loadData()
}
async function loadData() {
if (loading.value) return
loading.value = true
const started = Date.now()
selectedRid.value = null
const body = buildReportQueryPayload()
try {
const res: any = await searchStoreReport(
Object.keys(body).length > 0 ? body : undefined
)
if (res && (res.flag === 'success' || res.code === 200)) {
const raw = extractReportList(res)
fullList.value = withRowIds(raw)
columns.value = buildReportTableColumns(raw)
pagination.currentPage = 1
applyClientPage()
queryTime.value = Date.now() - started
} else {
fullList.value = []
list.value = []
columns.value = buildReportTableColumns([])
pagination.total = 0
ElMessage.error(res?.message || '查询失败')
}
} catch (e: any) {
fullList.value = []
list.value = []
columns.value = buildReportTableColumns([])
pagination.total = 0
ElMessage.error(e?.message || '请求失败')
} finally {
loading.value = false
}
}
function handleSortChange({ prop, order }: { prop: string; order: '' | 'ascending' | 'descending' | null }) {
currentSort.prop = prop || ''
currentSort.order = (order || '') as '' | 'ascending' | 'descending'
pagination.currentPage = 1
loadData()
}
function handlePageChange(page: number) {
pagination.currentPage = page
applyClientPage()
}
function handlePageSizeChange(size: number) {
pagination.pageSize = size
pagination.currentPage = 1
applyClientPage()
}
function handleRowClick(row: any) {
selectedRid.value = row?.__rid ?? null
}
onMounted(() => {
loadFilterData()
loadWarehouseList()
loadData()
resumeExportTaskFromStorage()
})
async function loadWarehouseList() {
try {
const res = await loadWarehouses() as any
const raw = res?.warehouses || res?.data?.list || res?.data || []
warehouseList.value = raw.map((item: any) => ({
warehouse_id: item.value ?? item.warehouse_id ?? item.id,
warehouse_name: item.label || item.warehouse_name || item.company_name || String(item.value ?? '')
}))
} catch {
// 仓库列表加载失败不影响主流程
}
}
</script>
<style lang="scss" scoped>
.storage-report-container {
display: flex;
width: 100%;
background-color: #f0f2f5;
.main-content {
flex: 1;
display: flex;
flex-direction: column;
padding: 10px;
overflow: hidden;
min-height: 0;
.toolbar {
padding: 5px;
border-bottom: 1px solid #ebeef5;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #fff;
.toolbar-left {
display: flex;
gap: 8px;
align-items: center;
flex-wrap: wrap;
}
.toolbar-title {
font-size: 14px;
font-weight: 500;
color: #303133;
margin-left: 4px;
}
}
.filter-hint {
margin: 6px 0 0;
font-size: 12px;
color: #909399;
line-height: 1.5;
code {
font-size: 12px;
padding: 0 4px;
background: #f4f4f5;
border-radius: 2px;
}
}
.split-stack {
flex: 1 1 auto;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
margin-top: 8px;
}
.pane-resizer {
flex: 0 0 6px;
min-height: 6px;
background: #e4e7ed;
cursor: row-resize;
flex-shrink: 0;
position: relative;
z-index: 2;
&:hover {
background: #dcdfe6;
}
}
.upper-wrapper {
overflow: hidden;
}
.upper-wrapper :deep(.upper-table-container) {
height: 100%;
display: flex;
flex-direction: column;
}
.upper-wrapper :deep(.upper-table-container) :deep(.table-container) {
height: auto !important;
flex: 1 1 auto;
min-height: 0;
overflow: hidden;
}
.upper-wrapper :deep(.el-table__header-wrapper) {
position: sticky;
top: 0;
z-index: 3;
background: #fff;
}
.upper-wrapper :deep(.el-table__body-wrapper) {
overflow: auto;
min-height: 0;
}
.lower-level {
display: flex;
flex-direction: column;
border-top: 1px solid #ebeef5;
overflow: hidden;
background-color: #fff;
.detail-header {
padding: 10px 12px;
border-bottom: 1px solid #ebeef5;
background: #fafafa;
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 8px;
}
.detail-title {
font-size: 14px;
font-weight: 500;
color: #303133;
}
.detail-sub {
font-size: 12px;
color: #909399;
code {
font-size: 12px;
padding: 0 4px;
background: #f4f4f5;
border-radius: 2px;
}
}
.detail-container {
flex: 1;
overflow: auto;
padding: 10px;
:deep(.el-descriptions__body) {
background: #fff;
}
:deep(.el-descriptions-item__cell) {
padding: 8px 12px;
}
}
}
.no-selection {
display: flex;
align-items: center;
justify-content: center;
color: #909399;
background-color: #fff;
border: 1px dashed #dcdfe6;
.empty-tip {
text-align: center;
font-size: 14px;
}
}
.empty-tip {
text-align: center;
font-size: 13px;
}
}
}
</style>

View File

@ -74,6 +74,10 @@
{{ row.auth_status_label || getAuthStatusLabel(row.auth_status) }}
</el-tag>
</template>
<template #column-needs_my_confirm="{ row }">
<el-tag v-if="row.needs_my_confirm" size="small" type="warning" effect="dark">待我确认</el-tag>
<span v-else class="text-muted">—</span>
</template>
<template #column-warehouse_use_status="{ row }">
<el-tag size="small" :type="row.warehouse_use_status === 1 ? 'success' : 'info'" effect="light">
{{ row.warehouse_use_status === 1 ? '启用' : '禁用' }}
@ -108,6 +112,13 @@
{{ formatDate(row.apply_time) }}
</template>
<template #column-actions="{ row }">
<el-button
v-if="row.needs_my_confirm"
size="small"
type="warning"
link
@click.stop="handleConfirmSign(row)"
>确认签约</el-button>
<el-button
size="small"
type="primary"
@ -898,7 +909,7 @@ import { storeWarehouseList, storeWarehouseUnbind,
storeWarehouseRename, storeWarehouseGetPolicyConfig, storeWarehouseGetPolicyConfigFields,
storeWarehouseSavePolicyConfig, saveApiConfig, storeWarehouseDeleteQimenConfig,
storeWarehouseAdjustPrintQuantity, storeWarehouseQueryPrintQuantityLogs, listApiConfig,
storeWarehouseOpenAccount
storeWarehouseOpenAccount, storeWarehouseConfirmSign
} from '@/api/storeWarehouse.store/storeWarehouse'
import { listInterfaceTypes, getExpressList, getPlatformList, getQimenAppList } from '@/api/index/index'
import ScanBox from '@/components/ScanBox/index.vue'
@ -1313,6 +1324,33 @@ function formatDate(dateStr: string | null | undefined) {
return new Date(dateStr).toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-')
}
// ─── 确认签约 ────────────────────────────────────────────────────────────────
async function handleConfirmSign(row: any) {
try {
await ElMessageBox.confirm(
`确认与「${row.store_name || row.remask || row.counterparty_name}」的签约关系?`,
'确认签约',
{ type: 'warning' }
)
} catch {
return
}
try {
const res = await storeWarehouseConfirmSign({ id: row.id }) as any
if (res?.flag === 'success' || res?.code === 200) {
ElMessage.success('签约已确认')
loadList()
if (selectedRow.value && selectedRow.value.id === row.id) {
selectedRow.value.needs_my_confirm = false
}
} else {
ElMessage.error(res?.message || '确认签约失败')
}
} catch {
ElMessage.error('确认签约失败')
}
}
// ─── 禁用/启用 ────────────────────────────────────────────────────────────────
async function handleUnbind(row: any, targetStatus: number) {
const actionLabel = targetStatus === 0 ? '禁用' : '启用'
@ -2227,6 +2265,10 @@ onMounted(loadList)
font-size: 12px;
}
.text-muted {
color: #c0c4cc;
}
.text-warning {
color: #e6a23c;
font-weight: 600;

View File

@ -175,11 +175,12 @@ export const columns = [
{ prop: 'store_id', label: '货主ID', width: 90 },
{ prop: 'counterparty_name', label: '货主', minWidth: 120 },
{ prop: 'auth_status', label: '签约状态', width: 100 },
{ prop: 'needs_my_confirm', label: '待确认', width: 90 },
{ prop: 'warehouse_use_status', label: '使用状态', width: 90 },
{ prop: 'print_quantity', label: '面单余额', width: 100 },
{ prop: 'has_qimen_config', label: '奇门配置', width: 100 },
{ prop: 'apply_time', label: '申请时间', width: 160 },
{ prop: 'actions', label: '操作', width: 380, fixed: 'right' }
{ prop: 'actions', label: '操作', width: 460, fixed: 'right' }
]
export const availableFields = [