diff --git a/src/views/mes/deviceledger/detail/editIndex.vue b/src/views/mes/deviceledger/detail/editIndex.vue index 30acd00b..926713b1 100644 --- a/src/views/mes/deviceledger/detail/editIndex.vue +++ b/src/views/mes/deviceledger/detail/editIndex.vue @@ -618,28 +618,6 @@ const setDefaultSelections = () => { }) } -// 设置默认选中的行 -const setBJDefaultSelections = () => { - // 等待DOM更新完成 - nextTick(() => { - if (!bjMultipleTableRef.value) return - bjMultipleTableRef.value.clearSelection() - const rawSubjectIds = toRaw(formData.value.beijianIds) - if (rawSubjectIds.length != 0) { - let row = { - id: undefined - } - bjMultipleTableRef.value.toggleRowSelection(row, true) - } - // 遍历数据,找到需要选中的行 - bjList.value.forEach(row => { - let id = row.id; - if (rawSubjectIds.includes(row.id)) { - bjMultipleTableRef.value.toggleRowSelection(row, true) - } - }) - }) -} const normalizeNumberish = (value: any): number | undefined => { if (value === null || value === undefined || value === '') return undefined if (typeof value === 'number') return Number.isFinite(value) ? value : undefined @@ -949,8 +927,78 @@ const getDetail = async () => { } } + +// 方法1:直接监听 data +watch(bjList, (newData, oldData) => { + // 可以在这里执行相关操作 + if (newData.length > 0) { + // 数据加载完成后的操作 + setBJDefaultSelections() + } +}, { deep: true }) + + +//const defaultSelectedIds = [144, 143,141] + +// 设置默认选中的行 +const setBJDefaultSelections = () => { + // 等待DOM更新完成 + nextTick(() => { + if (!bjMultipleTableRef.value) return + bjMultipleTableRef.value.clearSelection() + const rawSubjectIds = toRaw(formData.value.beijianIds) + if (rawSubjectIds.length != 0) { + let row = { + id: undefined + } + bjMultipleTableRef.value.toggleRowSelection(row, true) + } + // 遍历数据,找到需要选中的行 + bjList.value.forEach(row => { + let id = row.id; + if (rawSubjectIds.includes(row.id)) { + bjMultipleTableRef.value.toggleRowSelection(row, true) + } + }) + }) +} +async function initForm() { + // 修改时,设置数据 + if (deviceId.value) { + formLoading.value = true + try { + const detail = await DeviceLedgerApi.getDeviceLedger(deviceId.value) + const templateJson = (detail as any)?.templateJson + const parsedTemplateJson = typeof templateJson === 'string' + ? JSON.parse(templateJson) + : templateJson + formData.value = { + ...initFormData(), + ...(detail as any), + templateJson: parsedTemplateJson, + isCode: (detail as any)?.isCode ?? false, + isScheduled: normalizeNumberish((detail as any)?.isScheduled ?? (detail as any)?.isScheduled) ?? 0, + ratedCapacity: normalizeNumberish((detail as any)?.ratedCapacity), + deviceType: normalizeNumberish((detail as any)?.deviceType), + deviceLine: normalizeNumberish((detail as any)?.deviceLine), + deviceManagerIds: parseIdsValue((detail as any)?.deviceManager), + productionDate: normalizeYmd((detail as any)?.productionDate), + factoryEntryDate: normalizeYmd((detail as any)?.factoryEntryDate), + componentIds: parseIdsValue((detail as any)?.componentId), + beijianIds: parseIdsValue((detail as any)?.beijianId), + qrcodeUrl: (detail as any)?.qrcodeUrl, + } + savedCriticalComponentOptions.value = buildCriticalComponentOptions((detail as any)?.componentList ?? []) + savedBeijianOptions.value = buildBeijianOptions((detail as any)?.beijianList ?? []) + } finally { + formLoading.value = false + } + } +} + onMounted(async () => { await ensureOptionsLoaded() + initForm() // await getDetail() getList()