67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import type { Ref } from 'vue'
|
|
|
|
type ColumnConfig = {
|
|
type: 'text'
|
|
data: string
|
|
title: string
|
|
width?: number
|
|
readOnly?: boolean
|
|
}
|
|
|
|
type CreateSettingsDeps = {
|
|
formulaInput: Ref<string>
|
|
}
|
|
|
|
const createRowSchema = (columns: ColumnConfig[]) => {
|
|
const schema: Record<string, null> = {}
|
|
columns.forEach((col) => {
|
|
if (col.data) schema[col.data] = null
|
|
})
|
|
return schema
|
|
}
|
|
|
|
const createMockRows = (count: number) => {
|
|
return Array.from({ length: count }, (_, index) => {
|
|
const rowNumber = index + 1
|
|
const rowText = String(rowNumber).padStart(3, '0')
|
|
return {
|
|
seq: String(rowNumber),
|
|
code: `DW${rowText}`,
|
|
name: `单位汇总费用${rowNumber}`,
|
|
value: String((rowNumber * 6).toFixed(2)),
|
|
}
|
|
})
|
|
}
|
|
|
|
export const createUnitSummarySettings = ({ formulaInput }: CreateSettingsDeps) => {
|
|
const columns: ColumnConfig[] = [
|
|
{ type: 'text', data: 'seq', title: '序号', width: 60, readOnly: true },
|
|
{ type: 'text', data: 'name', title: '费用名称', width: 240, readOnly: true },
|
|
{ type: 'text', data: 'code', title: '代号', width: 160, readOnly: true },
|
|
]
|
|
|
|
const allowedSelectionDataKeys = new Set(['code', 'value'])
|
|
|
|
return {
|
|
data: createMockRows(30),
|
|
//dataSchema: createRowSchema(columns),
|
|
colWidths: 150,
|
|
height: 400,
|
|
columns,
|
|
rowHeaders: false,
|
|
nestedRows: false,
|
|
bindRowsWithHeaders: true,
|
|
selectionMode: 'single',
|
|
className: 'htCenter',
|
|
afterSelection(row: number, col: number) {
|
|
if (row < 0 || col < 0) return
|
|
const selectedDataKey = columns?.[col]?.data
|
|
if (!selectedDataKey || !allowedSelectionDataKeys.has(selectedDataKey)) return
|
|
const cellValue = this.getDataAtCell(row, col)
|
|
if (cellValue == null) return
|
|
formulaInput.value += String(cellValue)
|
|
},
|
|
}
|
|
}
|
|
|