fix(material): 解决物料表单编辑时的数据加载问题

This commit is contained in:
zxy 2026-03-20 15:45:30 +08:00
parent 0f2dd58b14
commit 092331c5c6

View File

@ -120,6 +120,7 @@
</Dialog>
</template>
<script setup lang="ts">
import { nextTick } from 'vue'
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
import * as MaterialApi from '@/api/heli/material'
import {getSupplierPage} from "@/api/heli/supplier";
@ -174,6 +175,8 @@ const formRef = ref() // 表单 Ref
const supplierList = ref<any[]>([]) //
const supplierSelectList = ref<any[]>([])
const supplierSelectLoading = ref(false);
const isLoading = ref(false) // watch
const originalMatCate = ref() //
const remoteSupplierSearch = (query: string) => {
if (query) {
@ -196,9 +199,13 @@ const open = async (type: string, id?: number) => {
resetForm()
//
formLoading.value = true
isLoading.value = true
try {
if (id) {
formData.value = await MaterialApi.getMaterial(id)
const data = await MaterialApi.getMaterial(id)
formData.value = data
//
originalMatCate.value = data.matCate
}
let params = {
pageNo: 1,
@ -210,6 +217,9 @@ const open = async (type: string, id?: number) => {
supplierSelectList.value = supplierData.list;
} finally {
formLoading.value = false
nextTick(() => {
isLoading.value = false
})
}
}
@ -280,8 +290,18 @@ const handleSelectedSupplier = (newValue: any) => {
/** 监听物料类型变化查询matcode并更新code */
watch(() => formData.value.matCate, async (newVal) => {
//
if (isLoading.value) {
return
}
//
if (!newVal) {
formData.value.code = undefined
originalMatCate.value = undefined
return
}
//
if (formType.value === 'update' && newVal === originalMatCate.value) {
return
}
try {