This commit is contained in:
wintsa 2026-03-27 09:35:46 +08:00
parent 9799231a4c
commit b1728bbc47
6 changed files with 259 additions and 21 deletions

View File

@ -0,0 +1,209 @@
<script setup lang="ts">
import { computed, nextTick, onActivated, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { AgGridVue } from 'ag-grid-vue3'
import type { ColDef, GridApi, GridOptions, GridReadyEvent } from 'ag-grid-community'
import { AG_GRID_LOCALE_CN } from '@ag-grid-community/locale'
import { myTheme, gridOptions, agGridWrapClass, agGridStyle } from '@/lib/diyAgGridOptions'
import { withReadonlyAutoHeight } from '@/lib/agGridReadonlyAutoHeight'
import { formatThousandsFlexible } from '@/lib/numberFormat'
import { createScaleAutoGroupColumn } from '@/lib/pricingScaleColumns'
import { buildScaleDetailDict, buildScaleIdLabelMap } from '@/lib/pricingScaleDict'
import { parseProjectIndexFromPathKey } from '@/lib/pricingScaleLink'
import { useZxFwPricingStore } from '@/pinia/zxFwPricing'
import { getMajorDictEntries } from '@/sql'
import type { ScaleDetailRow } from '@/types/pricing'
const props = defineProps<{
contractId: string
serviceId: string | number
method: 'investScale' | 'landScale'
}>()
type MajorLite = {
code: string
name: string
defCoe: number | null
hasCost?: boolean
hasArea?: boolean
}
const { t } = useI18n()
const zxFwPricingStore = useZxFwPricingStore()
const gridApi = ref<GridApi<ScaleDetailRow> | null>(null)
let autoHeightTimer: ReturnType<typeof setTimeout> | null = null
const isInvestmentFormula = computed(() => props.method === 'investScale')
const methodLabel = computed(() =>
isInvestmentFormula.value
? t('zxFwView.categories.investmentScaleFormula')
: t('zxFwView.categories.landScaleFormula')
)
const ensureMethodStateLoaded = async () => {
await zxFwPricingStore.loadServicePricingMethodState<ScaleDetailRow>(
props.contractId,
props.serviceId,
props.method
)
}
const methodState = computed(() =>
zxFwPricingStore.getServicePricingMethodState<ScaleDetailRow>(
props.contractId,
props.serviceId,
props.method
)
)
const rowData = computed<ScaleDetailRow[]>(() => {
const rows = methodState.value?.detailRows
return Array.isArray(rows) ? rows : []
})
const idLabelMap = computed(() => {
const majorEntries = getMajorDictEntries().map(({ id, item }) => [id, item] as [string, MajorLite])
const detailDict = buildScaleDetailDict(
majorEntries,
isInvestmentFormula.value
? ({ hasCost, hasArea }) => hasCost && !hasArea
: ({ hasArea }) => hasArea
)
return buildScaleIdLabelMap(detailDict)
})
const numberFormatter = (params: { value?: unknown }) =>
typeof params.value === 'number' && Number.isFinite(params.value)
? formatThousandsFlexible(params.value, 3)
: ''
const columnDefs = computed<ColDef<ScaleDetailRow>[]>(() =>
withReadonlyAutoHeight<ScaleDetailRow>([
{
headerName: t('zxFwView.formulaColumns.amount'),
field: 'budgetFee',
minWidth: 130,
flex: 1,
headerClass: 'ag-right-aligned-header',
cellClassRules: {
'ag-right-aligned-cell': () => true
},
valueFormatter: numberFormatter
},
{
headerName: t('pricingScale.columns.basicWork'),
field: 'budgetFeeBasic',
minWidth: 130,
flex: 1,
headerClass: 'ag-right-aligned-header',
cellClassRules: {
'ag-right-aligned-cell': () => true
},
valueFormatter: numberFormatter
},
{
headerName: t('zxFwView.formulaColumns.basicFormula'),
field: 'basicFormula',
minWidth: 260,
flex: 2
},
{
headerName: t('pricingScale.columns.optionalWork'),
field: 'budgetFeeOptional',
minWidth: 130,
flex: 1,
headerClass: 'ag-right-aligned-header',
cellClassRules: {
'ag-right-aligned-cell': () => true
},
valueFormatter: numberFormatter
},
{
headerName: t('zxFwView.formulaColumns.optionalFormula'),
field: 'optionalFormula',
minWidth: 260,
flex: 2
}
]) as ColDef<ScaleDetailRow>[]
)
const autoGroupColumnDef = computed<ColDef<ScaleDetailRow>>(() =>
createScaleAutoGroupColumn<ScaleDetailRow>({
totalLabel: methodLabel.value,
idLabelMap: idLabelMap.value,
parseProjectIndexFromPathKey
})
)
const detailGridOptions: GridOptions<ScaleDetailRow> = {
...gridOptions
}
const syncAutoRowHeights = async () => {
await nextTick()
const api = gridApi.value
if (!api || api.isDestroyed?.()) return
api.resetRowHeights()
api.onRowHeightChanged()
api.refreshCells({ force: true })
}
const scheduleAutoRowHeights = () => {
if (autoHeightTimer) clearTimeout(autoHeightTimer)
autoHeightTimer = setTimeout(() => {
autoHeightTimer = null
void syncAutoRowHeights()
}, 0)
}
const onGridReady = (event: GridReadyEvent<ScaleDetailRow>) => {
gridApi.value = event.api
scheduleAutoRowHeights()
}
watch(rowData, () => {
scheduleAutoRowHeights()
}, { deep: true })
watch(() => props.method, () => {
void ensureMethodStateLoaded()
scheduleAutoRowHeights()
})
onMounted(() => {
void ensureMethodStateLoaded()
})
onActivated(() => {
void ensureMethodStateLoaded()
scheduleAutoRowHeights()
})
onBeforeUnmount(() => {
if (autoHeightTimer) clearTimeout(autoHeightTimer)
})
</script>
<template>
<div class="flex h-full min-h-0 flex-col gap-3">
<div class="flex items-center justify-between gap-3">
<div>
<h3 class="text-sm font-semibold text-foreground">{{ methodLabel }}</h3>
<p class="text-xs text-muted-foreground">{{ t('zxFwView.formulaColumns.subtitle') }}</p>
</div>
</div>
<div :class="agGridWrapClass">
<AgGridVue
:theme="myTheme"
:style="agGridStyle"
:row-data="rowData"
:column-defs="columnDefs"
:auto-group-column-def="autoGroupColumnDef"
:grid-options="detailGridOptions"
:locale-text="AG_GRID_LOCALE_CN"
@grid-ready="onGridReady"
/>
</div>
</div>
</template>

View File

@ -443,15 +443,7 @@ watch(canUseLandScale, enabled => {
<div class="quick-calc-shell h-full min-h-0">
<div class="quick-calc-layout">
<section class="quick-calc-panel quick-calc-panel--catalog">
<header class="quick-calc-panel__header">
<div class="quick-calc-panel__title-wrap">
<h2 class="quick-calc-panel__title">{{ t('quickCalc.catalogEyebrow') }}</h2>
</div>
<div class="quick-calc-status">
<span class="quick-calc-status__item">{{ t('quickCalc.industryLabel', { name: industryLabel }) }}</span>
</div>
</header>
<div class="quick-calc-toolbar">
<label class="quick-calc-toolbar__field">
@ -561,13 +553,7 @@ watch(canUseLandScale, enabled => {
</section>
<aside class="quick-calc-panel quick-calc-panel--form">
<header class="quick-calc-panel__header">
<div class="quick-calc-panel__title-wrap">
<h2 class="quick-calc-panel__title">{{ t('quickCalc.formEyebrow') }}</h2>
</div>
</header>
<div class="quick-calc-form">
<div class="quick-calc-form-stack">

View File

@ -15,6 +15,7 @@ import { computed, defineAsyncComponent, defineComponent, h, markRaw, type Compo
import { useI18n } from 'vue-i18n'
import TypeLine from '@/layout/typeLine.vue'
import MethodUnavailableNotice from '@/features/shared/components/MethodUnavailableNotice.vue'
import ScaleFormulaReadonlyPane from '@/features/pricing/components/ScaleFormulaReadonlyPane.vue'
interface ServiceMethodType {
scale?: boolean | null
@ -91,6 +92,26 @@ const landScaleView = createPricingPane('LandScalePricingPane')
const workloadView = createPricingPane('WorkloadPricingPane')
const hourlyView = createPricingPane('HourlyPricingPane')
const createScaleFormulaPane = (
method: 'investScale' | 'landScale',
name: 'InvestmentScaleFormulaPane' | 'LandScaleFormulaPane'
) =>
markRaw(
defineComponent({
name,
setup() {
return () => h(ScaleFormulaReadonlyPane, {
contractId: props.contractId,
serviceId: props.serviceId,
method
})
}
})
)
const investmentScaleFormulaView = createScaleFormulaPane('investScale', 'InvestmentScaleFormulaPane')
const landScaleFormulaView = createScaleFormulaPane('landScale', 'LandScaleFormulaPane')
const workContentPane = markRaw(
defineComponent({
name: 'WorkContentPane',
@ -138,11 +159,21 @@ const pricingCategories = computed<PricingCategoryItem[]>(() => [
label: t('zxFwView.categories.investmentScale'),
component: methodAvailability.value.investmentScale ? investmentScaleView : investmentScaleUnavailableView
},
{
key: 'investment-scale-formula',
label: t('zxFwView.categories.investmentScaleFormula'),
component: methodAvailability.value.investmentScale ? investmentScaleFormulaView : investmentScaleUnavailableView
},
{
key: 'land-scale-method',
label: t('zxFwView.categories.landScale'),
component: methodAvailability.value.landScale ? landScaleView : landScaleUnavailableView
},
{
key: 'land-scale-formula',
label: t('zxFwView.categories.landScaleFormula'),
component: methodAvailability.value.landScale ? landScaleFormulaView : landScaleUnavailableView
},
{
key: 'workload-method',
label: t('zxFwView.categories.workload'),

View File

@ -404,11 +404,19 @@ export const enUS = {
workContentTitle: 'Work Content',
categories: {
investmentScale: 'Investment Scale',
investmentScaleFormula: 'Investment Scale Formula',
landScale: 'Land Scale',
landScaleFormula: 'Land Scale Formula',
workload: 'Workload',
hourly: 'Hourly',
workContent: 'Work Content'
},
formulaColumns: {
subtitle: 'Shows the latest detail rows from the current pricing-method store and stays in sync with store updates.',
amount: 'Amount (CNY)',
basicFormula: 'Basic Work Formula',
optionalFormula: 'Optional Work Formula'
},
unavailable: {
investmentScaleTitle: 'Investment Scale Not Applicable',
investmentScaleMessage: 'Scale method is not enabled for this service, so Investment Scale is not editable.',
@ -470,8 +478,6 @@ export const enUS = {
},
quickCalc: {
projectName: 'Quick Calculation',
catalogEyebrow: 'Category List',
formEyebrow: 'Parameter Form',
industryLabel: 'Industry {name}',
selectIndustry: 'Select industry',
saving: 'Saving...',

View File

@ -404,11 +404,19 @@ export const zhCN = {
workContentTitle: '工作内容',
categories: {
investmentScale: '投资规模法',
investmentScaleFormula: '投资规模法计算公式',
landScale: '用地规模法',
landScaleFormula: '用地规模法计算公式',
workload: '工作量法',
hourly: '工时法',
workContent: '工作内容'
},
formulaColumns: {
subtitle: '直接展示当前计价法 store 的最新明细,随数据变更自动同步。',
amount: '金额(元)',
basicFormula: '基本工作计算式',
optionalFormula: '可选工作计算式'
},
unavailable: {
investmentScaleTitle: '该服务不适用投资规模法',
investmentScaleMessage: '当前服务未启用规模法,投资规模法不可编辑。',
@ -470,8 +478,6 @@ export const zhCN = {
},
quickCalc: {
projectName: '快速计算',
catalogEyebrow: '分类清单',
formEyebrow: '参数表单',
industryLabel: '行业 {name}',
selectIndustry: '请选择工程行业',
saving: '保存中...',

View File

@ -1 +1 @@
{"root":["./src/main.ts","./src/sql.ts","./src/components/ui/button/index.ts","./src/components/ui/card/index.ts","./src/components/ui/scroll-area/index.ts","./src/components/ui/tooltip/index.ts","./src/features/ht/contracts.ts","./src/features/ht/importexport.ts","./src/features/ht/types.ts","./src/features/tab/importexport.ts","./src/features/tab/types.ts","./src/i18n/dictionary-en.ts","./src/i18n/index.ts","./src/i18n/locales/en-us.ts","./src/i18n/locales/zh-cn.ts","./src/lib/aggridreadonlyautoheight.ts","./src/lib/aggridresetheader.ts","./src/lib/contractsegment.ts","./src/lib/decimal.ts","./src/lib/diyaggridoptions.ts","./src/lib/number.ts","./src/lib/numberformat.ts","./src/lib/pricinghourlycalc.ts","./src/lib/pricingmethodtotals.ts","./src/lib/pricingpersistcontrol.ts","./src/lib/pricingpinnedrows.ts","./src/lib/pricingscalecalc.ts","./src/lib/pricingscalecolumns.ts","./src/lib/pricingscaledetail.ts","./src/lib/pricingscaledict.ts","./src/lib/pricingscalefee.ts","./src/lib/pricingscalegrid.ts","./src/lib/pricingscalelink.ts","./src/lib/pricingscalepanedata.ts","./src/lib/pricingscalepanelifecycle.ts","./src/lib/pricingscaleproject.ts","./src/lib/pricingscalerowmap.ts","./src/lib/pricingworkloadcalc.ts","./src/lib/projectevents.ts","./src/lib/projectkvstore.ts","./src/lib/projectregistry.ts","./src/lib/projectsessionlock.ts","./src/lib/projectworkspace.ts","./src/lib/reportexportbuilders.ts","./src/lib/utils.ts","./src/lib/workspace.ts","./src/lib/xmfactordefaults.ts","./src/lib/zwarchive.ts","./src/lib/zxfwpricingsync.ts","./src/pinia/kv.ts","./src/pinia/tab.ts","./src/pinia/uiprefs.ts","./src/pinia/zxfwpricing.ts","./src/pinia/zxfwpricinghtfee.ts","./src/pinia/zxfwpricingkeys.ts","./src/pinia/plugin/indexdb.ts","./src/pinia/plugin/types.d.ts","./src/types/pricing.ts","./src/app.vue","./src/components/ui/button/button.vue","./src/components/ui/card/card.vue","./src/components/ui/card/cardaction.vue","./src/components/ui/card/cardcontent.vue","./src/components/ui/card/carddescription.vue","./src/components/ui/card/cardfooter.vue","./src/components/ui/card/cardheader.vue","./src/components/ui/card/cardtitle.vue","./src/components/ui/scroll-area/scrollarea.vue","./src/components/ui/scroll-area/scrollbar.vue","./src/components/ui/tooltip/tooltipcontent.vue","./src/features/ht/components/ht.vue","./src/features/ht/components/htadditionalworkfee.vue","./src/features/ht/components/htbaseinfo.vue","./src/features/ht/components/htconsultcategoryfactor.vue","./src/features/ht/components/htcontractsummary.vue","./src/features/ht/components/htfeeratemethodform.vue","./src/features/ht/components/htmajorfactor.vue","./src/features/ht/components/htreservefee.vue","./src/features/ht/components/htcard.vue","./src/features/ht/components/htinfo.vue","./src/features/ht/components/zxfw.vue","./src/features/pricing/components/hourlypricingpane.vue","./src/features/pricing/components/investmentscalepricingpane.vue","./src/features/pricing/components/landscalepricingpane.vue","./src/features/pricing/components/workloadpricingpane.vue","./src/features/shared/components/hourlyfeegrid.vue","./src/features/shared/components/htfeegrid.vue","./src/features/shared/components/htfeemethodgrid.vue","./src/features/shared/components/methodunavailablenotice.vue","./src/features/shared/components/servicecheckboxselector.vue","./src/features/shared/components/workcontentgrid.vue","./src/features/shared/components/xmfactorgrid.vue","./src/features/shared/components/xmcommonaggrid.vue","./src/features/workbench/components/homeentryview.vue","./src/features/workbench/components/htfeemethodtypelineview.vue","./src/features/workbench/components/quickcalcworkbenchview.vue","./src/features/workbench/components/zxfwview.vue","./src/features/xm/components/xmconsultcategoryfactor.vue","./src/features/xm/components/xmmajorfactor.vue","./src/features/xm/components/info.vue","./src/features/xm/components/xmcard.vue","./src/features/xm/components/xminfo.vue","./src/layout/tab.vue","./src/layout/typeline.vue"],"version":"5.9.3"}
{"root":["./src/main.ts","./src/sql.ts","./src/components/ui/button/index.ts","./src/components/ui/card/index.ts","./src/components/ui/scroll-area/index.ts","./src/components/ui/tooltip/index.ts","./src/features/ht/contracts.ts","./src/features/ht/importexport.ts","./src/features/ht/types.ts","./src/features/tab/importexport.ts","./src/features/tab/types.ts","./src/i18n/dictionary-en.ts","./src/i18n/index.ts","./src/i18n/locales/en-us.ts","./src/i18n/locales/zh-cn.ts","./src/lib/aggridreadonlyautoheight.ts","./src/lib/aggridresetheader.ts","./src/lib/contractsegment.ts","./src/lib/decimal.ts","./src/lib/diyaggridoptions.ts","./src/lib/number.ts","./src/lib/numberformat.ts","./src/lib/pricinghourlycalc.ts","./src/lib/pricingmethodtotals.ts","./src/lib/pricingpersistcontrol.ts","./src/lib/pricingpinnedrows.ts","./src/lib/pricingscalecalc.ts","./src/lib/pricingscalecolumns.ts","./src/lib/pricingscaledetail.ts","./src/lib/pricingscaledict.ts","./src/lib/pricingscalefee.ts","./src/lib/pricingscalegrid.ts","./src/lib/pricingscalelink.ts","./src/lib/pricingscalepanedata.ts","./src/lib/pricingscalepanelifecycle.ts","./src/lib/pricingscaleproject.ts","./src/lib/pricingscalerowmap.ts","./src/lib/pricingworkloadcalc.ts","./src/lib/projectevents.ts","./src/lib/projectkvstore.ts","./src/lib/projectregistry.ts","./src/lib/projectsessionlock.ts","./src/lib/projectworkspace.ts","./src/lib/reportexportbuilders.ts","./src/lib/utils.ts","./src/lib/workspace.ts","./src/lib/xmfactordefaults.ts","./src/lib/zwarchive.ts","./src/lib/zxfwpricingsync.ts","./src/pinia/kv.ts","./src/pinia/tab.ts","./src/pinia/uiprefs.ts","./src/pinia/zxfwpricing.ts","./src/pinia/zxfwpricinghtfee.ts","./src/pinia/zxfwpricingkeys.ts","./src/pinia/plugin/indexdb.ts","./src/pinia/plugin/types.d.ts","./src/types/pricing.ts","./src/app.vue","./src/components/ui/button/button.vue","./src/components/ui/card/card.vue","./src/components/ui/card/cardaction.vue","./src/components/ui/card/cardcontent.vue","./src/components/ui/card/carddescription.vue","./src/components/ui/card/cardfooter.vue","./src/components/ui/card/cardheader.vue","./src/components/ui/card/cardtitle.vue","./src/components/ui/scroll-area/scrollarea.vue","./src/components/ui/scroll-area/scrollbar.vue","./src/components/ui/tooltip/tooltipcontent.vue","./src/features/ht/components/ht.vue","./src/features/ht/components/htadditionalworkfee.vue","./src/features/ht/components/htbaseinfo.vue","./src/features/ht/components/htconsultcategoryfactor.vue","./src/features/ht/components/htcontractsummary.vue","./src/features/ht/components/htfeeratemethodform.vue","./src/features/ht/components/htmajorfactor.vue","./src/features/ht/components/htreservefee.vue","./src/features/ht/components/htcard.vue","./src/features/ht/components/htinfo.vue","./src/features/ht/components/zxfw.vue","./src/features/pricing/components/hourlypricingpane.vue","./src/features/pricing/components/investmentscalepricingpane.vue","./src/features/pricing/components/landscalepricingpane.vue","./src/features/pricing/components/scaleformulareadonlypane.vue","./src/features/pricing/components/workloadpricingpane.vue","./src/features/shared/components/hourlyfeegrid.vue","./src/features/shared/components/htfeegrid.vue","./src/features/shared/components/htfeemethodgrid.vue","./src/features/shared/components/methodunavailablenotice.vue","./src/features/shared/components/servicecheckboxselector.vue","./src/features/shared/components/workcontentgrid.vue","./src/features/shared/components/xmfactorgrid.vue","./src/features/shared/components/xmcommonaggrid.vue","./src/features/workbench/components/homeentryview.vue","./src/features/workbench/components/htfeemethodtypelineview.vue","./src/features/workbench/components/quickcalcworkbenchview.vue","./src/features/workbench/components/zxfwview.vue","./src/features/xm/components/xmconsultcategoryfactor.vue","./src/features/xm/components/xmmajorfactor.vue","./src/features/xm/components/info.vue","./src/features/xm/components/xmcard.vue","./src/features/xm/components/xminfo.vue","./src/layout/tab.vue","./src/layout/typeline.vue"],"version":"5.9.3"}