fix(material): 解决物料表单编辑时的数据加载问题
This commit is contained in:
parent
0f2dd58b14
commit
092331c5c6
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user