diff --git a/src/views/mes/deviceledger/DeviceLedgerForm.vue b/src/views/mes/deviceledger/DeviceLedgerForm.vue index fe481c2d..9bc067ca 100644 --- a/src/views/mes/deviceledger/DeviceLedgerForm.vue +++ b/src/views/mes/deviceledger/DeviceLedgerForm.vue @@ -76,6 +76,7 @@ value-key="id" :placeholder="t('EquipmentManagement.EquipmentLedger.placeholderDeviceType')" class="!w-full" + @change="() => { formData.typeName = findDeviceTypeName(formData.deviceType) }" /> @@ -910,6 +911,7 @@ const initFormData = () => ({ isScheduled: 0, ratedCapacity: undefined, deviceType: undefined as string | undefined, + typeName: undefined as string | undefined, deviceLine: undefined as string | undefined, supplier: undefined, workshop: undefined, @@ -991,6 +993,15 @@ watch( const treeSelectProps = { label: 'name', children: 'children' } const deviceTypeTree = ref([]) +const findDeviceTypeName = (id: string | number): string | undefined => { + const stack = [...deviceTypeTree.value] + while (stack.length) { + const node = stack.pop()! + if (String(node.id) === String(id)) return node.name + if (Array.isArray(node.children) && node.children.length) stack.push(...node.children) + } + return undefined +} const users = ref([]) type SelectionOption = { label: string; value: number } const criticalComponentOptions = ref([]) @@ -1554,6 +1565,7 @@ const submitForm = async () => { isScheduled: normalizeNumberish((formData.value as any).isScheduled) ?? 0, ratedCapacity: normalizeNumberish((formData.value as any).ratedCapacity), deviceType: (formData.value as any).deviceType ?? undefined, + typeName: (formData.value as any).typeName ?? findDeviceTypeName((formData.value as any).deviceType), deviceLine: (formData.value as any).deviceLine ?? undefined, productionDate: normalizeYmd(formData.value.productionDate), outgoingTime: normalizeYmd((formData.value as any).outgoingTime), diff --git a/src/views/mes/deviceledger/detail/editIndex.vue b/src/views/mes/deviceledger/detail/editIndex.vue index 0f7c3a2d..c71e60ec 100644 --- a/src/views/mes/deviceledger/detail/editIndex.vue +++ b/src/views/mes/deviceledger/detail/editIndex.vue @@ -74,6 +74,7 @@ t('EquipmentManagement.EquipmentLedger.placeholderDeviceType') " class="!w-full" + @change="() => { formData.typeName = findDeviceTypeName(formData.deviceType) }" /> @@ -1186,6 +1187,7 @@ const initFormData = () => ({ isScheduled: 0, ratedCapacity: undefined, deviceType: undefined as string | undefined, + typeName: undefined as string | undefined, deviceLine: undefined as string | undefined, supplier: undefined, workshop: undefined, @@ -1284,6 +1286,15 @@ const formRules = reactive({ }) const treeSelectProps = { label: 'name', children: 'children' } const deviceTypeTree = ref([]) +const findDeviceTypeName = (id: string | number): string | undefined => { + const stack = [...deviceTypeTree.value] + while (stack.length) { + const node = stack.pop()! + if (String(node.id) === String(id)) return node.name + if (Array.isArray(node.children) && node.children.length) stack.push(...node.children) + } + return undefined +} const users = ref([]) type SelectionOption = { label: string; value: number } const criticalComponentOptions = ref([]) @@ -1676,6 +1687,7 @@ const buildSubmitData = () => { isScheduled: normalizeNumberish((formData.value as any).isScheduled) ?? 0, ratedCapacity: normalizeNumberish((formData.value as any).ratedCapacity), deviceType: (formData.value as any).deviceType ?? undefined, + typeName: (formData.value as any).typeName ?? findDeviceTypeName((formData.value as any).deviceType), deviceLine: (formData.value as any).deviceLine ?? undefined, productionDate: normalizeYmd(formData.value.productionDate), outgoingTime: normalizeYmd((formData.value as any).outgoingTime), diff --git a/src/views/mes/deviceledger/index.vue b/src/views/mes/deviceledger/index.vue index 21e70e6a..35cd00e0 100644 --- a/src/views/mes/deviceledger/index.vue +++ b/src/views/mes/deviceledger/index.vue @@ -344,14 +344,12 @@ ([]) const deviceTypeTree = ref([]) -const deviceTypeNameMap = ref>({}) const ALL_TYPE_NODE_ID = -1 -const buildDeviceTypeNameMap = (nodes: DeviceTypeTreeVO[]) => { - const map: Record = {} - const stack = [...nodes] - while (stack.length) { - const node = stack.pop()! - if (node.id != null) map[String(node.id)] = node.name - if (Array.isArray(node.children) && node.children.length) stack.push(...node.children) - } - deviceTypeNameMap.value = map -} - const isAllTypeNode = (node: any) => Number(node?.id) === ALL_TYPE_NODE_ID const buildTypeTreeWithAll = (nodes: DeviceLineTreeVO[]) => { @@ -785,7 +771,6 @@ const getDeviceTypeTree = async () => { const data = await DeviceTypeApi.getDeviceTypeTree({}) const treeData = JSON.parse(JSON.stringify(data ?? [])) deviceTypeTree.value = treeData - buildDeviceTypeNameMap(treeData) } const handleTypeNodeClick = (node: any) => { @@ -972,11 +957,7 @@ const buildTreeQrcodePrintData = () => { } } -const getDeviceTypeName = (value: any) => { - const id = String(value ?? '') - if (deviceTypeNameMap.value[id]) return deviceTypeNameMap.value[id] - return value ?? '' -} + const formatScheduleLabel = (value: any) => { return Number(value) === 1