From 491344f1d61c85957b9a257677f2cb7b14f17db6 Mon Sep 17 00:00:00 2001 From: chenhao Date: Thu, 27 Nov 2025 15:17:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(purchaseorder):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E5=8D=95=E8=AF=A6=E6=83=85=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 通过 prop 传递订单数据替代原有的 loadPurchaseOrder 方法调用 - 在 PurchaseOrderDetail 和 PurchaseOrderDetailView 组件中添加 orderData 属性支持 - 更新父组件中的引用,确保数据正确传递到子组件 - 移除冗余的 watch 监听逻辑,简化代码结构 - 保留 loadPurchaseOrder 方法以保证向后兼容性 - 优化组件创建时的数据初始化流程 --- .../components/PurchaseOrderDetail.vue | 42 +++++++++++-- .../components/PurchaseOrderDetailView.vue | 26 ++++++-- .../oms_vue/src/views/purchaseorder/index.vue | 60 +++++++++---------- 3 files changed, 88 insertions(+), 40 deletions(-) diff --git a/oms_web/oms_vue/src/views/purchaseorder/components/PurchaseOrderDetail.vue b/oms_web/oms_vue/src/views/purchaseorder/components/PurchaseOrderDetail.vue index bd8b86ab..0576cd45 100644 --- a/oms_web/oms_vue/src/views/purchaseorder/components/PurchaseOrderDetail.vue +++ b/oms_web/oms_vue/src/views/purchaseorder/components/PurchaseOrderDetail.vue @@ -193,7 +193,12 @@ import {preciseCurrencyRound} from "@/utils/ruoyi"; export default { name: "PurchaseOrderDetail", components: { SelectUser, SelectProduct }, - + props: { + orderData: { + type: Object, + default: null + } + }, data() { return { // 产品选择弹窗 @@ -279,22 +284,51 @@ export default { return (preciseCurrencyRound((this.totalAmountWithTax - this.totalAmountWithoutTax )) ) || 0; } }, + watch: { + orderData: { + handler(newVal) { + if (newVal) { + this.form = JSON.parse(JSON.stringify(newVal)); + // 等待 vendorOptions 加载完成后再处理制造商 + this.$nextTick(() => { + this.handleVendorChange(this.form.vendorId); + // 确保 omsPurchaseOrderItemList 至少有一个空行 + if (this.form.omsPurchaseOrderItemList && this.form.omsPurchaseOrderItemList.length === 0) { + this.form.omsPurchaseOrderItemList.push(this.getNewPurchaseOrderItem()); + } + }); + } else { + // orderData 为 null 时重置表单为新增状态 + this.resetForm(); + } + }, + immediate: false, + deep: false + } + }, created() { this.getVendorList().then(() => { getDicts("product_type").then(response => { this.productTypeOptions = response.data; }); + // 如果已经有 orderData 则立即处理 + if (this.orderData) { + this.form = JSON.parse(JSON.stringify(this.orderData)); + this.handleVendorChange(this.form.vendorId); + if (this.form.omsPurchaseOrderItemList && this.form.omsPurchaseOrderItemList.length === 0) { + this.form.omsPurchaseOrderItemList.push(this.getNewPurchaseOrderItem()); + } + } }); }, methods: { loadPurchaseOrder(id) { - if (id){ + // 此方法保留用于兼容性,实际数据通过 prop 传递 + if (!this.orderData && id) { getPurchaseorder(id).then(response => { this.form = response.data; console.log(this.form) - // 加载订单后,根据vendorId回显制造商信息 this.handleVendorChange(this.form.vendorId); - // 确保 omsPurchaseOrderItemList 至少有一个空行如果它是空的 if (this.form.omsPurchaseOrderItemList && this.form.omsPurchaseOrderItemList.length === 0) { this.form.omsPurchaseOrderItemList.push(this.getNewPurchaseOrderItem()); } diff --git a/oms_web/oms_vue/src/views/purchaseorder/components/PurchaseOrderDetailView.vue b/oms_web/oms_vue/src/views/purchaseorder/components/PurchaseOrderDetailView.vue index 5defb02e..d361d881 100644 --- a/oms_web/oms_vue/src/views/purchaseorder/components/PurchaseOrderDetailView.vue +++ b/oms_web/oms_vue/src/views/purchaseorder/components/PurchaseOrderDetailView.vue @@ -291,19 +291,37 @@ export default { return (preciseCurrencyRound((this.totalAmountWithTax - this.totalAmountWithoutTax))) || 0; } }, + watch: { + orderData: { + handler(newVal) { + if (newVal) { + this.form = JSON.parse(JSON.stringify(newVal)); + // 等待 vendorOptions 加载完成后再处理制造商 + this.$nextTick(() => { + this.handleVendorChange(this.form.vendorId); + }); + } + }, + immediate: false, + deep: false + } + }, created() { this.getVendorList().then(() => { getDicts("product_type").then(response => { this.productTypeOptions = response.data; }); + // 如果已经有 orderData 则立即处理 + if (this.orderData) { + this.form = JSON.parse(JSON.stringify(this.orderData)); + this.handleVendorChange(this.form.vendorId); + } }); }, methods: { loadPurchaseOrder(id) { - if (this.orderData) { - this.form = this.orderData; - this.handleVendorChange(this.form.vendorId); - } else if (id) { + // 此方法保留用于兼容性,实际数据通过 prop 传递 + if (!this.orderData && id) { getPurchaseorder(id).then(response => { this.form = response.data; this.handleVendorChange(this.form.vendorId); diff --git a/oms_web/oms_vue/src/views/purchaseorder/index.vue b/oms_web/oms_vue/src/views/purchaseorder/index.vue index 8db29769..ec017e2e 100644 --- a/oms_web/oms_vue/src/views/purchaseorder/index.vue +++ b/oms_web/oms_vue/src/views/purchaseorder/index.vue @@ -169,8 +169,9 @@ /> - - + @@ -188,7 +189,7 @@ size="80%" > - @@ -255,6 +256,8 @@ export default { // 总条数 total: 0, currentOrderId: null, + // 当前订单数据 + currentOrderData: null, // 采购单主表表格数据 purchaseorderList: [], // 弹出层标题 @@ -263,8 +266,8 @@ export default { open: false, // 是否显示详情抽屉 showDetailDrawer: false, - // 详情订单ID - detailOrderId: null, + // 详情订单数据 + detailOrderData: null, // 当前详情订单编号 currentDetailPurchaseNo: null, // 是否显示历史详情抽屉 @@ -293,25 +296,18 @@ export default { this.getList(); }, watch:{ - // 监听currentOrderId变化 + // 监听对话框打开 open(val) { - if (val) { - this.$nextTick(()=>{ - this.$refs.purchaseOrderDetail?.loadPurchaseOrder(this.currentOrderId) - }) - }else{ - this.currentOrderId=null - this.$refs.purchaseOrderDetail?.resetForm() + if (!val) { + this.currentOrderId = null; + this.currentOrderData = null; + this.$refs.purchaseOrderDetail?.resetForm(); } }, // 监听详情抽屉变化 showDetailDrawer(val) { - if (val) { - this.$nextTick(()=>{ - this.$refs.detailViewOnly?.loadPurchaseOrder(this.detailOrderId) - }) - } else { - this.detailOrderId = null; + if (!val) { + this.detailOrderData = null; this.currentDetailPurchaseNo = null; this.$refs.detailViewOnly?.resetForm(); } @@ -321,10 +317,6 @@ export default { if (!val) { this.historyDetailOrderData = null; this.$refs.historyDetailView?.resetForm(); - }else{ - this.$nextTick(()=>{ - this.$refs.historyDetailView?.loadPurchaseOrder(this.detailOrderId) - }) } } }, @@ -362,17 +354,19 @@ export default { }, /** 新增按钮操作 */ handleAdd() { - + this.currentOrderData = null; + this.currentOrderId = null; this.open = true; this.title = "添加采购单主表"; - }, /** 修改按钮操作 */ handleUpdate(row) { - this.currentOrderId = row.id; - this.open = true; - this.title = "修改采购单主表"; - + getPurchaseorder(row.id).then(response => { + this.currentOrderData = response.data; + this.currentOrderId = row.id; + this.open = true; + this.title = "修改采购单主表"; + }); }, /** 提交按钮 */ submitForm() { @@ -403,9 +397,11 @@ export default { }, /** 查看详情按钮操作 */ handleViewDetails(row) { - this.detailOrderId = row.id; - this.currentDetailPurchaseNo = row.purchaseNo; - this.showDetailDrawer = true; + getPurchaseorder(row.id).then(response => { + this.detailOrderData = response.data; + this.currentDetailPurchaseNo = row.purchaseNo; + this.showDetailDrawer = true; + }); }, /** 处理查看历史详情事件 */ handleViewHistoryDetailEvent(row) {