feat: fix stocktake deletion bug, and add pagination, search, sorting to stocktake lists

This commit is contained in:
DXC
2026-03-19 16:21:09 +08:00
parent 5510bae3b2
commit 53c198f363
4 changed files with 255 additions and 50 deletions

View File

@ -211,57 +211,50 @@
destroy-on-close
class="inventory-drawer"
>
<div class="drawer-layout">
<div class="drawer-layout" v-loading="listLoading">
<div class="search-bar">
<el-input v-model="searchKeyword" placeholder="搜索 SKU/名称..." :prefix-icon="Search" clearable />
<el-select v-model="filterType" placeholder="状态" style="width: 100px; margin-left: 8px;">
<el-option label="全部" value="all" />
<el-option label="已盘" value="scanned" />
<el-option label="未盘" value="missing" />
</el-select>
<el-input v-model="listKeyword" placeholder="搜索 SKU..." :prefix-icon="Search" clearable @keyup.enter="handleListSearch" @clear="handleListSearch" style="width: 240px" />
<el-button type="primary" @click="handleListSearch">搜索</el-button>
</div>
<div class="table-container">
<el-table
:data="filteredList"
:data="listData"
height="100%"
stripe
border
row-key="uniqueKey"
row-key="id"
style="width: 100%"
>
<el-table-column prop="name" label="名称" min-width="90" show-overflow-tooltip />
<el-table-column prop="sku" label="SKU" width="110" show-overflow-tooltip />
<el-table-column label="序列号/批次" min-width="150" show-overflow-tooltip>
<el-table-column prop="sku" label="SKU" width="140" show-overflow-tooltip />
<el-table-column prop="material_name" label="名称" min-width="120" show-overflow-tooltip />
<el-table-column prop="spec_model" label="规格" width="120" show-overflow-tooltip />
<el-table-column prop="stock_qty" label="账面数" width="80" align="center" />
<el-table-column prop="quantity" label="实盘数" width="80" align="center" />
<el-table-column label="差异" width="80" align="center">
<template #default="{ row }">
<span>{{ row.serial_number || row.batch_number || row.batch_no || '-' }}</span>
</template>
</el-table-column>
<el-table-column label="实盘" width="60" align="center">
<template #default="scope">
<span v-if="scope.row.scanned" class="actual-qty-text">{{ scope.row.qty_actual }}</span>
<span v-else class="text-gray">-</span>
</template>
</el-table-column>
<el-table-column label="操作" width="90" align="center" fixed="right">
<template #default="scope">
<el-button
v-if="userStore.hasPermission('inventory_stocktake:operation')"
type="primary"
link
icon="Edit"
@click.stop="openQtyDialog(scope.row)"
>
修改
</el-button>
<span :style="{ color: row.diff_qty > 0 ? '#67C23A' : row.diff_qty < 0 ? '#F56C6C' : '#909399' }">
{{ row.diff_qty > 0 ? '+' : '' }}{{ row.diff_qty || 0 }}
</span>
</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip />
</el-table>
</div>
<!-- 分页 -->
<div class="drawer-footer" style="display: flex; justify-content: flex-end; padding: 10px;">
<el-pagination
v-model:current-page="listPage"
v-model:page-size="listLimit"
:page-sizes="[20, 50, 100, 200]"
:total="listTotal"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleListLimitChange"
@current-change="handleListPageChange"
/>
</div>
<div class="drawer-footer">
<el-button @click="showList = false" style="width: 100%">关闭列表</el-button>
</div>
@ -443,6 +436,14 @@ const showVarianceDialog = ref(false)
// ★ 新增: 差异列表搜索
const searchSku = ref('')
// ★ 新增: 盘点清单弹窗分页
const listPage = ref(1)
const listLimit = ref(20)
const listTotal = ref(0)
const listKeyword = ref('')
const listLoading = ref(false)
const listData = ref<any[]>([])
// ★ 新增: 盘点开始防呆倒计时
const countdown = ref(0)
let countdownTimer: any = null
@ -606,9 +607,10 @@ const checkServerDraft = async () => {
const res: any = await request({
url: '/v1/inbound/stock/draft/list',
method: 'get',
params: {}
params: { page: 1, limit: 1 } // 只获取一条记录来获取总数
})
serverDraftCount.value = (res && res.length) || 0
// 后端返回格式已改为 { items: [], total: number }
serverDraftCount.value = (res && res.total) || 0
} catch (e) {}
}
@ -670,12 +672,15 @@ const resumeSession = async () => {
btnLoading.value = true
try {
// 获取最新的会话(后端已移除 is_finished 字段)
const drafts: any = await request({
// 后端返回格式已改为 { items: [], total: number }
const res: any = await request({
url: '/v1/inbound/stock/draft/list',
method: 'get',
params: {}
params: { page: 1, limit: 10000 } // 获取足够多的数据
})
const drafts = res && res.items ? res.items : []
if (!drafts || drafts.length === 0) {
ElMessage.warning('没有找到未完成的盘点记录')
return
@ -981,7 +986,55 @@ const filteredVarianceList = computed(() => {
)
})
const openInventoryList = () => { showList.value = true }
// ★ 新增: 获取盘点清单数据(后端分页)
const fetchInventoryList = async () => {
listLoading.value = true
try {
const res: any = await request({
url: '/v1/inbound/stock/draft/list',
method: 'get',
params: {
page: listPage.value,
limit: listLimit.value,
keyword: listKeyword.value
}
})
if (res) {
listData.value = res.items || []
listTotal.value = res.total || 0
}
} catch (e) {
ElMessage.error('获取盘点清单失败')
} finally {
listLoading.value = false
}
}
// ★ 修改: 打开盘点清单弹窗
const openInventoryList = async () => {
showList.value = true
listPage.value = 1
listKeyword.value = ''
await fetchInventoryList()
}
// ★ 新增: 盘点清单搜索
const handleListSearch = () => {
listPage.value = 1
fetchInventoryList()
}
// ★ 新增: 盘点清单分页变化
const handleListPageChange = (page: number) => {
listPage.value = page
fetchInventoryList()
}
const handleListLimitChange = (limit: number) => {
listLimit.value = limit
listPage.value = 1
fetchInventoryList()
}
// ★ 修改:结束盘点按钮直接调用 finishStocktake跳过二次确认弹窗
const openFinishDialog = () => {