535 lines
22 KiB
Vue
535 lines
22 KiB
Vue
<template>
|
||
<div style="margin-bottom: 10px">
|
||
<el-config-provider :locale="zhCn">
|
||
<div style="display: flex;justify-content: space-between;">
|
||
<el-row>
|
||
<el-autocomplete v-model="goodsIdQuery" :fetch-suggestions="filterGoodsId"
|
||
popper-class="my-autocomplete" placeholder="料号" @select="handleSelectGoodsId"
|
||
:suffix-icon="Search" style="width: 196px; margin-right: 10px;">
|
||
<template #default="{ item }">
|
||
<div>
|
||
料号:<span class="goods_id">{{ item.goodsId }}</span>
|
||
;
|
||
名称:<span class="goods_name">{{ item.goodsName }}</span>
|
||
</div>
|
||
</template>
|
||
</el-autocomplete>
|
||
<el-input v-model="vehicleIdQuery" style="width: 196px; margin-right: 10px;" placeholder="箱号"
|
||
:suffix-icon="Search" />
|
||
<el-input v-model="locationIdQuery" style="width: 196px; margin-right: 10px;" placeholder="库位"
|
||
:suffix-icon="Search" />
|
||
<el-button type="primary" @click="search()">搜索</el-button>
|
||
<el-button type="warning" @click="reset()">重置</el-button>
|
||
</el-row>
|
||
<el-row>
|
||
<el-button type="success" @click="exportExcel()">导出</el-button>
|
||
</el-row>
|
||
</div>
|
||
<br />
|
||
<el-table id="stock-table" :data="displayStocks" stripe border v-loading="loading" class="table-class"
|
||
max-height="650px" 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 v-slot="scope">
|
||
<el-radio :label="scope.row.stockId" v-model="stockId"> </el-radio>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="stockId" label="库存编号" fixed="left" min-width="120px" 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" show-overflow-tooltip />
|
||
<el-table-column prop="goodsName" label="物料名称" min-width="120px" 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="入库数量" min-width="120px" />
|
||
<el-table-column prop="remainNum" label="剩余数量" min-width="120px" />
|
||
<el-table-column prop="goodsStatus" label="物料状态" :formatter="goodsStatusFormat" min-width="120px" />
|
||
<el-table-column prop="stockStatus" label="库存状态" :formatter="stockStatusFormat" fixed="right"
|
||
min-width="120px" />
|
||
<el-table-column prop="isInventory" label="是否盘点" :formatter="yesOrNoFormat" min-width="120px" />
|
||
<el-table-column prop="inventoryTaskId" label="盘点任务号" min-width="120px" />
|
||
<el-table-column prop="noUseDays" label="未使用天数" min-width="120px" />
|
||
<el-table-column prop="createTime" label="上架时间" sortable="custom" :formatter="timeFormat" min-width="120px"
|
||
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" />
|
||
<el-table-column fixed="right" label="操作" width="120px" v-if="selStock == null">
|
||
<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="currentPage" v-model:page-size="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="total" />
|
||
<el-dialog v-model="dialogVisible" title="库存信息" width="40%" draggable :show-close="false">
|
||
<el-form ref="stockFormRef" :model="stockFormEntity" :label-position="labelPosition" label-width="100px"
|
||
style="max-width: 100%" :rules="rules" status-icon>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12" :offset="0">
|
||
<el-form-item label="库存编号" prop="stockId">
|
||
<el-input v-model="stockFormEntity.stockId" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="箱号" prop="vehicleId">
|
||
<el-input v-model="stockFormEntity.vehicleId" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12" :offset="0">
|
||
<el-form-item label="料号" prop="goodsId">
|
||
<el-input v-model="stockFormEntity.goodsId" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="料名" prop="goodsName">
|
||
<el-input v-model="stockFormEntity.goodsName" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12" :offset="0">
|
||
<el-form-item label="入库数量" prop="totalNum">
|
||
<el-input-number v-model.number="stockFormEntity.totalNum" controls-position="right"
|
||
:min="0" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="剩余数量(为0时删除库存)" prop="remainNum">
|
||
<el-input-number v-model.number="stockFormEntity.remainNum" controls-position="right"
|
||
:min="0" :max="stockFormEntity.totalNum" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12" :offset="0">
|
||
<el-form-item label="库位" prop="locationId">
|
||
<el-input v-model="stockFormEntity.locationId" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="未使用天数" prop="noUseDays">
|
||
<el-input-number v-model.number="stockFormEntity.noUseDays" controls-position="right"
|
||
:min="0" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12" :offset="0">
|
||
<el-form-item label="库存状态" prop="stockStatus">
|
||
<el-select-v2 v-model="stockFormEntity.stockStatus" placeholder="请选择库存状态"
|
||
:options="stockStatusOptions"></el-select-v2>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="物料状态" prop="goodsStatus">
|
||
<el-select-v2 v-model="stockFormEntity.goodsStatus" placeholder="请选择物料状态"
|
||
:options="goodsStatusOptions"></el-select-v2>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12" :offset="0">
|
||
<el-form-item label="盘点任务号" prop="inventoryTaskId">
|
||
<el-input v-model="stockFormEntity.inventoryTaskId" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="是否盘点" prop="isInventory">
|
||
<el-input v-model="stockFormEntity.isInventory" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12" :offset="0">
|
||
<el-form-item label="创建时间" prop="createTime">
|
||
<el-input v-model="stockFormEntity.createTime" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="最近更新时间" prop="lastUpdateTime">
|
||
<el-input v-model="stockFormEntity.lastUpdateTime" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12" :offset="0">
|
||
<el-form-item label="最近更新用户" prop="lastUpdateUser">
|
||
<el-input v-model="stockFormEntity.lastUpdateUser" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form>
|
||
<template #footer>
|
||
<span class="dialog-footer">
|
||
<el-button @click="dialogVisible = false">取消</el-button>
|
||
<el-button type="primary" @click="submitStockInfo(stockFormEntity)">
|
||
确定
|
||
</el-button>
|
||
</span>
|
||
</template>
|
||
</el-dialog>
|
||
</el-config-provider>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import store from '@/store'
|
||
import { getAllStocks, updateStockInfo } from '@/api/stock.js'
|
||
import { getGoodsInfoByGoodsId } from '@/api/goods.js'
|
||
import { downloadStockExcel } from '@/api/excel.js'
|
||
import { dateFormatter, locationFormatter, timeFormatter, yesOrNoFormatter } from '@/utils/formatter.js'
|
||
import { toUnderScoreCase } from '@/utils/stringUtils.js'
|
||
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
|
||
import { Search } from '@element-plus/icons-vue'
|
||
import { ref, reactive } from 'vue'
|
||
import { errorBox } from '@/utils/myMessageBox.js'
|
||
import { ElMessage } from 'element-plus'
|
||
// import FileSaver from 'file-saver';
|
||
// import * as XLSX from 'xlsx';
|
||
</script>
|
||
<script>
|
||
export default {
|
||
name: 'stock',
|
||
props: ['selStock'],
|
||
emits: ['update:selStock'],
|
||
data() {
|
||
return {
|
||
displayStocks: [],
|
||
currentPage: 1,
|
||
pageSize: 10,
|
||
total: 0,
|
||
sortBy: '',
|
||
isAsc: true,
|
||
goodsIdQuery: '',
|
||
vehicleIdQuery: '',
|
||
locationIdQuery: '',
|
||
loading: true,
|
||
stockId: '',
|
||
stockFormRef: ref(),
|
||
stockFormEntity: reactive({}),
|
||
rules: reactive({}),
|
||
labelPosition: 'top',
|
||
dialogVisible: false,
|
||
goodsStatusOptions: [
|
||
{
|
||
value: 0,
|
||
label: '合格'
|
||
},
|
||
{
|
||
value: 1,
|
||
label: '不合格'
|
||
},
|
||
{
|
||
value: 2,
|
||
label: '延期'
|
||
},
|
||
{
|
||
value: 3,
|
||
label: '过期'
|
||
},
|
||
{
|
||
value: 5,
|
||
label: '长时间未使用'
|
||
}
|
||
],
|
||
stockStatusOptions: [
|
||
{
|
||
value: 0,
|
||
label: '库存正常'
|
||
},
|
||
{
|
||
value: 1,
|
||
label: '出库中'
|
||
},
|
||
{
|
||
value: 2,
|
||
label: '盘点中'
|
||
},
|
||
{
|
||
value: 3,
|
||
label: '移库中'
|
||
},
|
||
{
|
||
value: 4,
|
||
label: '拣选中'
|
||
},
|
||
{
|
||
value: 5,
|
||
label: '回库中'
|
||
},
|
||
{
|
||
value: 9,
|
||
label: '库存锁定'
|
||
}
|
||
],
|
||
goodsList: [],
|
||
}
|
||
},
|
||
mounted() {
|
||
this.search()
|
||
this.loadAllGoodsInfo()
|
||
},
|
||
methods: {
|
||
loadAllGoodsInfo() {
|
||
const request = {
|
||
userName: store.getters.getUserName
|
||
}
|
||
getGoodsInfoByGoodsId(request).then(res => {
|
||
const tableResponse = res.data
|
||
if (tableResponse.code == 0) {
|
||
this.goodsList = tableResponse.returnData
|
||
} else {
|
||
errorBox(tableResponse.message)
|
||
}
|
||
}).catch(err => {
|
||
console.log(err)
|
||
errorBox('查询物料信息异常。')
|
||
})
|
||
},
|
||
filterGoodsId(queryString, cb) {
|
||
const results = queryString
|
||
? this.goodsList.filter(this.createFilter(queryString))
|
||
: this.goodsList
|
||
// call callback function to return suggestion objects
|
||
cb(results)
|
||
},
|
||
createFilter(queryString) {
|
||
return (restaurant) => {
|
||
return (
|
||
restaurant.goodsId.toLowerCase().indexOf(queryString.toLowerCase()) != -1
|
||
)
|
||
}
|
||
},
|
||
handleSelectGoodsId(item) {
|
||
this.goodsIdQuery = item.goodsId
|
||
},
|
||
locationFormat: (row, column, cellValue, index) => {
|
||
return locationFormatter(cellValue)
|
||
},
|
||
dateFormat: (row, column, cellValue, index) => {
|
||
return dateFormatter(cellValue)
|
||
},
|
||
timeFormat: (row, column, cellValue, index) => {
|
||
return timeFormatter(cellValue)
|
||
},
|
||
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 '长时间未使用'
|
||
}
|
||
},
|
||
stockStatusFormat: (row, column, cellValue, index) => {
|
||
switch (cellValue) {
|
||
case 0:
|
||
return '库存正常'
|
||
case 1:
|
||
return '出库中'
|
||
case 2:
|
||
return '盘点中'
|
||
case 3:
|
||
return '移库中'
|
||
case 4:
|
||
return '拣选中'
|
||
case 5:
|
||
return '回库中'
|
||
case 9:
|
||
return '库存锁定'
|
||
default:
|
||
return '异常'
|
||
}
|
||
},
|
||
yesOrNoFormat: (row, column, cellValue, index) => {
|
||
return yesOrNoFormatter(cellValue)
|
||
},
|
||
rowStyle: ({ row, rowIndex }) => {
|
||
if (row.goodsStatus == 3) {
|
||
return { "color": "red" }
|
||
}
|
||
if (row.goodsStatus == 5) {
|
||
return { "color": "yellow" }
|
||
}
|
||
},
|
||
handleSortChange(data) {
|
||
this.sortBy = toUnderScoreCase(data.prop)
|
||
this.isAsc = data.order == 'ascending'
|
||
this.search()
|
||
},
|
||
search() {
|
||
this.loading = true
|
||
const request = {
|
||
pageNo: this.currentPage,
|
||
pageSize: this.pageSize,
|
||
sortBy: this.sortBy,
|
||
isAsc: this.isAsc,
|
||
goodsId: this.goodsIdQuery.trim(),
|
||
vehicleId: this.vehicleIdQuery.trim(),
|
||
locationId: this.locationIdQuery.trim(),
|
||
userName: store.getters.getUserName
|
||
}
|
||
getAllStocks(request).then(res => {
|
||
const tableResponse = res.data
|
||
if (tableResponse.code == 0) {
|
||
this.displayStocks = tableResponse.returnData.lists
|
||
this.total = tableResponse.returnData.total
|
||
} else {
|
||
errorBox(tableResponse.message)
|
||
}
|
||
}).catch(err => {
|
||
console.log(err)
|
||
errorBox('查询库存错误')
|
||
})
|
||
this.loading = false
|
||
},
|
||
reset() {
|
||
this.goodsIdQuery = ''
|
||
this.vehicleIdQuery = ''
|
||
this.locationIdQuery = ''
|
||
this.search()
|
||
},
|
||
getCurrentRow(row) {
|
||
this.stockId = row.stockId
|
||
this.$emit('update:selStock', row)
|
||
},
|
||
exportExcel() {
|
||
const params = {
|
||
goodsId: this.goodsIdQuery.trim(),
|
||
vehicleId: this.vehicleIdQuery.trim(),
|
||
locationId: this.locationIdQuery.trim(),
|
||
userName: store.getters.getUserName
|
||
}
|
||
downloadStockExcel(params).then(res => {
|
||
const link = document.createElement('a');//创建a标签
|
||
try {
|
||
// let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'}); //如果后台返回的不是blob对象类型,先定义成blob对象格式,该type导出为xls格式,
|
||
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)
|
||
errorBox('下载文件失败')
|
||
}
|
||
}).catch(err => {
|
||
console.log(err)
|
||
errorBox('导出失败')
|
||
})
|
||
},
|
||
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
|
||
},
|
||
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>
|
||
.el-pagination {
|
||
padding-left: 5px;
|
||
}
|
||
|
||
.el-row .el-button {
|
||
width: 72px;
|
||
margin-left: 0px;
|
||
margin-right: 5px;
|
||
}
|
||
|
||
.table-class {
|
||
width: 100%;
|
||
}
|
||
|
||
.el-row .el-form-item .el-select-v2 {
|
||
width: 100% !important;
|
||
}
|
||
|
||
.el-row .el-form-item .el-input-number {
|
||
width: 100% !important;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
</style> |