811 lines
26 KiB
Vue
811 lines
26 KiB
Vue
<!--
|
||
CheckStockPickerDialog — 添加盘点明细
|
||
|
||
两种模式(由来源盘点单的 type 决定):
|
||
- 商品类(type=store/goods):从 storage.inventory.list 选商品 → stock.check.addDetail 传 stock_ids
|
||
- 库位类(type=all/location):从库位列表(index.searchSpace)勾选库位 →
|
||
· 已勾选库位 → stock.check.addLocationDetail 传 location_ids(库位ID直查,不解析编码)
|
||
· 未勾选但手填了库位编码 → stock.check.addDetail 传 locations(兼容通道)
|
||
· 未勾选且未填且 type=all → stock.check.addDetail 不传库位,由后端自动拉取全仓启用库位
|
||
|
||
无效项提示:addLocationDetail → invalid_location_ids;addDetail → invalid_stock_ids / invalid_locations。
|
||
仅 created(新建)/ rejected(驳回)状态可添加,后端会校验。
|
||
-->
|
||
<template>
|
||
<el-dialog
|
||
:model-value="visible"
|
||
:title="dialogTitle"
|
||
width="min(1080px, 95vw)"
|
||
align-center
|
||
:close-on-click-modal="false"
|
||
@update:model-value="handleVisibleChange"
|
||
@closed="handleClosed"
|
||
>
|
||
<div class="picker-body">
|
||
<!-- ===== 商品类任务:从库存明细挑选商品 → stock_ids ===== -->
|
||
<template v-if="!isLocationMode">
|
||
<!-- 筛选行 -->
|
||
<div class="picker-filters">
|
||
<el-input
|
||
v-model="filters.keyword"
|
||
size="small"
|
||
clearable
|
||
placeholder="商品编码 / 名称 / 条码"
|
||
class="filter-item filter-item--keyword"
|
||
@keyup.enter="handleSearch"
|
||
/>
|
||
<el-input
|
||
v-model="filters.batch_no"
|
||
size="small"
|
||
clearable
|
||
placeholder="批次号"
|
||
class="filter-item"
|
||
@keyup.enter="handleSearch"
|
||
/>
|
||
<el-button size="small" type="primary" :loading="loading" @click="handleSearch">
|
||
查询
|
||
</el-button>
|
||
<el-button size="small" @click="handleResetFilters">重置</el-button>
|
||
</div>
|
||
|
||
<!-- 库存列表 -->
|
||
<div ref="tableHostRef" class="table-host">
|
||
<el-table
|
||
ref="tableRef"
|
||
v-loading="loading"
|
||
:data="rows"
|
||
:row-key="(row: any) => row._key"
|
||
border
|
||
stripe
|
||
size="small"
|
||
:height="tableHeight"
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<el-table-column type="selection" width="45" :reserve-selection="true" />
|
||
<el-table-column prop="item_code" label="商品编码" min-width="130" show-overflow-tooltip />
|
||
<el-table-column prop="item_name" label="商品名称" min-width="160" show-overflow-tooltip />
|
||
<el-table-column prop="spec" label="规格" min-width="110" show-overflow-tooltip />
|
||
<el-table-column prop="store_name" label="货主" min-width="110" show-overflow-tooltip />
|
||
<el-table-column prop="space_code" label="库位" min-width="120" show-overflow-tooltip />
|
||
<el-table-column prop="batch_no" label="批次号" min-width="110" show-overflow-tooltip />
|
||
<el-table-column prop="quantity" label="库存数量" width="100" align="center" />
|
||
<el-table-column prop="available_quantity" label="可用数量" width="100" align="center" />
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无库存数据</div>
|
||
</template>
|
||
</el-table>
|
||
</div>
|
||
|
||
<!-- 分页 -->
|
||
<div class="pagination-container">
|
||
<el-pagination
|
||
v-model:current-page="pagination.page"
|
||
v-model:page-size="pagination.pageSize"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
:total="pagination.total"
|
||
layout="total, sizes, prev, pager, next"
|
||
background
|
||
size="small"
|
||
@current-change="loadRows"
|
||
@size-change="handleSizeChange"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- ===== 库位类任务:勾选库位(location_ids)→ addLocationDetail ===== -->
|
||
<template v-else>
|
||
<el-alert
|
||
type="info"
|
||
:closable="false"
|
||
show-icon
|
||
:title="locationAlertText"
|
||
/>
|
||
|
||
<!-- 库位筛选 -->
|
||
<div class="picker-filters">
|
||
<el-input
|
||
v-model="spaceFilters.keyword"
|
||
size="small"
|
||
clearable
|
||
placeholder="库位编码 / 自定义名称 / 自定义编码"
|
||
class="filter-item filter-item--keyword"
|
||
@keyup.enter="handleSpaceSearch"
|
||
/>
|
||
<el-button size="small" type="primary" :loading="spaceLoading" @click="handleSpaceSearch">
|
||
查询
|
||
</el-button>
|
||
<el-button size="small" @click="handleSpaceReset">重置</el-button>
|
||
</div>
|
||
|
||
<!-- 库位列表(多选,跨页保留勾选) -->
|
||
<div ref="spaceTableHostRef" class="table-host">
|
||
<el-table
|
||
ref="spaceTableRef"
|
||
v-loading="spaceLoading"
|
||
:data="spaceRows"
|
||
:row-key="(row: any) => row.id"
|
||
border
|
||
stripe
|
||
size="small"
|
||
:height="tableHeight"
|
||
@selection-change="handleSpaceSelectionChange"
|
||
>
|
||
<el-table-column type="selection" width="45" :reserve-selection="true" />
|
||
<el-table-column prop="id" label="库位ID" width="90" align="center" />
|
||
<el-table-column prop="custom_name" label="自定义名称" min-width="140" show-overflow-tooltip />
|
||
<el-table-column prop="custom_code" label="自定义编码" min-width="140" show-overflow-tooltip />
|
||
<el-table-column prop="space_code" label="库位编码" min-width="150" show-overflow-tooltip />
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无库位数据</div>
|
||
</template>
|
||
</el-table>
|
||
</div>
|
||
|
||
<!-- 分页 -->
|
||
<div class="pagination-container">
|
||
<el-pagination
|
||
v-model:current-page="spacePagination.page"
|
||
v-model:page-size="spacePagination.pageSize"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
:total="spacePagination.total"
|
||
layout="total, sizes, prev, pager, next"
|
||
background
|
||
size="small"
|
||
@current-change="loadSpaceRows"
|
||
@size-change="handleSpaceSizeChange"
|
||
/>
|
||
</div>
|
||
|
||
<!-- 已勾选库位 -->
|
||
<div class="location-preview">
|
||
<span class="stat-text">已选 {{ selectedLocationIds.length }} 个库位</span>
|
||
<el-tag
|
||
v-for="row in selectedSpaceRows.slice(0, 50)"
|
||
:key="row.id"
|
||
size="small"
|
||
closable
|
||
class="location-tag"
|
||
@close="removeSpaceRow(row)"
|
||
>
|
||
{{ spaceLabel(row) }}
|
||
</el-tag>
|
||
<el-button
|
||
v-if="selectedSpaceRows.length"
|
||
link
|
||
size="small"
|
||
type="danger"
|
||
@click="clearSpaceSelection"
|
||
>
|
||
清空
|
||
</el-button>
|
||
<span v-if="selectedSpaceRows.length > 50" class="stat-text">
|
||
…等共 {{ selectedSpaceRows.length }} 个
|
||
</span>
|
||
</div>
|
||
|
||
<!-- 兼容通道:手动输入库位编码(走 addDetail 的 locations) -->
|
||
<el-collapse class="location-manual">
|
||
<el-collapse-item name="manual">
|
||
<template #title>
|
||
<span class="collapse-title">手动输入库位编码(可选 · 未勾选库位时生效)</span>
|
||
</template>
|
||
<el-input
|
||
v-model="locationText"
|
||
type="textarea"
|
||
:rows="4"
|
||
resize="none"
|
||
placeholder="每行一个库位编码,也可用逗号 / 空格分隔,如:A-01-01"
|
||
/>
|
||
<div class="stat-text">已识别 {{ locationCodes.length }} 个库位编码</div>
|
||
</el-collapse-item>
|
||
</el-collapse>
|
||
</template>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<div class="dialog-footer">
|
||
<span class="selected-tip">{{ submitChannelTip }}</span>
|
||
<div class="footer-buttons">
|
||
<el-button size="small" @click="handleVisibleChange(false)">取消</el-button>
|
||
<el-button
|
||
size="small"
|
||
type="primary"
|
||
:loading="submitting"
|
||
:disabled="!canSubmit"
|
||
@click="handleSubmit"
|
||
>
|
||
确认添加
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, nextTick, reactive, ref, watch } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { useResizeObserver } from '@vueuse/core'
|
||
import { getInventoryList } from '@/api/storage.inventory/inventory'
|
||
import * as indexApi from '@/api/index/index'
|
||
import {
|
||
stockCheckAddDetail,
|
||
stockCheckAddLocationDetail,
|
||
type StockCheckAddDetailParams
|
||
} from '@/api/stock.check/stock.check'
|
||
import { isCheckApiSuccess, isLocationScopeType } from '../config/template-config'
|
||
|
||
defineOptions({ name: 'CheckStockPickerDialog' })
|
||
|
||
const props = defineProps<{
|
||
visible: boolean
|
||
/** 目标盘点单ID */
|
||
taskId?: number
|
||
/** 目标盘点单号(展示用) */
|
||
taskTitle?: string
|
||
/** 目标盘点单范围类型(all/location=库位类 → 添加库位;store/goods=商品类 → 添加商品) */
|
||
taskType?: string
|
||
}>()
|
||
|
||
const emit = defineEmits<{
|
||
(e: 'update:visible', value: boolean): void
|
||
/** 添加成功 */
|
||
(e: 'success', result: { added: number; skipped: number }): void
|
||
}>()
|
||
|
||
/** 库位类任务(明细为库位行)→ 走库位编码输入模式 */
|
||
const isLocationMode = computed(() => isLocationScopeType(props.taskType))
|
||
|
||
const dialogTitle = computed(() => {
|
||
const suffix = props.taskTitle ? ` — ${props.taskTitle}` : ''
|
||
return isLocationMode.value ? `添加盘点库位${suffix}` : `添加盘点商品${suffix}`
|
||
})
|
||
|
||
// ===== 库位模式:库位选择(多选,主通道) =====
|
||
const spaceFilters = reactive({ keyword: '' })
|
||
const spaceRows = ref<Record<string, any>[]>([])
|
||
const spaceLoading = ref(false)
|
||
const spaceTableRef = ref<any>(null)
|
||
const spaceTableHostRef = ref<HTMLElement | null>(null)
|
||
const selectedSpaceRows = ref<Record<string, any>[]>([])
|
||
const spacePagination = reactive({ page: 1, pageSize: 20, total: 0 })
|
||
|
||
/** 已勾选库位ID(去重,>0) */
|
||
const selectedLocationIds = computed<number[]>(() => {
|
||
const ids = selectedSpaceRows.value
|
||
.map((row) => Number(row.id ?? row.space_id))
|
||
.filter((id) => Number.isFinite(id) && id > 0)
|
||
return [...new Set(ids)]
|
||
})
|
||
|
||
/** 库位展示名:自定义名称 → 自定义编码 → 库位编码 → ID */
|
||
function spaceLabel(row: Record<string, any>): string {
|
||
return (
|
||
toText(row?.custom_name) ||
|
||
toText(row?.custom_code) ||
|
||
toText(row?.space_code) ||
|
||
`ID ${row?.id ?? ''}`
|
||
)
|
||
}
|
||
|
||
// ===== 库位模式:手动输入库位编码(次选,走 addDetail 的 locations) =====
|
||
/** 库位编码输入(每行一个,或逗号/空格/顿号分隔) */
|
||
const locationText = ref('')
|
||
|
||
/** 解析后的库位编码(去重去空) */
|
||
const locationCodes = computed<string[]>(() => {
|
||
const parts = locationText.value.split(/[\s,,、;;]+/)
|
||
return [...new Set(parts.map((s) => s.trim()).filter(Boolean))]
|
||
})
|
||
|
||
const locationAlertText = computed(() =>
|
||
props.taskType === 'all'
|
||
? '按库位盘点(默认全仓):勾选库位则按库位添加;一个都不勾选时,由后端自动拉取全仓库启用库位生成盘点范围。'
|
||
: '按库位盘点:请从下方列表勾选要盘点的库位(后端按库位ID直接入库,无需担心编码写错)。'
|
||
)
|
||
|
||
/** 库位模式:勾了库位 / 填了库位编码 / all 类型(允许不选=全仓) */
|
||
const canSubmit = computed(() => {
|
||
if (isLocationMode.value) {
|
||
return (
|
||
selectedLocationIds.value.length > 0 || locationCodes.value.length > 0 || props.taskType === 'all'
|
||
)
|
||
}
|
||
return selectedStockIds.value.length > 0
|
||
})
|
||
|
||
/** 底部提示:当前会走哪条提交通道 */
|
||
const submitChannelTip = computed(() => {
|
||
if (!isLocationMode.value) {
|
||
return `已选 ${selectedRows.value.length} 行 · 去重后 ${selectedStockIds.value.length} 个商品`
|
||
}
|
||
if (selectedLocationIds.value.length > 0) {
|
||
return `已选 ${selectedLocationIds.value.length} 个库位 · 按库位ID添加`
|
||
}
|
||
if (locationCodes.value.length > 0) {
|
||
return `未勾选库位 · 将按手动输入的 ${locationCodes.value.length} 个库位编码添加`
|
||
}
|
||
return props.taskType === 'all'
|
||
? '未选库位 · 将由后端生成全仓库盘点范围'
|
||
: '请至少勾选一个库位'
|
||
})
|
||
|
||
const filters = reactive({ keyword: '', batch_no: '' })
|
||
const rows = ref<Record<string, any>[]>([])
|
||
const loading = ref(false)
|
||
const submitting = ref(false)
|
||
const selectedRows = ref<Record<string, any>[]>([])
|
||
|
||
const pagination = reactive({ page: 1, pageSize: 20, total: 0 })
|
||
|
||
const tableRef = ref<any>(null)
|
||
const tableHostRef = ref<HTMLElement | null>(null)
|
||
const tableHeight = ref(360)
|
||
|
||
useResizeObserver(tableHostRef, (entries) => {
|
||
const h = entries[0]?.contentRect.height ?? 0
|
||
if (h >= 120) tableHeight.value = Math.floor(h)
|
||
})
|
||
|
||
// 库位列表与商品列表共用同一个自适应高度(同一时刻只渲染一个)
|
||
useResizeObserver(spaceTableHostRef, (entries) => {
|
||
const h = entries[0]?.contentRect.height ?? 0
|
||
if (h >= 120) tableHeight.value = Math.floor(h)
|
||
})
|
||
|
||
/** 提交前按 stock_id 去重 */
|
||
const selectedStockIds = computed(() => {
|
||
const ids = selectedRows.value
|
||
.map((row) => Number(row.stock_id))
|
||
.filter((id) => Number.isFinite(id) && id > 0)
|
||
return [...new Set(ids)]
|
||
})
|
||
|
||
function handleVisibleChange(value: boolean) {
|
||
emit('update:visible', value)
|
||
}
|
||
|
||
function handleClosed() {
|
||
tableRef.value?.clearSelection?.()
|
||
spaceTableRef.value?.clearSelection?.()
|
||
selectedRows.value = []
|
||
selectedSpaceRows.value = []
|
||
rows.value = []
|
||
spaceRows.value = []
|
||
spacePagination.page = 1
|
||
spacePagination.total = 0
|
||
spaceFilters.keyword = ''
|
||
locationText.value = ''
|
||
submitting.value = false
|
||
}
|
||
|
||
/** 对象/数组属性统一转文本 */
|
||
function toText(value: any): string {
|
||
if (value === undefined || value === null || value === '') return ''
|
||
if (typeof value === 'string') return value
|
||
if (Array.isArray(value)) return value.map((v) => toText(v)).filter(Boolean).join('/')
|
||
if (typeof value === 'object') {
|
||
const picked = value.name ?? value.value ?? value.label ?? value.sku_property
|
||
return picked ? toText(picked) : ''
|
||
}
|
||
return String(value)
|
||
}
|
||
|
||
function mapRow(item: any, index: number): Record<string, any> {
|
||
const stockId = Number(item?.stock_id)
|
||
const spaceId = item?.space_id ?? item?.space?.id ?? ''
|
||
const batchNo = toText(item?.batch_no)
|
||
return {
|
||
_key: `${stockId}-${spaceId}-${batchNo}-${index}`,
|
||
stock_id: stockId,
|
||
item_code: toText(item?.stock?.item_code),
|
||
item_name: toText(item?.stock?.item_name),
|
||
spec: toText(item?.stock?.sku_property),
|
||
store_name: toText(item?.store_name ?? item?.stock?.store_name),
|
||
space_code: toText(item?.space?.space_code),
|
||
batch_no: batchNo,
|
||
quantity: item?.quantity ?? '—',
|
||
available_quantity: item?.available_quantity ?? '—'
|
||
}
|
||
}
|
||
|
||
async function loadRows() {
|
||
loading.value = true
|
||
try {
|
||
const keyword = filters.keyword.trim()
|
||
const batchNo = filters.batch_no.trim()
|
||
const res: any = await getInventoryList({
|
||
where: {
|
||
// stock_query 为虚拟筛选字段:按商品编码/名称/条码/SKU ID 模糊匹配
|
||
...(keyword ? { stock_query: { operator: 'like', value: keyword } } : {}),
|
||
...(batchNo ? { batch_no: batchNo } : {})
|
||
},
|
||
pagination: { page: pagination.page, pageSize: pagination.pageSize },
|
||
group_by_batch: false
|
||
})
|
||
if (!isCheckApiSuccess(res)) {
|
||
throw new Error(res?.message || '查询库存失败')
|
||
}
|
||
const data = res.data ?? res
|
||
const rawList: any[] = Array.isArray(data.list) ? data.list : []
|
||
rows.value = rawList
|
||
.map((item, index) => mapRow(item, index))
|
||
.filter((row) => Number.isFinite(row.stock_id) && row.stock_id > 0)
|
||
pagination.total = Number(data.total ?? data.pagination?.total ?? rows.value.length) || 0
|
||
nextTick(() => tableRef.value?.setScrollTop?.(0))
|
||
} catch (e: any) {
|
||
console.error('[stockcheck] 查询库存失败', e)
|
||
ElMessage.error(e?.message || '查询库存失败')
|
||
rows.value = []
|
||
pagination.total = 0
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function handleSearch() {
|
||
pagination.page = 1
|
||
loadRows()
|
||
}
|
||
|
||
function handleResetFilters() {
|
||
filters.keyword = ''
|
||
filters.batch_no = ''
|
||
pagination.page = 1
|
||
loadRows()
|
||
}
|
||
|
||
function handleSizeChange() {
|
||
pagination.page = 1
|
||
loadRows()
|
||
}
|
||
|
||
function handleSelectionChange(selection: Record<string, any>[]) {
|
||
selectedRows.value = selection
|
||
}
|
||
|
||
// ===== 库位列表(index.searchSpace,仅取库位ID/编码/名称) =====
|
||
async function loadSpaceRows() {
|
||
spaceLoading.value = true
|
||
try {
|
||
const res: any = await indexApi.searchSpace({
|
||
keyword: spaceFilters.keyword.trim(),
|
||
page: spacePagination.page,
|
||
pageSize: spacePagination.pageSize
|
||
})
|
||
const data = res?.data ?? res
|
||
const rawList: any[] = Array.isArray(data?.list) ? data.list : Array.isArray(data) ? data : []
|
||
spaceRows.value = rawList
|
||
.map((item) => ({
|
||
...item,
|
||
id: Number(item?.id ?? item?.space_id),
|
||
custom_name: toText(item?.custom_name ?? item?.customName),
|
||
custom_code: toText(item?.custom_code ?? item?.customCode ?? item?.custom_barcode),
|
||
space_code: toText(item?.space_code)
|
||
}))
|
||
.filter((row) => Number.isFinite(row.id) && row.id > 0)
|
||
spacePagination.total =
|
||
Number(data?.pagination?.total ?? data?.total ?? spaceRows.value.length) || 0
|
||
nextTick(() => spaceTableRef.value?.setScrollTop?.(0))
|
||
} catch (e: any) {
|
||
console.error('[stockcheck] 查询库位失败', e)
|
||
ElMessage.error(e?.message || '查询库位失败')
|
||
spaceRows.value = []
|
||
spacePagination.total = 0
|
||
} finally {
|
||
spaceLoading.value = false
|
||
}
|
||
}
|
||
|
||
function handleSpaceSearch() {
|
||
spacePagination.page = 1
|
||
loadSpaceRows()
|
||
}
|
||
|
||
function handleSpaceReset() {
|
||
spaceFilters.keyword = ''
|
||
spacePagination.page = 1
|
||
loadSpaceRows()
|
||
}
|
||
|
||
function handleSpaceSizeChange() {
|
||
spacePagination.page = 1
|
||
loadSpaceRows()
|
||
}
|
||
|
||
function handleSpaceSelectionChange(selection: Record<string, any>[]) {
|
||
selectedSpaceRows.value = selection
|
||
}
|
||
|
||
/** 移除单个已选库位(同时取消表格勾选,避免与 reserve-selection 不一致) */
|
||
function removeSpaceRow(row: Record<string, any>) {
|
||
spaceTableRef.value?.toggleRowSelection?.(row, false)
|
||
selectedSpaceRows.value = selectedSpaceRows.value.filter(
|
||
(item) => String(item.id) !== String(row.id)
|
||
)
|
||
}
|
||
|
||
function clearSpaceSelection() {
|
||
spaceTableRef.value?.clearSelection?.()
|
||
selectedSpaceRows.value = []
|
||
}
|
||
|
||
/** 数组 → 去重后的有效数字列表 */
|
||
function toNumberList(value: unknown): number[] {
|
||
if (!Array.isArray(value)) return []
|
||
return value.map((v) => Number(v)).filter((v) => Number.isFinite(v))
|
||
}
|
||
|
||
/** 数组 → 去空后的字符串列表 */
|
||
function toStringList(value: unknown): string[] {
|
||
if (!Array.isArray(value)) return []
|
||
return value.filter((v) => v !== undefined && v !== null && v !== '').map((v) => String(v))
|
||
}
|
||
|
||
/**
|
||
* 统一处理「添加明细」响应:校验成功码、提取 added/skipped、汇总无效项提示。
|
||
* 失败时抛错(由调用方 catch 提示)。
|
||
*/
|
||
function resolveAddResult(
|
||
res: any,
|
||
invalid: { ids?: number[]; codes?: string[]; stocks?: number[] } = {}
|
||
): { added: number; skipped: number } {
|
||
if (!isCheckApiSuccess(res)) {
|
||
throw new Error(res?.message || '添加盘点明细失败')
|
||
}
|
||
const data = res?.data ?? res
|
||
const added = Number(data?.added ?? 0)
|
||
const skipped = Number(data?.skipped ?? 0)
|
||
const parts = [`新增 ${added} 项`]
|
||
if (skipped) parts.push(`跳过已存在 ${skipped} 项`)
|
||
if (invalid.ids?.length) parts.push(`无效库位 ${invalid.ids.length} 个`)
|
||
if (invalid.codes?.length) parts.push(`无效库位编码 ${invalid.codes.length} 个`)
|
||
if (invalid.stocks?.length) parts.push(`无效商品 ${invalid.stocks.length} 个`)
|
||
if (invalid.ids?.length || invalid.codes?.length || invalid.stocks?.length) {
|
||
ElMessage.warning(parts.join(','))
|
||
} else {
|
||
ElMessage.success(parts.join(','))
|
||
}
|
||
return { added, skipped }
|
||
}
|
||
|
||
async function handleSubmit() {
|
||
const taskId = Number(props.taskId)
|
||
if (!Number.isFinite(taskId) || taskId <= 0) {
|
||
ElMessage.error('缺少盘点单ID,无法添加明细')
|
||
return
|
||
}
|
||
if (isLocationMode.value) {
|
||
await submitLocationRows(taskId)
|
||
return
|
||
}
|
||
await submitGoodsRows(taskId)
|
||
}
|
||
|
||
/**
|
||
* 库位类任务:三条通道(优先级从高到低)
|
||
* ① 已勾选库位 → stock.check.addLocationDetail(库位ID直查,不解析编码)
|
||
* ② 未勾选但填了库位编码 → stock.check.addDetail(locations 兼容通道)
|
||
* ③ type=all 且都未填 → stock.check.addDetail 不传库位,后端自动生成全仓盘点范围
|
||
*/
|
||
async function submitLocationRows(taskId: number) {
|
||
const locationIds = selectedLocationIds.value
|
||
if (locationIds.length > 0) {
|
||
submitting.value = true
|
||
try {
|
||
const res: any = await stockCheckAddLocationDetail({ id: taskId, location_ids: locationIds })
|
||
const data = res?.data ?? res
|
||
const result = resolveAddResult(res, { ids: toNumberList(data?.invalid_location_ids) })
|
||
emit('update:visible', false)
|
||
emit('success', result)
|
||
} catch (e: any) {
|
||
console.error('[stockcheck] 添加盘点库位失败', e)
|
||
ElMessage.error(e?.message || '添加盘点库位失败')
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
return
|
||
}
|
||
|
||
const payload: StockCheckAddDetailParams = { id: taskId }
|
||
if (locationCodes.value.length > 0) {
|
||
payload.locations = locationCodes.value
|
||
} else if (props.taskType === 'all') {
|
||
// type=all:不传库位,由后端自动拉取全仓启用库位
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
'未选择库位,将由后端自动拉取全仓库启用库位生成盘点范围,确定继续?',
|
||
'添加盘点库位',
|
||
{ confirmButtonText: '确定继续', cancelButtonText: '取消', type: 'warning' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
} else {
|
||
ElMessage.warning('请至少选择一个库位')
|
||
return
|
||
}
|
||
|
||
submitting.value = true
|
||
try {
|
||
const res: any = await stockCheckAddDetail(payload)
|
||
const data = res?.data ?? res
|
||
const result = resolveAddResult(res, {
|
||
codes: toStringList(data?.invalid_locations),
|
||
// 编码通道一般不会返回库位ID无效项,兜底提示(addDetail 响应的新增字段)
|
||
ids: toNumberList(data?.invalid_location_ids)
|
||
})
|
||
emit('update:visible', false)
|
||
emit('success', result)
|
||
} catch (e: any) {
|
||
console.error('[stockcheck] 添加盘点明细失败', e)
|
||
ElMessage.error(e?.message || '添加盘点明细失败')
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
}
|
||
|
||
/** 商品类任务:stock.check.addDetail 传 stock_ids */
|
||
async function submitGoodsRows(taskId: number) {
|
||
const stockIds = selectedStockIds.value
|
||
if (!stockIds.length) {
|
||
ElMessage.warning('请先勾选要盘点的商品')
|
||
return
|
||
}
|
||
|
||
submitting.value = true
|
||
try {
|
||
const res: any = await stockCheckAddDetail({ id: taskId, stock_ids: stockIds })
|
||
const data = res?.data ?? res
|
||
const result = resolveAddResult(res, { stocks: toNumberList(data?.invalid_stock_ids) })
|
||
emit('update:visible', false)
|
||
emit('success', result)
|
||
} catch (e: any) {
|
||
console.error('[stockcheck] 添加盘点明细失败', e)
|
||
ElMessage.error(e?.message || '添加盘点明细失败')
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
}
|
||
|
||
watch(
|
||
() => props.visible,
|
||
(visible) => {
|
||
if (!visible) return
|
||
filters.keyword = ''
|
||
filters.batch_no = ''
|
||
pagination.page = 1
|
||
pagination.total = 0
|
||
selectedRows.value = []
|
||
rows.value = []
|
||
locationText.value = ''
|
||
spaceFilters.keyword = ''
|
||
spacePagination.page = 1
|
||
spacePagination.total = 0
|
||
selectedSpaceRows.value = []
|
||
spaceRows.value = []
|
||
nextTick(() => {
|
||
tableRef.value?.clearSelection?.()
|
||
spaceTableRef.value?.clearSelection?.()
|
||
})
|
||
// 两种模式各自拉数据:商品模式拉库存列表,库位模式拉库位列表
|
||
if (isLocationMode.value) void loadSpaceRows()
|
||
else void loadRows()
|
||
}
|
||
)
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.picker-body {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
/* 筛选行:不要套卡片,仅做对齐 + 单行 */
|
||
.picker-filters {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
gap: 8px;
|
||
flex-shrink: 0;
|
||
|
||
.filter-item {
|
||
width: 200px;
|
||
}
|
||
|
||
.filter-item--keyword {
|
||
width: 260px;
|
||
}
|
||
}
|
||
|
||
.table-host {
|
||
flex: 1;
|
||
min-height: 200px;
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.empty-tip {
|
||
font-size: 13px;
|
||
color: #909399;
|
||
}
|
||
|
||
/* 库位模式:预览已识别的库位编码 */
|
||
.location-preview {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
gap: 6px;
|
||
max-height: 120px;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
/* 库位模式:手动输入库位编码(兼容通道) */
|
||
.location-manual {
|
||
flex-shrink: 0;
|
||
border-top: none;
|
||
|
||
:deep(.el-collapse-item__header) {
|
||
height: 32px;
|
||
line-height: 32px;
|
||
border-bottom: none;
|
||
font-size: 12px;
|
||
}
|
||
|
||
:deep(.el-collapse-item__wrap) {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.collapse-title {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
}
|
||
|
||
.location-tag {
|
||
margin: 0;
|
||
}
|
||
|
||
.stat-text {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
|
||
/* 分页器:右对齐 + 「每页条数」下拉与 UpperTable 同宽 80px */
|
||
.pagination-container {
|
||
flex-shrink: 0;
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
align-items: center;
|
||
|
||
:deep(.el-select--small) {
|
||
width: 80px;
|
||
}
|
||
|
||
:deep(.el-input__wrapper) {
|
||
padding: 0 4px;
|
||
}
|
||
}
|
||
|
||
.dialog-footer {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
|
||
.selected-tip {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
|
||
.footer-buttons {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
}
|
||
</style>
|