diff --git a/src/components/common/HtFeeMethodGrid.vue b/src/components/common/HtFeeMethodGrid.vue index 6cfbeef..5b4b2d4 100644 --- a/src/components/common/HtFeeMethodGrid.vue +++ b/src/components/common/HtFeeMethodGrid.vue @@ -610,13 +610,12 @@ watch( ) watch( - () => pricingPaneReloadStore.seq, + () => pricingPaneReloadStore.persistedSeq, (nextVersion, prevVersion) => { - if (nextVersion === prevVersion || nextVersion === 0) return const contractId = String(props.contractId || '').trim() if (!contractId) return - if (!matchPricingPaneReload(pricingPaneReloadStore.lastEvent, contractId, ZXFW_RELOAD_SERVICE_KEY)) return + if (!matchPricingPaneReload(pricingPaneReloadStore.lastPersistedEvent, contractId, ZXFW_RELOAD_SERVICE_KEY)) return void loadFromIndexedDB() } ) diff --git a/src/components/common/XmFactorGrid.vue b/src/components/common/XmFactorGrid.vue index 1d69337..d9bb91b 100644 --- a/src/components/common/XmFactorGrid.vue +++ b/src/components/common/XmFactorGrid.vue @@ -117,6 +117,14 @@ const buildDefaultRows = (): FactorRow[] => { } type SourceRow = Pick & Partial> +const hasMeaningfulFactorValue = (rows: SourceRow[] | undefined) => + Array.isArray(rows) && + rows.some(row => { + const hasBudgetValue = typeof row?.budgetValue === 'number' && Number.isFinite(row.budgetValue) + const hasRemark = typeof row?.remark === 'string' && row.remark.trim() !== '' + return hasBudgetValue || hasRemark + }) + const mergeWithDictRows = (rowsFromDb: SourceRow[] | undefined): FactorRow[] => { const dbValueMap = new Map() for (const row of rowsFromDb || []) { @@ -235,7 +243,7 @@ const loadGridState = async (storageKey: string): Promise => { const loadFromIndexedDB = async () => { try { const data = await loadGridState(props.storageKey) - if (data) { + if (data && hasMeaningfulFactorValue(data.detailRows)) { detailRows.value = mergeWithDictRows(data.detailRows) return } @@ -243,14 +251,20 @@ const loadFromIndexedDB = async () => { const parentStorageKey = props.parentStorageKey?.trim() if (parentStorageKey) { const parentData = await loadGridState(parentStorageKey) - if (parentData) { + if (parentData && hasMeaningfulFactorValue(parentData.detailRows)) { detailRows.value = mergeWithDictRows(parentData.detailRows) await saveToIndexedDB() return } } + if (data) { + detailRows.value = mergeWithDictRows(data.detailRows) + return + } + detailRows.value = buildDefaultRows() + await saveToIndexedDB() } catch (error) { console.error('loadFromIndexedDB failed:', error) detailRows.value = buildDefaultRows() diff --git a/src/components/common/xmCommonAgGrid.vue b/src/components/common/xmCommonAgGrid.vue index b41c369..7cbbc05 100644 --- a/src/components/common/xmCommonAgGrid.vue +++ b/src/components/common/xmCommonAgGrid.vue @@ -179,8 +179,26 @@ const loadFromIndexedDB = async (api: GridApi) => { roughCalcEnabled.value = Boolean(contractData?.roughCalcEnabled) applyPinnedTotalAmount(api, contractData?.totalAmount) - if (contractData?.detailRows) { - detailRows.value = mergeWithDictRows(contractData.detailRows) + const contractRows = Array.isArray(contractData?.detailRows) ? contractData.detailRows : [] + const hasContractRows = contractRows.length > 0 + const hasContractScaleValue = hasContractRows + ? contractRows.some(row => { + const amount = row?.amount + const landArea = row?.landArea + return ( + (typeof amount === 'number' && Number.isFinite(amount)) || + (typeof landArea === 'number' && Number.isFinite(landArea)) + ) + }) + : false + const isLegacyEmptyScaleRows = + hasContractRows && + !hasContractScaleValue && + !roughCalcEnabled.value && + typeof contractData?.totalAmount === 'number' && + Number.isFinite(contractData.totalAmount) + if (hasContractRows && !isLegacyEmptyScaleRows) { + detailRows.value = mergeWithDictRows(contractRows) return } @@ -190,12 +208,8 @@ const loadFromIndexedDB = async (api: GridApi) => { roughCalcEnabled.value = Boolean(xmData?.roughCalcEnabled) applyPinnedTotalAmount(api, xmData?.totalAmount) - if (xmData?.detailRows) { - - detailRows.value = mergeWithDictRows(xmData.detailRows.map(e => ({...e, - amount: null, - landArea: null - }))) + if (Array.isArray(xmData?.detailRows) && xmData.detailRows.length > 0) { + detailRows.value = mergeWithDictRows(xmData.detailRows) return } } diff --git a/src/components/views/HtConsultCategoryFactor.vue b/src/components/views/HtConsultCategoryFactor.vue index 0ff4c08..33dcf9a 100644 --- a/src/components/views/HtConsultCategoryFactor.vue +++ b/src/components/views/HtConsultCategoryFactor.vue @@ -60,5 +60,6 @@ onActivated(() => { :dict="filteredServiceDict" :disable-budget-edit-when-standard-null="true" :exclude-notshow-by-zxflxs="true" + :init-budget-value-from-standard="true" /> diff --git a/src/components/views/HtFeeRateMethodForm.vue b/src/components/views/HtFeeRateMethodForm.vue index b06d7be..bb37f68 100644 --- a/src/components/views/HtFeeRateMethodForm.vue +++ b/src/components/views/HtFeeRateMethodForm.vue @@ -51,6 +51,7 @@ const formatAmount = (value: number | null) => value == null ? '' : formatThousandsFlexible(value, 3) const loadBase = async () => { + const contractId = String(props.contractId || '').trim() if (!contractId) { base.value = null @@ -112,14 +113,10 @@ const applyRateInput = () => { rateInput.value = next == null ? '' : String(next) } -let saveTimer: ReturnType | null = null -let basePollTimer: ReturnType | null = null + watch([rate, remark, budgetFee], () => { - if (saveTimer) clearTimeout(saveTimer) - saveTimer = setTimeout(() => { - void saveForm() - }, 250) + void saveForm() }) watch( @@ -130,41 +127,28 @@ watch( ) watch( - () => pricingPaneReloadStore.seq, + () => pricingPaneReloadStore.persistedSeq, (nextVersion, prevVersion) => { - console.log(pricingPaneReloadStore.seq) if (nextVersion === prevVersion || nextVersion === 0) return const contractId = String(props.contractId || '').trim() if (!contractId) return - if (!matchPricingPaneReload(pricingPaneReloadStore.lastEvent, contractId, ZXFW_RELOAD_SERVICE_KEY)) return + if (!matchPricingPaneReload(pricingPaneReloadStore.lastPersistedEvent, contractId, ZXFW_RELOAD_SERVICE_KEY)) return void loadBase() } ) onMounted(async () => { await Promise.all([loadBase(), loadForm()]) - if (!basePollTimer) { - basePollTimer = setInterval(() => { - void loadBase() - }, 1000) - } + }) onActivated(async () => { await Promise.all([loadBase(), loadForm()]) - if (!basePollTimer) { - basePollTimer = setInterval(() => { - void loadBase() - }, 1000) - } + }) onBeforeUnmount(() => { - if (saveTimer) clearTimeout(saveTimer) - if (basePollTimer) { - clearInterval(basePollTimer) - basePollTimer = null - } + void saveForm() }) @@ -175,48 +159,27 @@ onBeforeUnmount(() => {