Compare commits
No commits in common. "f79e8e0da632afac2e9e8e6d97f7c4b7f27ae6e8" and "d1dda7f9fa356165a64bd0fef484182398dab2b0" have entirely different histories.
f79e8e0da6
...
d1dda7f9fa
@ -186,7 +186,7 @@ const columnDefs: ColDef<FeeRow>[] = [
|
||||
headerClass: 'ag-right-aligned-header',
|
||||
cellClass: 'ag-right-aligned-cell editable-cell-line',
|
||||
editable: true,
|
||||
valueParser: params => parseNumberOrNull(params.newValue, { precision: 2 }),
|
||||
valueParser: params => parseNumberOrNull(params.newValue, { precision: 3 }),
|
||||
valueFormatter: formatEditableUnitPrice,
|
||||
cellClassRules: {
|
||||
'editable-cell-empty': params => params.value == null || params.value === ''
|
||||
|
||||
@ -49,8 +49,6 @@ interface DictGroup {
|
||||
|
||||
interface DetailRow {
|
||||
id: string
|
||||
projectIndex?: number
|
||||
majorDictId?: string
|
||||
groupCode: string
|
||||
groupName: string
|
||||
majorCode: string
|
||||
@ -127,64 +125,6 @@ const isMutipleService = computed(() => {
|
||||
return service?.mutiple === true
|
||||
})
|
||||
const projectCount = ref<number>(1)
|
||||
const PROJECT_PATH_PREFIX = 'project-'
|
||||
const PROJECT_ROW_ID_SEPARATOR = '::'
|
||||
const normalizeProjectCount = (value: unknown) => {
|
||||
const parsed = Number(value)
|
||||
if (!Number.isFinite(parsed)) return 1
|
||||
return Math.max(1, Math.floor(parsed))
|
||||
}
|
||||
const getTargetProjectCount = () => (isMutipleService.value ? normalizeProjectCount(projectCount.value) : 1)
|
||||
const buildProjectGroupPathKey = (projectIndex: number) => `${PROJECT_PATH_PREFIX}${projectIndex}`
|
||||
const parseProjectIndexFromPathKey = (value: string) => {
|
||||
const match = /^project-(\d+)$/.exec(value)
|
||||
if (!match) return null
|
||||
return normalizeProjectCount(Number(match[1]))
|
||||
}
|
||||
const buildScopedRowId = (projectIndex: number, majorId: string) =>
|
||||
isMutipleService.value ? `${projectIndex}${PROJECT_ROW_ID_SEPARATOR}${majorId}` : majorId
|
||||
const parseScopedRowId = (id: unknown) => {
|
||||
const rawId = String(id || '')
|
||||
const match = /^(\d+)::(.+)$/.exec(rawId)
|
||||
if (!match) {
|
||||
return {
|
||||
projectIndex: 1,
|
||||
majorDictId: rawId
|
||||
}
|
||||
}
|
||||
return {
|
||||
projectIndex: normalizeProjectCount(Number(match[1])),
|
||||
majorDictId: String(match[2] || '').trim()
|
||||
}
|
||||
}
|
||||
const resolveRowProjectIndex = (row: Partial<DetailRow> | undefined) => {
|
||||
if (!row) return 1
|
||||
if (typeof row.projectIndex === 'number' && Number.isFinite(row.projectIndex)) {
|
||||
return normalizeProjectCount(row.projectIndex)
|
||||
}
|
||||
if (Array.isArray(row.path) && row.path.length > 0) {
|
||||
const projectIndexFromPath = parseProjectIndexFromPathKey(String(row.path[0] || ''))
|
||||
if (projectIndexFromPath != null) return projectIndexFromPath
|
||||
}
|
||||
return parseScopedRowId(row.id).projectIndex
|
||||
}
|
||||
const resolveRowMajorDictId = (row: Partial<DetailRow> | undefined) => {
|
||||
if (!row) return ''
|
||||
const direct = String(row.majorDictId || '').trim()
|
||||
if (direct) return majorIdAliasMap.get(direct) || direct
|
||||
const parsed = parseScopedRowId(row.id).majorDictId
|
||||
return majorIdAliasMap.get(parsed) || parsed
|
||||
}
|
||||
const makeProjectMajorKey = (projectIndex: number, majorDictId: string) =>
|
||||
`${normalizeProjectCount(projectIndex)}:${String(majorDictId || '').trim()}`
|
||||
const inferProjectCountFromRows = (rows?: Array<Partial<DetailRow>>) => {
|
||||
if (!isMutipleService.value) return 1
|
||||
let maxProjectIndex = 1
|
||||
for (const row of rows || []) {
|
||||
maxProjectIndex = Math.max(maxProjectIndex, resolveRowProjectIndex(row))
|
||||
}
|
||||
return maxProjectIndex
|
||||
}
|
||||
const totalLabel = computed(() => {
|
||||
const industryName = industryNameMap.get(activeIndustryCode.value.trim()) || ''
|
||||
return industryName ? `${industryName}总投资` : '总投资'
|
||||
@ -306,45 +246,38 @@ for (const group of detailDict) {
|
||||
}
|
||||
}
|
||||
|
||||
const buildDefaultRows = (projectCountValue = getTargetProjectCount()): DetailRow[] => {
|
||||
const buildDefaultRows = (): DetailRow[] => {
|
||||
if (!activeIndustryCode.value) return []
|
||||
const rows: DetailRow[] = []
|
||||
for (let projectIndex = 1; projectIndex <= projectCountValue; projectIndex++) {
|
||||
for (const group of detailDict) {
|
||||
if (activeIndustryCode.value && !isMajorIdInIndustryScope(group.id, activeIndustryCode.value)) continue
|
||||
for (const child of group.children) {
|
||||
const rowId = buildScopedRowId(projectIndex, child.id)
|
||||
rows.push({
|
||||
id: rowId,
|
||||
projectIndex,
|
||||
majorDictId: child.id,
|
||||
groupCode: group.code,
|
||||
groupName: group.name,
|
||||
majorCode: child.code,
|
||||
majorName: child.name,
|
||||
hasCost: child.hasCost,
|
||||
hasArea: child.hasArea,
|
||||
amount: null,
|
||||
benchmarkBudget: null,
|
||||
benchmarkBudgetBasic: null,
|
||||
benchmarkBudgetOptional: null,
|
||||
benchmarkBudgetBasicChecked: true,
|
||||
benchmarkBudgetOptionalChecked: true,
|
||||
basicFormula: '',
|
||||
optionalFormula: '',
|
||||
consultCategoryFactor: null,
|
||||
majorFactor: null,
|
||||
workStageFactor: 1,
|
||||
workRatio: 100,
|
||||
budgetFee: null,
|
||||
budgetFeeBasic: null,
|
||||
budgetFeeOptional: null,
|
||||
remark: '',
|
||||
path: isMutipleService.value
|
||||
? [buildProjectGroupPathKey(projectIndex), group.id, rowId]
|
||||
: [group.id, rowId]
|
||||
})
|
||||
}
|
||||
for (const group of detailDict) {
|
||||
if (activeIndustryCode.value && !isMajorIdInIndustryScope(group.id, activeIndustryCode.value)) continue
|
||||
for (const child of group.children) {
|
||||
rows.push({
|
||||
id: child.id,
|
||||
groupCode: group.code,
|
||||
groupName: group.name,
|
||||
majorCode: child.code,
|
||||
majorName: child.name,
|
||||
hasCost: child.hasCost,
|
||||
hasArea: child.hasArea,
|
||||
amount: null,
|
||||
benchmarkBudget: null,
|
||||
benchmarkBudgetBasic: null,
|
||||
benchmarkBudgetOptional: null,
|
||||
benchmarkBudgetBasicChecked: true,
|
||||
benchmarkBudgetOptionalChecked: true,
|
||||
basicFormula: '',
|
||||
optionalFormula: '',
|
||||
consultCategoryFactor: null,
|
||||
majorFactor: null,
|
||||
workStageFactor: 1,
|
||||
workRatio: 100,
|
||||
budgetFee: null,
|
||||
budgetFeeBasic: null,
|
||||
budgetFeeOptional: null,
|
||||
remark: '',
|
||||
path: [group.id, child.id]
|
||||
})
|
||||
}
|
||||
}
|
||||
return rows
|
||||
@ -353,23 +286,15 @@ const buildDefaultRows = (projectCountValue = getTargetProjectCount()): DetailRo
|
||||
const calcOnlyCostScaleAmountFromRows = (rows?: Array<{ amount?: unknown }>) =>
|
||||
sumByNumber(rows || [], row => (typeof row?.amount === 'number' ? row.amount : null))
|
||||
|
||||
const getOnlyCostScaleMajorEntry = () => {
|
||||
const getOnlyCostScaleMajorFactorDefault = () => {
|
||||
const industryId = String(activeIndustryCode.value || '').trim()
|
||||
if (!industryId) return null
|
||||
if (!industryId) return 1
|
||||
const industryMajor = serviceEntries.find(([, item]) => {
|
||||
const majorIndustryId = String(item?.industryId ?? '').trim()
|
||||
return majorIndustryId === industryId && !String(item?.code || '').includes('-')
|
||||
})
|
||||
if (!industryMajor) return null
|
||||
const [id, item] = industryMajor
|
||||
return { id, item }
|
||||
}
|
||||
|
||||
const getOnlyCostScaleMajorFactorDefault = () => {
|
||||
const industryMajor = getOnlyCostScaleMajorEntry()
|
||||
if (!industryMajor) return 1
|
||||
const majorId = industryMajor.id
|
||||
const majorItem = industryMajor.item
|
||||
const [majorId, majorItem] = industryMajor
|
||||
const fromMap = majorFactorMap.value.get(String(majorId))
|
||||
if (typeof fromMap === 'number' && Number.isFinite(fromMap)) return fromMap
|
||||
if (typeof majorItem?.defCoe === 'number' && Number.isFinite(majorItem.defCoe)) return majorItem.defCoe
|
||||
@ -378,7 +303,6 @@ const getOnlyCostScaleMajorFactorDefault = () => {
|
||||
|
||||
const buildOnlyCostScaleRow = (
|
||||
amount: number | null,
|
||||
projectIndex: number,
|
||||
fromDb?: Partial<
|
||||
Pick<
|
||||
DetailRow,
|
||||
@ -392,13 +316,11 @@ const buildOnlyCostScaleRow = (
|
||||
>
|
||||
>
|
||||
): DetailRow => ({
|
||||
id: buildScopedRowId(projectIndex, getOnlyCostScaleMajorEntry()?.id || ONLY_COST_SCALE_ROW_ID),
|
||||
projectIndex,
|
||||
majorDictId: getOnlyCostScaleMajorEntry()?.id || ONLY_COST_SCALE_ROW_ID,
|
||||
groupCode: getOnlyCostScaleMajorEntry()?.item?.code || 'TOTAL',
|
||||
groupName: getOnlyCostScaleMajorEntry()?.item?.name || totalLabel.value,
|
||||
majorCode: getOnlyCostScaleMajorEntry()?.item?.code || 'TOTAL',
|
||||
majorName: getOnlyCostScaleMajorEntry()?.item?.name || totalLabel.value,
|
||||
id: ONLY_COST_SCALE_ROW_ID,
|
||||
groupCode: 'TOTAL',
|
||||
groupName: '总投资',
|
||||
majorCode: 'TOTAL',
|
||||
majorName: '总投资',
|
||||
hasCost: true,
|
||||
hasArea: false,
|
||||
amount,
|
||||
@ -420,56 +342,21 @@ const buildOnlyCostScaleRow = (
|
||||
budgetFeeBasic: null,
|
||||
budgetFeeOptional: null,
|
||||
remark: typeof fromDb?.remark === 'string' ? fromDb.remark : '',
|
||||
path: isMutipleService.value
|
||||
? [buildProjectGroupPathKey(projectIndex), buildScopedRowId(projectIndex, getOnlyCostScaleMajorEntry()?.id || ONLY_COST_SCALE_ROW_ID)]
|
||||
: [buildScopedRowId(projectIndex, getOnlyCostScaleMajorEntry()?.id || ONLY_COST_SCALE_ROW_ID)]
|
||||
path: [ONLY_COST_SCALE_ROW_ID]
|
||||
})
|
||||
|
||||
const buildOnlyCostScaleRows = (
|
||||
rowsFromDb?: Array<Partial<DetailRow> & Pick<DetailRow, 'id'>>,
|
||||
options?: { projectCount?: number; cloneFromProjectOne?: boolean }
|
||||
rowsFromDb?: Array<Partial<DetailRow> & Pick<DetailRow, 'id'>>
|
||||
): DetailRow[] => {
|
||||
const targetProjectCount = normalizeProjectCount(options?.projectCount ?? getTargetProjectCount())
|
||||
const onlyCostMajorId = getOnlyCostScaleMajorEntry()?.id || ONLY_COST_SCALE_ROW_ID
|
||||
const dbValueMap = new Map<string, Partial<DetailRow> & Pick<DetailRow, 'id'>>()
|
||||
for (const row of rowsFromDb || []) {
|
||||
const projectIndex = resolveRowProjectIndex(row)
|
||||
const majorDictId = resolveRowMajorDictId(row) || onlyCostMajorId
|
||||
dbValueMap.set(makeProjectMajorKey(projectIndex, majorDictId), row)
|
||||
if (String(row.id || '') === ONLY_COST_SCALE_ROW_ID && !dbValueMap.has(makeProjectMajorKey(projectIndex, onlyCostMajorId))) {
|
||||
dbValueMap.set(makeProjectMajorKey(projectIndex, onlyCostMajorId), row)
|
||||
}
|
||||
}
|
||||
|
||||
const result: DetailRow[] = []
|
||||
for (let projectIndex = 1; projectIndex <= targetProjectCount; projectIndex++) {
|
||||
const key = makeProjectMajorKey(projectIndex, onlyCostMajorId)
|
||||
const firstProjectKey = makeProjectMajorKey(1, onlyCostMajorId)
|
||||
const fromDb =
|
||||
dbValueMap.get(key) ||
|
||||
(options?.cloneFromProjectOne && projectIndex > 1 ? dbValueMap.get(firstProjectKey) : undefined)
|
||||
const fallbackAmount =
|
||||
options?.cloneFromProjectOne && projectIndex > 1 && fromDb == null
|
||||
? calcOnlyCostScaleAmountFromRows(rowsFromDb)
|
||||
: null
|
||||
result.push(
|
||||
buildOnlyCostScaleRow(
|
||||
typeof fromDb?.amount === 'number' ? fromDb.amount : fallbackAmount,
|
||||
projectIndex,
|
||||
fromDb
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return result
|
||||
const totalAmount = calcOnlyCostScaleAmountFromRows(rowsFromDb)
|
||||
const onlyRow = rowsFromDb?.find(row => String(row.id) === ONLY_COST_SCALE_ROW_ID)
|
||||
return [buildOnlyCostScaleRow(totalAmount, onlyRow)]
|
||||
}
|
||||
|
||||
type SourceRow = Pick<DetailRow, 'id'> &
|
||||
Partial<
|
||||
Pick<
|
||||
DetailRow,
|
||||
| 'projectIndex'
|
||||
| 'majorDictId'
|
||||
| 'amount'
|
||||
| 'benchmarkBudget'
|
||||
| 'benchmarkBudgetBasic'
|
||||
@ -490,32 +377,22 @@ type SourceRow = Pick<DetailRow, 'id'> &
|
||||
>
|
||||
const mergeWithDictRows = (
|
||||
rowsFromDb: SourceRow[] | undefined,
|
||||
options?: {
|
||||
includeAmount?: boolean
|
||||
includeFactorValues?: boolean
|
||||
projectCount?: number
|
||||
cloneFromProjectOne?: boolean
|
||||
}
|
||||
options?: { includeAmount?: boolean; includeFactorValues?: boolean }
|
||||
): DetailRow[] => {
|
||||
const includeAmount = options?.includeAmount ?? true
|
||||
const includeFactorValues = options?.includeFactorValues ?? true
|
||||
const targetProjectCount = normalizeProjectCount(options?.projectCount ?? getTargetProjectCount())
|
||||
const dbValueMap = new Map<string, SourceRow>()
|
||||
for (const row of rowsFromDb || []) {
|
||||
const projectIndex = resolveRowProjectIndex(row)
|
||||
const majorDictId = resolveRowMajorDictId(row)
|
||||
if (!majorDictId) continue
|
||||
dbValueMap.set(makeProjectMajorKey(projectIndex, majorDictId), row)
|
||||
const rowId = String(row.id)
|
||||
dbValueMap.set(rowId, row)
|
||||
const aliasId = majorIdAliasMap.get(rowId)
|
||||
if (aliasId && !dbValueMap.has(aliasId)) {
|
||||
dbValueMap.set(aliasId, row)
|
||||
}
|
||||
}
|
||||
|
||||
return buildDefaultRows(targetProjectCount).map(row => {
|
||||
const rowProjectIndex = resolveRowProjectIndex(row)
|
||||
const rowMajorDictId = resolveRowMajorDictId(row)
|
||||
const fromDb =
|
||||
dbValueMap.get(makeProjectMajorKey(rowProjectIndex, rowMajorDictId)) ||
|
||||
(options?.cloneFromProjectOne && rowProjectIndex > 1
|
||||
? dbValueMap.get(makeProjectMajorKey(1, rowMajorDictId))
|
||||
: undefined)
|
||||
return buildDefaultRows().map(row => {
|
||||
const fromDb = dbValueMap.get(row.id)
|
||||
if (!fromDb) return row
|
||||
const hasConsultCategoryFactor = Object.prototype.hasOwnProperty.call(fromDb, 'consultCategoryFactor')
|
||||
const hasMajorFactor = Object.prototype.hasOwnProperty.call(fromDb, 'majorFactor')
|
||||
@ -547,7 +424,7 @@ const mergeWithDictRows = (
|
||||
? fromDb.majorFactor
|
||||
: hasMajorFactor
|
||||
? null
|
||||
: getDefaultMajorFactorById(rowMajorDictId),
|
||||
: getDefaultMajorFactorById(row.id),
|
||||
workStageFactor: typeof fromDb.workStageFactor === 'number' ? fromDb.workStageFactor : row.workStageFactor,
|
||||
workRatio: typeof fromDb.workRatio === 'number' ? fromDb.workRatio : row.workRatio,
|
||||
budgetFee: typeof fromDb.budgetFee === 'number' ? fromDb.budgetFee : null,
|
||||
@ -575,6 +452,11 @@ const formatMajorFactor = (params: any) => {
|
||||
}
|
||||
|
||||
const formatEditableMoney = (params: any) => {
|
||||
if (isOnlyCostScaleService.value) {
|
||||
if (!params.node?.rowPinned) return ''
|
||||
if (params.value == null || params.value === '') return '点击输入'
|
||||
return formatThousandsFlexible(params.value, 3)
|
||||
}
|
||||
if (!params.node?.group && !params.node?.rowPinned && !params.data?.hasCost) {
|
||||
return ''
|
||||
}
|
||||
@ -595,7 +477,7 @@ type BudgetCheckField = 'benchmarkBudgetBasicChecked' | 'benchmarkBudgetOptional
|
||||
const createBudgetCellRendererWithCheck = (checkField: BudgetCheckField) => (params: any) => {
|
||||
const valueText = formatReadonlyMoney(params)
|
||||
const hasValue = params.value != null && params.value !== ''
|
||||
if (params.node?.group || params.node?.rowPinned || !params.data || !hasValue) {
|
||||
if (params.node?.group || (params.node?.rowPinned && !isOnlyCostScaleService.value) || !params.data || !hasValue) {
|
||||
return valueText
|
||||
}
|
||||
|
||||
@ -613,7 +495,11 @@ const createBudgetCellRendererWithCheck = (checkField: BudgetCheckField) => (par
|
||||
checkbox.checked = params.data[checkField] !== false
|
||||
checkbox.addEventListener('click', event => event.stopPropagation())
|
||||
checkbox.addEventListener('change', () => {
|
||||
const targetRow = params.data as DetailRow | undefined
|
||||
const isOnlyCostScalePinned = isOnlyCostScaleService.value && Boolean(params.node?.rowPinned)
|
||||
const targetRow =
|
||||
isOnlyCostScalePinned
|
||||
? detailRows.value[0]
|
||||
: (params.data as DetailRow | undefined)
|
||||
if (!targetRow) return
|
||||
|
||||
targetRow[checkField] = checkbox.checked
|
||||
@ -709,6 +595,7 @@ const getBudgetFeeSplit = (
|
||||
|
||||
const getMergeColSpanBeforeTotal = (params: any) => {
|
||||
if (!params.node?.group && !params.node?.rowPinned) return 1
|
||||
if (isOnlyCostScaleService.value && params.node?.rowPinned) return 1
|
||||
const displayedColumns = params.api?.getAllDisplayedColumns?.()
|
||||
if (!Array.isArray(displayedColumns) || !params.column) return 1
|
||||
const currentIndex = displayedColumns.findIndex((column: any) => column.getColId() === params.column.getColId())
|
||||
@ -726,15 +613,20 @@ const columnDefs: Array<ColDef<DetailRow> | ColGroupDef<DetailRow>> = [
|
||||
flex: 2,
|
||||
|
||||
editable: params => {
|
||||
if (isOnlyCostScaleService.value) return Boolean(params.node?.rowPinned)
|
||||
return !params.node?.group && !params.node?.rowPinned && Boolean(params.data?.hasCost)
|
||||
},
|
||||
cellClass: params =>
|
||||
!params.node?.group && !params.node?.rowPinned && params.data?.hasCost
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? 'ag-right-aligned-cell editable-cell-line'
|
||||
: !params.node?.group && !params.node?.rowPinned && params.data?.hasCost
|
||||
? 'ag-right-aligned-cell editable-cell-line'
|
||||
: 'ag-right-aligned-cell',
|
||||
cellClassRules: {
|
||||
'editable-cell-empty': params =>
|
||||
!params.node?.group && !params.node?.rowPinned && Boolean(params.data?.hasCost) && (params.value == null || params.value === '')
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? params.value == null || params.value === ''
|
||||
: !params.node?.group && !params.node?.rowPinned && Boolean(params.data?.hasCost) && (params.value == null || params.value === '')
|
||||
},
|
||||
valueParser: params => parseNumberOrNull(params.newValue, { precision: 3 }),
|
||||
valueFormatter: formatEditableMoney
|
||||
@ -753,7 +645,7 @@ const columnDefs: Array<ColDef<DetailRow> | ColGroupDef<DetailRow>> = [
|
||||
cellClass: 'ag-right-aligned-cell',
|
||||
valueGetter: params =>
|
||||
params.node?.rowPinned
|
||||
? null
|
||||
? (isOnlyCostScaleService.value ? getCheckedBenchmarkBudgetSplitByAmount(params.data)?.basic ?? null : null)
|
||||
: getCheckedBenchmarkBudgetSplitByAmount(params.data)?.basic ?? null,
|
||||
cellRenderer: createBudgetCellRendererWithCheck('benchmarkBudgetBasicChecked'),
|
||||
valueFormatter: formatReadonlyMoney
|
||||
@ -768,7 +660,7 @@ const columnDefs: Array<ColDef<DetailRow> | ColGroupDef<DetailRow>> = [
|
||||
cellClass: 'ag-right-aligned-cell',
|
||||
valueGetter: params =>
|
||||
params.node?.rowPinned
|
||||
? null
|
||||
? (isOnlyCostScaleService.value ? getCheckedBenchmarkBudgetSplitByAmount(params.data)?.optional ?? null : null)
|
||||
: getCheckedBenchmarkBudgetSplitByAmount(params.data)?.optional ?? null,
|
||||
cellRenderer: createBudgetCellRendererWithCheck('benchmarkBudgetOptionalChecked'),
|
||||
valueFormatter: formatReadonlyMoney
|
||||
@ -783,7 +675,7 @@ const columnDefs: Array<ColDef<DetailRow> | ColGroupDef<DetailRow>> = [
|
||||
cellClass: 'ag-right-aligned-cell',
|
||||
valueGetter: params =>
|
||||
params.node?.rowPinned
|
||||
? null
|
||||
? (isOnlyCostScaleService.value ? getCheckedBenchmarkBudgetSplitByAmount(params.data)?.total ?? null : null)
|
||||
: getCheckedBenchmarkBudgetSplitByAmount(params.data)?.total ?? null,
|
||||
valueFormatter: formatReadonlyMoney
|
||||
}
|
||||
@ -799,14 +691,21 @@ const columnDefs: Array<ColDef<DetailRow> | ColGroupDef<DetailRow>> = [
|
||||
colId: 'consultCategoryFactor',
|
||||
minWidth: 80,
|
||||
flex: 1,
|
||||
editable: params => !params.node?.group && !params.node?.rowPinned,
|
||||
editable: params =>
|
||||
isOnlyCostScaleService.value
|
||||
? Boolean(params.node?.rowPinned)
|
||||
: !params.node?.group && !params.node?.rowPinned,
|
||||
cellClass: params =>
|
||||
!params.node?.group && !params.node?.rowPinned
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? 'editable-cell-line'
|
||||
: '',
|
||||
: !params.node?.group && !params.node?.rowPinned
|
||||
? 'editable-cell-line'
|
||||
: '',
|
||||
cellClassRules: {
|
||||
'editable-cell-empty': params =>
|
||||
!params.node?.group && !params.node?.rowPinned && (params.value == null || params.value === '')
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? params.value == null || params.value === ''
|
||||
: !params.node?.group && !params.node?.rowPinned && (params.value == null || params.value === '')
|
||||
},
|
||||
valueParser: params => parseNumberOrNull(params.newValue, { precision: 3 }),
|
||||
valueFormatter: formatConsultCategoryFactor
|
||||
@ -817,14 +716,21 @@ const columnDefs: Array<ColDef<DetailRow> | ColGroupDef<DetailRow>> = [
|
||||
colId: 'majorFactor',
|
||||
minWidth: 80,
|
||||
flex: 1,
|
||||
editable: params => !params.node?.group && !params.node?.rowPinned,
|
||||
editable: params =>
|
||||
isOnlyCostScaleService.value
|
||||
? Boolean(params.node?.rowPinned)
|
||||
: !params.node?.group && !params.node?.rowPinned,
|
||||
cellClass: params =>
|
||||
!params.node?.group && !params.node?.rowPinned
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? 'editable-cell-line'
|
||||
: '',
|
||||
: !params.node?.group && !params.node?.rowPinned
|
||||
? 'editable-cell-line'
|
||||
: '',
|
||||
cellClassRules: {
|
||||
'editable-cell-empty': params =>
|
||||
!params.node?.group && !params.node?.rowPinned && (params.value == null || params.value === '')
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? params.value == null || params.value === ''
|
||||
: !params.node?.group && !params.node?.rowPinned && (params.value == null || params.value === '')
|
||||
},
|
||||
valueParser: params => parseNumberOrNull(params.newValue, { precision: 3 }),
|
||||
valueFormatter: formatMajorFactor
|
||||
@ -835,14 +741,21 @@ const columnDefs: Array<ColDef<DetailRow> | ColGroupDef<DetailRow>> = [
|
||||
colId: 'workStageFactor',
|
||||
minWidth: 80,
|
||||
flex: 1,
|
||||
editable: params => !params.node?.group && !params.node?.rowPinned,
|
||||
editable: params =>
|
||||
isOnlyCostScaleService.value
|
||||
? Boolean(params.node?.rowPinned)
|
||||
: !params.node?.group && !params.node?.rowPinned,
|
||||
cellClass: params =>
|
||||
!params.node?.group && !params.node?.rowPinned
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? 'editable-cell-line'
|
||||
: '',
|
||||
: !params.node?.group && !params.node?.rowPinned
|
||||
? 'editable-cell-line'
|
||||
: '',
|
||||
cellClassRules: {
|
||||
'editable-cell-empty': params =>
|
||||
!params.node?.group && !params.node?.rowPinned && (params.value == null || params.value === '')
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? params.value == null || params.value === ''
|
||||
: !params.node?.group && !params.node?.rowPinned && (params.value == null || params.value === '')
|
||||
},
|
||||
valueParser: params => parseNumberOrNull(params.newValue, { precision: 3 }),
|
||||
valueFormatter: formatEditableNumber
|
||||
@ -853,14 +766,21 @@ const columnDefs: Array<ColDef<DetailRow> | ColGroupDef<DetailRow>> = [
|
||||
colId: 'workRatio',
|
||||
minWidth: 80,
|
||||
flex: 1,
|
||||
editable: params => !params.node?.group && !params.node?.rowPinned,
|
||||
editable: params =>
|
||||
isOnlyCostScaleService.value
|
||||
? Boolean(params.node?.rowPinned)
|
||||
: !params.node?.group && !params.node?.rowPinned,
|
||||
cellClass: params =>
|
||||
!params.node?.group && !params.node?.rowPinned
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? 'editable-cell-line'
|
||||
: '',
|
||||
: !params.node?.group && !params.node?.rowPinned
|
||||
? 'editable-cell-line'
|
||||
: '',
|
||||
cellClassRules: {
|
||||
'editable-cell-empty': params =>
|
||||
!params.node?.group && !params.node?.rowPinned && (params.value == null || params.value === '')
|
||||
isOnlyCostScaleService.value && params.node?.rowPinned
|
||||
? params.value == null || params.value === ''
|
||||
: !params.node?.group && !params.node?.rowPinned && (params.value == null || params.value === '')
|
||||
},
|
||||
valueParser: params => parseNumberOrNull(params.newValue, { precision: 3 }),
|
||||
valueFormatter: formatEditableNumber
|
||||
@ -919,64 +839,54 @@ const autoGroupColumnDef: ColDef = {
|
||||
if (params.node?.rowPinned) {
|
||||
return totalLabel.value
|
||||
}
|
||||
const rowData = params.data as DetailRow | undefined
|
||||
if (!params.node?.group && rowData?.majorCode && rowData?.majorName) {
|
||||
return `${rowData.majorCode} ${rowData.majorName}`
|
||||
}
|
||||
const nodeId = String(params.value || '')
|
||||
const projectIndex = parseProjectIndexFromPathKey(nodeId)
|
||||
if (projectIndex != null) return `项目${projectIndex}`
|
||||
return idLabelMap.get(nodeId) || nodeId
|
||||
},
|
||||
tooltipValueGetter: params => {
|
||||
if (params.node?.rowPinned) return totalLabel.value
|
||||
const rowData = params.data as DetailRow | undefined
|
||||
if (!params.node?.group && rowData?.majorCode && rowData?.majorName) {
|
||||
return `${rowData.majorCode} ${rowData.majorName}`
|
||||
}
|
||||
const nodeId = String(params.value || '')
|
||||
const projectIndex = parseProjectIndexFromPathKey(nodeId)
|
||||
if (projectIndex != null) return `项目${projectIndex}`
|
||||
return idLabelMap.get(nodeId) || nodeId
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const totalAmount = computed(() => sumByNumber(detailRows.value, row => row.amount))
|
||||
const visibleDetailRows = computed(() => (isOnlyCostScaleService.value ? [] : detailRows.value))
|
||||
const onlyCostScaleSourceRow = computed(() => detailRows.value[0] ?? buildOnlyCostScaleRow(null))
|
||||
|
||||
|
||||
|
||||
const totalBudgetFeeBasic = computed(() => sumByNumber(detailRows.value, row => getBudgetFeeSplit(row)?.basic))
|
||||
const totalBudgetFeeOptional = computed(() => sumByNumber(detailRows.value, row => getBudgetFeeSplit(row)?.optional))
|
||||
const totalBudgetFee = computed(() => sumByNumber(detailRows.value, row => getBudgetFee(row)))
|
||||
const pinnedTopRowData = computed(() => {
|
||||
return [
|
||||
{
|
||||
id: 'pinned-total-row',
|
||||
groupCode: '',
|
||||
groupName: '',
|
||||
majorCode: '',
|
||||
majorName: '',
|
||||
hasCost: false,
|
||||
hasArea: false,
|
||||
amount: null,
|
||||
benchmarkBudget: null,
|
||||
benchmarkBudgetBasic: null,
|
||||
benchmarkBudgetOptional: null,
|
||||
benchmarkBudgetBasicChecked: true,
|
||||
benchmarkBudgetOptionalChecked: true,
|
||||
basicFormula: '',
|
||||
optionalFormula: '',
|
||||
consultCategoryFactor: null,
|
||||
majorFactor: null,
|
||||
workStageFactor: null,
|
||||
workRatio: null,
|
||||
budgetFee: totalBudgetFee.value,
|
||||
budgetFeeBasic: totalBudgetFeeBasic.value,
|
||||
budgetFeeOptional: totalBudgetFeeOptional.value,
|
||||
remark: '',
|
||||
path: ['TOTAL']
|
||||
}
|
||||
]
|
||||
})
|
||||
const pinnedTopRowData = computed(() => [
|
||||
{
|
||||
id: 'pinned-total-row',
|
||||
groupCode: '',
|
||||
groupName: '',
|
||||
majorCode: '',
|
||||
majorName: '',
|
||||
hasCost: false,
|
||||
hasArea: false,
|
||||
amount: isOnlyCostScaleService.value ? onlyCostScaleSourceRow.value.amount : null,
|
||||
benchmarkBudget: null,
|
||||
benchmarkBudgetBasic: null,
|
||||
benchmarkBudgetOptional: null,
|
||||
benchmarkBudgetBasicChecked: isOnlyCostScaleService.value ? onlyCostScaleSourceRow.value.benchmarkBudgetBasicChecked !== false : true,
|
||||
benchmarkBudgetOptionalChecked: isOnlyCostScaleService.value ? onlyCostScaleSourceRow.value.benchmarkBudgetOptionalChecked !== false : true,
|
||||
basicFormula: '',
|
||||
optionalFormula: '',
|
||||
consultCategoryFactor: isOnlyCostScaleService.value ? onlyCostScaleSourceRow.value.consultCategoryFactor : null,
|
||||
majorFactor: isOnlyCostScaleService.value ? onlyCostScaleSourceRow.value.majorFactor : null,
|
||||
workStageFactor: isOnlyCostScaleService.value ? onlyCostScaleSourceRow.value.workStageFactor : null,
|
||||
workRatio: isOnlyCostScaleService.value ? onlyCostScaleSourceRow.value.workRatio : null,
|
||||
budgetFee: totalBudgetFee.value,
|
||||
budgetFeeBasic: totalBudgetFeeBasic.value,
|
||||
budgetFeeOptional: totalBudgetFeeOptional.value,
|
||||
remark: '',
|
||||
path: ['TOTAL']
|
||||
}
|
||||
])
|
||||
|
||||
const syncComputedValuesToDetailRows = () => {
|
||||
for (const row of detailRows.value) {
|
||||
@ -1033,114 +943,26 @@ const saveToIndexedDB = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const getProjectMajorKeyFromRow = (row: Partial<DetailRow> | undefined) => {
|
||||
if (!row) return ''
|
||||
const majorDictId = resolveRowMajorDictId(row)
|
||||
if (!majorDictId) return ''
|
||||
return makeProjectMajorKey(resolveRowProjectIndex(row), majorDictId)
|
||||
}
|
||||
|
||||
const buildRowsFromImportDefaultSource = async (
|
||||
targetProjectCount: number
|
||||
): Promise<DetailRow[]> => {
|
||||
// 与“使用默认数据”同源:先强制刷新系数,再按合同卡片默认带出。
|
||||
await loadFactorDefaults()
|
||||
const htData = await localforage.getItem<{ detailRows: SourceRow[] }>(HT_DB_KEY.value)
|
||||
const hasContractRows = Array.isArray(htData?.detailRows) && htData.detailRows.length > 0
|
||||
if (isOnlyCostScaleService.value) {
|
||||
return hasContractRows
|
||||
? buildOnlyCostScaleRows(htData!.detailRows as any, { projectCount: targetProjectCount, cloneFromProjectOne: true })
|
||||
: buildOnlyCostScaleRows(undefined, { projectCount: targetProjectCount })
|
||||
}
|
||||
return hasContractRows
|
||||
? mergeWithDictRows(htData!.detailRows, {
|
||||
includeFactorValues: true,
|
||||
projectCount: targetProjectCount,
|
||||
cloneFromProjectOne: true
|
||||
})
|
||||
: buildDefaultRows(targetProjectCount).map(row => ({
|
||||
...row,
|
||||
consultCategoryFactor: getDefaultConsultCategoryFactor(),
|
||||
majorFactor: getDefaultMajorFactorById(row.majorDictId || row.id)
|
||||
}))
|
||||
}
|
||||
|
||||
const applyProjectCountChange = async (nextValue: unknown) => {
|
||||
const normalized = normalizeProjectCount(nextValue)
|
||||
projectCount.value = normalized
|
||||
if (!isMutipleService.value) return
|
||||
const previousRows = detailRows.value.map(row => ({ ...row }))
|
||||
const previousProjectCount = inferProjectCountFromRows(previousRows)
|
||||
if (normalized === previousProjectCount) return
|
||||
|
||||
if (normalized < previousProjectCount) {
|
||||
detailRows.value = isOnlyCostScaleService.value
|
||||
? buildOnlyCostScaleRows(previousRows as any, { projectCount: normalized })
|
||||
: mergeWithDictRows(previousRows as any, { projectCount: normalized })
|
||||
syncComputedValuesToDetailRows()
|
||||
await saveToIndexedDB()
|
||||
return
|
||||
}
|
||||
|
||||
const defaultRows = await buildRowsFromImportDefaultSource(normalized)
|
||||
const existingMap = new Map<string, DetailRow>()
|
||||
for (const row of previousRows) {
|
||||
const key = getProjectMajorKeyFromRow(row)
|
||||
if (!key) continue
|
||||
existingMap.set(key, row)
|
||||
}
|
||||
|
||||
detailRows.value = defaultRows.map(defaultRow => {
|
||||
const key = getProjectMajorKeyFromRow(defaultRow)
|
||||
const existingRow = key ? existingMap.get(key) : undefined
|
||||
if (!existingRow) return defaultRow
|
||||
if (resolveRowProjectIndex(existingRow) > previousProjectCount) return defaultRow
|
||||
return {
|
||||
...defaultRow,
|
||||
...existingRow,
|
||||
id: defaultRow.id,
|
||||
projectIndex: defaultRow.projectIndex,
|
||||
majorDictId: defaultRow.majorDictId,
|
||||
groupCode: defaultRow.groupCode,
|
||||
groupName: defaultRow.groupName,
|
||||
majorCode: defaultRow.majorCode,
|
||||
majorName: defaultRow.majorName,
|
||||
hasCost: defaultRow.hasCost,
|
||||
hasArea: defaultRow.hasArea,
|
||||
path: defaultRow.path
|
||||
}
|
||||
})
|
||||
syncComputedValuesToDetailRows()
|
||||
await saveToIndexedDB()
|
||||
}
|
||||
|
||||
const loadFromIndexedDB = async () => {
|
||||
try {
|
||||
const baseInfo = await localforage.getItem<XmBaseInfoState>(BASE_INFO_KEY)
|
||||
activeIndustryCode.value =
|
||||
typeof baseInfo?.projectIndustry === 'string' ? baseInfo.projectIndustry.trim() : ''
|
||||
projectCount.value = 1
|
||||
|
||||
|
||||
await ensureFactorDefaultsLoaded()
|
||||
const applyContractDefaultRows = async () => {
|
||||
const htData = await localforage.getItem<{ detailRows: SourceRow[] }>(HT_DB_KEY.value)
|
||||
const hasContractRows = Array.isArray(htData?.detailRows) && htData.detailRows.length > 0
|
||||
const targetProjectCount = getTargetProjectCount()
|
||||
if (isOnlyCostScaleService.value) {
|
||||
detailRows.value = hasContractRows
|
||||
? buildOnlyCostScaleRows(htData!.detailRows as any, { projectCount: targetProjectCount, cloneFromProjectOne: true })
|
||||
: buildOnlyCostScaleRows(undefined, { projectCount: targetProjectCount })
|
||||
detailRows.value = hasContractRows ? buildOnlyCostScaleRows(htData!.detailRows as any) : buildOnlyCostScaleRows()
|
||||
} else {
|
||||
detailRows.value = hasContractRows
|
||||
? mergeWithDictRows(htData!.detailRows, {
|
||||
includeFactorValues: true,
|
||||
projectCount: targetProjectCount,
|
||||
cloneFromProjectOne: true
|
||||
})
|
||||
: buildDefaultRows(targetProjectCount).map(row => ({
|
||||
? mergeWithDictRows(htData!.detailRows, { includeFactorValues: true })
|
||||
: buildDefaultRows().map(row => ({
|
||||
...row,
|
||||
consultCategoryFactor: getDefaultConsultCategoryFactor(),
|
||||
majorFactor: getDefaultMajorFactorById(row.majorDictId || row.id)
|
||||
majorFactor: getDefaultMajorFactorById(row.id)
|
||||
}))
|
||||
}
|
||||
syncComputedValuesToDetailRows()
|
||||
@ -1152,18 +974,9 @@ const loadFromIndexedDB = async () => {
|
||||
|
||||
const data = await localforage.getItem<XmInfoState>(DB_KEY.value)
|
||||
if (data) {
|
||||
if (isMutipleService.value) {
|
||||
projectCount.value = inferProjectCountFromRows(data.detailRows as any)
|
||||
}
|
||||
detailRows.value = isOnlyCostScaleService.value
|
||||
? buildOnlyCostScaleRows(data.detailRows as any, {
|
||||
projectCount: getTargetProjectCount(),
|
||||
cloneFromProjectOne: true
|
||||
})
|
||||
: mergeWithDictRows(data.detailRows as any, {
|
||||
projectCount: getTargetProjectCount(),
|
||||
cloneFromProjectOne: true
|
||||
})
|
||||
? buildOnlyCostScaleRows(data.detailRows as any)
|
||||
: mergeWithDictRows(data.detailRows)
|
||||
syncComputedValuesToDetailRows()
|
||||
return
|
||||
}
|
||||
@ -1171,9 +984,7 @@ const loadFromIndexedDB = async () => {
|
||||
await applyContractDefaultRows()
|
||||
} catch (error) {
|
||||
console.error('loadFromIndexedDB failed:', error)
|
||||
detailRows.value = isOnlyCostScaleService.value
|
||||
? buildOnlyCostScaleRows(undefined, { projectCount: getTargetProjectCount() })
|
||||
: buildDefaultRows(getTargetProjectCount())
|
||||
detailRows.value = isOnlyCostScaleService.value ? buildOnlyCostScaleRows() : buildDefaultRows()
|
||||
syncComputedValuesToDetailRows()
|
||||
}
|
||||
}
|
||||
@ -1188,22 +999,15 @@ const importContractData = async () => {
|
||||
await loadFactorDefaults()
|
||||
const htData = await localforage.getItem<{ detailRows: SourceRow[] }>(HT_DB_KEY.value)
|
||||
const hasContractRows = Array.isArray(htData?.detailRows) && htData.detailRows.length > 0
|
||||
const targetProjectCount = getTargetProjectCount()
|
||||
if (isOnlyCostScaleService.value) {
|
||||
detailRows.value = hasContractRows
|
||||
? buildOnlyCostScaleRows(htData!.detailRows as any, { projectCount: targetProjectCount, cloneFromProjectOne: true })
|
||||
: buildOnlyCostScaleRows(undefined, { projectCount: targetProjectCount })
|
||||
detailRows.value = hasContractRows ? buildOnlyCostScaleRows(htData!.detailRows as any) : buildOnlyCostScaleRows()
|
||||
} else {
|
||||
detailRows.value = hasContractRows
|
||||
? mergeWithDictRows(htData!.detailRows, {
|
||||
includeFactorValues: true,
|
||||
projectCount: targetProjectCount,
|
||||
cloneFromProjectOne: true
|
||||
})
|
||||
: buildDefaultRows(targetProjectCount).map(row => ({
|
||||
? mergeWithDictRows(htData!.detailRows, { includeFactorValues: true })
|
||||
: buildDefaultRows().map(row => ({
|
||||
...row,
|
||||
consultCategoryFactor: getDefaultConsultCategoryFactor(),
|
||||
majorFactor: getDefaultMajorFactorById(row.majorDictId || row.id)
|
||||
majorFactor: getDefaultMajorFactorById(row.id)
|
||||
}))
|
||||
}
|
||||
await saveToIndexedDB()
|
||||
@ -1214,9 +1018,7 @@ const importContractData = async () => {
|
||||
|
||||
const clearAllData = async () => {
|
||||
try {
|
||||
detailRows.value = isOnlyCostScaleService.value
|
||||
? buildOnlyCostScaleRows(undefined, { projectCount: getTargetProjectCount() })
|
||||
: buildDefaultRows(getTargetProjectCount())
|
||||
detailRows.value = isOnlyCostScaleService.value ? buildOnlyCostScaleRows() : buildDefaultRows()
|
||||
await saveToIndexedDB()
|
||||
} catch (error) {
|
||||
console.error('clearAllData failed:', error)
|
||||
@ -1237,7 +1039,29 @@ let persistTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
|
||||
let gridPersistTimer: ReturnType<typeof setTimeout> | null = null
|
||||
const handleCellValueChanged = () => {
|
||||
const applyOnlyCostScalePinnedValue = (field: string, rawValue: unknown) => {
|
||||
const parsedValue = parseNumberOrNull(rawValue, { precision: 3 })
|
||||
const current = detailRows.value[0]
|
||||
if (!current) {
|
||||
detailRows.value = [buildOnlyCostScaleRow(field === 'amount' ? parsedValue : null)]
|
||||
return
|
||||
}
|
||||
if (
|
||||
field !== 'amount' &&
|
||||
field !== 'consultCategoryFactor' &&
|
||||
field !== 'majorFactor' &&
|
||||
field !== 'workStageFactor' &&
|
||||
field !== 'workRatio'
|
||||
) {
|
||||
return
|
||||
}
|
||||
detailRows.value = [{ ...current, [field]: parsedValue }]
|
||||
}
|
||||
|
||||
const handleCellValueChanged = (event?: any) => {
|
||||
if (isOnlyCostScaleService.value && event?.node?.rowPinned && typeof event.colDef?.field === 'string') {
|
||||
applyOnlyCostScalePinnedValue(event.colDef.field, event.newValue)
|
||||
}
|
||||
syncComputedValuesToDetailRows()
|
||||
if (gridPersistTimer) clearTimeout(gridPersistTimer)
|
||||
gridPersistTimer = setTimeout(() => {
|
||||
@ -1288,16 +1112,10 @@ const processCellFromClipboard = (params: any) => {
|
||||
<h3 class="text-sm font-semibold text-foreground">投资规模明细</h3>
|
||||
<div v-if="isMutipleService" class="flex items-center gap-2">
|
||||
<span class="text-xs text-muted-foreground">项目数量</span>
|
||||
<NumberFieldRoot
|
||||
v-model="projectCount"
|
||||
:min="1"
|
||||
:step="1"
|
||||
class="inline-flex items-center rounded-md border bg-background"
|
||||
@update:model-value="value => void applyProjectCountChange(value)"
|
||||
>
|
||||
<NumberFieldDecrement class="cursor-pointer px-2 py-1 text-xs text-muted-foreground hover:bg-muted">-</NumberFieldDecrement>
|
||||
<NumberFieldRoot v-model="projectCount" :min="1" :step="1" class="inline-flex items-center rounded-md border bg-background">
|
||||
<NumberFieldDecrement class="px-2 py-1 text-xs text-muted-foreground hover:bg-muted">-</NumberFieldDecrement>
|
||||
<NumberFieldInput class="h-7 w-14 border-x bg-transparent px-2 text-center text-xs outline-none" />
|
||||
<NumberFieldIncrement class="cursor-pointer px-2 py-1 text-xs text-muted-foreground hover:bg-muted">+</NumberFieldIncrement>
|
||||
<NumberFieldIncrement class="px-2 py-1 text-xs text-muted-foreground hover:bg-muted">+</NumberFieldIncrement>
|
||||
</NumberFieldRoot>
|
||||
</div>
|
||||
</div>
|
||||
@ -1350,7 +1168,7 @@ const processCellFromClipboard = (params: any) => {
|
||||
</div>
|
||||
|
||||
<div class="ag-theme-quartz h-full min-h-0 w-full flex-1">
|
||||
<AgGridVue :style="{ height: '100%' }" :rowData="detailRows" :pinnedTopRowData="pinnedTopRowData"
|
||||
<AgGridVue :style="{ height: '100%' }" :rowData="visibleDetailRows" :pinnedTopRowData="pinnedTopRowData"
|
||||
:columnDefs="columnDefs" :autoGroupColumnDef="autoGroupColumnDef" :gridOptions="gridOptions" :theme="myTheme"
|
||||
@cell-value-changed="handleCellValueChanged" :suppressColumnVirtualisation="true"
|
||||
:suppressRowVirtualisation="true" :cellSelection="{ handle: { mode: 'range' } }" :enableClipboard="true"
|
||||
|
||||
@ -49,8 +49,6 @@ interface DictGroup {
|
||||
|
||||
interface DetailRow {
|
||||
id: string
|
||||
projectIndex?: number
|
||||
majorDictId?: string
|
||||
groupCode: string
|
||||
groupName: string
|
||||
majorCode: string
|
||||
@ -121,64 +119,6 @@ const isMutipleService = computed(() => {
|
||||
return service?.mutiple === true
|
||||
})
|
||||
const projectCount = ref<number>(1)
|
||||
const PROJECT_PATH_PREFIX = 'project-'
|
||||
const PROJECT_ROW_ID_SEPARATOR = '::'
|
||||
const normalizeProjectCount = (value: unknown) => {
|
||||
const parsed = Number(value)
|
||||
if (!Number.isFinite(parsed)) return 1
|
||||
return Math.max(1, Math.floor(parsed))
|
||||
}
|
||||
const getTargetProjectCount = () => (isMutipleService.value ? normalizeProjectCount(projectCount.value) : 1)
|
||||
const buildProjectGroupPathKey = (projectIndex: number) => `${PROJECT_PATH_PREFIX}${projectIndex}`
|
||||
const parseProjectIndexFromPathKey = (value: string) => {
|
||||
const match = /^project-(\d+)$/.exec(value)
|
||||
if (!match) return null
|
||||
return normalizeProjectCount(Number(match[1]))
|
||||
}
|
||||
const buildScopedRowId = (projectIndex: number, majorId: string) =>
|
||||
isMutipleService.value ? `${projectIndex}${PROJECT_ROW_ID_SEPARATOR}${majorId}` : majorId
|
||||
const parseScopedRowId = (id: unknown) => {
|
||||
const rawId = String(id || '')
|
||||
const match = /^(\d+)::(.+)$/.exec(rawId)
|
||||
if (!match) {
|
||||
return {
|
||||
projectIndex: 1,
|
||||
majorDictId: rawId
|
||||
}
|
||||
}
|
||||
return {
|
||||
projectIndex: normalizeProjectCount(Number(match[1])),
|
||||
majorDictId: String(match[2] || '').trim()
|
||||
}
|
||||
}
|
||||
const resolveRowProjectIndex = (row: Partial<DetailRow> | undefined) => {
|
||||
if (!row) return 1
|
||||
if (typeof row.projectIndex === 'number' && Number.isFinite(row.projectIndex)) {
|
||||
return normalizeProjectCount(row.projectIndex)
|
||||
}
|
||||
if (Array.isArray(row.path) && row.path.length > 0) {
|
||||
const projectIndexFromPath = parseProjectIndexFromPathKey(String(row.path[0] || ''))
|
||||
if (projectIndexFromPath != null) return projectIndexFromPath
|
||||
}
|
||||
return parseScopedRowId(row.id).projectIndex
|
||||
}
|
||||
const resolveRowMajorDictId = (row: Partial<DetailRow> | undefined) => {
|
||||
if (!row) return ''
|
||||
const direct = String(row.majorDictId || '').trim()
|
||||
if (direct) return majorIdAliasMap.get(direct) || direct
|
||||
const parsed = parseScopedRowId(row.id).majorDictId
|
||||
return majorIdAliasMap.get(parsed) || parsed
|
||||
}
|
||||
const makeProjectMajorKey = (projectIndex: number, majorDictId: string) =>
|
||||
`${normalizeProjectCount(projectIndex)}:${String(majorDictId || '').trim()}`
|
||||
const inferProjectCountFromRows = (rows?: Array<Partial<DetailRow>>) => {
|
||||
if (!isMutipleService.value) return 1
|
||||
let maxProjectIndex = 1
|
||||
for (const row of rows || []) {
|
||||
maxProjectIndex = Math.max(maxProjectIndex, resolveRowProjectIndex(row))
|
||||
}
|
||||
return maxProjectIndex
|
||||
}
|
||||
|
||||
const detailRows = ref<DetailRow[]>([])
|
||||
const getDefaultConsultCategoryFactor = () =>
|
||||
@ -291,46 +231,39 @@ for (const group of detailDict) {
|
||||
}
|
||||
}
|
||||
|
||||
const buildDefaultRows = (projectCountValue = getTargetProjectCount()): DetailRow[] => {
|
||||
const buildDefaultRows = (): DetailRow[] => {
|
||||
if (!activeIndustryCode.value) return []
|
||||
const rows: DetailRow[] = []
|
||||
for (let projectIndex = 1; projectIndex <= projectCountValue; projectIndex++) {
|
||||
for (const group of detailDict) {
|
||||
if (activeIndustryCode.value && !isMajorIdInIndustryScope(group.id, activeIndustryCode.value)) continue
|
||||
for (const child of group.children) {
|
||||
const rowId = buildScopedRowId(projectIndex, child.id)
|
||||
rows.push({
|
||||
id: rowId,
|
||||
projectIndex,
|
||||
majorDictId: child.id,
|
||||
groupCode: group.code,
|
||||
groupName: group.name,
|
||||
majorCode: child.code,
|
||||
majorName: child.name,
|
||||
hasCost: child.hasCost,
|
||||
hasArea: child.hasArea,
|
||||
amount: null,
|
||||
landArea: null,
|
||||
benchmarkBudget: null,
|
||||
benchmarkBudgetBasic: null,
|
||||
benchmarkBudgetOptional: null,
|
||||
benchmarkBudgetBasicChecked: true,
|
||||
benchmarkBudgetOptionalChecked: true,
|
||||
basicFormula: '',
|
||||
optionalFormula: '',
|
||||
consultCategoryFactor: null,
|
||||
majorFactor: null,
|
||||
workStageFactor: 1,
|
||||
workRatio: 100,
|
||||
budgetFee: null,
|
||||
budgetFeeBasic: null,
|
||||
budgetFeeOptional: null,
|
||||
remark: '',
|
||||
path: isMutipleService.value
|
||||
? [buildProjectGroupPathKey(projectIndex), group.id, rowId]
|
||||
: [group.id, rowId]
|
||||
})
|
||||
}
|
||||
for (const group of detailDict) {
|
||||
if (activeIndustryCode.value && !isMajorIdInIndustryScope(group.id, activeIndustryCode.value)) continue
|
||||
for (const child of group.children) {
|
||||
rows.push({
|
||||
id: child.id,
|
||||
groupCode: group.code,
|
||||
groupName: group.name,
|
||||
majorCode: child.code,
|
||||
majorName: child.name,
|
||||
hasCost: child.hasCost,
|
||||
hasArea: child.hasArea,
|
||||
amount: null,
|
||||
landArea: null,
|
||||
benchmarkBudget: null,
|
||||
benchmarkBudgetBasic: null,
|
||||
benchmarkBudgetOptional: null,
|
||||
benchmarkBudgetBasicChecked: true,
|
||||
benchmarkBudgetOptionalChecked: true,
|
||||
basicFormula: '',
|
||||
optionalFormula: '',
|
||||
consultCategoryFactor: null,
|
||||
majorFactor: null,
|
||||
workStageFactor: 1,
|
||||
workRatio: 100,
|
||||
budgetFee: null,
|
||||
budgetFeeBasic: null,
|
||||
budgetFeeOptional: null,
|
||||
remark: '',
|
||||
path: [group.id, child.id]
|
||||
})
|
||||
}
|
||||
}
|
||||
return rows
|
||||
@ -340,8 +273,6 @@ type SourceRow = Pick<DetailRow, 'id'> &
|
||||
Partial<
|
||||
Pick<
|
||||
DetailRow,
|
||||
| 'projectIndex'
|
||||
| 'majorDictId'
|
||||
| 'amount'
|
||||
| 'landArea'
|
||||
| 'benchmarkBudget'
|
||||
@ -363,32 +294,22 @@ type SourceRow = Pick<DetailRow, 'id'> &
|
||||
>
|
||||
const mergeWithDictRows = (
|
||||
rowsFromDb: SourceRow[] | undefined,
|
||||
options?: {
|
||||
includeScaleValues?: boolean
|
||||
includeFactorValues?: boolean
|
||||
projectCount?: number
|
||||
cloneFromProjectOne?: boolean
|
||||
}
|
||||
options?: { includeScaleValues?: boolean; includeFactorValues?: boolean }
|
||||
): DetailRow[] => {
|
||||
const includeScaleValues = options?.includeScaleValues ?? true
|
||||
const includeFactorValues = options?.includeFactorValues ?? true
|
||||
const targetProjectCount = normalizeProjectCount(options?.projectCount ?? getTargetProjectCount())
|
||||
const dbValueMap = new Map<string, SourceRow>()
|
||||
for (const row of rowsFromDb || []) {
|
||||
const projectIndex = resolveRowProjectIndex(row)
|
||||
const majorDictId = resolveRowMajorDictId(row)
|
||||
if (!majorDictId) continue
|
||||
dbValueMap.set(makeProjectMajorKey(projectIndex, majorDictId), row)
|
||||
const rowId = String(row.id)
|
||||
dbValueMap.set(rowId, row)
|
||||
const aliasId = majorIdAliasMap.get(rowId)
|
||||
if (aliasId && !dbValueMap.has(aliasId)) {
|
||||
dbValueMap.set(aliasId, row)
|
||||
}
|
||||
}
|
||||
|
||||
return buildDefaultRows(targetProjectCount).map(row => {
|
||||
const rowProjectIndex = resolveRowProjectIndex(row)
|
||||
const rowMajorDictId = resolveRowMajorDictId(row)
|
||||
const fromDb =
|
||||
dbValueMap.get(makeProjectMajorKey(rowProjectIndex, rowMajorDictId)) ||
|
||||
(options?.cloneFromProjectOne && rowProjectIndex > 1
|
||||
? dbValueMap.get(makeProjectMajorKey(1, rowMajorDictId))
|
||||
: undefined)
|
||||
return buildDefaultRows().map(row => {
|
||||
const fromDb = dbValueMap.get(row.id)
|
||||
if (!fromDb) return row
|
||||
const hasConsultCategoryFactor = Object.prototype.hasOwnProperty.call(fromDb, 'consultCategoryFactor')
|
||||
const hasMajorFactor = Object.prototype.hasOwnProperty.call(fromDb, 'majorFactor')
|
||||
@ -421,7 +342,7 @@ const mergeWithDictRows = (
|
||||
? fromDb.majorFactor
|
||||
: hasMajorFactor
|
||||
? null
|
||||
: getDefaultMajorFactorById(rowMajorDictId),
|
||||
: getDefaultMajorFactorById(row.id),
|
||||
workStageFactor: typeof fromDb.workStageFactor === 'number' ? fromDb.workStageFactor : row.workStageFactor,
|
||||
workRatio: typeof fromDb.workRatio === 'number' ? fromDb.workRatio : row.workRatio,
|
||||
budgetFee: typeof fromDb.budgetFee === 'number' ? fromDb.budgetFee : null,
|
||||
@ -767,24 +688,12 @@ const autoGroupColumnDef: ColDef = {
|
||||
if (params.node?.rowPinned) {
|
||||
return totalLabel.value
|
||||
}
|
||||
const rowData = params.data as DetailRow | undefined
|
||||
if (!params.node?.group && rowData?.majorCode && rowData?.majorName) {
|
||||
return `${rowData.majorCode} ${rowData.majorName}`
|
||||
}
|
||||
const nodeId = String(params.value || '')
|
||||
const projectIndex = parseProjectIndexFromPathKey(nodeId)
|
||||
if (projectIndex != null) return `项目${projectIndex}`
|
||||
return idLabelMap.get(nodeId) || nodeId
|
||||
},
|
||||
tooltipValueGetter: params => {
|
||||
if (params.node?.rowPinned) return totalLabel.value
|
||||
const rowData = params.data as DetailRow | undefined
|
||||
if (!params.node?.group && rowData?.majorCode && rowData?.majorName) {
|
||||
return `${rowData.majorCode} ${rowData.majorName}`
|
||||
}
|
||||
const nodeId = String(params.value || '')
|
||||
const projectIndex = parseProjectIndexFromPathKey(nodeId)
|
||||
if (projectIndex != null) return `项目${projectIndex}`
|
||||
return idLabelMap.get(nodeId) || nodeId
|
||||
}
|
||||
}
|
||||
@ -885,102 +794,22 @@ const saveToIndexedDB = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const getProjectMajorKeyFromRow = (row: Partial<DetailRow> | undefined) => {
|
||||
if (!row) return ''
|
||||
const majorDictId = resolveRowMajorDictId(row)
|
||||
if (!majorDictId) return ''
|
||||
return makeProjectMajorKey(resolveRowProjectIndex(row), majorDictId)
|
||||
}
|
||||
|
||||
const buildRowsFromImportDefaultSource = async (
|
||||
targetProjectCount: number
|
||||
): Promise<DetailRow[]> => {
|
||||
// 与“使用默认数据”同源:先强制刷新系数,再按合同卡片默认带出。
|
||||
await loadFactorDefaults()
|
||||
const htData = await localforage.getItem<{ detailRows: SourceRow[] }>(HT_DB_KEY.value)
|
||||
const hasContractRows = Array.isArray(htData?.detailRows) && htData.detailRows.length > 0
|
||||
return hasContractRows
|
||||
? mergeWithDictRows(htData!.detailRows, {
|
||||
includeFactorValues: true,
|
||||
projectCount: targetProjectCount,
|
||||
cloneFromProjectOne: true
|
||||
})
|
||||
: buildDefaultRows(targetProjectCount).map(row => ({
|
||||
...row,
|
||||
consultCategoryFactor: getDefaultConsultCategoryFactor(),
|
||||
majorFactor: getDefaultMajorFactorById(row.majorDictId || row.id)
|
||||
}))
|
||||
}
|
||||
|
||||
const applyProjectCountChange = async (nextValue: unknown) => {
|
||||
const normalized = normalizeProjectCount(nextValue)
|
||||
projectCount.value = normalized
|
||||
if (!isMutipleService.value) return
|
||||
const previousRows = detailRows.value.map(row => ({ ...row }))
|
||||
const previousProjectCount = inferProjectCountFromRows(previousRows)
|
||||
if (normalized === previousProjectCount) return
|
||||
|
||||
if (normalized < previousProjectCount) {
|
||||
detailRows.value = mergeWithDictRows(previousRows as any, { projectCount: normalized })
|
||||
syncComputedValuesToDetailRows()
|
||||
await saveToIndexedDB()
|
||||
return
|
||||
}
|
||||
|
||||
const defaultRows = await buildRowsFromImportDefaultSource(normalized)
|
||||
const existingMap = new Map<string, DetailRow>()
|
||||
for (const row of previousRows) {
|
||||
const key = getProjectMajorKeyFromRow(row)
|
||||
if (!key) continue
|
||||
existingMap.set(key, row)
|
||||
}
|
||||
|
||||
detailRows.value = defaultRows.map(defaultRow => {
|
||||
const key = getProjectMajorKeyFromRow(defaultRow)
|
||||
const existingRow = key ? existingMap.get(key) : undefined
|
||||
if (!existingRow) return defaultRow
|
||||
if (resolveRowProjectIndex(existingRow) > previousProjectCount) return defaultRow
|
||||
return {
|
||||
...defaultRow,
|
||||
...existingRow,
|
||||
id: defaultRow.id,
|
||||
projectIndex: defaultRow.projectIndex,
|
||||
majorDictId: defaultRow.majorDictId,
|
||||
groupCode: defaultRow.groupCode,
|
||||
groupName: defaultRow.groupName,
|
||||
majorCode: defaultRow.majorCode,
|
||||
majorName: defaultRow.majorName,
|
||||
hasCost: defaultRow.hasCost,
|
||||
hasArea: defaultRow.hasArea,
|
||||
path: defaultRow.path
|
||||
}
|
||||
})
|
||||
syncComputedValuesToDetailRows()
|
||||
await saveToIndexedDB()
|
||||
}
|
||||
|
||||
const loadFromIndexedDB = async () => {
|
||||
try {
|
||||
const baseInfo = await localforage.getItem<XmBaseInfoState>(BASE_INFO_KEY)
|
||||
activeIndustryCode.value =
|
||||
typeof baseInfo?.projectIndustry === 'string' ? baseInfo.projectIndustry.trim() : ''
|
||||
projectCount.value = 1
|
||||
|
||||
await ensureFactorDefaultsLoaded()
|
||||
const applyContractDefaultRows = async () => {
|
||||
const htData = await localforage.getItem<{ detailRows: SourceRow[] }>(HT_DB_KEY.value)
|
||||
const hasContractRows = Array.isArray(htData?.detailRows) && htData.detailRows.length > 0
|
||||
const targetProjectCount = getTargetProjectCount()
|
||||
detailRows.value = hasContractRows
|
||||
? mergeWithDictRows(htData!.detailRows, {
|
||||
includeFactorValues: true,
|
||||
projectCount: targetProjectCount,
|
||||
cloneFromProjectOne: true
|
||||
})
|
||||
: buildDefaultRows(targetProjectCount).map(row => ({
|
||||
? mergeWithDictRows(htData!.detailRows, { includeFactorValues: true })
|
||||
: buildDefaultRows().map(row => ({
|
||||
...row,
|
||||
consultCategoryFactor: getDefaultConsultCategoryFactor(),
|
||||
majorFactor: getDefaultMajorFactorById(row.majorDictId || row.id)
|
||||
majorFactor: getDefaultMajorFactorById(row.id)
|
||||
}))
|
||||
syncComputedValuesToDetailRows()
|
||||
}
|
||||
@ -991,13 +820,7 @@ const loadFromIndexedDB = async () => {
|
||||
|
||||
const data = await localforage.getItem<XmInfoState>(DB_KEY.value)
|
||||
if (data) {
|
||||
if (isMutipleService.value) {
|
||||
projectCount.value = inferProjectCountFromRows(data.detailRows as any)
|
||||
}
|
||||
detailRows.value = mergeWithDictRows(data.detailRows as any, {
|
||||
projectCount: getTargetProjectCount(),
|
||||
cloneFromProjectOne: true
|
||||
})
|
||||
detailRows.value = mergeWithDictRows(data.detailRows)
|
||||
syncComputedValuesToDetailRows()
|
||||
return
|
||||
}
|
||||
@ -1005,7 +828,7 @@ const loadFromIndexedDB = async () => {
|
||||
await applyContractDefaultRows()
|
||||
} catch (error) {
|
||||
console.error('loadFromIndexedDB failed:', error)
|
||||
detailRows.value = buildDefaultRows(getTargetProjectCount())
|
||||
detailRows.value = buildDefaultRows()
|
||||
syncComputedValuesToDetailRows()
|
||||
}
|
||||
}
|
||||
@ -1020,17 +843,12 @@ const importContractData = async () => {
|
||||
await loadFactorDefaults()
|
||||
const htData = await localforage.getItem<{ detailRows: SourceRow[] }>(HT_DB_KEY.value)
|
||||
const hasContractRows = Array.isArray(htData?.detailRows) && htData.detailRows.length > 0
|
||||
const targetProjectCount = getTargetProjectCount()
|
||||
detailRows.value = hasContractRows
|
||||
? mergeWithDictRows(htData!.detailRows, {
|
||||
includeFactorValues: true,
|
||||
projectCount: targetProjectCount,
|
||||
cloneFromProjectOne: true
|
||||
})
|
||||
: buildDefaultRows(targetProjectCount).map(row => ({
|
||||
? mergeWithDictRows(htData!.detailRows, { includeFactorValues: true })
|
||||
: buildDefaultRows().map(row => ({
|
||||
...row,
|
||||
consultCategoryFactor: getDefaultConsultCategoryFactor(),
|
||||
majorFactor: getDefaultMajorFactorById(row.majorDictId || row.id)
|
||||
majorFactor: getDefaultMajorFactorById(row.id)
|
||||
}))
|
||||
await saveToIndexedDB()
|
||||
} catch (error) {
|
||||
@ -1040,7 +858,7 @@ const importContractData = async () => {
|
||||
|
||||
const clearAllData = async () => {
|
||||
try {
|
||||
detailRows.value = buildDefaultRows(getTargetProjectCount())
|
||||
detailRows.value = buildDefaultRows()
|
||||
await saveToIndexedDB()
|
||||
} catch (error) {
|
||||
console.error('clearAllData failed:', error)
|
||||
@ -1112,16 +930,10 @@ const processCellFromClipboard = (params: any) => {
|
||||
<h3 class="text-sm font-semibold text-foreground">用地规模明细</h3>
|
||||
<div v-if="isMutipleService" class="flex items-center gap-2">
|
||||
<span class="text-xs text-muted-foreground">项目数量</span>
|
||||
<NumberFieldRoot
|
||||
v-model="projectCount"
|
||||
:min="1"
|
||||
:step="1"
|
||||
class="inline-flex items-center rounded-md border bg-background"
|
||||
@update:model-value="value => void applyProjectCountChange(value)"
|
||||
>
|
||||
<NumberFieldDecrement class="cursor-pointer px-2 py-1 text-xs text-muted-foreground hover:bg-muted">-</NumberFieldDecrement>
|
||||
<NumberFieldRoot v-model="projectCount" :min="1" :step="1" class="inline-flex items-center rounded-md border bg-background">
|
||||
<NumberFieldDecrement class="px-2 py-1 text-xs text-muted-foreground hover:bg-muted">-</NumberFieldDecrement>
|
||||
<NumberFieldInput class="h-7 w-14 border-x bg-transparent px-2 text-center text-xs outline-none" />
|
||||
<NumberFieldIncrement class="cursor-pointer px-2 py-1 text-xs text-muted-foreground hover:bg-muted">+</NumberFieldIncrement>
|
||||
<NumberFieldIncrement class="px-2 py-1 text-xs text-muted-foreground hover:bg-muted">+</NumberFieldIncrement>
|
||||
</NumberFieldRoot>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -371,7 +371,6 @@ const tabScrollAreaRef = ref<HTMLElement | null>(null)
|
||||
const showTabScrollLeft = ref(false)
|
||||
const showTabScrollRight = ref(false)
|
||||
const isTabStripHover = ref(false)
|
||||
const isTabDragging = ref(false)
|
||||
const tabTitleOverflowMap = ref<Record<string, boolean>>({})
|
||||
let tabStripViewportEl: HTMLElement | null = null
|
||||
let tabTitleOverflowRafId: number | null = null
|
||||
@ -545,14 +544,6 @@ const canMoveTab = (event: any) => {
|
||||
return true
|
||||
}
|
||||
|
||||
const handleTabDragStart = () => {
|
||||
isTabDragging.value = true
|
||||
}
|
||||
|
||||
const handleTabDragEnd = () => {
|
||||
isTabDragging.value = false
|
||||
}
|
||||
|
||||
const setTabItemRef = (id: string, el: Element | ComponentPublicInstance | null) => {
|
||||
if (el instanceof HTMLElement) {
|
||||
tabItemElMap.set(id, el)
|
||||
@ -1350,9 +1341,9 @@ watch(
|
||||
<template>
|
||||
<TooltipProvider>
|
||||
<div class="flex flex-col w-full h-screen bg-background overflow-hidden">
|
||||
<div class="flex items-start gap-2 border-b bg-muted/30 px-2 pt-1 min-h-14 flex-none">
|
||||
<div class="flex items-start gap-2 border-b bg-muted/30 px-2 pt-2 flex-none">
|
||||
<div
|
||||
class="flex min-w-0 flex-1 items-start gap-1 h-full self-start"
|
||||
class="mb-2 flex min-w-0 flex-1 items-center gap-1"
|
||||
@mouseenter="isTabStripHover = true"
|
||||
@mouseleave="isTabStripHover = false"
|
||||
>
|
||||
@ -1371,26 +1362,20 @@ watch(
|
||||
v-model="tabsModel"
|
||||
item-key="id"
|
||||
tag="div"
|
||||
:class="['tab-strip-sortable flex w-max gap-0', isTabDragging ? 'is-dragging' : '']"
|
||||
:animation="260"
|
||||
easing="cubic-bezier(0.22, 1, 0.36, 1)"
|
||||
ghost-class="tab-drag-ghost"
|
||||
chosen-class="tab-drag-chosen"
|
||||
drag-class="tab-drag-active"
|
||||
class="flex w-max gap-1"
|
||||
:animation="180"
|
||||
:move="canMoveTab"
|
||||
@start="handleTabDragStart"
|
||||
@end="handleTabDragEnd"
|
||||
>
|
||||
<template #item="{ element: tab }">
|
||||
<div
|
||||
:ref="el => setTabItemRef(tab.id, el)"
|
||||
@mousedown.left="tabStore.activeTabId = tab.id"
|
||||
@click="tabStore.activeTabId = tab.id"
|
||||
@contextmenu.prevent="openTabContextMenu($event, tab.id)"
|
||||
:class="[
|
||||
'tab-item group relative -mb-px -ml-px first:ml-0 flex items-center h-10 px-4 min-w-[120px] max-w-[220px] cursor-pointer rounded-t-md border border-transparent transition-[background-color,border-color,color,box-shadow,transform] duration-200 text-sm',
|
||||
tabStore.activeTabId === tab.id && !isTabDragging
|
||||
? 'z-10 bg-background text-foreground !border-border !border-b-0 font-medium'
|
||||
: 'bg-muted/25 text-muted-foreground hover:bg-muted/40 hover:text-foreground hover:border-border/70',
|
||||
'group relative flex items-center h-9 px-4 min-w-[120px] max-w-[220px] cursor-pointer rounded-t-md border-x border-t transition-all text-sm',
|
||||
tabStore.activeTabId === tab.id
|
||||
? 'bg-background border-border font-medium'
|
||||
: 'border-transparent hover:bg-muted text-muted-foreground',
|
||||
tab.id !== 'XmView' ? 'cursor-move' : ''
|
||||
]"
|
||||
>
|
||||
@ -1430,12 +1415,12 @@ watch(
|
||||
>
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex shrink-0 self-start items-start gap-1 mb-1">
|
||||
<div ref="dataMenuRef" class="relative shrink-0">
|
||||
|
||||
<div ref="dataMenuRef" class="relative mb-2 shrink-0">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="h-9 min-h-9 shrink-0 px-3 py-0 text-sm leading-none cursor-pointer"
|
||||
class="h-9 min-h-9 px-3 py-0 text-sm leading-none cursor-pointer"
|
||||
@click="dataMenuOpen = !dataMenuOpen"
|
||||
>
|
||||
<ChevronDown class="h-4 w-4 mr-1" />
|
||||
@ -1473,63 +1458,61 @@ watch(
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="h-9 min-h-9 shrink-0 px-3 py-0 text-sm leading-none cursor-pointer"
|
||||
@click="openUserGuide(0)"
|
||||
>
|
||||
<CircleHelp class="h-4 w-4 mr-1" />
|
||||
使用引导
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="mb-2 h-9 min-h-9 shrink-0 px-3 py-0 text-sm leading-none cursor-pointer"
|
||||
@click="openUserGuide(0)"
|
||||
>
|
||||
<CircleHelp class="h-4 w-4 mr-1" />
|
||||
使用引导
|
||||
</Button>
|
||||
|
||||
<AlertDialogRoot>
|
||||
<AlertDialogTrigger as-child>
|
||||
<Button variant="destructive" size="sm" class="h-9 min-h-9 shrink-0 px-3 py-0 text-sm leading-none cursor-pointer">
|
||||
<RotateCcw class="h-4 w-4 mr-1" />
|
||||
重置
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay class="fixed inset-0 z-50 bg-black/45" />
|
||||
<AlertDialogContent class="fixed left-1/2 top-1/2 z-50 w-[92vw] max-w-md -translate-x-1/2 -translate-y-1/2 rounded-lg border bg-background p-5 shadow-xl">
|
||||
<AlertDialogTitle class="text-base font-semibold">确认重置</AlertDialogTitle>
|
||||
<AlertDialogDescription class="mt-2 text-sm text-muted-foreground">
|
||||
将清空所有项目数据,并恢复默认页面,确认继续吗?
|
||||
</AlertDialogDescription>
|
||||
<div class="mt-4 flex items-center justify-end gap-2">
|
||||
<AlertDialogCancel as-child>
|
||||
<Button variant="outline">取消</Button>
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction as-child>
|
||||
<Button variant="destructive" @click="handleReset">确认重置</Button>
|
||||
</AlertDialogAction>
|
||||
</div>
|
||||
</AlertDialogContent>
|
||||
</AlertDialogPortal>
|
||||
</AlertDialogRoot>
|
||||
|
||||
<AlertDialogRoot :open="importConfirmOpen" @update:open="importConfirmOpen = $event">
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay class="fixed inset-0 z-50 bg-black/45" />
|
||||
<AlertDialogContent class="fixed left-1/2 top-1/2 z-50 w-[92vw] max-w-md -translate-x-1/2 -translate-y-1/2 rounded-lg border bg-background p-5 shadow-xl">
|
||||
<AlertDialogTitle class="text-base font-semibold">确认导入覆盖</AlertDialogTitle>
|
||||
<AlertDialogDescription class="mt-2 text-sm text-muted-foreground">
|
||||
将使用“{{ pendingImportFileName || '所选文件' }}”覆盖当前本地全部数据,是否继续?
|
||||
</AlertDialogDescription>
|
||||
<div class="mt-4 flex items-center justify-end gap-2">
|
||||
<AlertDialogCancel as-child>
|
||||
<Button variant="outline" @click="cancelImportConfirm">取消</Button>
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction as-child>
|
||||
<Button variant="destructive" @click="confirmImportOverride">确认覆盖</Button>
|
||||
</AlertDialogAction>
|
||||
</div>
|
||||
</AlertDialogContent>
|
||||
</AlertDialogPortal>
|
||||
</AlertDialogRoot>
|
||||
</div>
|
||||
<AlertDialogRoot>
|
||||
<AlertDialogTrigger as-child>
|
||||
<Button variant="destructive" size="sm" class="mb-2 h-9 min-h-9 shrink-0 px-3 py-0 text-sm leading-none">
|
||||
<RotateCcw class="h-4 w-4 mr-1" />
|
||||
重置
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay class="fixed inset-0 z-50 bg-black/45" />
|
||||
<AlertDialogContent class="fixed left-1/2 top-1/2 z-50 w-[92vw] max-w-md -translate-x-1/2 -translate-y-1/2 rounded-lg border bg-background p-5 shadow-xl">
|
||||
<AlertDialogTitle class="text-base font-semibold">确认重置</AlertDialogTitle>
|
||||
<AlertDialogDescription class="mt-2 text-sm text-muted-foreground">
|
||||
将清空所有项目数据,并恢复默认页面,确认继续吗?
|
||||
</AlertDialogDescription>
|
||||
<div class="mt-4 flex items-center justify-end gap-2">
|
||||
<AlertDialogCancel as-child>
|
||||
<Button variant="outline">取消</Button>
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction as-child>
|
||||
<Button variant="destructive" @click="handleReset">确认重置</Button>
|
||||
</AlertDialogAction>
|
||||
</div>
|
||||
</AlertDialogContent>
|
||||
</AlertDialogPortal>
|
||||
</AlertDialogRoot>
|
||||
|
||||
<AlertDialogRoot :open="importConfirmOpen" @update:open="importConfirmOpen = $event">
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay class="fixed inset-0 z-50 bg-black/45" />
|
||||
<AlertDialogContent class="fixed left-1/2 top-1/2 z-50 w-[92vw] max-w-md -translate-x-1/2 -translate-y-1/2 rounded-lg border bg-background p-5 shadow-xl">
|
||||
<AlertDialogTitle class="text-base font-semibold">确认导入覆盖</AlertDialogTitle>
|
||||
<AlertDialogDescription class="mt-2 text-sm text-muted-foreground">
|
||||
将使用“{{ pendingImportFileName || '所选文件' }}”覆盖当前本地全部数据,是否继续?
|
||||
</AlertDialogDescription>
|
||||
<div class="mt-4 flex items-center justify-end gap-2">
|
||||
<AlertDialogCancel as-child>
|
||||
<Button variant="outline" @click="cancelImportConfirm">取消</Button>
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction as-child>
|
||||
<Button variant="destructive" @click="confirmImportOverride">确认覆盖</Button>
|
||||
</AlertDialogAction>
|
||||
</div>
|
||||
</AlertDialogContent>
|
||||
</AlertDialogPortal>
|
||||
</AlertDialogRoot>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-auto relative">
|
||||
@ -1629,27 +1612,6 @@ watch(
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.tab-strip-sortable > .tab-item {
|
||||
transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
|
||||
.tab-strip-sortable.is-dragging > .tab-item {
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
.tab-drag-ghost {
|
||||
opacity: 0.32;
|
||||
}
|
||||
|
||||
.tab-drag-chosen {
|
||||
transform: scale(1.015);
|
||||
box-shadow: 0 10px 24px rgb(0 0 0 / 18%);
|
||||
}
|
||||
|
||||
.tab-drag-active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.tab-strip-scroll-area :deep([data-slot="scroll-area-viewport"]) {
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
@ -310,46 +310,20 @@ const getOnlyCostScaleBudgetFee = (
|
||||
majorFactorMap?: Map<string, number | null>,
|
||||
industryId?: string | null
|
||||
) => {
|
||||
const totalAmount = sumByNumber(rowsFromDb || [], row =>
|
||||
typeof row?.amount === 'number' && Number.isFinite(row.amount) ? row.amount : null
|
||||
)
|
||||
const onlyRow = (rowsFromDb || []).find(row => String(row?.id || '') === ONLY_COST_SCALE_ROW_ID)
|
||||
const consultCategoryFactor =
|
||||
toFiniteNumberOrNull(onlyRow?.consultCategoryFactor) ??
|
||||
consultCategoryFactorMap?.get(String(serviceId)) ??
|
||||
getDefaultConsultCategoryFactor(serviceId)
|
||||
const industryMajorEntry = getIndustryMajorEntryByIndustryId(industryId)
|
||||
const sourceRows = rowsFromDb || []
|
||||
const defaultConsultCategoryFactor =
|
||||
consultCategoryFactorMap?.get(String(serviceId)) ?? getDefaultConsultCategoryFactor(serviceId)
|
||||
const defaultMajorFactor =
|
||||
const majorFactor =
|
||||
toFiniteNumberOrNull(onlyRow?.majorFactor) ??
|
||||
(industryMajorEntry ? majorFactorMap?.get(industryMajorEntry.id) ?? null : null) ??
|
||||
toFiniteNumberOrNull(industryMajorEntry?.item?.defCoe) ??
|
||||
1
|
||||
|
||||
// 新版 onlyCostScale 支持“按项目行”存储(如 1::majorId、2::majorId),每行需独立计费后求和。
|
||||
const usePerRowCalculation = sourceRows.some(row => {
|
||||
if (typeof row?.projectIndex === 'number' && Number.isFinite(row.projectIndex)) return true
|
||||
const id = String(row?.id || '')
|
||||
return /^\d+::/.test(id)
|
||||
})
|
||||
if (usePerRowCalculation) {
|
||||
return sumByNumber(sourceRows, row => {
|
||||
const amount = toFiniteNumberOrNull(row?.amount)
|
||||
if (amount == null) return null
|
||||
return getScaleBudgetFee({
|
||||
benchmarkBudget: getBenchmarkBudgetByAmount(amount),
|
||||
majorFactor: toFiniteNumberOrNull(row?.majorFactor) ?? defaultMajorFactor,
|
||||
consultCategoryFactor: toFiniteNumberOrNull(row?.consultCategoryFactor) ?? defaultConsultCategoryFactor,
|
||||
workStageFactor: toFiniteNumberOrNull(row?.workStageFactor) ?? 1,
|
||||
workRatio: toFiniteNumberOrNull(row?.workRatio) ?? 100
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const totalAmount = sumByNumber(sourceRows, row =>
|
||||
typeof row?.amount === 'number' && Number.isFinite(row.amount) ? row.amount : null
|
||||
)
|
||||
const onlyRow =
|
||||
sourceRows.find(row => String(row?.id || '') === ONLY_COST_SCALE_ROW_ID) ||
|
||||
sourceRows.find(row => hasOwn(row, 'consultCategoryFactor') || hasOwn(row, 'majorFactor')) ||
|
||||
sourceRows[0]
|
||||
const consultCategoryFactor =
|
||||
toFiniteNumberOrNull(onlyRow?.consultCategoryFactor) ?? defaultConsultCategoryFactor
|
||||
const majorFactor =
|
||||
toFiniteNumberOrNull(onlyRow?.majorFactor) ?? defaultMajorFactor
|
||||
const workStageFactor = toFiniteNumberOrNull(onlyRow?.workStageFactor) ?? 1
|
||||
const workRatio = toFiniteNumberOrNull(onlyRow?.workRatio) ?? 100
|
||||
return getScaleBudgetFee({
|
||||
@ -371,15 +345,12 @@ const buildOnlyCostScaleDetailRows = (
|
||||
const totalAmount = sumByNumber(rowsFromDb || [], row =>
|
||||
typeof row?.amount === 'number' && Number.isFinite(row.amount) ? row.amount : null
|
||||
)
|
||||
const industryMajorEntry = getIndustryMajorEntryByIndustryId(industryId)
|
||||
const onlyCostRowId = industryMajorEntry?.id || ONLY_COST_SCALE_ROW_ID
|
||||
const onlyRow =
|
||||
(rowsFromDb || []).find(row => String(row?.id || '') === ONLY_COST_SCALE_ROW_ID) ||
|
||||
(rowsFromDb || []).find(row => String(row?.id || '') === onlyCostRowId)
|
||||
const onlyRow = (rowsFromDb || []).find(row => String(row?.id || '') === ONLY_COST_SCALE_ROW_ID)
|
||||
const consultCategoryFactor =
|
||||
toFiniteNumberOrNull(onlyRow?.consultCategoryFactor) ??
|
||||
consultCategoryFactorMap?.get(String(serviceId)) ??
|
||||
getDefaultConsultCategoryFactor(serviceId)
|
||||
const industryMajorEntry = getIndustryMajorEntryByIndustryId(industryId)
|
||||
const majorFactor =
|
||||
toFiniteNumberOrNull(onlyRow?.majorFactor) ??
|
||||
(industryMajorEntry ? majorFactorMap?.get(industryMajorEntry.id) ?? null : null) ??
|
||||
@ -390,7 +361,7 @@ const buildOnlyCostScaleDetailRows = (
|
||||
|
||||
return [
|
||||
{
|
||||
id: onlyCostRowId,
|
||||
id: ONLY_COST_SCALE_ROW_ID,
|
||||
amount: totalAmount,
|
||||
consultCategoryFactor,
|
||||
majorFactor,
|
||||
|
||||
39
src/sql.ts
39
src/sql.ts
@ -583,7 +583,7 @@ async function generateTemplate(data) {
|
||||
},
|
||||
],
|
||||
},
|
||||
m5: {//数量单价
|
||||
m5: {
|
||||
fee: 10000,
|
||||
det: [
|
||||
{
|
||||
@ -610,12 +610,11 @@ async function generateTemplate(data) {
|
||||
code: { richText: [{ font: { charset: 134, color: { theme: 1 }, italic: true, name: '宋体', size: 10 }, text: 'C' }, { font: { charset: 134, color: { theme: 1 }, italic: true, name: 'Calibri', size: 10, vertAlign: 'subscript' }, text: 'X' }] },
|
||||
name: '咨询服务协调工作',
|
||||
fee: 10000,
|
||||
m0: { //费率计取
|
||||
|
||||
coe: 0.03,//费率
|
||||
m0: {
|
||||
coe: 0.03,
|
||||
fee: 10000,
|
||||
},
|
||||
m4: { //工时法
|
||||
m4: {
|
||||
person_num: 10,
|
||||
work_day: 3,
|
||||
fee: 10000,
|
||||
@ -1326,7 +1325,7 @@ async function generateTemplate(data) {
|
||||
if (addobj.m4) {
|
||||
cusInsertRowFunc(4 + num_4, [sheet_4.getRow(4)], sheet_4, (targetRow) => {
|
||||
targetRow.getCell(1).value = num_4++;
|
||||
targetRow.getCell(2).value = addobj.code;
|
||||
targetRow.getCell(2).value = addobj.ref;
|
||||
targetRow.getCell(3).value = addobj.name;
|
||||
targetRow.getCell(4).value = numberFormatter(addobj.m4.person_num, 0);
|
||||
targetRow.getCell(5).value = numberFormatter(addobj.m4.work_day, 2);
|
||||
@ -1334,7 +1333,7 @@ async function generateTemplate(data) {
|
||||
});
|
||||
cusInsertRowFunc(4 + num_4_1, [sheet_4_1.getRow(4)], sheet_4_1, (targetRow) => {
|
||||
targetRow.getCell(1).value = num_4_1++;
|
||||
targetRow.getCell(2).value = addobj.code;
|
||||
targetRow.getCell(2).value = addobj.ref;
|
||||
targetRow.getCell(3).value = addobj.name;
|
||||
targetRow.getCell(4).value = '/';
|
||||
targetRow.getCell(5).value = '/';
|
||||
@ -1362,20 +1361,20 @@ async function generateTemplate(data) {
|
||||
if (addobj.m5) {
|
||||
cusInsertRowFunc(4 + num_5, [sheet_5.getRow(4)], sheet_5, (targetRow) => {
|
||||
num_5++;
|
||||
targetRow.getCell(1).value = addobj.code;
|
||||
targetRow.getCell(1).value = addobj.ref;
|
||||
targetRow.getCell(2).value = addobj.name;
|
||||
targetRow.getCell(3).value = '/';
|
||||
targetRow.getCell(4).value = '/';
|
||||
targetRow.getCell(5).value = '/';
|
||||
targetRow.getCell(6).value = numberFormatter(addobj.m5.fee, 2);
|
||||
});
|
||||
const tmpJSS = JSON.stringify(addobj.code);
|
||||
const tmpJSS = JSON.stringify(addobj.ref);
|
||||
addobj.m5.det.forEach((eobj, eindex) => {
|
||||
let code = JSON.parse(tmpJSS);
|
||||
code.richText.push({ font: { charset: 134, color: { theme: 1 }, italic: true, name: '宋体', size: 10 }, text: '-' + (eindex + 1) });
|
||||
let ref = JSON.parse(tmpJSS);
|
||||
ref.richText.push({ font: { charset: 134, color: { theme: 1 }, italic: true, name: '宋体', size: 10 }, text: '-' + (eindex + 1) });
|
||||
cusInsertRowFunc(4 + num_5, [sheet_5.getRow(4)], sheet_5, (targetRow) => {
|
||||
num_5++;
|
||||
targetRow.getCell(1).value = code;
|
||||
targetRow.getCell(1).value = ref;
|
||||
targetRow.getCell(2).value = eobj.name;
|
||||
targetRow.getCell(3).value = eobj.unit;
|
||||
targetRow.getCell(4).value = numberFormatter(eobj.amount, 3);
|
||||
@ -1392,7 +1391,7 @@ async function generateTemplate(data) {
|
||||
endRows++;
|
||||
cusInsertRowFunc(ci.services.length + 3 + endRows, [sheet_1.getRow(3)], sheet_1, (targetRow) => {
|
||||
targetRow.getCell(1).value = ci.services.length + endRows;
|
||||
targetRow.getCell(2).value = ci.reserve.code;
|
||||
targetRow.getCell(2).value = ci.reserve.ref;
|
||||
targetRow.getCell(3).value = ci.reserve.name;
|
||||
let tmpArr = [];
|
||||
if (ci.reserve.m0) tmpArr.push(`按上述小计及附加工作费之和的${ci.reserve.m0.coe}计得${ci.reserve.m0.fee}元`);
|
||||
@ -1404,7 +1403,7 @@ async function generateTemplate(data) {
|
||||
if (ci.reserve.m4) {
|
||||
cusInsertRowFunc(4 + num_4, [sheet_4.getRow(4)], sheet_4, (targetRow) => {
|
||||
targetRow.getCell(1).value = num_4++;
|
||||
targetRow.getCell(2).value = ci.reserve.code;
|
||||
targetRow.getCell(2).value = ci.reserve.ref;
|
||||
targetRow.getCell(3).value = ci.reserve.name;
|
||||
targetRow.getCell(4).value = numberFormatter(ci.reserve.m4.person_num, 0);
|
||||
targetRow.getCell(5).value = numberFormatter(ci.reserve.m4.work_day, 2);
|
||||
@ -1412,7 +1411,7 @@ async function generateTemplate(data) {
|
||||
});
|
||||
cusInsertRowFunc(4 + num_4_1, [sheet_4_1.getRow(4)], sheet_4_1, (targetRow) => {
|
||||
targetRow.getCell(1).value = num_4_1++;
|
||||
targetRow.getCell(2).value = ci.reserve.code;
|
||||
targetRow.getCell(2).value = ci.reserve.ref;
|
||||
targetRow.getCell(3).value = ci.reserve.name;
|
||||
targetRow.getCell(4).value = '/';
|
||||
targetRow.getCell(5).value = '/';
|
||||
@ -1440,20 +1439,20 @@ async function generateTemplate(data) {
|
||||
if (ci.reserve.m5) {
|
||||
cusInsertRowFunc(4 + num_5, [sheet_5.getRow(4)], sheet_5, (targetRow) => {
|
||||
num_5++;
|
||||
targetRow.getCell(1).value = ci.reserve.code;
|
||||
targetRow.getCell(1).value = ci.reserve.ref;
|
||||
targetRow.getCell(2).value = ci.reserve.name;
|
||||
targetRow.getCell(3).value = '/';
|
||||
targetRow.getCell(4).value = '/';
|
||||
targetRow.getCell(5).value = '/';
|
||||
targetRow.getCell(6).value = numberFormatter(ci.reserve.m5.fee, 2);
|
||||
});
|
||||
const tmpJSS = JSON.stringify(ci.reserve.code);
|
||||
const tmpJSS = JSON.stringify(ci.reserve.ref);
|
||||
ci.reserve.m5.det.forEach((eobj, eindex) => {
|
||||
let code = JSON.parse(tmpJSS);
|
||||
code.richText.push({ font: { charset: 134, color: { theme: 1 }, italic: true, name: '宋体', size: 10 }, text: '-' + (eindex + 1) });
|
||||
let ref = JSON.parse(tmpJSS);
|
||||
ref.richText.push({ font: { charset: 134, color: { theme: 1 }, italic: true, name: '宋体', size: 10 }, text: '-' + (eindex + 1) });
|
||||
cusInsertRowFunc(4 + num_5, [sheet_5.getRow(4)], sheet_5, (targetRow) => {
|
||||
num_5++;
|
||||
targetRow.getCell(1).value = code;
|
||||
targetRow.getCell(1).value = ref;
|
||||
targetRow.getCell(2).value = eobj.name;
|
||||
targetRow.getCell(3).value = eobj.unit;
|
||||
targetRow.getCell(4).value = numberFormatter(eobj.amount, 3);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user