Commit c2ea7e08 by yubin

页面修改

parent a885a8a9
......@@ -47,14 +47,10 @@
</template>
</PageTitle>
<!-- 页面容器 - 修改为参考样式 -->
<div class="page-container">
<page-wrapper-search
:model="queryParams"
ref="queryForm"
size="small"
@search="handleQuery"
@reset="resetQuery"
>
<!-- 替换原有page-wrapper-search为el-form内联搜索 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
<el-form-item label="库位编码" prop="locationCode">
<el-input
v-model="queryParams.locationCode"
......@@ -71,7 +67,6 @@
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<!-- 仓库查询相关已注释 -->
<!-- <el-form-item label="仓库" prop="warehouseId">
<el-input
v-model="queryWarehouseName"
......@@ -104,7 +99,7 @@
v-model="queryParams.locationType"
placeholder="请选择库位类型"
clearable
style="width: 100%;"
class="w20"
>
<el-option
v-for="item in dict.type.location_type"
......@@ -119,7 +114,7 @@
v-model="queryParams.locationUsage"
placeholder="请选择库位使用"
clearable
style="width: 100%;"
class="w20"
>
<el-option
v-for="item in dict.type.location_usage"
......@@ -134,7 +129,7 @@
v-model="queryParams.allowMixedProducts"
placeholder="请选择是否允许混放产品"
clearable
style="width: 100%;"
class="w20"
>
<el-option
v-for="item in dict.type.yorn"
......@@ -160,7 +155,12 @@
@keyup.enter.native="handleQuery"
/>
</el-form-item>
</page-wrapper-search>
<!-- 搜索和重置按钮 -->
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<div class="table-container">
<el-table
......@@ -221,18 +221,16 @@
<div><strong>拣货区:</strong>{{ scope.row.pickingArea || '-' }}</div>
</el-col>
</el-row>
<!-- 允许存放物料名称已注释 -->
<!-- <el-row :gutter="20" style="margin: 10px 0;">
<el-row :gutter="20" style="margin: 10px 0;">
<el-col :span="24">
<div><strong>允许存放物料名称:</strong>{{ scope.row.allowedCategoryNames || '-' }}</div>
</el-col>
</el-row> -->
</el-row>
</template>
</el-table-column>
<el-table-column type="selection" width="55" align="center" fixed />
<el-table-column label="库位编码" align="center" prop="locationCode" min-width="120" fixed />
<el-table-column label="库位名称" align="center" prop="locationName" min-width="150" />
<!-- 仓库列已注释 -->
<!-- <el-table-column label="仓库" align="center" prop="warehousesName" width="180">
<template slot-scope="scope">
{{ scope.row.warehousesName }}
......@@ -266,8 +264,7 @@
<el-table-column label="库位容量(千克)" align="center" prop="capacity" min-width="120" />
<el-table-column label="体积容量(立方米)" align="center" prop="volumeCapacity" min-width="120" />
<el-table-column label="允许存放的危险等级" align="center" prop="allowedHazardLevels" min-width="140" />
<!-- 允许存放物料名称列已注释 -->
<!-- <el-table-column label="允许存放的物料名称" align="center" prop="allowedCategoryNames" min-width="200">
<el-table-column label="允许存放的物料名称" align="center" prop="allowedCategoryNames" min-width="200">
<template slot-scope="scope">
<el-tooltip
:content="scope.row.allowedCategoryNames"
......@@ -297,7 +294,7 @@
</div>
</el-tooltip>
</template>
</el-table-column> -->
</el-table-column>
<el-table-column label="温区" align="center" prop="temperatureZone" width="100" />
<el-table-column label="应用状态" align="center" prop="isEnabled" width="100">
<template slot-scope="scope">
......@@ -361,7 +358,6 @@
</el-form-item>
</el-col>
</el-row>
<!-- 仓库表单项已注释 -->
<!-- <el-form-item label="仓库" prop="warehouseId">
<el-input
v-model="form.warehouseName"
......@@ -515,8 +511,7 @@
<el-input v-model="form.allowedHazardLevels" placeholder="请输入允许存放的危险等级" />
</el-form-item>
</el-col>
<!-- 允许存放物料表单项已注释 -->
<!-- <el-col :span="12">
<el-col :span="12">
<el-form-item label="允许存放物料" prop="allowedCategoryIds">
<div style="display: flex; align-items: center; flex-direction: column; gap: 8px;">
<el-input
......@@ -528,7 +523,7 @@
/>
</div>
</el-form-item>
</el-col> -->
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
......@@ -555,8 +550,8 @@
</div>
</el-dialog>
<!-- 选择允许存放的物料对话框已注释 -->
<!-- <el-dialog
<!-- 选择允许存放的物料对话框 -->
<el-dialog
title="选择允许存放的物料"
:visible.sync="showMaterialSelect"
width="1000px"
......@@ -576,7 +571,7 @@
<el-button @click="handleMaterialSelectionCancel">取消</el-button>
<el-button type="primary" @click="confirmMaterialSelection">确认选择</el-button>
</div>
</el-dialog> -->
</el-dialog>
<!-- 导入组件 -->
<import-excel
......@@ -588,7 +583,7 @@
@success="getList"
/>
<!-- 仓库选择器组件已注释 -->
<!-- 仓库选择器组件 -->
<!-- <WarehouseSelector
v-model="warehouseSelectorVisible"
@selected="handleWarehouseSelected"
......@@ -598,19 +593,15 @@
<script>
import { listLocations, getLocations, delLocations, addLocations, updateLocations } from "@/api/inventory/locations"
// 仓库相关API已注释
// import { listWarehouses } from "@/api/inventory/warehouses"
// 物料选择器组件已注释
// import materialsSeletor from "../../../components/materialsSeletor.vue"
import { listWarehouses } from "@/api/inventory/warehouses"
import materialsSeletor from "../../../components/materialsSeletor.vue"
// import WarehouseSelector from "@/views/compononents/WarehouseSelector.vue"
import ImportExcel from "@/components/ImportExcel/index"
// 物料相关API已注释
// import { listMaterials } from "@/api/inventory/materials"
import { listMaterials } from "@/api/inventory/materials"
export default {
name: "Locations",
// 组件注册已注释物料选择器
components: { /* materialsSeletor, */ ImportExcel },
components: { materialsSeletor, ImportExcel },
dicts: ['sys_normal_disable', 'location_type', 'location_usage', 'yorn','is_enabled'],
data() {
return {
......@@ -618,7 +609,7 @@ export default {
ids: [],
single: true,
multiple: true,
showSearch: true,
showSearch: true, // 新增:控制搜索框显示
total: 0,
locationsList: [],
title: "",
......@@ -630,8 +621,7 @@ export default {
pageSize: 10,
locationCode: null,
locationName: null,
// 仓库查询参数已注释
// warehouseId: null,
warehouseId: null,
locationType: null,
layerCode: null,
locationUsage: null,
......@@ -645,9 +635,8 @@ export default {
id: null,
locationCode: null,
locationName: null,
// 仓库相关字段已注释
// warehouseId: null,
// warehouseName: null,
warehouseId: null,
warehouseName: null,
locationType: null,
zoneCode: null,
rowCode: null,
......@@ -656,9 +645,8 @@ export default {
capacity: null,
volumeCapacity: null,
allowedHazardLevels: null,
// 物料分类相关字段已注释
// allowedCategoryIds: null, // 原materialCodes
// allowedCategoryNames: null, // 原materialNames
allowedCategoryIds: null, // 原materialCodes
allowedCategoryNames: null, // 原materialNames
temperatureZone: null,
isEnabled: 1,
isUsed: 1,
......@@ -683,7 +671,6 @@ export default {
{ required: true, message: '库位名称不能为空', trigger: 'blur' },
{ min: 1, max: 100, message: '库位名称长度不能超过100个字符', trigger: 'blur' }
],
// 仓库验证规则已注释
// warehouseId: [
// { required: true, message: '仓库不能为空', trigger: 'change' }
// ],
......@@ -704,172 +691,170 @@ export default {
]
},
// 仓库相关数据已注释
// warehouseList: [],
// loadingWarehouse: false,
// queryWarehouseName: '',
// 物料选择相关数据已注释
// showMaterialSelect: false,
// tempSelectedMaterials: {
// materialCodes: [],
// names: [],
// categoryIds: []
// },
// materialCodeToNameMap: {},
// materialMapLoaded: false,
// 仓库选择器相关数据已注释
// warehouseSelectorVisible: false,
// warehouseSelectTarget: '',
// 仓库相关
warehouseList: [],
loadingWarehouse: false,
queryWarehouseName: '',
// 物料选择相关
showMaterialSelect: false,
tempSelectedMaterials: {
materialCodes: [],
names: [],
categoryIds: []
},
materialCodeToNameMap: {},
materialMapLoaded: false,
// 仓库选择器相关
warehouseSelectorVisible: false,
warehouseSelectTarget: '',
currentDetailItem: null
}
},
created() {
console.log('【Locations组件】开始初始化')
this.getList()
// 仓库列表加载已注释
// this.getWarehouseList()
// 物料映射表初始化已注释
// this.initMaterialCodeToNameMap()
this.getWarehouseList()
this.initMaterialCodeToNameMap()
},
methods: {
// 物料选择器初始化已注释
// initMaterialSelector() {
// console.log('【初始化物料选择器】清空残留数据')
// // 1. 清空临时选择数据(区分新增/修改)
// this.tempSelectedMaterials = {
// materialCodes: this.form.id ? (this.form.allowedCategoryIds ? this.form.allowedCategoryIds.split(',').filter(u => u.trim()) : []) : [],
// names: this.form.id ? (this.form.allowedCategoryNames ? this.form.allowedCategoryNames.split(',').filter(n => n.trim()) : []) : [],
// categoryIds: this.form.id ? (this.form.allowedCategoryIds ? this.form.allowedCategoryIds.split(',').filter(c => c.trim()) : []) : []
// }
// // 2. 延迟打开弹窗,确保数据先清空
// this.$nextTick(() => {
// this.showMaterialSelect = true
// // 3. 兼容子组件清空选中状态(如果有该方法)
// if (this.$refs.materialsSeletor && this.$refs.materialsSeletor.clearSelection) {
// this.$refs.materialsSeletor.clearSelection()
// // 修改模式下重新设置选中值
// if (this.form.id) {
// this.$refs.materialsSeletor.setSelection(this.tempSelectedMaterials.materialCodes)
// }
// }
// })
// },
// 清空查询仓库已注释
// clearQueryWarehouse() {
// console.log('【清空查询仓库】执行清空操作')
// this.queryWarehouseName = ''
// this.queryParams.warehouseId = null
// this.handleQuery()
// },
// 清空表单仓库已注释
// clearFormWarehouse() {
// console.log('【清空表单仓库】执行清空操作')
// this.form.warehouseName = ''
// this.form.warehouseId = null
// },
// 仓库选择回调已注释
// handleWarehouseSelected(warehouse) {
// console.log('【仓库选择回调】选中的仓库数据:', warehouse)
// if (!warehouse) return
// const warehouseId = warehouse.warehousesId || warehouse.warehouseId || warehouse.id
// const warehouseName = warehouse.warehousesName || warehouse.name || warehouse.warehouseName
// if (this.warehouseSelectTarget === 'query') {
// this.queryParams.warehouseId = warehouseId
// this.queryWarehouseName = warehouseName
// this.handleQuery()
// } else {
// this.form.warehouseId = warehouseId
// this.form.warehouseName = warehouseName
// if (this.currentDetailItem) {
// this.currentDetailItem.warehouseId = warehouseId
// this.currentDetailItem.warehouseName = warehouseName
// }
// }
// this.warehouseSelectorVisible = false
// },
// 打开仓库选择器已注释
// openWarehouseSelector(target = 'form') {
// console.log('【打开仓库选择器】目标:', target)
// this.warehouseSelectTarget = target
// this.warehouseSelectorVisible = true
// },
// 获取仓库列表已注释
// getWarehouseList() {
// console.log('【获取仓库列表】开始请求仓库数据')
// this.loadingWarehouse = true
// listWarehouses({ pageNum: 1, pageSize: 1000, isUsed: 1 }).then(response => {
// console.log('【获取仓库列表】请求成功,返回数据:', response)
// this.warehouseList = response.rows || []
// this.loadingWarehouse = false
// }).catch(error => {
// console.error('【获取仓库列表】请求失败:', error)
// this.warehouseList = []
// this.loadingWarehouse = false
// })
// },
// 根据仓库ID获取仓库名称已注释
// getWarehouseNameById(warehouseId) {
// console.log('【根据仓库ID获取名称】仓库ID:', warehouseId)
// if (!warehouseId) return '-'
// const warehouse = this.warehouseList.find(item =>
// item.warehousesId === warehouseId || item.warehouseId === warehouseId || item.id === warehouseId
// )
// const warehouseName = warehouse ? (warehouse.warehousesName || warehouse.name || warehouse.warehouseName || '-') : '-'
// console.log('【根据仓库ID获取名称】匹配到的仓库名称:', warehouseName)
// return warehouseName
// },
// 初始化物料编码-名称映射表已注释
// async initMaterialCodeToNameMap() {
// console.log('【初始化物料映射表】开始加载物料数据')
// try {
// this.materialMapLoaded = true
// let pageNum = 1
// const pageSize = 1000
// let hasMore = true
// this.materialCodeToNameMap = {}
// while (hasMore) {
// console.log(`【初始化物料映射表】请求第${pageNum}页物料数据,每页${pageSize}条`)
// const response = await listMaterials({
// pageNum,
// pageSize,
// isUsed: 1,
// materialCode: null,
// materialName: null
// })
// if (response.rows && response.rows.length) {
// console.log(`【初始化物料映射表】第${pageNum}页返回${response.rows.length}条物料数据`)
// response.rows.forEach(item => {
// if (item.materialCode && item.materialName) {
// const code = item.materialCode.trim().toUpperCase()
// this.materialCodeToNameMap[code] = item.materialName
// }
// })
// hasMore = pageNum * pageSize < response.total
// pageNum++
// } else {
// hasMore = false
// }
// }
// console.log('【初始化物料映射表】完成,映射表长度:', Object.keys(this.materialCodeToNameMap).length)
// } catch (error) {
// console.error('【初始化物料映射表】失败:', error)
// this.materialMapLoaded = false
// this.$modal.msgError('物料数据加载失败,请刷新页面重试!')
// }
// },
// ========== 新增:初始化物料选择器(核心修复数据残留) ==========
initMaterialSelector() {
console.log('【初始化物料选择器】清空残留数据')
// 1. 清空临时选择数据(区分新增/修改)
this.tempSelectedMaterials = {
materialCodes: this.form.id ? (this.form.allowedCategoryIds ? this.form.allowedCategoryIds.split(',').filter(u => u.trim()) : []) : [],
names: this.form.id ? (this.form.allowedCategoryNames ? this.form.allowedCategoryNames.split(',').filter(n => n.trim()) : []) : [],
categoryIds: this.form.id ? (this.form.allowedCategoryIds ? this.form.allowedCategoryIds.split(',').filter(c => c.trim()) : []) : []
}
// 2. 延迟打开弹窗,确保数据先清空
this.$nextTick(() => {
this.showMaterialSelect = true
// 3. 兼容子组件清空选中状态(如果有该方法)
if (this.$refs.materialsSeletor && this.$refs.materialsSeletor.clearSelection) {
this.$refs.materialsSeletor.clearSelection()
// 修改模式下重新设置选中值
if (this.form.id) {
this.$refs.materialsSeletor.setSelection(this.tempSelectedMaterials.materialCodes)
}
}
})
},
// 清空查询仓库
clearQueryWarehouse() {
console.log('【清空查询仓库】执行清空操作')
this.queryWarehouseName = ''
this.queryParams.warehouseId = null
this.handleQuery()
},
// 清空表单仓库
clearFormWarehouse() {
console.log('【清空表单仓库】执行清空操作')
this.form.warehouseName = ''
this.form.warehouseId = null
},
// 仓库选择回调
handleWarehouseSelected(warehouse) {
console.log('【仓库选择回调】选中的仓库数据:', warehouse)
if (!warehouse) return
const warehouseId = warehouse.warehousesId || warehouse.warehouseId || warehouse.id
const warehouseName = warehouse.warehousesName || warehouse.name || warehouse.warehouseName
if (this.warehouseSelectTarget === 'query') {
this.queryParams.warehouseId = warehouseId
this.queryWarehouseName = warehouseName
this.handleQuery()
} else {
this.form.warehouseId = warehouseId
this.form.warehouseName = warehouseName
if (this.currentDetailItem) {
this.currentDetailItem.warehouseId = warehouseId
this.currentDetailItem.warehouseName = warehouseName
}
}
this.warehouseSelectorVisible = false
},
// 打开仓库选择器
openWarehouseSelector(target = 'form') {
console.log('【打开仓库选择器】目标:', target)
this.warehouseSelectTarget = target
this.warehouseSelectorVisible = true
},
// 获取仓库列表
getWarehouseList() {
console.log('【获取仓库列表】开始请求仓库数据')
this.loadingWarehouse = true
listWarehouses({ pageNum: 1, pageSize: 1000, isUsed: 1 }).then(response => {
console.log('【获取仓库列表】请求成功,返回数据:', response)
this.warehouseList = response.rows || []
this.loadingWarehouse = false
}).catch(error => {
console.error('【获取仓库列表】请求失败:', error)
this.warehouseList = []
this.loadingWarehouse = false
})
},
// 根据仓库ID获取仓库名称
getWarehouseNameById(warehouseId) {
console.log('【根据仓库ID获取名称】仓库ID:', warehouseId)
if (!warehouseId) return '-'
const warehouse = this.warehouseList.find(item =>
item.warehousesId === warehouseId || item.warehouseId === warehouseId || item.id === warehouseId
)
const warehouseName = warehouse ? (warehouse.warehousesName || warehouse.name || warehouse.warehouseName || '-') : '-'
console.log('【根据仓库ID获取名称】匹配到的仓库名称:', warehouseName)
return warehouseName
},
// 初始化物料编码-名称映射表
async initMaterialCodeToNameMap() {
console.log('【初始化物料映射表】开始加载物料数据')
try {
this.materialMapLoaded = true
let pageNum = 1
const pageSize = 1000
let hasMore = true
this.materialCodeToNameMap = {}
while (hasMore) {
console.log(`【初始化物料映射表】请求第${pageNum}页物料数据,每页${pageSize}条`)
const response = await listMaterials({
pageNum,
pageSize,
isUsed: 1,
materialCode: null,
materialName: null
})
if (response.rows && response.rows.length) {
console.log(`【初始化物料映射表】第${pageNum}页返回${response.rows.length}条物料数据`)
response.rows.forEach(item => {
if (item.materialCode && item.materialName) {
const code = item.materialCode.trim().toUpperCase()
this.materialCodeToNameMap[code] = item.materialName
}
})
hasMore = pageNum * pageSize < response.total
pageNum++
} else {
hasMore = false
}
}
console.log('【初始化物料映射表】完成,映射表长度:', Object.keys(this.materialCodeToNameMap).length)
} catch (error) {
console.error('【初始化物料映射表】失败:', error)
this.materialMapLoaded = false
this.$modal.msgError('物料数据加载失败,请刷新页面重试!')
}
},
// 行点击事件
handleRowClick(row, event, column) {
......@@ -886,8 +871,7 @@ export default {
const params = {
...this.queryParams,
isUsed: 1,
// 仓库ID参数已注释
// warehousesId: this.queryParams.warehouseId,
warehousesId: this.queryParams.warehouseId,
warehouseId: undefined
}
console.log('【获取库位列表】最终请求参数:', params)
......@@ -914,13 +898,16 @@ export default {
// 重置查询条件
resetQuery() {
console.log('【重置查询条件】执行重置操作')
// 修改:使用el-form的resetFields方法
if (this.$refs.queryForm) {
this.$refs.queryForm.resetFields()
}
this.queryParams = {
pageNum: 1,
pageSize: 10,
locationCode: null,
locationName: null,
// 仓库查询参数已注释
// warehouseId: null,
warehouseId: null,
locationType: null,
layerCode: null,
locationUsage: null,
......@@ -928,8 +915,7 @@ export default {
zoneCode: null,
pickingArea: null
}
// 仓库名称重置已注释
// this.queryWarehouseName = ''
this.queryWarehouseName = ''
this.getList()
},
......@@ -969,76 +955,73 @@ export default {
// 映射后端字段到前端
const formData = {
...rowData,
// 仓库相关字段映射已注释
// warehouseId: rowData.warehousesId || rowData.warehouseId || rowData.id,
warehouseId: rowData.warehousesId || rowData.warehouseId || rowData.id,
warehousesId: undefined
}
this.form = JSON.parse(JSON.stringify(formData))
// 设置仓库名称已注释
// if (this.form.warehouseId) {
// this.form.warehouseName = this.getWarehouseNameById(this.form.warehouseId)
// }
// 设置仓库名称
if (this.form.warehouseId) {
this.form.warehouseName = this.getWarehouseNameById(this.form.warehouseId)
}
// 物料映射表初始化已注释
// await this.initMaterialCodeToNameMap()
await this.initMaterialCodeToNameMap()
// 物料相关处理已注释
// 处理物料编码和名称(支持数组或字符串格式)
// let materialCodes = []
// let materialNames = []
// // 优先从allowedCategoryIds数组读取(原materialIds)
// if (Array.isArray(rowData.allowedCategoryIds) && rowData.allowedCategoryIds.length) {
// materialCodes = rowData.allowedCategoryIds
// .filter(code => code && code.trim())
// .map(code => code.trim().toUpperCase())
// .filter((code, index, self) => self.indexOf(code) === index)
// }
// // 兼容字符串格式
// else if (rowData.allowedCategoryIds) {
// materialCodes = rowData.allowedCategoryIds.split(',')
// .filter(code => code && code.trim())
// .map(code => code.trim().toUpperCase())
// .filter((code, index, self) => self.indexOf(code) === index)
// }
// // 处理物料名称
// if (Array.isArray(rowData.allowedCategoryNames) && rowData.allowedCategoryNames.length) {
// materialNames = rowData.allowedCategoryNames
// .filter(name => name && name.trim())
// .filter((name, index, self) => self.indexOf(name) === index)
// }
// else if (rowData.allowedCategoryNames) {
// materialNames = rowData.allowedCategoryNames.split(',')
// .filter(name => name && name.trim())
// .filter((name, index, self) => self.indexOf(name) === index)
// }
// // 兜底:通过物料编码映射名称
// else if (materialCodes.length) {
// materialNames = materialCodes.map(code => {
// return this.materialCodeToNameMap[code] || `【未匹配】${code}`
// })
// }
// // 处理分类ID(现在存储的是物料编码)
// let categoryIds = materialCodes
// // 更新表单数据
// this.form.allowedCategoryIds = materialCodes.join(',')
// this.form.allowedCategoryNames = materialNames.join(',')
// // 更新临时选择数据
// this.tempSelectedMaterials = {
// materialCodes: materialCodes,
// names: materialNames,
// categoryIds: categoryIds
// }
// console.log('【修改库位】处理后的物料数据:', {
// allowedCategoryIds: this.form.allowedCategoryIds,
// allowedCategoryNames: this.form.allowedCategoryNames
// })
let materialCodes = []
let materialNames = []
// 优先从allowedCategoryIds数组读取(原materialIds)
if (Array.isArray(rowData.allowedCategoryIds) && rowData.allowedCategoryIds.length) {
materialCodes = rowData.allowedCategoryIds
.filter(code => code && code.trim())
.map(code => code.trim().toUpperCase())
.filter((code, index, self) => self.indexOf(code) === index)
}
// 兼容字符串格式
else if (rowData.allowedCategoryIds) {
materialCodes = rowData.allowedCategoryIds.split(',')
.filter(code => code && code.trim())
.map(code => code.trim().toUpperCase())
.filter((code, index, self) => self.indexOf(code) === index)
}
// 处理物料名称
if (Array.isArray(rowData.allowedCategoryNames) && rowData.allowedCategoryNames.length) {
materialNames = rowData.allowedCategoryNames
.filter(name => name && name.trim())
.filter((name, index, self) => self.indexOf(name) === index)
}
else if (rowData.allowedCategoryNames) {
materialNames = rowData.allowedCategoryNames.split(',')
.filter(name => name && name.trim())
.filter((name, index, self) => self.indexOf(name) === index)
}
// 兜底:通过物料编码映射名称
else if (materialCodes.length) {
materialNames = materialCodes.map(code => {
return this.materialCodeToNameMap[code] || `【未匹配】${code}`
})
}
// 处理分类ID(现在存储的是物料编码)
let categoryIds = materialCodes
// 更新表单数据
this.form.allowedCategoryIds = materialCodes.join(',')
this.form.allowedCategoryNames = materialNames.join(',')
// 更新临时选择数据
this.tempSelectedMaterials = {
materialCodes: materialCodes,
names: materialNames,
categoryIds: categoryIds
}
console.log('【修改库位】处理后的物料数据:', {
allowedCategoryIds: this.form.allowedCategoryIds,
allowedCategoryNames: this.form.allowedCategoryNames
})
this.open = true
this.title = "修改库位"
......@@ -1054,26 +1037,24 @@ export default {
this.$refs["form"].validate(valid => {
if (valid) {
console.log('【提交表单】表单验证通过,开始格式化数据')
// 物料字段格式化已注释
// 格式化物料相关字段(去重、过滤空值)
// const formatField = (value) => {
// if (!value) return ''
// const result = value.split(',')
// .filter(item => item && item.trim())
// .filter((item, index, self) => self.indexOf(item) === index)
// .join(',')
// console.log(`【提交表单】格式化字段值 "${value}" 结果: "${result}"`)
// return result
// }
// this.form.allowedCategoryIds = formatField(this.form.allowedCategoryIds)
// this.form.allowedCategoryNames = formatField(this.form.allowedCategoryNames)
const formatField = (value) => {
if (!value) return ''
const result = value.split(',')
.filter(item => item && item.trim())
.filter((item, index, self) => self.indexOf(item) === index)
.join(',')
console.log(`【提交表单】格式化字段值 "${value}" 结果: "${result}"`)
return result
}
this.form.allowedCategoryIds = formatField(this.form.allowedCategoryIds)
this.form.allowedCategoryNames = formatField(this.form.allowedCategoryNames)
// 转换表单数据
const submitData = {
...this.form,
// 仓库ID映射已注释
// warehousesId: this.form.warehouseId,
warehousesId: this.form.warehouseId,
warehouseId: undefined,
warehouseName: undefined
}
......@@ -1124,77 +1105,76 @@ export default {
console.log('【导出库位】执行导出操作,查询参数:', this.queryParams)
const exportParams = {
...this.queryParams,
// 仓库ID参数已注释
// warehousesId: this.queryParams.warehouseId,
warehousesId: this.queryParams.warehouseId,
warehouseId: undefined
}
console.log('【导出库位】最终导出参数:', exportParams)
this.download('inventory/locations/export', exportParams, `locations_${new Date().getTime()}.xlsx`)
},
// 物料选择变化已注释
// handleMaterialSelectionChange(selectedData) {
// console.log('【物料选择变化】接收到的选择数据:', selectedData)
// // 修复:从selectedData中取materialIds(而非materialCodes)
// const materialCodes = (selectedData.materialIds || [])
// .filter(code => code && code.trim())
// .map(code => code.trim().toUpperCase())
// .filter((code, index, self) => self.indexOf(code) === index)
// // 物料名称取selectedData.names
// const names = (selectedData.names || [])
// .filter(name => name && name.trim())
// .filter((name, index, self) => self.indexOf(name) === index)
// // 分类ID取selectedData.categoryIds(现在存储的是物料编码)
// const categoryIds = materialCodes
// this.tempSelectedMaterials = {
// materialCodes,
// names,
// categoryIds
// }
// console.log('【物料选择变化】处理后的临时选择数据:', this.tempSelectedMaterials)
// },
// 取消物料选择已注释
// handleMaterialSelectionCancel() {
// console.log('【取消物料选择】执行取消操作,恢复原有选择状态')
// this.showMaterialSelect = false
// // 恢复原有选择状态
// this.tempSelectedMaterials = {
// materialCodes: this.form.allowedCategoryIds ? this.form.allowedCategoryIds.split(',').filter(u => u.trim()) : [],
// names: this.form.allowedCategoryNames ? this.form.allowedCategoryNames.split(',').filter(n => n.trim()) : [],
// categoryIds: this.form.allowedCategoryIds ? this.form.allowedCategoryIds.split(',').filter(c => c.trim()) : []
// }
// console.log('【取消物料选择】恢复后的临时选择数据:', this.tempSelectedMaterials)
// },
// 确认物料选择已注释
// confirmMaterialSelection() {
// console.log('【确认物料选择】当前临时选择数据:', this.tempSelectedMaterials)
// // 修复:判断tempSelectedMaterials.materialCodes是否有值
// if (!this.tempSelectedMaterials.materialCodes.length) {
// console.warn('【确认物料选择】未选择任何物料,提示用户')
// this.$modal.msgWarning('请至少选择一个物料!')
// return
// }
// // 更新表单数据(确保去重和过滤)
// this.form.allowedCategoryIds = this.tempSelectedMaterials.materialCodes.join(',')
// this.form.allowedCategoryNames = this.tempSelectedMaterials.names.join(',')
// console.log('【确认物料选择】更新后的表单物料数据:', {
// allowedCategoryIds: this.form.allowedCategoryIds,
// allowedCategoryNames: this.form.allowedCategoryNames
// })
// this.showMaterialSelect = false
// this.$modal.msgSuccess(`成功选择 ${this.tempSelectedMaterials.names.length} 个物料`)
// },
// 物料选择变化
handleMaterialSelectionChange(selectedData) {
console.log('【物料选择变化】接收到的选择数据:', selectedData)
// 修复:从selectedData中取materialIds(而非materialCodes)
const materialCodes = (selectedData.materialIds || [])
.filter(code => code && code.trim())
.map(code => code.trim().toUpperCase())
.filter((code, index, self) => self.indexOf(code) === index)
// 物料名称取selectedData.names
const names = (selectedData.names || [])
.filter(name => name && name.trim())
.filter((name, index, self) => self.indexOf(name) === index)
// 分类ID取selectedData.categoryIds(现在存储的是物料编码)
const categoryIds = materialCodes
this.tempSelectedMaterials = {
materialCodes,
names,
categoryIds
}
console.log('【物料选择变化】处理后的临时选择数据:', this.tempSelectedMaterials)
},
// 取消物料选择
handleMaterialSelectionCancel() {
console.log('【取消物料选择】执行取消操作,恢复原有选择状态')
this.showMaterialSelect = false
// 恢复原有选择状态
this.tempSelectedMaterials = {
materialCodes: this.form.allowedCategoryIds ? this.form.allowedCategoryIds.split(',').filter(u => u.trim()) : [],
names: this.form.allowedCategoryNames ? this.form.allowedCategoryNames.split(',').filter(n => n.trim()) : [],
categoryIds: this.form.allowedCategoryIds ? this.form.allowedCategoryIds.split(',').filter(c => c.trim()) : []
}
console.log('【取消物料选择】恢复后的临时选择数据:', this.tempSelectedMaterials)
},
// 确认物料选择
confirmMaterialSelection() {
console.log('【确认物料选择】当前临时选择数据:', this.tempSelectedMaterials)
// 修复:判断tempSelectedMaterials.materialCodes是否有值
if (!this.tempSelectedMaterials.materialCodes.length) {
console.warn('【确认物料选择】未选择任何物料,提示用户')
this.$modal.msgWarning('请至少选择一个物料!')
return
}
// 更新表单数据(确保去重和过滤)
this.form.allowedCategoryIds = this.tempSelectedMaterials.materialCodes.join(',')
this.form.allowedCategoryNames = this.tempSelectedMaterials.names.join(',')
console.log('【确认物料选择】更新后的表单物料数据:', {
allowedCategoryIds: this.form.allowedCategoryIds,
allowedCategoryNames: this.form.allowedCategoryNames
})
this.showMaterialSelect = false
this.$modal.msgSuccess(`成功选择 ${this.tempSelectedMaterials.names.length} 个物料`)
},
// 导入库位
handleImport() {
......@@ -1209,9 +1189,8 @@ export default {
id: null,
locationCode: null,
locationName: null,
// 仓库相关字段已注释
// warehouseId: null,
// warehouseName: null,
warehouseId: null,
warehouseName: null,
locationType: null,
zoneCode: null,
rowCode: null,
......@@ -1220,9 +1199,8 @@ export default {
capacity: null,
volumeCapacity: null,
allowedHazardLevels: null,
// 物料分类相关字段已注释
// allowedCategoryIds: null, // 原materialCodes
// allowedCategoryNames: null, // 原materialNames
allowedCategoryIds: null, // 原materialCodes
allowedCategoryNames: null, // 原materialNames
temperatureZone: null,
isEnabled: 1,
isUsed: 1,
......@@ -1236,16 +1214,15 @@ export default {
allowMixedProducts: null,
allowMixedBatches: null
}
// 物料临时数据重置已注释
// this.tempSelectedMaterials = {
// materialCodes: [],
// names: [],
// categoryIds: []
// }
// 物料选择器清空已注释
// if (this.$refs.materialsSeletor && this.$refs.materialsSeletor.clearSelection) {
// this.$refs.materialsSeletor.clearSelection()
// }
this.tempSelectedMaterials = {
materialCodes: [],
names: [],
categoryIds: []
}
// 修复:清空物料选择器残留
if (this.$refs.materialsSeletor && this.$refs.materialsSeletor.clearSelection) {
this.$refs.materialsSeletor.clearSelection()
}
if (this.$refs.form) {
this.$refs.form.resetFields()
}
......@@ -1263,21 +1240,37 @@ export default {
</script>
<style scoped>
/* 修改:使用参考样式的布局 */
.app-container {
padding: 20px;
height: 100%;
}
/* 新增:参考样式的页面容器 */
.page-container {
padding: 16px;
background: #fff;
border-radius: 4px;
margin-bottom: 16px;
display: flex;
flex-direction: column;
height: calc(100% - 80px);
height: calc(100vh - 140px);
min-height: 600px;
}
/* 新增:表格容器样式 */
.table-container {
flex: 1;
min-height: 0;
margin-top: 16px;
overflow: hidden;
display: flex;
flex-direction: column;
overflow-x: auto;
}
/* 新增:选择器宽度样式 */
.w20 {
width: 150px;
}
.category-tags {
......
......@@ -54,7 +54,6 @@
:multiple="false"
/>
</div>
</el-dialog>
<!-- 库存信息列表 -->
......@@ -207,13 +206,10 @@
</el-col>
</el-row>
<!-- 已生成明细项 -->
<el-row v-if="details.length > 0" style="margin: 10px 0;">
<el-col :span="24">
<div style="margin-bottom: 8px; font-weight: 600; color: #1989fa;">
已生成明细项
</div>
<!-- 已生成明细项(新增调试提示) -->
<el-row style="margin: 10px 0;">
<el-table
v-if="details.length > 0"
:data="details"
border
size="small"
......@@ -224,7 +220,6 @@
<el-table-column prop="batchId" label="批次" width="150" />
<el-table-column prop="warehousesName" label="仓库名称" width="120" />
<el-table-column prop="locationName" label="库位名称" width="120" />
<el-table-column prop="plannedQuantity" label="计划数量" width="100" />
<el-table-column prop="actualQuantity" label="实际数量" width="100" fixed="right"/>
<el-table-column prop="unitPrice" label="单价" width="100" />
......@@ -247,7 +242,6 @@
</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
</el-form>
......@@ -339,15 +333,26 @@ export default {
},
computed: {
currentSelectedRow() {
console.log('【computed currentSelectedRow】', {
currentSelectedRowId: this.currentSelectedRowId,
matchRow: this.inventoryList.find(row => row.inventoryId === this.currentSelectedRowId)
});
return this.inventoryList.find(row => row.inventoryId === this.currentSelectedRowId) || null;
},
isMaterialLocked() {
return this.initDetails.length > 0 || !!this.initForm.materialId;
const result = this.initDetails.length > 0 || !!this.initForm.materialId;
console.log('【computed isMaterialLocked】', {
initDetailsLength: this.initDetails.length,
initFormMaterialId: this.initForm.materialId,
result
});
return result;
}
},
watch: {
open: {
handler(newVal) {
console.log('【watch open】', { newVal });
if (newVal) {
this.isInitEcho = false;
this.form = {
......@@ -360,6 +365,11 @@ export default {
this.selectedMaterialInfo = null;
this.currentSelectedRowId = null;
this.details = this.initDetails.length > 0 ? JSON.parse(JSON.stringify(this.initDetails)) : [];
console.log('【open=true 初始化数据】', {
form: this.form,
details: this.details,
initDetails: this.initDetails
});
this.$nextTick(async () => {
if (this.form.materialId && this.form.materialId.trim()) {
await this.handleMaterialIdChange();
......@@ -383,6 +393,7 @@ export default {
},
initForm: {
handler(val) {
console.log('【watch initForm】', { val });
if (this.open) {
this.form = {
...this.$options.data().form,
......@@ -410,6 +421,11 @@ export default {
},
inventoryList: {
handler(newVal) {
console.log('【watch inventoryList】', {
newValLength: newVal.length,
isInitEcho: this.isInitEcho,
open: this.open
});
if (this.open && newVal.length > 0 && !this.isInitEcho) {
this.initEchoDetails();
this.isInitEcho = true;
......@@ -421,6 +437,7 @@ export default {
},
outboundOrderId: {
handler(val) {
console.log('【watch outboundOrderId】', { val });
if (this.open) {
this.form.outboundOrderId = val || this.form.outboundOrderId;
}
......@@ -440,10 +457,12 @@ export default {
}
},
async handleMaterialIdChange() {
console.log('【handleMaterialIdChange 开始】', { materialId: this.form.materialId });
this.closeLoading();
const materialId = this.form.materialId?.trim() || '';
if (!materialId) {
this.inventoryList = [];
console.log('【handleMaterialIdChange】物料ID为空,清空库存列表');
return;
}
......@@ -454,19 +473,19 @@ export default {
lock: true,
background: 'rgba(0, 0, 0, 0.7)'
});
console.log("this.form", this.form);
console.log("【handleMaterialIdChange】查询参数", {
materialId: materialId,
outboundOrderId: this.ordersId
});
const params = {
materialId: materialId,
outboundOrderId: this.ordersId
};
console.log('【查询库存参数】', params);
const res = await listInventoryByMaterialId(params);
console.log('【库存接口返回】', res);
console.log('【库存接口原始行数据】', res.rows);
console.log('【handleMaterialIdChange】库存接口返回', res);
if (res.code === 200) {
this.inventoryList = [];
(res.rows || []).forEach(item => {
console.log('【单条库存数据】', item);
const newRow = {
inventoryId: item.id,
id: item.id,
......@@ -498,9 +517,7 @@ export default {
if (this.inventoryList.length > 0 && !this.form.materialName) {
this.$set(this.form, 'materialName', this.inventoryList[0].materialName || '');
}
console.log('【组装后的库存列表】', this.inventoryList);
console.log('【待回显的initDetails】', this.initDetails);
console.log('【handleMaterialIdChange】组装后的库存列表', this.inventoryList);
if (this.inventoryList.length === 0) {
this.$message.warning('未查询到该物料的库存信息');
}
......@@ -511,16 +528,26 @@ export default {
} catch (error) {
this.$message.error('查询库存失败:' + (error.message || '网络异常'));
this.inventoryList = [];
console.error('【handleMaterialIdChange】查询库存异常', error);
} finally {
this.$nextTick(() => {
this.closeLoading();
// 新增:查询库存后主动同步明细
this.syncDetails(false);
});
}
},
initEchoDetails() {
console.log('【开始回显】inventoryList=', this.inventoryList, 'initDetails=', this.initDetails);
if (this.initDetails.length === 0 || this.inventoryList.length === 0) return;
console.log('【initEchoDetails 开始】', {
inventoryList: this.inventoryList,
initDetails: this.initDetails
});
if (this.initDetails.length === 0 || this.inventoryList.length === 0) {
console.log('【initEchoDetails】initDetails或inventoryList为空,跳过回显');
return;
}
// 重置库存行的明细字段
this.inventoryList.forEach(row => {
this.$set(row, 'actualQuantity', null);
this.$set(row, 'plannedQuantity', null);
......@@ -532,7 +559,8 @@ export default {
this.$set(row, 'remark', '');
});
this.initDetails.forEach(detail => {
// 回显initDetails数据
this.initDetails.forEach((detail, index) => {
let targetRow = null;
targetRow = this.inventoryList.find(row => row.inventoryId === detail.inventoryId);
......@@ -552,10 +580,15 @@ export default {
}
if (!targetRow) {
console.warn('【匹配失败】明细无对应库存行,detail.inventoryId=', detail.inventoryId);
console.warn(`【initEchoDetails】第${index+1}条明细匹配失败`, {
detailInventoryId: detail.inventoryId,
detailBatchId: detail.batchId,
inventoryList: this.inventoryList
});
return;
}
// 赋值回显字段
this.$set(targetRow, 'actualQuantity', detail.actualQuantity ?? null);
this.$set(targetRow, 'plannedQuantity', detail.plannedQuantity ?? null);
this.$set(targetRow, 'divisor', detail.divisor ?? null);
......@@ -567,62 +600,98 @@ export default {
if (detail.warehousesName) this.$set(targetRow, 'warehousesName', detail.warehousesName);
if (detail.locationName) this.$set(targetRow, 'locationName', detail.locationName);
if (detail.materialName) this.$set(targetRow, 'materialName', detail.materialName);
console.log(`【initEchoDetails】第${index+1}条明细回显成功`, targetRow);
});
this.syncDetails(false);
console.log('【回显完成】inventoryList=', this.inventoryList);
console.log('【initEchoDetails 完成】', { inventoryList: this.inventoryList });
},
handleRowClick(row) {
console.log('【handleRowClick】', { row });
if (!row) return;
this.currentSelectedRowId = row.inventoryId;
// 新增:点击行后同步明细
this.syncDetails(false);
},
handleRowActualQtyInput(row) {
console.log('【handleRowActualQtyInput】', {
rowInventoryId: row.inventoryId,
inputValue: row.actualQuantity,
availableQty: (row.quantity || 0) - (row.lockedQuantity || 0)
});
if (isNaN(row.actualQuantity) || row.actualQuantity === '' || row.actualQuantity === null) {
this.$set(row, 'actualQuantity', null);
console.log('【handleRowActualQtyInput】输入值非法,重置为null');
return;
}
const availableQty = (row.quantity || 0) - (row.lockedQuantity || 0);
if (row.actualQuantity > availableQty) {
this.$message.warning(`实际数量不能超过可用数量${availableQty}`);
this.$set(row, 'actualQuantity', availableQty);
console.log('【handleRowActualQtyInput】实际数量超限,重置为可用数量', availableQty);
} else if (row.actualQuantity < 1) {
this.$message.warning('实际数量不能小于1');
this.$set(row, 'actualQuantity', 1);
console.log('【handleRowActualQtyInput】实际数量小于1,重置为1');
}
},
handleRowPlannedQtyInput(row) {
console.log('【handleRowPlannedQtyInput】', {
rowInventoryId: row.inventoryId,
inputValue: row.plannedQuantity,
availableQty: (row.quantity || 0) - (row.lockedQuantity || 0)
});
if (isNaN(row.plannedQuantity) || row.plannedQuantity === '' || row.plannedQuantity === null) {
this.$set(row, 'plannedQuantity', null);
console.log('【handleRowPlannedQtyInput】输入值非法,重置为null');
return;
}
const availableQty = (row.quantity || 0) - (row.lockedQuantity || 0);
if (row.plannedQuantity > availableQty) {
this.$message.warning(`计划数量不能超过可用数量${availableQty}`);
this.$set(row, 'plannedQuantity', availableQty);
console.log('【handleRowPlannedQtyInput】计划数量超限,重置为可用数量', availableQty);
} else if (row.plannedQuantity < 1) {
this.$message.warning('计划数量不能小于1');
this.$set(row, 'plannedQuantity', 1);
console.log('【handleRowPlannedQtyInput】计划数量小于1,重置为1');
}
},
// 改造后的 syncDetails:仅校验有实际数量的行,且有值才校验
syncDetails(strict = true) {
// 核心方法:同步明细(添加完整日志)
syncDetails(strict = true) {
console.log('========== syncDetails 开始 ==========', {
strictMode: strict,
inventoryListLength: this.inventoryList.length,
inventoryList: JSON.parse(JSON.stringify(this.inventoryList))
});
this.details = [];
const errorMessages = []; // 收集有值但不合规的字段提示
const errorMessages = [];
let validRows = [];
// 第一步:先过滤出「实际数量有值」的行(核心:无实际数量的行直接排除)
// 第一步:筛选有实际数量的行
const rowsWithActualQty = this.inventoryList.filter(row => {
return row.actualQuantity !== null && row.actualQuantity !== undefined;
const hasActualQty = row.actualQuantity !== null && row.actualQuantity !== undefined;
console.log(`【syncDetails】库存行${row.inventoryId}`, {
hasActualQty,
actualQuantity: row.actualQuantity
});
return hasActualQty;
});
console.log('【syncDetails】筛选出有实际数量的行', {
rowsWithActualQtyLength: rowsWithActualQty.length,
rowsWithActualQty: rowsWithActualQty
});
if (strict && rowsWithActualQty.length > 0) {
// 严格模式:仅校验有实际数量的行,且「有值才校验」
// 严格模式下校验
validRows = rowsWithActualQty.filter((row, index) => {
const rowErrors = [];
const rowName = `第${index + 1}行【${row.materialName || '未知物料'}`;
const rowName = `第${index + 1}行【${row.materialName || '未知物料'}】(inventoryId:${row.inventoryId})`;
const availableQty = (row.quantity || 0) - (row.lockedQuantity || 0);
// 1. 实际数量(必校验,因为能走到这步说明有值)
// 校验实际数量
if (row.actualQuantity < 1) {
rowErrors.push('实际数量不能小于1');
}
......@@ -630,7 +699,7 @@ syncDetails(strict = true) {
rowErrors.push(`实际数量不能超过可用库存(${availableQty})`);
}
// 2. 计划数量(有值才校验)
// 校验计划数量
if (row.plannedQuantity !== null && row.plannedQuantity !== undefined) {
if (row.plannedQuantity < 1) {
rowErrors.push('计划数量不能小于1');
......@@ -638,28 +707,33 @@ syncDetails(strict = true) {
if (row.plannedQuantity > availableQty) {
rowErrors.push(`计划数量不能超过可用库存(${availableQty})`);
}
}else{
} else {
rowErrors.push(`请填写计划数量`);
}
// 3. 除数(有值才校验,无值不提示)
// 校验单价
if (row.unitPrice !== null && row.unitPrice !== undefined) {
// 若有值但为0/负数,可补充校验(按需)
if (row.unitPrice <= 0) {
rowErrors.push('请填写单价');
rowErrors.push('单价不能小于等于0');
}
}
// 收集当前行的错误(仅有值但不合规的字段)
// 记录当前行的校验结果
if (rowErrors.length > 0) {
errorMessages.push(`${rowName}${rowErrors.join('、')}`);
console.log(`【syncDetails】${rowName} 校验失败`, rowErrors);
return false;
}
console.log(`【syncDetails】${rowName} 校验通过`);
return true;
});
} else {
// 非严格模式:直接使用有实际数量的行
validRows = rowsWithActualQty;
console.log('【syncDetails】非严格模式,直接使用有实际数量的行', validRows);
}
// 格式化通过校验的行并同步到details
// 填充details数组
validRows.forEach(row => {
const newDetail = {
inventoryId: row.inventoryId,
......@@ -684,15 +758,22 @@ syncDetails(strict = true) {
this.details.push(newDetail);
});
// 返回错误信息,供提交方法使用
return errorMessages;
},
console.log('========== syncDetails 结束 ==========', {
errorMessages,
validRowsLength: validRows.length,
finalDetailsLength: this.details.length,
finalDetails: this.details
});
// 提交方法:集成精准提示
handleSubmit() {
return errorMessages;
},
// 提交方法(添加完整日志)
handleSubmit() {
console.log('========== handleSubmit 开始 ==========');
// 1. 校验物料ID
if (!this.form.materialId?.trim()) {
this.$message.error('请先选择物料ID');
console.log('【handleSubmit】物料ID为空,提交失败');
return;
}
......@@ -700,15 +781,15 @@ handleSubmit() {
this.$refs.detailForm.validate(async (valid) => {
if (!valid) {
this.$message.error('表单校验失败,请检查必填项');
console.log('【handleSubmit】基础表单校验失败');
return;
}
console.log("syncDetails前", this.details);
// 执行明细校验,接收错误信息
console.log('【handleSubmit】基础表单校验通过,开始同步明细');
// 执行明细校验
const detailErrors = this.syncDetails(true);
console.log("syncDetails后", this.details);
// 3. 提示有值但不合规的字段
// 3. 提示校验错误
if (detailErrors.length > 0) {
this.$message.error({
title: '明细数据校验失败',
......@@ -717,12 +798,17 @@ handleSubmit() {
duration: 15000,
showClose: true
});
console.log('【handleSubmit】明细校验失败', detailErrors);
return;
}
// 4. 兜底:有实际数量的行都校验通过,但无有效行(比如实际数量都<1
// 4. 检查是否有有效明细
if (this.details.length === 0) {
this.$message.error('无有效明细数据,请检查实际数量及相关字段');
console.log('【handleSubmit】无有效明细数据', {
detailsLength: this.details.length,
inventoryList: this.inventoryList
});
return;
}
......@@ -734,13 +820,15 @@ handleSubmit() {
materialId: this.form.materialId || detail.materialId
}));
console.log('提交的明细数据:', submitDetails);
console.log('【handleSubmit】提交明细数据', submitDetails);
this.$emit('submit', submitDetails);
this.$emit('update:open', false);
console.log('========== handleSubmit 完成 ==========');
});
},
},
removeDetail(row) {
console.log('【removeDetail】', { row });
this.details = this.details.filter(d => d.inventoryId !== row.inventoryId);
const inventoryRow = this.inventoryList.find(item => item.inventoryId === row.inventoryId);
if (inventoryRow) {
......@@ -757,9 +845,10 @@ handleSubmit() {
}
}
this.syncDetails(this.initDetails.length === 0);
console.log('【removeDetail 完成】', { details: this.details });
},
handleClose() {
console.log('【handleClose】弹窗关闭');
this.closeLoading();
this.$nextTick(() => {
this.form = this.$options.data().form;
......@@ -776,43 +865,42 @@ handleSubmit() {
});
this.$emit('update:open', false);
},
// 修复:接收selection-change事件参数,兼容多种字段名
handleMaterialSelectionChange(selectedData) {
console.log("【物料选择事件触发】选中数据:", selectedData);
// 兼容数组格式(multiple=false时可能返回对象,需转为数组)
console.log('【handleMaterialSelectionChange】', { selectedData });
// 兼容数组格式
const selectList = Array.isArray(selectedData) ? selectedData : selectedData ? [selectedData] : [];
if (selectList.length > 0) {
this.selectedMaterialInfo = selectList[0];
// 关键:兼容常见的物料ID字段名(id/materialId/uuid)
this.selectedMaterialId = this.selectedMaterialInfo.id || this.selectedMaterialInfo.materialId || this.selectedMaterialInfo.uuid || '';
// 兼容常见的物料名称字段名(materialName/name)
this.$set(this.form, 'materialName', this.selectedMaterialInfo.materialName || this.selectedMaterialInfo.name || '');
console.log("【物料选择成功】ID:", this.selectedMaterialId, "名称:", this.form.materialName);
console.log('【handleMaterialSelectionChange】物料选择成功', {
selectedMaterialId: this.selectedMaterialId,
materialName: this.form.materialName
});
} else {
this.selectedMaterialInfo = null;
this.selectedMaterialId = '';
this.$set(this.form, 'materialName', '');
console.log("【物料选择清空】");
console.log('【handleMaterialSelectionChange】物料选择清空');
}
},
// 修复:增强校验逻辑,增加组件存在性检查和异步同步
confirmMaterialSelect() {
// 标记为“用户主动操作”
console.log('【confirmMaterialSelect】开始');
this.isUserInitiatedSelect = true;
// 1. 检查选择器组件是否存在
if (!this.$refs.materialsSeletor) {
this.$message.error('物料选择器组件加载失败,请重试');
console.error('【confirmMaterialSelect】物料选择器组件不存在');
return;
}
// 2. 异步等待组件数据同步(避免取值过早)
// 2. 异步等待组件数据同步
this.$nextTick(() => {
// 3. 强制触发选中数据同步
const selector = this.$refs.materialsSeletor;
let selectedData = [];
// 兼容组件的多种取值方式
if (selector.getSelectedMaterials) {
selectedData = selector.getSelectedMaterials();
} else if (selector.selectedList) {
......@@ -820,10 +908,10 @@ handleSubmit() {
} else if (selector.value) {
selectedData = selector.value;
}
// 触发数据同步(覆盖事件未触发的场景)
console.log('【confirmMaterialSelect】从选择器获取数据', selectedData);
// 触发数据同步
this.handleMaterialSelectionChange(selectedData);
// 5. 容错处理:确保物料ID有效
const materialId = this.selectedMaterialInfo.id || this.selectedMaterialInfo.materialId || this.selectedMaterialInfo.uuid || '';
......@@ -840,6 +928,7 @@ handleSubmit() {
// 重置标记
this.isUserInitiatedSelect = false;
console.log('【confirmMaterialSelect】完成');
});
}
},
......
......@@ -54,13 +54,14 @@
<!-- 页面容器 -->
<div class="page-container">
<!-- 搜索区域 -->
<page-wrapper-search
<!-- 搜索区域 - 参考样式修改 -->
<el-form
:model="queryParams"
ref="queryForm"
size="small"
@search="handleQuery"
@reset="resetQuery"
:inline="true"
v-show="showSearch"
label-width="100px"
>
<el-form-item label="出库单号" prop="orderId">
<el-input
......@@ -96,7 +97,7 @@
v-model="queryParams.orderTypeId"
placeholder="请输入出库类型"
clearable
style="width: 100%"
style="width: 150px"
>
<el-option
v-for="dict in dict.type.inbound_outbound_type"
......@@ -120,7 +121,7 @@
v-model="queryParams.orderStatus"
placeholder="请选择订单状态"
clearable
style="width: 100%"
style="width: 150px"
>
<el-option
v-for="dict in dict.type.outbound_order_status"
......@@ -150,7 +151,13 @@
</template>
</el-input>
</el-form-item>
</page-wrapper-search>
<!-- 新增搜索和重置按钮 -->
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<!-- 表格容器 -->
<div class="table-container">
......@@ -1271,6 +1278,13 @@ export default {
ownerId: false,
outboundOrderId: false
}
// 核心修改:设置出库日期默认值为当前日期
const today = new Date()
const year = today.getFullYear()
const month = String(today.getMonth() + 1).padStart(2, '0')
const day = String(today.getDate()).padStart(2, '0')
this.form.inboundDate = `${year}-${month}-${day}`
this.open = true
this.title = "添加出库单"
},
......@@ -1563,3 +1577,41 @@ export default {
}
}
</script>
<style scoped>
.page-container {
padding: 16px;
background: #fff;
border-radius: 4px;
margin-bottom: 16px;
display: flex;
flex-direction: column;
height: calc(100vh - 140px);
min-height: 600px;
}
.table-container {
flex: 1;
min-height: 0;
margin-top: 16px;
display: flex;
flex-direction: column;
overflow-x: auto;
}
/* 补充样式,保持和参考页面一致 */
.el-form-item {
margin-bottom: 16px;
}
.material-group {
margin-bottom: 16px;
}
.mb8 {
margin-bottom: 8px;
}
.mb10 {
margin-bottom: 10px;
}
</style>
\ No newline at end of file
<template>
<div class="app-container">
<PageTitle>
<template #buttons>
<el-button
type="primary"
plain
......@@ -12,7 +10,6 @@
@click="handleAdd"
v-hasPermi="['inventory:owners:add']"
>新增</el-button>
<el-button
type="success"
plain
......@@ -22,7 +19,6 @@
@click="handleUpdate"
v-hasPermi="['inventory:owners:edit']"
>修改</el-button>
<el-button
type="danger"
plain
......@@ -32,7 +28,6 @@
@click="handleDelete"
v-hasPermi="['inventory:owners:remove']"
>删除</el-button>
<el-button
type="success"
plain
......@@ -41,7 +36,6 @@
@click="handleImport"
v-hasPermi="['inventory:owners:add']"
>导入</el-button>
<el-button
type="warning"
plain
......@@ -50,19 +44,18 @@
@click="handleExport"
v-hasPermi="['inventory:owners:export']"
>导出</el-button>
</template>
</PageTitle>
<div class="page-container">
<page-wrapper-search
<!-- 替换原有page-wrapper-search为原生el-form -->
<el-form
:model="queryParams"
ref="queryForm"
size="small"
@search="handleQuery"
@reset="resetQuery"
:inline="true"
v-show="showSearch"
label-width="100px"
>
<el-form-item label="货主编码" prop="ownerCode">
<el-input
......@@ -80,7 +73,6 @@
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<!-- 新增英文名称查询项 -->
<el-form-item label="英文名称" prop="englishName">
<el-input
v-model="queryParams.englishName"
......@@ -97,14 +89,12 @@
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="是否激活" prop="isActive">
<el-select
v-model="queryParams.isActive"
placeholder="请选择是否激活"
clearable
@keyup.enter.native="handleQuery"
style="width: 100%"
style="width: 150px"
>
<el-option
v-for="dict in dict.type.yes_no"
......@@ -114,14 +104,19 @@
></el-option>
</el-select>
</el-form-item>
</page-wrapper-search>
<!-- 独立的搜索和重置按钮 -->
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<div class="table-container">
<el-table v-loading="loading" :data="ownersList" height="100%" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" fixed />
<el-table-column label="货主编码" align="center" prop="ownerCode" width="120" fixed/>
<el-table-column label="货主名称" align="center" prop="ownerName"width="220" />
<!-- 新增英文名称表格列 -->
<el-table-column label="英文名称" align="center" prop="englishName"width="220" />
<el-table-column label="货主名称" align="center" prop="ownerName" width="220" />
<el-table-column label="英文名称" align="center" prop="englishName" width="220" />
<el-table-column label="货主类型" align="center" prop="ownerType">
<template slot-scope="scope">
<dict-tag :options="dict.type.owner_type" :value="scope.row.ownerType"/>
......@@ -131,14 +126,13 @@
<el-table-column label="联系电话" align="center" prop="contactPhone" width="120"/>
<el-table-column label="邮箱" align="center" prop="email" width="200"/>
<el-table-column label="地址" align="center" prop="address" width="220"/>
<el-table-column label="税号" align="center" prop="taxNumber"width="180" />
<el-table-column label="税号" align="center" prop="taxNumber" width="180" />
<el-table-column label="银行账户" align="center" prop="bankAccount" width="180"/>
<el-table-column label="是否激活" align="center" prop="isActive">
<template slot-scope="scope">
<dict-tag :options="dict.type.yes_no" :value="scope.row.isActive"/>
</template>
</el-table-column>
<el-table-column label="创建日期" align="center" prop="createTime" width="160" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120" fixed="right">
<template slot-scope="scope">
......@@ -161,7 +155,6 @@
</el-table>
</div>
<pagination
v-show="total>0"
:total="total"
......@@ -171,9 +164,6 @@
/>
</div>
<!-- 添加或修改货主信息对话框 -->
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
......@@ -189,7 +179,6 @@
</el-form-item>
</el-col>
</el-row>
<!-- 新增英文名称表单项 -->
<el-row :gutter="20">
<el-col :span="24">
<el-form-item label="英文名称" prop="englishName">
......@@ -249,7 +238,6 @@
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="银行账户" prop="bankAccount">
<el-input v-model="form.bankAccount" placeholder="请输入银行账户" />
......@@ -271,11 +259,10 @@
template-name="owners_importTemplate"
@success="getList"
/>
</div>
</template>
<script>
<script>
import { listOwners, getOwners, delOwners, addOwners, updateOwners } from "@/api/inventory/owners"
import ImportExcel from "@/components/ImportExcel/index"
......@@ -309,7 +296,7 @@ export default {
pageSize: 10,
ownerCode: null,
ownerName: null,
englishName: null, // 新增英文名称查询参数
englishName: null,
ownerType: null,
contactPerson: null,
contactPhone: null,
......@@ -332,7 +319,7 @@ export default {
ownerName: [
{ required: true, message: '货主名称不能为空', trigger: 'blur' }
],
englishName: [ // 新增英文名称校验规则(非必填,可根据需求调整)
englishName: [
{ required: false, message: '英文名称不能为空', trigger: 'blur' }
],
contactPerson: [
......@@ -377,7 +364,7 @@ export default {
id: null,
ownerCode: null,
ownerName: null,
englishName: null, // 新增英文名称表单重置
englishName: null,
ownerType: null,
contactPerson: null,
contactPhone: null,
......@@ -401,12 +388,15 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.queryParams={
// 使用el-form的resetFields方法重置表单
this.$refs.queryForm.resetFields()
// 手动重置复杂类型的参数(如下拉框)
this.queryParams = {
pageNum: 1,
pageSize: 10,
ownerCode: null,
ownerName: null,
englishName: null, // 新增英文名称查询参数重置
englishName: null,
ownerType: null,
contactPerson: null,
contactPhone: null,
......@@ -418,7 +408,7 @@ export default {
sortNo: null,
createUserCode: null,
updateUserCode: null
},
}
this.handleQuery()
},
// 多选框选中数据
......@@ -486,3 +476,26 @@ export default {
}
}
</script>
<style scoped>
/* 添加参考页面的样式,保证布局一致 */
.page-container {
padding: 16px;
background: #fff;
border-radius: 4px;
margin-bottom: 16px;
display: flex;
flex-direction: column;
height: calc(100vh - 140px);
min-height: 600px;
}
.table-container {
flex: 1;
min-height: 0;
margin-top: 16px;
display: flex;
flex-direction: column;
overflow-x: auto;
}
</style>
\ No newline at end of file
......@@ -36,18 +36,20 @@
@click="handleExport"
v-hasPermi="['inventory:warehouses:export']"
>导出</el-button>
<!-- 新增导入按钮(和其他页面保持一致) -->
<el-button
type="success"
plain
icon="el-icon-upload"
size="medium"
@click="handleImport"
v-hasPermi="['inventory:warehouses:add']"
>导入</el-button>
</template>
</PageTitle>
<div class="page-container">
<page-wrapper-search
:model="queryParams"
ref="queryForm"
size="small"
@search="handleQuery"
@reset="resetQuery"
>
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
<el-form-item label="仓库编码" prop="warehousesCode">
<el-input
v-model="queryParams.warehousesCode"
......@@ -69,7 +71,7 @@
v-model="queryParams.warehouseType"
placeholder="请选择仓库类型"
clearable
style="width: 100%"
class="w20"
>
<el-option
v-for="dict in dict.type.warehouse_type"
......@@ -92,14 +94,18 @@
v-model="queryParams.isEnabled"
placeholder="请选择应用状态"
clearable
style="width: 100%"
@change="handleQuery"
class="w20"
>
<el-option label="启用" value="1" />
<el-option label="停用" value="0" />
</el-select>
</el-form-item>
</page-wrapper-search>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<div class="table-container">
<el-table v-loading="loading" :data="warehousesList" height="100%" @selection-change="handleSelectionChange">
......@@ -126,6 +132,36 @@
</el-tag>
</template>
</el-table-column>
<!-- 新增:允许存放物料列 - 修复可选链语法 -->
<el-table-column label="允许存放物料" align="center" prop="allowMaterialCodes" min-width="150">
<template slot-scope="scope">
<el-tooltip
:content="scope.row.allowMaterialCodes && scope.row.allowMaterialCodes.length ? scope.row.allowMaterialCodes.join(',') : '无'"
placement="top"
effect="light"
>
<div class="material-tags">
<el-tag
v-for="(code, index) in (scope.row.allowMaterialCodes && scope.row.allowMaterialCodes.length ? scope.row.allowMaterialCodes.slice(0, 3) : [])"
:key="index"
type="info"
size="small"
style="margin-right: 5px;"
>
{{ code }}
</el-tag>
<el-tag
v-if="scope.row.allowMaterialCodes && scope.row.allowMaterialCodes.length > 3"
type="info"
size="small"
style="background: #f0f9eb; border-color: #c2e7b0;"
>
+{{ scope.row.allowMaterialCodes.length - 3 }}
</el-tag>
</div>
</el-tooltip>
</template>
</el-table-column>
<el-table-column label="创建日期" align="center" prop="createTime" min-width="160" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120" fixed="right">
<template slot-scope="scope">
......@@ -163,7 +199,11 @@
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="仓库编码" prop="warehousesCode">
<el-input v-model="form.warehousesCode" placeholder="请输入仓库编码" />
<el-input
v-model="form.warehousesCode"
placeholder="请输入仓库编码"
:readonly="!!form.id" <!-- 修改时编码不可改 -->
/>
</el-form-item>
</el-col>
<el-col :span="12">
......@@ -226,11 +266,32 @@
<el-row :gutter="20">
<el-col :span="24">
<el-form-item label="仓库地点" prop="address">
<el-input v-model="form.address" type="textarea" placeholder="请输入内容" :rows="3" />
<el-input v-model="form.address" type="textarea" placeholder="请输入仓库地点" :rows="3" />
</el-form-item>
</el-col>
</el-row>
<!-- 新增:允许存放物料选择项(和其他页面选择器交互一致) -->
<el-row :gutter="20">
<el-col :span="24">
<el-form-item label="允许存放物料" prop="allowMaterialCodes">
<el-input
v-model="allowMaterialDisplay"
placeholder="请选择允许存放的物料(可选)"
readonly
@click="openMaterialSelector"
:suffix-icon="''"
>
<template v-if="allowMaterialDisplay" #suffix>
<i
class="el-icon-circle-close el-input__icon"
style="cursor: pointer;"
@click.stop="clearMaterialSelection"
></i>
</template>
</el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
......@@ -238,6 +299,25 @@
</div>
</el-dialog>
<!-- 物料选择器弹窗 -->
<el-dialog
title="选择允许存放的物料"
:visible.sync="materialSelectorVisible"
width="1000px"
append-to-body
:close-on-click-modal="false"
>
<MaterialSelector
ref="materialSelector"
@selection-change="handleMaterialSelectionChange"
:selected-material-codes="form.allowMaterialCodes"
:multiple="true"
/>
<div slot="footer" class="dialog-footer">
<el-button @click="materialSelectorVisible = false">取消</el-button>
<el-button type="primary" @click="confirmMaterialSelection">确认选择</el-button>
</div>
</el-dialog>
<!-- 导入组件 -->
<import-excel
......@@ -254,7 +334,6 @@
<script>
import { listWarehouses, getWarehouses, delWarehouses, addWarehouses, updateWarehouses } from "@/api/inventory/warehouses"
import ImportExcel from "@/components/ImportExcel/index"
// 仅注册组件,不修改路径(保持你原有路径)
import MaterialSelector from '@/components/materialsSeletor.vue'
export default {
......@@ -314,8 +393,7 @@ export default {
updateUserCode: null
},
// 表单参数
// 1. 先强制重置form为初始值(新增场景的默认值)
form:{
form: {
id: null,
warehousesCode: null,
warehousesName: null,
......@@ -332,11 +410,12 @@ export default {
createUserCode: null,
updateTime: null,
updateUserCode: null,
allowMaterialCodes: []
allowMaterialCodes: [] // 允许存放的物料编码
},
// 新增:物料选择器相关
// 物料选择器相关
materialSelectorVisible: false,
allowMaterialDisplay: '',
allowMaterialDisplay: '', // 物料选择器显示文本
tempSelectedMaterials: [], // 临时选中的物料编码
// 表单校验
rules: {
warehousesCode: [
......@@ -356,9 +435,7 @@ export default {
area: [
{
validator: (rule, value, callback) => {
// 空值直接通过(如果需要必填,可加required规则)
if (!value) return callback();
// 验证是否为数字(兼容字符串格式的数字,如"123")
if (isNaN(Number(value))) {
callback(new Error('仓库区域必须为数字值'));
} else {
......@@ -367,11 +444,10 @@ export default {
},
trigger: 'blur'
}
],
// 新增:联系电话校验(手机号格式)
],
contactPhone: [
{ validator: validatePhone, trigger: 'blur' }
],
]
}
}
},
......@@ -383,53 +459,68 @@ export default {
getList() {
this.loading = true
listWarehouses(this.queryParams).then(response => {
this.warehousesList = response.rows
this.total = response.total
this.warehousesList = response.rows || []
this.total = response.total || 0
this.loading = false
}).catch(error => {
console.error('查询仓库列表失败:', error)
this.warehousesList = []
this.total = 0
this.loading = false
})
},
// 取消按钮
cancel() {
this.open = false
this.reset()
// 重置选中状态
this.ids = []
this.single = true
this.multiple = true
// 重置物料选择器
this.materialSelectorVisible = false
this.allowMaterialDisplay = ''
this.tempSelectedMaterials = []
},
// 表单重置
reset() {
if (this.$refs.form) {
this.$refs.form.resetFields(); // 恢复初始值
this.$refs.form.clearValidate(); // 清除校验提示
this.$refs.form.resetFields()
this.$refs.form.clearValidate()
}
this.form.id = null;
this.form.warehousesCode = ''; // 用空字符串而非null,匹配输入框默认值
this.form.warehousesName = '';
this.form.warehouseType = undefined; // 让下拉框回到未选择状态
this.form.address = '';
this.form.area = '';
this.form.capacity = null;
this.form.manager = '';
this.form.contactPhone = '';
this.form.isEnabled = 1; // 新增默认启用
this.form.sortNo = 0;
this.form.allowMaterialCodes = [];
this.allowMaterialDisplay = '';
// 3. 重置选中状态
this.ids = [];
this.single = true;
this.multiple = true;
this.materialSelectorVisible = false;
// 重置表单为初始状态
this.form = {
id: null,
warehousesCode: '',
warehousesName: '',
warehouseType: undefined,
address: '',
area: '',
capacity: null,
manager: '',
contactPhone: '',
isEnabled: 1,
isUsed: null,
sortNo: 0,
createTime: null,
createUserCode: null,
updateTime: null,
updateUserCode: null,
allowMaterialCodes: []
}
// 重置选中状态
this.ids = []
this.single = true
this.multiple = true
// 重置物料选择相关
this.allowMaterialDisplay = ''
this.tempSelectedMaterials = []
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.queryParams = {
......@@ -449,96 +540,148 @@ export default {
createUserCode: null,
updateUserCode: null
}
// 重置选中状态
this.ids = []
this.single = true
this.multiple = true
this.handleQuery()
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.title = "添加仓库";
this.open = true; // 先打开弹窗,渲染表单DOM
// 等待DOM渲染完成后再重置
this.$nextTick(() => {
this.reset();
});
this.reset()
this.open = true
this.title = "添加仓库"
},
/** 修改按钮操作 */
handleUpdate(row) {
// 1. 先重置,再赋值(避免旧数据残留)
this.reset();
const id = row.id || (this.ids.length > 0 ? this.ids[0] : null);
this.reset()
const id = row.id || (this.ids.length > 0 ? this.ids[0] : null)
if (!id) {
this.$modal.msgWarning("请选择要修改的仓库");
return;
this.$modal.msgWarning("请选择要修改的仓库")
return
}
getWarehouses(id).then(response => {
// 2. 赋值前确保弹窗已打开
this.open = true;
this.title = "修改仓库";
// 3. 深度赋值,避免响应式丢失
this.form = { ...response.data };
// 4. 处理物料编码反显(如果有)
this.form = { ...response.data }
// 处理物料编码反显
if (this.form.allowMaterialCodes && this.form.allowMaterialCodes.length) {
this.formatMaterialDisplay(this.form.allowMaterialCodes);
this.allowMaterialDisplay = this.form.allowMaterialCodes.join(', ')
this.tempSelectedMaterials = [...this.form.allowMaterialCodes]
}
});
this.open = true
this.title = "修改仓库"
}).catch(error => {
console.error('获取仓库详情失败:', error)
this.$modal.msgError('获取仓库详情失败,请重试')
})
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
// 格式化物料编码(去重、过滤空值)
this.form.allowMaterialCodes = this.tempSelectedMaterials
.filter(code => code && code.trim())
.filter((code, index, self) => self.indexOf(code) === index)
const request = this.form.id ? updateWarehouses(this.form) : addWarehouses(this.form)
request.then(response => {
this.$modal.msgSuccess(this.form.id ? "修改成功" : "新增成功")
this.open = false
this.getList()
// 重置选中状态
this.ids = []
this.single = true
this.multiple = true
}).catch(() => {
this.reset() // 提交后重置表单
}).catch(error => {
console.error('提交仓库数据失败:', error)
this.$modal.msgError(this.form.id ? "修改失败" : "新增失败")
})
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
// 统一转为数组格式
const ids = row.id ? [row.id] : this.ids
if (ids.length === 0) {
this.$modal.msgWarning("请选择要删除的仓库")
return
}
this.$modal.confirm(
row.id ? `是否确认删除仓库编为"${row.warehousesCode}"的数据项?` : `是否确认删除选中的${ids.length}条仓库数据项?`
row.id ? `是否确认删除仓库编为"${row.warehousesCode}"的数据项?` : `是否确认删除选中的${ids.length}条仓库数据项?`
).then(() => {
return delWarehouses(ids)
}).then(() => {
this.getList()
this.$modal.msgSuccess("删除成功")
// 重置选中状态
this.ids = []
this.single = true
this.multiple = true
}).catch(() => {})
},
/** 导出按钮操作 */
handleExport() {
this.download('inventory/warehouses/export', {
...this.queryParams
}, `warehouses_${new Date().getTime()}.xlsx`)
},
/** 导入组件 */
/** 导入按钮操作 */
handleImport() {
this.$refs.import.show()
},
// 打开物料选择器
openMaterialSelector() {
// 初始化临时选中数据
this.tempSelectedMaterials = [...this.form.allowMaterialCodes]
this.materialSelectorVisible = true
// 清空子组件选中状态(如果有该方法)
this.$nextTick(() => {
if (this.$refs.materialSelector && this.$refs.materialSelector.clearSelection) {
this.$refs.materialSelector.clearSelection()
// 回显已选物料
if (this.tempSelectedMaterials.length) {
this.$refs.materialSelector.setSelection(this.tempSelectedMaterials)
}
}
})
},
// 物料选择变化回调
handleMaterialSelectionChange(selectedData) {
// 兼容不同格式的返回值
this.tempSelectedMaterials = (selectedData.materialIds || selectedData || [])
.filter(code => code && code.trim())
.map(code => code.trim())
.filter((code, index, self) => self.indexOf(code) === index)
},
// 确认物料选择
confirmMaterialSelection() {
if (!this.tempSelectedMaterials.length) {
this.allowMaterialDisplay = ''
} else {
this.allowMaterialDisplay = this.tempSelectedMaterials.join(', ')
}
this.form.allowMaterialCodes = [...this.tempSelectedMaterials]
this.materialSelectorVisible = false
},
// 清空物料选择
clearMaterialSelection() {
this.allowMaterialDisplay = ''
this.tempSelectedMaterials = []
this.form.allowMaterialCodes = []
}
}
}
......@@ -565,4 +708,15 @@ export default {
.dialog-footer {
text-align: center;
}
.material-tags {
display: flex;
flex-wrap: wrap;
align-items: center;
}
/deep/ .el-tooltip__popper {
max-width: 300px;
white-space: normal;
}
</style>
\ No newline at end of file
......@@ -108,7 +108,7 @@
<if test="orderId != null and orderId != ''"> and oo.order_id like concat('%', #{orderId}, '%')</if>
<if test="batchCode != null and batchCode != ''"> and oo.batch_code like concat('%', #{batchCode}, '%')</if>
<if test="systemNo != null and systemNo != ''"> and oo.system_no like concat('%', #{systemNo}, '%')</if>
<if test="orderTypeId != null and orderTypeId != ''"> and oo.order_type_id = {orderTypeId}</if>
<if test="orderTypeId != null and orderTypeId != ''"> and oo.order_type_id = #{orderTypeId}</if>
<if test="orderType != null and orderType != ''"> and oo.order_type = #{orderType}</if>
<if test="batchCode != null and batchCode != ''"> and oo.batch_code like concat('%', #{batchCode}, '%')</if>
<if test="warehouseId != null and warehouseId != ''"> and oo.warehouse_id = #{warehouseId}</if>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论