diff --git a/src/views/modules/npcIqc/logisticsManagement.vue b/src/views/modules/npcIqc/logisticsManagement.vue index 82b24c9..92b3e56 100644 --- a/src/views/modules/npcIqc/logisticsManagement.vue +++ b/src/views/modules/npcIqc/logisticsManagement.vue @@ -191,14 +191,14 @@ - + - 保存 + 保存 关闭 @@ -275,6 +275,7 @@ import LogisticsAttachmentTab from './com_logisticsAttachmentTab.vue' import ComPoOrderCustomerPicker from '@/views/modules/order/com_poOrder_CustomerPicker.vue' import { searchLogistics, getPoList, getAvailablePoList, updateLogisticsPo, removeLogisticsPo, updateTelexRelease, changeLogisticsFlexId } from '@/api/npcIqc/npcIqc.js' +import { listActiveShipMethods } from '@/api/port/portTransit.js' import Chooselist from '@/views/modules/common/Chooselist_eam' import excel from '@/utils/excel-util.js' @@ -352,12 +353,8 @@ export default { item: '', method: '' }, - // Method 下拉选项(与 poOrder 运输方式口径一致) - methodOptions: [ - { label: '海运 SEA', value: 'SEA' }, - { label: '空运 AIR', value: 'AIR' }, - { label: '陆运 ROAD', value: 'ROAD' } - ] + // Method 下拉选项:与订单模块同源,运行时从 listActiveShipMethods 加载启用的运输方式 method_desc + methodOptions: [] } }, mounted () { @@ -479,12 +476,18 @@ export default { } }, - // 打开新增物流弹窗 + // 打开新增物流弹窗(与编辑同模型:增删仅前端暂存,点底部"保存"才写库) openAddDialog () { this.dialogMode = 'add' this.addForm = { flexId: '', supplierNo: '', supplierName: '', customer: '' } this.addPoList = [] this.telexRelease = 'No' + this.telexDirty = false + this.pendingAddOrderNos = [] + this.pendingRemoveOrderNos = [] + this.originalFlexId = '' + this.flexIdDirty = false + this.editSaving = false this.availableSearch = { po: '', item: '', method: '' } this.addDialogVisible = true }, @@ -573,9 +576,36 @@ export default { } this.availableSelection = [] this.availableDialogVisible = true + this.loadMethodOptions() this.loadAvailablePoList() }, + // 加载 Method(运输方式)下拉选项:与订单模块同源,取启用运输方式的 method_desc(与 POHeader.ship_via 存储口径一致) + loadMethodOptions () { + if (this.methodOptions.length) { + return + } + listActiveShipMethods().then(({ data }) => { + if (data && data.code === 0) { + const rows = Array.isArray(data.rows) ? data.rows : [] + const seen = new Set() + this.methodOptions = rows.reduce((options, row) => { + const label = String((row && row.methodDesc) || '').trim() + if (!label || seen.has(label)) { + return options + } + seen.add(label) + options.push({ label: label, value: label }) + return options + }, []) + } else { + this.methodOptions = [] + } + }).catch(() => { + this.methodOptions = [] + }) + }, + // 加载该供应商下可选的PO(排除当前表格中已有数据) loadAvailablePoList () { this.availableLoading = true @@ -613,52 +643,29 @@ export default { this.availableSelection = val }, - // 保存选中的PO:新增模式立即写库;编辑模式仅前端暂存(点底部"保存"才写库) + // 保存选中的PO:新增/编辑均只前端暂存(addPoList+待新增清单),点底部"保存"才写库 saveAvailablePo () { if (!this.availableSelection.length) { this.$message.warning('请至少选择一条PO') return } - if (this.dialogMode === 'edit') { - // 编辑模式:只改前端 addPoList,不碰数据库 - this.availableSelection.forEach(row => { - if (!this.addPoList.some(exist => exist.orderNo === row.orderNo)) { - this.addPoList.push(row) - } - // 若之前暂存过移除,则抵消 - const rmIdx = this.pendingRemoveOrderNos.indexOf(row.orderNo) - if (rmIdx !== -1) this.pendingRemoveOrderNos.splice(rmIdx, 1) - // 记录待新增 - if (this.pendingAddOrderNos.indexOf(row.orderNo) === -1) { - this.pendingAddOrderNos.push(row.orderNo) - } - }) - this.availableDialogVisible = false - this.$message.success('已添加,点击底部"保存"后生效') - return - } - const params = { - flexId: this.addForm.flexId, - supplierNo: this.addForm.supplierNo, - site: this.$store.state.user.site, - orderNoList: this.availableSelection.map(row => row.orderNo) - } - updateLogisticsPo(params).then(({ data }) => { - if (data.code === 0) { - this.$message.success('保存成功') - this.availableDialogVisible = false - // 刷新第一个弹窗表格及主列表 - this.loadAddPoList() - this.getMainData() - } else { - this.$message.error(data.msg || '保存失败') + this.availableSelection.forEach(row => { + if (!this.addPoList.some(exist => exist.orderNo === row.orderNo)) { + this.addPoList.push(row) + } + // 若之前暂存过移除,则抵消 + const rmIdx = this.pendingRemoveOrderNos.indexOf(row.orderNo) + if (rmIdx !== -1) this.pendingRemoveOrderNos.splice(rmIdx, 1) + // 记录待新增 + if (this.pendingAddOrderNos.indexOf(row.orderNo) === -1) { + this.pendingAddOrderNos.push(row.orderNo) } - }).catch(() => { - this.$message.error('保存失败') }) + this.availableDialogVisible = false + this.$message.success('已添加') }, - // 移除:将该PO订单的 c_flexid 置空、Telex 重置为 No(按 order_no 整单) + // 移除:将该PO订单的 c_flexid 置空、Telex 重置为 No(按 order_no 整单);新增/编辑均只前端暂存 handleRemovePo (row) { if (!this.addForm.flexId) { this.$message.warning('请先填写LOGISTICS ID') @@ -669,50 +676,34 @@ export default { cancelButtonText: '取消', type: 'warning' }).then(() => { - if (this.dialogMode === 'edit') { - // 编辑模式:只改前端,不碰数据库 - const idx = this.addPoList.findIndex(r => r.orderNo === row.orderNo) - if (idx !== -1) this.addPoList.splice(idx, 1) - const addIdx = this.pendingAddOrderNos.indexOf(row.orderNo) - if (addIdx !== -1) { - // 本次暂存新增又移除 → 直接抵消,不需写库 - this.pendingAddOrderNos.splice(addIdx, 1) - } else if (this.pendingRemoveOrderNos.indexOf(row.orderNo) === -1) { - // 数据库已有的 → 记录为待移除 - this.pendingRemoveOrderNos.push(row.orderNo) - } - this.$message.success('已移除,点击底部"保存"后生效') - return - } - const params = { - site: this.$store.state.user.site, - flexId: this.addForm.flexId, - supplierNo: this.addForm.supplierNo, - orderNoList: [row.orderNo] + // 只改前端,不碰数据库,点底部"保存"才写库 + const idx = this.addPoList.findIndex(r => r.orderNo === row.orderNo) + if (idx !== -1) this.addPoList.splice(idx, 1) + const addIdx = this.pendingAddOrderNos.indexOf(row.orderNo) + if (addIdx !== -1) { + // 本次暂存新增又移除 → 直接抵消,不需写库 + this.pendingAddOrderNos.splice(addIdx, 1) + } else if (this.pendingRemoveOrderNos.indexOf(row.orderNo) === -1) { + // 数据库已有的 → 记录为待移除 + this.pendingRemoveOrderNos.push(row.orderNo) } - removeLogisticsPo(params).then(({ data }) => { - if (data.code === 0) { - this.$message.success('移除成功') - this.loadAddPoList() - this.getMainData() - } else { - this.$message.error(data.msg || '移除失败') - } - }).catch(() => { - this.$message.error('移除失败') - }) + this.$message.success('已移除') }).catch(() => {}) }, - // 编辑界面:点击底部"保存"才一次性提交本次所有暂存改动(移除→改单号→新增→Telex) + // 新增/编辑界面:点击底部"保存"才一次性提交本次所有暂存改动(移除→改单号→新增→Telex) saveEditAll () { if (!this.addForm.flexId) { this.$message.warning('缺少物流单号') return } + if (this.dialogMode === 'add' && !this.addForm.supplierNo) { + this.$message.warning('请先填写供应商编码') + return + } const site = this.$store.state.user.site const supplierNo = this.addForm.supplierNo - const oldFlexId = this.originalFlexId // 数据库当前值 + const oldFlexId = this.originalFlexId || this.addForm.flexId // 数据库当前值(新增模式未暂存改单号,取当前填写值) const newFlexId = this.addForm.flexId // 可能已暂存修改 const flexIdChanged = this.flexIdDirty && newFlexId !== oldFlexId const removeList = this.pendingRemoveOrderNos.slice() @@ -760,8 +751,10 @@ export default { this.getMainData() }).catch(err => { this.$message.error((err && err.message) || '保存失败') - // 部分提交可能已生效,回退前端显示为库中实际值,避免新旧单号不一致 - this.addForm.flexId = this.originalFlexId + // 部分提交可能已生效,回退前端显示为库中实际值,避免新旧单号不一致(仅改单号暂存生效的编辑模式) + if (this.originalFlexId) { + this.addForm.flexId = this.originalFlexId + } this.flexIdDirty = false this.loadAddPoList() this.getMainData() @@ -791,7 +784,7 @@ export default { this.addForm.flexId = newVal this.flexIdDirty = true this.changeFlexIdDialogVisible = false - this.$message.success('已修改,点击底部"保存"后生效') + this.$message.success('已修改') }, // 加载PO清单