feat(purchaseorder): 优化采购单详情加载逻辑
- 通过 prop 传递订单数据替代原有的 loadPurchaseOrder 方法调用 - 在 PurchaseOrderDetail 和 PurchaseOrderDetailView 组件中添加 orderData 属性支持 - 更新父组件中的引用,确保数据正确传递到子组件 - 移除冗余的 watch 监听逻辑,简化代码结构 - 保留 loadPurchaseOrder 方法以保证向后兼容性 - 优化组件创建时的数据初始化流程dev_1.0.0
parent
b3f1fdf2ae
commit
491344f1d6
|
|
@ -193,7 +193,12 @@ import {preciseCurrencyRound} from "@/utils/ruoyi";
|
||||||
export default {
|
export default {
|
||||||
name: "PurchaseOrderDetail",
|
name: "PurchaseOrderDetail",
|
||||||
components: { SelectUser, SelectProduct },
|
components: { SelectUser, SelectProduct },
|
||||||
|
props: {
|
||||||
|
orderData: {
|
||||||
|
type: Object,
|
||||||
|
default: null
|
||||||
|
}
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
// 产品选择弹窗
|
// 产品选择弹窗
|
||||||
|
|
@ -279,22 +284,51 @@ export default {
|
||||||
return (preciseCurrencyRound((this.totalAmountWithTax - this.totalAmountWithoutTax )) ) || 0;
|
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() {
|
created() {
|
||||||
this.getVendorList().then(() => {
|
this.getVendorList().then(() => {
|
||||||
getDicts("product_type").then(response => {
|
getDicts("product_type").then(response => {
|
||||||
this.productTypeOptions = response.data;
|
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: {
|
methods: {
|
||||||
loadPurchaseOrder(id) {
|
loadPurchaseOrder(id) {
|
||||||
if (id){
|
// 此方法保留用于兼容性,实际数据通过 prop 传递
|
||||||
|
if (!this.orderData && id) {
|
||||||
getPurchaseorder(id).then(response => {
|
getPurchaseorder(id).then(response => {
|
||||||
this.form = response.data;
|
this.form = response.data;
|
||||||
console.log(this.form)
|
console.log(this.form)
|
||||||
// 加载订单后,根据vendorId回显制造商信息
|
|
||||||
this.handleVendorChange(this.form.vendorId);
|
this.handleVendorChange(this.form.vendorId);
|
||||||
// 确保 omsPurchaseOrderItemList 至少有一个空行如果它是空的
|
|
||||||
if (this.form.omsPurchaseOrderItemList && this.form.omsPurchaseOrderItemList.length === 0) {
|
if (this.form.omsPurchaseOrderItemList && this.form.omsPurchaseOrderItemList.length === 0) {
|
||||||
this.form.omsPurchaseOrderItemList.push(this.getNewPurchaseOrderItem());
|
this.form.omsPurchaseOrderItemList.push(this.getNewPurchaseOrderItem());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -291,19 +291,37 @@ export default {
|
||||||
return (preciseCurrencyRound((this.totalAmountWithTax - this.totalAmountWithoutTax))) || 0;
|
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() {
|
created() {
|
||||||
this.getVendorList().then(() => {
|
this.getVendorList().then(() => {
|
||||||
getDicts("product_type").then(response => {
|
getDicts("product_type").then(response => {
|
||||||
this.productTypeOptions = response.data;
|
this.productTypeOptions = response.data;
|
||||||
});
|
});
|
||||||
|
// 如果已经有 orderData 则立即处理
|
||||||
|
if (this.orderData) {
|
||||||
|
this.form = JSON.parse(JSON.stringify(this.orderData));
|
||||||
|
this.handleVendorChange(this.form.vendorId);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadPurchaseOrder(id) {
|
loadPurchaseOrder(id) {
|
||||||
if (this.orderData) {
|
// 此方法保留用于兼容性,实际数据通过 prop 传递
|
||||||
this.form = this.orderData;
|
if (!this.orderData && id) {
|
||||||
this.handleVendorChange(this.form.vendorId);
|
|
||||||
} else if (id) {
|
|
||||||
getPurchaseorder(id).then(response => {
|
getPurchaseorder(id).then(response => {
|
||||||
this.form = response.data;
|
this.form = response.data;
|
||||||
this.handleVendorChange(this.form.vendorId);
|
this.handleVendorChange(this.form.vendorId);
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,9 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 添加或修改采购单主表对话框 -->
|
<!-- 添加或修改采购单主表对话框 -->
|
||||||
<el-dialog :title="title" :visible.sync="open" width="80vw" append-to-body>
|
<el-dialog :title="title" :visible.sync="open" width="80vw" append-to-body >
|
||||||
<purchase-order-detail ref="purchaseOrderDetail" @close="open = false"
|
<purchase-order-detail ref="purchaseOrderDetail" :order-data="currentOrderData"
|
||||||
|
@close="open = false"
|
||||||
@success="getList">
|
@success="getList">
|
||||||
|
|
||||||
</purchase-order-detail>
|
</purchase-order-detail>
|
||||||
|
|
@ -188,7 +189,7 @@
|
||||||
size="80%"
|
size="80%"
|
||||||
>
|
>
|
||||||
<ApproveLayout title="采购单详情" :style="{ 'max-height': '90vh' }" v-if="showDetailDrawer">
|
<ApproveLayout title="采购单详情" :style="{ 'max-height': '90vh' }" v-if="showDetailDrawer">
|
||||||
<purchase-order-detail-view ref="detailViewOnly" @close="showDetailDrawer = false"
|
<purchase-order-detail-view ref="detailViewOnly" :order-data="detailOrderData" @close="showDetailDrawer = false"
|
||||||
@success="getList" :showHistory="true"
|
@success="getList" :showHistory="true"
|
||||||
@view-history-detail="handleViewHistoryDetailEvent">
|
@view-history-detail="handleViewHistoryDetailEvent">
|
||||||
</purchase-order-detail-view>
|
</purchase-order-detail-view>
|
||||||
|
|
@ -255,6 +256,8 @@ export default {
|
||||||
// 总条数
|
// 总条数
|
||||||
total: 0,
|
total: 0,
|
||||||
currentOrderId: null,
|
currentOrderId: null,
|
||||||
|
// 当前订单数据
|
||||||
|
currentOrderData: null,
|
||||||
// 采购单主表表格数据
|
// 采购单主表表格数据
|
||||||
purchaseorderList: [],
|
purchaseorderList: [],
|
||||||
// 弹出层标题
|
// 弹出层标题
|
||||||
|
|
@ -263,8 +266,8 @@ export default {
|
||||||
open: false,
|
open: false,
|
||||||
// 是否显示详情抽屉
|
// 是否显示详情抽屉
|
||||||
showDetailDrawer: false,
|
showDetailDrawer: false,
|
||||||
// 详情订单ID
|
// 详情订单数据
|
||||||
detailOrderId: null,
|
detailOrderData: null,
|
||||||
// 当前详情订单编号
|
// 当前详情订单编号
|
||||||
currentDetailPurchaseNo: null,
|
currentDetailPurchaseNo: null,
|
||||||
// 是否显示历史详情抽屉
|
// 是否显示历史详情抽屉
|
||||||
|
|
@ -293,25 +296,18 @@ export default {
|
||||||
this.getList();
|
this.getList();
|
||||||
},
|
},
|
||||||
watch:{
|
watch:{
|
||||||
// 监听currentOrderId变化
|
// 监听对话框打开
|
||||||
open(val) {
|
open(val) {
|
||||||
if (val) {
|
if (!val) {
|
||||||
this.$nextTick(()=>{
|
this.currentOrderId = null;
|
||||||
this.$refs.purchaseOrderDetail?.loadPurchaseOrder(this.currentOrderId)
|
this.currentOrderData = null;
|
||||||
})
|
this.$refs.purchaseOrderDetail?.resetForm();
|
||||||
}else{
|
|
||||||
this.currentOrderId=null
|
|
||||||
this.$refs.purchaseOrderDetail?.resetForm()
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 监听详情抽屉变化
|
// 监听详情抽屉变化
|
||||||
showDetailDrawer(val) {
|
showDetailDrawer(val) {
|
||||||
if (val) {
|
if (!val) {
|
||||||
this.$nextTick(()=>{
|
this.detailOrderData = null;
|
||||||
this.$refs.detailViewOnly?.loadPurchaseOrder(this.detailOrderId)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.detailOrderId = null;
|
|
||||||
this.currentDetailPurchaseNo = null;
|
this.currentDetailPurchaseNo = null;
|
||||||
this.$refs.detailViewOnly?.resetForm();
|
this.$refs.detailViewOnly?.resetForm();
|
||||||
}
|
}
|
||||||
|
|
@ -321,10 +317,6 @@ export default {
|
||||||
if (!val) {
|
if (!val) {
|
||||||
this.historyDetailOrderData = null;
|
this.historyDetailOrderData = null;
|
||||||
this.$refs.historyDetailView?.resetForm();
|
this.$refs.historyDetailView?.resetForm();
|
||||||
}else{
|
|
||||||
this.$nextTick(()=>{
|
|
||||||
this.$refs.historyDetailView?.loadPurchaseOrder(this.detailOrderId)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -362,17 +354,19 @@ export default {
|
||||||
},
|
},
|
||||||
/** 新增按钮操作 */
|
/** 新增按钮操作 */
|
||||||
handleAdd() {
|
handleAdd() {
|
||||||
|
this.currentOrderData = null;
|
||||||
|
this.currentOrderId = null;
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "添加采购单主表";
|
this.title = "添加采购单主表";
|
||||||
|
|
||||||
},
|
},
|
||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
handleUpdate(row) {
|
handleUpdate(row) {
|
||||||
this.currentOrderId = row.id;
|
getPurchaseorder(row.id).then(response => {
|
||||||
this.open = true;
|
this.currentOrderData = response.data;
|
||||||
this.title = "修改采购单主表";
|
this.currentOrderId = row.id;
|
||||||
|
this.open = true;
|
||||||
|
this.title = "修改采购单主表";
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
submitForm() {
|
submitForm() {
|
||||||
|
|
@ -403,9 +397,11 @@ export default {
|
||||||
},
|
},
|
||||||
/** 查看详情按钮操作 */
|
/** 查看详情按钮操作 */
|
||||||
handleViewDetails(row) {
|
handleViewDetails(row) {
|
||||||
this.detailOrderId = row.id;
|
getPurchaseorder(row.id).then(response => {
|
||||||
this.currentDetailPurchaseNo = row.purchaseNo;
|
this.detailOrderData = response.data;
|
||||||
this.showDetailDrawer = true;
|
this.currentDetailPurchaseNo = row.purchaseNo;
|
||||||
|
this.showDetailDrawer = true;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/** 处理查看历史详情事件 */
|
/** 处理查看历史详情事件 */
|
||||||
handleViewHistoryDetailEvent(row) {
|
handleViewHistoryDetailEvent(row) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue