新增批量盘点功能

This commit is contained in:
杨学谦 2025-12-24 10:35:06 +08:00
parent 76a199028c
commit 1621d3f5b1
2 changed files with 741 additions and 0 deletions

View File

@ -0,0 +1,718 @@
<template>
<el-config-provider :locale="zhCn">
<el-container class="content">
<div class="work-area">
<fieldset class="search-area">
<el-form ref="stockQueryFormRef" :model="stockQuery" :label-position="labelPosition"
label-width="auto" style="max-width: 100%" status-icon>
<div style="display: flex;justify-content: space-between;">
<el-row>
<el-form-item label="箱号">
<el-input v-model="stockQuery.vehicleId" @keyup.enter="search()" clearable />
</el-form-item>
<el-form-item label="料号">
<el-input v-model="stockQuery.goodsId" @keyup.enter="search()" clearable />
</el-form-item>
<el-form-item label="未使用天数">
<el-select-v2
v-model="stockQuery.noUseDays"
placeholder="请选择未使用天数"
:options="noUseDaysOptions"
@change="search()" style="width: 196px;">
</el-select-v2>
</el-form-item>
<el-form-item label="起始日期">
<el-date-picker v-model="stockQuery.fromDate" type="date" placeholder="起始日期"
:shortcuts="shortcuts" style="width: 196px;" clearable />
</el-form-item>
<el-form-item label="结束日期">
<el-date-picker v-model="stockQuery.toDate" type="date" placeholder="结束日期"
:shortcuts="shortcuts" style="width: 196px;" clearable />
</el-form-item>
</el-row>
<div class="button-group">
<el-button
type="primary"
@click="search()">
查询库存
</el-button>
<el-button
type="warning"
@click="clearQuery()">
清除输入
</el-button>
<el-button
type="success"
@click="exportExcel()">
导出Excel
</el-button>
<el-button
type="primary"
:disabled="selectedRows.length === 0"
@click="handleBatchInventory"
:class="{ 'disabled-batch-btn': selectedRows.length === 0 }">
批量盘点({{ selectedRows.length }})
</el-button>
</div>
</div>
</el-form>
</fieldset>
<div class="table-area">
<el-table :data="displayStocks" border v-loading="tableLoading" class="table-class"
:max-height="maxHeight" highlight-current-row @row-click="getCurrentRow" :row-style="rowStyle"
:header-cell-style="{ 'text-align': 'center' }" :cell-style="{ 'text-align': 'center' }"
@sort-change="handleSortChange">
<!-- 添加多选框列 -->
<el-table-column width="65px" fixed="left">
<template #header>
<el-checkbox
v-model="isSelectAll"
@change="handleSelectAllChange">
&nbsp;
</el-checkbox>
</template>
<template v-slot="scope">
<el-checkbox
:label="scope.row.stockId"
v-model="scope.row.checked"
@change="handleSelectionChange(scope.row)">
&nbsp;
</el-checkbox>
</template>
</el-table-column>
<!-- <el-table-column prop="stockId" label="库存编号" fixed="left" min-width="120px" sortable="custom"-->
<!-- show-overflow-tooltip />-->
<el-table-column prop="lastInventoryTime" label="最近盘点时间" fixed="left" sortable="custom" :formatter="timeFormat"
min-width="140px" show-overflow-tooltip />
<el-table-column prop="vehicleId" label="箱号" fixed="left" min-width="120px" sortable="custom"
show-overflow-tooltip />
<el-table-column prop="goodsId" label="物料号" fixed="left" min-width="120px" sortable="custom"
show-overflow-tooltip />
<el-table-column prop="specialStock" label="特殊库存" min-width="120px" sortable="custom"
show-overflow-tooltip />
<el-table-column prop="specialStockNo" label="特殊库存号" min-width="120px" sortable="custom"
show-overflow-tooltip />
<el-table-column prop="specialStockItemNo" label="特殊库存item号" min-width="120px" sortable="custom"
show-overflow-tooltip />
<el-table-column prop="batchNo" label="批次号" min-width="120px" sortable="custom"
show-overflow-tooltip />
<el-table-column prop="goodsDesc" label="物料名称" min-width="120px" sortable="custom" show-overflow-tooltip />
<el-table-column prop="locationId" label="库位" :formatter="locationFormat" min-width="120px"
sortable="custom" show-overflow-tooltip />
<el-table-column prop="totalNum" label="入库数量" sortable="custom" min-width="120px" show-overflow-tooltip />
<el-table-column prop="remainNum" label="剩余可用数量" sortable="custom" min-width="120px" show-overflow-tooltip />
<el-table-column prop="realNum" label="实际剩余数量" sortable="custom" min-width="120px" show-overflow-tooltip />
<el-table-column prop="goodsStatus" label="物料状态" :formatter="goodsStatusFormat"
min-width="120px" sortable="custom" show-overflow-tooltip />
<el-table-column prop="stockStatus" label="库存状态" :formatter="stockStatusFormat" fixed="right"
min-width="120px" sortable="custom" show-overflow-tooltip />
<el-table-column prop="firstInTime" label="上架时间" sortable="custom" :formatter="timeFormat"
min-width="120px" show-overflow-tooltip />
<el-table-column prop="firstInUser" label="上架用户" min-width="120px" sortable="custom" show-overflow-tooltip />
<el-table-column prop="lastUpdateTime" label="最近更新时间" sortable="custom" :formatter="timeFormat"
min-width="140px" show-overflow-tooltip />
<el-table-column prop="lastUpdateUser" label="最近更新用户" min-width="120px" show-overflow-tooltip />
<!-- <el-table-column fixed="right" label="操作" width="120px">
<template v-slot="scope">
<el-button plain type="primary" @click="editCurrentRowStock(scope.row)">编辑</el-button>
</template>
</el-table-column> -->
</el-table>
<br />
<el-pagination v-model:current-page="baseTableQuery.currentPage"
v-model:page-size="baseTableQuery.pageSize" :page-sizes="[10, 25, 50]" :small="false"
:disabled="false" :background="false" :default-page-size="10" @size-change="search"
@current-change="search" layout="total, sizes, prev, pager, next, jumper"
:total="baseTableQuery.total" />
</div>
<!-- 批量盘点确认对话框 -->
<el-dialog
v-model="showBatchInventoryDialog"
title="确认批量盘点"
width="500px"
draggable
center>
<div class="dialog-content">
<el-alert
:title="`您确定要对以下 ${selectedRows.length} 条数据进行盘点操作吗?`"
type="warning"
show-icon
:closable="false" style="margin-bottom: 20px;">
</el-alert>
<div class="selected-summary">
<h4>选中数据概览</h4>
<div class="summary-item">
<span class="summary-label">料号种类</span>
<span>{{ [...new Set(selectedRows.map(item => item.goodsId))].length }} </span>
</div>
<div class="summary-item">
<span class="summary-label">箱号数量</span>
<span>{{ selectedRows.length }} </span>
</div>
</div>
<div class="selected-list">
<h4>选中数据详情</h4>
<el-table
:data="selectedRows.slice(0, 50)"
max-height="250"
size="small"
border>
<el-table-column prop="goodsId" label="料号" width="120" show-overflow-tooltip />
<el-table-column prop="vehicleId" label="箱号" width="120" show-overflow-tooltip />
<el-table-column prop="locationId" label="库位" width="100" show-overflow-tooltip />
<el-table-column prop="specialStock" label="特殊库存" width="100" show-overflow-tooltip />
</el-table>
</div>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="showBatchInventoryDialog = false" size="default">取消</el-button>
<el-button type="primary" @click="confirmBatchInventory" size="default">确认盘点</el-button>
</div>
</template>
</el-dialog>
</div>
</el-container>
</el-config-provider>
</template>
<script setup>
import store from '@/store'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import { queryStocksByPage } from '@/api/stock.js'
import { exportStockExcel } from '@/api/excel.js'
import { dateFormatter, locationFormatter, timeFormatter, yesOrNoFormatter } from '@/utils/formatter.js'
import { ref, reactive, onMounted, nextTick, onBeforeUnmount } from 'vue'
import { ElMessage } from 'element-plus'
import { genTableRequest, addAllOptionOfOptions } from '@/utils/generator.js'
import { labelPosition, shortcuts } from '@/constant/form'
import { stockStatusOptions, goodsStatusOptions } from '@/constant/options'
import {batchRequestInventory} from "@/api/task";
/**
* 常量定义
*/
/**
* 变量定义
*/
//
let selectedRows = ref([]) //
let isSelectAll = ref(false) //
let showBatchInventoryDialog = ref(false) //
let maxHeight = ref(window.innerHeight * 0.55)
let tableLoading = ref(false)
let displayStocks = ref([])
let baseTableQuery = reactive({
currentPage: 1,
pageSize: 10,
total: 0,
sortBy: new Map([['firstInTime', true]]),
standId: store.getters.getStandId,
userName: store.getters.getUserName
})
let stockQuery = reactive({
vehicleId: '',
goodsId: '',
locationId: '',
stockStatus: -99,
goodsStatus: -99,
fromDate: null,
toDate: null,
noUseDays: null // 使
})
let stockQueryFormRef = ref()
let goodsIdList = ref([])
let showStockEditFlag = ref(false)
let stockId = ''
let stockFormRef = ref()
let stockFormEntity = reactive({})
/**
* 系统方法
*/
onMounted(() => {
nextTick(() => {
window.addEventListener('resize', resizeHeight)
search()
})
})
onBeforeUnmount(() => {
nextTick(() => {
window.removeEventListener('resize', resizeHeight)
})
})
const resizeHeight = () => {
maxHeight.value = window.innerHeight * 0.55
}
/**
* 自定义方法
*/
//
const noUseDaysOptions = ref([
{ label: '全部', value: null },
{ label: '7天', value: 7 },
{ label: '15天', value: 15 },
{ label: '30天', value: 30 },
{ label: '60天', value: 60 },
{ label: '90天', value: 90 }
])
//
const handleSelectionChange = (row) => {
if (row.checked) {
//
if (!selectedRows.value.some(item => item.stockId === row.stockId)) {
selectedRows.value.push(row)
}
} else {
//
selectedRows.value = selectedRows.value.filter(item => item.stockId !== row.stockId)
//
isSelectAll.value = false
}
}
//
const handleSelectAllChange = (val) => {
displayStocks.value.forEach(row => {
row.checked = val
})
if (val) {
//
selectedRows.value = [...displayStocks.value]
} else {
//
selectedRows.value = []
}
}
//
const handleBatchInventory = () => {
if (selectedRows.value.length === 0) {
ElMessage.warning('请至少选择一条记录')
return
}
showBatchInventoryDialog.value = true
}
//
const confirmBatchInventory = () => {
//
const requestData = {
invUser: store.getters.getUserName, // 使
invStand: store.getters.getStandId, // 使ID
items: selectedRows.value.map(row => ({
goodsId: row.goodsId,
vehicleId: row.vehicleId,
specialStock: row.specialStock,
specialStockNo: row.specialStockNo,
specialStockItemNo: row.specialStockItemNo,
batchNo: row.batchNo
}))
};
console.log('批量盘点数据:', requestData);
//
batchRequestInventory(requestData).then(res => {
if (res.data.code === 0) {
ElMessage.success('批量盘点成功');
showBatchInventoryDialog.value = false;
search(); //
//
selectedRows.value.forEach(row => {
row.checked = false;
});
selectedRows.value = [];
isSelectAll.value = false;
} else {
ElMessage.error(res.data.message);
}
}).catch(() => {
ElMessage.error('批量盘点失败');
});
};
//
const search = () => {
tableLoading.value = true
let request = genTableRequest(baseTableQuery)
//
request.vehicleId = stockQuery.vehicleId.trim()
request.goodsId = stockQuery.goodsId.trim()
request.locationId = stockQuery.locationId.trim()
request.stockStatus = stockQuery.stockStatus === -99 ? null : stockQuery.stockStatus
request.goodsStatus = stockQuery.goodsStatus === -99 ? null : stockQuery.goodsStatus
request.fromDate = stockQuery.fromDate == null ? null : dateFormatter(stockQuery.fromDate)
request.toDate = stockQuery.toDate == null ? null : dateFormatter(stockQuery.toDate)
request.noUseDays = stockQuery.noUseDays // 使
queryStocksByPage(request).then((res) => {
const response = res.data
if (response.code === 0) {
const data = response.data
console.log(data)
if (data != null) {
displayStocks.value = data.lists
baseTableQuery.total = data.total
} else {
displayStocks.value = []
baseTableQuery.total = 0
}
} else {
ElMessage.error(response.message)
}
}).catch(err => {
console.log(err)
ElMessage.error('查询库存信息异常。')
}).finally(() => {
tableLoading.value = false
})
}
const clearQuery = () => {
stockQuery.vehicleId = '',
stockQuery.goodsId = '',
stockQuery.locationId = '',
stockQuery.stockStatus = -99,
stockQuery.goodsStatus = -99,
stockQuery.fromDate = null,
stockQuery.toDate = null,
stockQuery.noUseDays = null
}
const loadAllGoodsInfo = () => {
const request = {
userName: store.getters.getUserName
}
getGoodsInfoByGoodsId(request).then(res => {
const tableResponse = res.data
if (tableResponse.code == 0) {
this.goodsList = tableResponse.returnData
} else {
ElMessage.error(tableResponse.message)
}
}).catch(err => {
console.log(err)
ElMessage.error('查询物料信息异常。')
})
}
const filterGoodsId = (queryString, cb) => {
const results = queryString
? this.goodsList.filter(this.createFilter(queryString))
: this.goodsList
// call callback function to return suggestion objects
cb(results)
}
const createFilter = (queryString) => {
return (restaurant) => {
return (
restaurant.goodsId.toLowerCase().indexOf(queryString.toLowerCase()) != -1
)
}
}
const handleSelectGoodsId = (item) => {
this.goodsIdQuery = item.goodsId
}
const locationFormat = (row, column, cellValue, index) => {
return locationFormatter(cellValue)
}
const dateFormat = (row, column, cellValue, index) => {
return dateFormatter(cellValue)
}
const timeFormat = (row, column, cellValue, index) => {
return timeFormatter(cellValue)
}
const goodsStatusFormat = (row, column, cellValue, index) => {
if (cellValue === 0) {
return '正常'
} else if (cellValue === 1) {
return '不合格'
} else if (cellValue === 2) {
return '延期'
} else if (cellValue === 3) {
return '过期'
} else if (cellValue === 5) {
return '长时间未使用'
}
}
const stockStatusFormat = (row, column, cellValue, index) => {
switch (cellValue) {
case 0:
return '在库中'
case 1:
return '出库中'
case 2:
return '已出库'
case 3:
return '回库中'
case 4:
return '盘点中'
case 9:
return '库存锁定'
default:
return '异常'
}
}
const yesOrNoFormat = (row, column, cellValue, index) => {
return yesOrNoFormatter(cellValue)
}
const rowStyle = ({ row, rowIndex }) => {
const styles = {};
// 30
if (row.lastInventoryTime) {
const lastInventoryDate = new Date(row.lastInventoryTime);
const currentDate = new Date();
const timeDiff = currentDate - lastInventoryDate;
const daysDiff = timeDiff / (1000 * 60 * 60 * 24);
if (daysDiff < 30) {
styles.backgroundColor = "#e5f6fb"; // 绿
}
}
// goodsStatus
if (row.goodsStatus === 3) {
styles.color = "red";
} else if (row.goodsStatus === 5) {
styles.color = "yellow";
}
return Object.keys(styles).length > 0 ? styles : null;
}
const handleSortChange = (data) => {
if (baseTableQuery.sortBy.has(data.prop)) {
baseTableQuery.sortBy.delete(data.prop)
}
baseTableQuery.sortBy.set(data.prop, data.order == 'ascending')
search()
}
const getCurrentRow = (row) => {
stockId = row.stockId
}
const exportExcel = () => {
const params = {
vehicleId: stockQuery.vehicleId,
goodsId: stockQuery.goodsId,
locationId: stockQuery.locationId,
stockStatus: stockQuery.stockStatus == -99 ? null : stockQuery.stockStatus,
goodsStatus: stockQuery.goodsStatus == -99 ? null : stockQuery.goodsStatus,
fromDate: stockQuery.fromDate,
toDate: stockQuery.toDate
}
exportStockExcel(params).then(res => {
const link = document.createElement('a');//a
try {
// let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'}); //blobblobtypexls
let blob = res.data //blob
// let _fileName = res.headers['content-disposition'].split(';')[1].split('=')[1]; //
let _fileName = "库存报表" + dateFormatter(new Date) + ".xlsx"
link.style.display = 'none'//
// URL
const url = window.URL || window.webkitURL || window.moxURL
link.href = url.createObjectURL(blob)
link.setAttribute('download', _fileName.substring(_fileName.lastIndexOf('_') + 1))
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
url.revokeObjectURL(link.href)//url
} catch (e) {
console.log(e)
ElMessage.error('下载文件失败')
}
}).catch(err => {
console.log(err)
ElMessage.error('导出失败')
})
}
const editCurrentRowStock = (row) => {
this.stockFormEntity = {
stockId: row.stockId,
locationId: row.locationId,
vehicleId: row.vehicleId,
stockStatus: row.stockStatus,
createTime: row.createTime,
lastUpdateTime: row.lastUpdateTime,
lastUpdateUser: row.lastUpdateUser,
isInventory: row.isInventory,
inventoryTaskId: row.inventoryTaskId,
noUseDays: row.noUseDays,
goodsId: row.goodsId,
goodsName: row.goodsName,
goodsStatus: row.goodsStatus,
remainNum: row.remainNum,
totalNum: row.totalNum
}
this.dialogVisible = true
}
const submitStockInfo = () => {
const request = {
stockId: this.stockFormEntity.stockId,
locationId: this.stockFormEntity.locationId,
vehicleId: this.stockFormEntity.vehicleId,
stockStatus: this.stockFormEntity.stockStatus,
goodsId: this.stockFormEntity.goodsId,
goodsStatus: this.stockFormEntity.goodsStatus,
remainNum: this.stockFormEntity.remainNum,
userName: store.getters.getUserName
}
updateStockInfo(request).then(res => {
if (res.data.code == 0) {
this.dialogVisible = false
ElMessage.success('更新库存成功')
this.search()
} else {
errorBox(res.data.message)
}
}).catch(err => {
console.log(err)
errorBox('更新库存失败')
})
}
</script>
<style scoped>
.content {
display: flex;
width: 100%;
}
.work-area {
width: 100%;
/* padding: 5px; */
}
.search-area {
margin: auto;
min-height: fit-content;
max-height: 40%;
margin-bottom: 10px;
min-width: inherit;
border: solid 1px;
border-radius: 10px;
box-shadow: 0px 15px 10px -15px #000;
overflow: auto;
padding: 10px;
}
.table-area {
margin: auto;
min-height: fit-content;
max-height: 60%;
margin-bottom: 10px;
min-width: inherit;
border: solid 1px;
border-radius: 10px;
box-shadow: 0px 15px 10px -15px #000;
overflow: auto;
padding: 10px;
}
.el-form-item {
margin: 5px 5px 5px 5px;
}
.el-form-item .el-input {
width: 196px;
}
.table-class {
margin: 5px 5px 5px 5px;
width: inherit;
}
.el-pagination {
padding-left: 5px;
}
.my-autocomplete li {
width: 196px;
line-height: normal;
padding: 7px;
}
.my-autocomplete li .name {
text-overflow: ellipsis;
overflow: hidden;
}
.my-autocomplete li .addr {
font-size: 12px;
color: #b4b4b4;
}
.my-autocomplete li .highlighted .addr {
color: #ddd;
}
.my-autocomplete li .goods_id {
color: brown;
}
.my-autocomplete li .goods_name {
color: cornflowerblue;
}
/* 新增的弹窗样式 */
.dialog-content {
padding: 20px;
}
.selected-summary {
background-color: #f5f7fa;
border-radius: 4px;
padding: 15px;
margin-bottom: 20px;
}
.summary-item {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
}
.summary-label {
font-weight: bold;
}
.selected-list h4 {
margin-bottom: 10px;
}
.more-info {
text-align: center;
color: #909399;
margin-top: 10px;
font-size: 14px;
}
.dialog-footer {
text-align: right;
padding: 20px 0 0;
}
.dialog-footer .el-button {
margin-left: 10px;
}
.button-group {
display: flex;
gap: 10px;
align-items: center;
justify-content: flex-start;
flex-wrap: wrap;
padding: 10px 0;
}
.button-group .el-button {
height: 32px;
min-width: 80px;
margin: 0;
}
</style>

View File

@ -0,0 +1,23 @@
// 在com.wms_main.model.dto.request.wms包下创建
package com.wms_main.model.dto.request.wms;
import lombok.Data;
import java.util.List;
@Data
public class BatchInventoryRequest {
private List<InventoryItem> items;
private String invUser; // 盘点用户
private String invStand; // 盘点站台
@Data
public static class InventoryItem {
private String goodsId;
private String vehicleId;
private String specialStock;
private String specialStockNo;
private String specialStockItemNo;
private String batchNo;
}
}