gm-printer 11.0.2-beta.2 → 11.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/demo.js +9 -9
- package/package.json +1 -1
- package/src/common/editor_store.js +2 -37
- package/src/common/editor_title.js +4 -10
- package/src/editor/index.js +0 -2
- package/src/editor_settle/editor.js +1 -2
- package/src/index.js +1 -5
- package/src/printer/page_summary.js +46 -21
- package/src/printer/printer.js +3 -3
- package/src/printer/store.js +5 -8
- package/src/printer/table_diy_overallOrder_tr.js +43 -58
- package/src/printer/table_diy_summary_tr.js +54 -14
- package/src/printer/table_subtotal_tr.js +48 -45
- package/src/util.js +104 -1
- package/src/editor/context_menu_config.js +0 -335
- package/src/editor/editor_menu_config.js +0 -140
- package/src/examining_report_editor/context_menu.js +0 -94
- package/src/examining_report_editor/editor.js +0 -85
- package/src/examining_report_editor/index.js +0 -4
- package/src/examining_report_editor/store.js +0 -78
package/package.json
CHANGED
|
@@ -94,45 +94,13 @@ class EditorStore {
|
|
|
94
94
|
|
|
95
95
|
@action
|
|
96
96
|
setSubtotalFieldsCol(arr) {
|
|
97
|
+
// this.overallOrderShow = !this.overallOrderShow
|
|
98
|
+
// 重新计算每页合计的单元格
|
|
97
99
|
const table = this.config.contents[arr[2]]
|
|
98
|
-
if (!table?.subtotal?.show) return
|
|
99
|
-
|
|
100
|
-
const colSpanLength = getColSpanLength(table)
|
|
101
|
-
if (!table.subtotal.fields?.length) {
|
|
102
|
-
set(table.subtotal, {
|
|
103
|
-
fields: [
|
|
104
|
-
{
|
|
105
|
-
name: '每页合计:',
|
|
106
|
-
valueField: 'real_item_price',
|
|
107
|
-
colSpan: colSpanLength
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
})
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
100
|
const subtotalLength = table.subtotal.fields.length
|
|
115
101
|
table.subtotal.fields[subtotalLength - 1].colSpan += 1
|
|
116
102
|
}
|
|
117
103
|
|
|
118
|
-
@action
|
|
119
|
-
updateSelectedRegionAfterContentInsert(insertIndex) {
|
|
120
|
-
const updateNameIndex = name => {
|
|
121
|
-
if (!name) return name
|
|
122
|
-
const parts = name.split('.')
|
|
123
|
-
if (parts[0] !== 'contents') return name
|
|
124
|
-
const regionIndex = ~~parts[2]
|
|
125
|
-
if (regionIndex >= insertIndex) {
|
|
126
|
-
parts[2] = String(regionIndex + 1)
|
|
127
|
-
return parts.join('.')
|
|
128
|
-
}
|
|
129
|
-
return name
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
this.selectedRegion = updateNameIndex(this.selectedRegion)
|
|
133
|
-
this.selected = updateNameIndex(this.selected)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
104
|
@action
|
|
137
105
|
setMultiDigitDecimal(bool) {
|
|
138
106
|
this.isMultiDigitDecimal = bool
|
|
@@ -298,7 +266,6 @@ class EditorStore {
|
|
|
298
266
|
{ batchPrintConfig: 1, isFixLastFooter: true },
|
|
299
267
|
config
|
|
300
268
|
)
|
|
301
|
-
this.defaultTableDataKey = config.defaultTableDataKey || 'orders'
|
|
302
269
|
this.originConfig = config
|
|
303
270
|
this.selected = null
|
|
304
271
|
this.selectedRegion = null
|
|
@@ -1238,8 +1205,6 @@ class EditorStore {
|
|
|
1238
1205
|
}
|
|
1239
1206
|
})
|
|
1240
1207
|
}
|
|
1241
|
-
this.updateSelectedRegionAfterContentInsert(index)
|
|
1242
|
-
this.config = toJS(this.config)
|
|
1243
1208
|
}
|
|
1244
1209
|
}
|
|
1245
1210
|
}
|
|
@@ -72,15 +72,13 @@ class EditorTitle extends React.Component {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
handleTestPrint = () => {
|
|
75
|
-
|
|
76
|
-
const { mockData, editStore, isSomeSubtotalTr } = this.props
|
|
75
|
+
const { mockData, editStore } = this.props
|
|
77
76
|
doPrint(
|
|
78
77
|
{
|
|
79
78
|
config: toJS(editStore.config),
|
|
80
79
|
data: mockData
|
|
81
80
|
},
|
|
82
|
-
true
|
|
83
|
-
isSomeSubtotalTr
|
|
81
|
+
true
|
|
84
82
|
)
|
|
85
83
|
}
|
|
86
84
|
|
|
@@ -142,14 +140,10 @@ class EditorTitle extends React.Component {
|
|
|
142
140
|
EditorTitle.propTypes = {
|
|
143
141
|
onSave: PropTypes.func.isRequired,
|
|
144
142
|
isPurchase: PropTypes.bool,
|
|
145
|
-
editStore: PropTypes.object
|
|
146
|
-
// 标识是否为结款单每页合计场景
|
|
147
|
-
isSomeSubtotalTr: PropTypes.bool
|
|
143
|
+
editStore: PropTypes.object
|
|
148
144
|
}
|
|
149
145
|
EditorTitle.defaultProps = {
|
|
150
|
-
isPurchase: false
|
|
151
|
-
// 默认按非结款单每页合计场景处理
|
|
152
|
-
isSomeSubtotalTr: false
|
|
146
|
+
isPurchase: false
|
|
153
147
|
}
|
|
154
148
|
|
|
155
149
|
EditorTitle.wrappedComponent.propTypes = {
|
package/src/editor/index.js
CHANGED
|
@@ -42,8 +42,7 @@ class Editor extends React.Component {
|
|
|
42
42
|
|
|
43
43
|
{showEditor && (
|
|
44
44
|
<div className='gm-printer-edit-zone'>
|
|
45
|
-
{
|
|
46
|
-
<EditorTitle onSave={onSave} isSomeSubtotalTr={isSomeSubtotalTr} />
|
|
45
|
+
<EditorTitle onSave={onSave} />
|
|
47
46
|
<Gap height='10px' />
|
|
48
47
|
<EditorSelect />
|
|
49
48
|
<Gap height='5px' />
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// ‼️优先初始化语言设置(必须先初始化语言)
|
|
2
2
|
import '../locales'
|
|
3
|
-
import Editor
|
|
4
|
-
|
|
3
|
+
import Editor from './editor'
|
|
5
4
|
import EditorPurchase from './editor_purchase'
|
|
6
|
-
import EditorExaminingReport from './examining_report_editor'
|
|
7
5
|
import EditorStockIn from './editor_stockin'
|
|
8
6
|
import EditorStockOut from './editor_stockout'
|
|
9
7
|
import EditorSettle from './editor_settle'
|
|
@@ -29,11 +27,9 @@ export { setLocale } from '../locales'
|
|
|
29
27
|
|
|
30
28
|
export {
|
|
31
29
|
Editor,
|
|
32
|
-
Editor2,
|
|
33
30
|
EditorStockIn,
|
|
34
31
|
EditorStockOut,
|
|
35
32
|
EditorPurchase,
|
|
36
|
-
EditorExaminingReport,
|
|
37
33
|
EditorSettle,
|
|
38
34
|
EditorStatement,
|
|
39
35
|
EditorAccoutStatement,
|
|
@@ -1,32 +1,44 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import _ from 'lodash'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getDataKey,
|
|
5
|
+
isMultiTable,
|
|
6
|
+
formatSumWithPrecision,
|
|
7
|
+
getHighPrecisionField,
|
|
8
|
+
extractSumField,
|
|
9
|
+
templateSumResult
|
|
10
|
+
} from '../util'
|
|
4
11
|
import Big from 'big.js'
|
|
5
12
|
import { observer } from 'mobx-react'
|
|
6
13
|
import { get } from 'mobx'
|
|
7
14
|
import i18next from '../../locales'
|
|
8
15
|
|
|
9
|
-
const regExp = text => {
|
|
10
|
-
const match = /{{([^{}]+)}}/.exec(text)
|
|
11
|
-
const key = match ? match[1] : ''
|
|
12
|
-
return key ? key.split('.')[1] : ''
|
|
13
|
-
}
|
|
14
16
|
/**
|
|
15
17
|
* 每列统计
|
|
16
18
|
* @param key
|
|
17
19
|
* @param dataList
|
|
18
20
|
* @param summaryFieldsResultToNumber 需要转换为数字的汇总字段
|
|
21
|
+
* @param formatter 精度格式化函数,由 stationv2 传入 AmountPrecisionUtil(precision_control)
|
|
22
|
+
* @param highPrecisionMapping 高精度字段映射,优先用高精度字段求和
|
|
19
23
|
* @returns {*|string}
|
|
20
24
|
*/
|
|
21
|
-
const sumCol = (
|
|
25
|
+
const sumCol = (
|
|
26
|
+
key,
|
|
27
|
+
dataList,
|
|
28
|
+
summaryFieldsResultToNumber = [],
|
|
29
|
+
formatter,
|
|
30
|
+
highPrecisionMapping
|
|
31
|
+
) => {
|
|
22
32
|
let result
|
|
23
33
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
// 优先使用高精度字段求和
|
|
35
|
+
const sumKey = getHighPrecisionField(key, highPrecisionMapping)
|
|
36
|
+
const sum = dataList.reduce((acc, item) => {
|
|
37
|
+
const val = item[sumKey] ?? item._origin?.[sumKey] ?? 0
|
|
38
|
+
acc = acc.plus(val)
|
|
39
|
+
return acc
|
|
40
|
+
}, Big(0))
|
|
41
|
+
result = formatSumWithPrecision(sum, formatter)
|
|
30
42
|
|
|
31
43
|
if (summaryFieldsResultToNumber.includes(key)) {
|
|
32
44
|
result = Number(result)
|
|
@@ -63,9 +75,16 @@ const PageSummary = props => {
|
|
|
63
75
|
printerStore.config?.summaryFieldsResultToNumber
|
|
64
76
|
if (summaryFieldsResultToNumber) {
|
|
65
77
|
summaryFieldsResultToNumber = summaryFieldsResultToNumber.map(item =>
|
|
66
|
-
|
|
78
|
+
extractSumField(item)
|
|
67
79
|
)
|
|
68
80
|
}
|
|
81
|
+
const formatter = printerStore.config?.payAmountFormatter
|
|
82
|
+
const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
|
|
83
|
+
|
|
84
|
+
const summaryKeys = summaryConfig.summaryColumns.map(text =>
|
|
85
|
+
extractSumField(text)
|
|
86
|
+
)
|
|
87
|
+
|
|
69
88
|
return (
|
|
70
89
|
<tr>
|
|
71
90
|
{_.map(columns, (col, index) => {
|
|
@@ -74,13 +93,19 @@ const PageSummary = props => {
|
|
|
74
93
|
if (index === 0) {
|
|
75
94
|
html = i18next.t('合计')
|
|
76
95
|
} else {
|
|
77
|
-
const key =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
const key = extractSumField(col.text)
|
|
97
|
+
if (key && summaryKeys.includes(key)) {
|
|
98
|
+
const sum = sumCol(
|
|
99
|
+
key,
|
|
100
|
+
currentPageTableData,
|
|
101
|
+
summaryFieldsResultToNumber,
|
|
102
|
+
formatter,
|
|
103
|
+
highPrecisionMapping
|
|
104
|
+
)
|
|
105
|
+
html = templateSumResult(col.text, sum, key)
|
|
106
|
+
} else {
|
|
107
|
+
html = ' '
|
|
108
|
+
}
|
|
84
109
|
}
|
|
85
110
|
|
|
86
111
|
return (
|
package/src/printer/printer.js
CHANGED
|
@@ -103,10 +103,10 @@ class Printer extends React.Component {
|
|
|
103
103
|
componentDidMount() {
|
|
104
104
|
const { printerStore, config, getremainpageHeight } = this.props
|
|
105
105
|
const batchPrintConfig = config.batchPrintConfig
|
|
106
|
-
//
|
|
107
|
-
printerStore.setReady(true)
|
|
108
|
-
// 连续打印不需要分页计算
|
|
106
|
+
// 连续打印不需要计算
|
|
109
107
|
if (batchPrintConfig !== 2) {
|
|
108
|
+
// didMount 代表第一次渲染完成
|
|
109
|
+
printerStore.setReady(true)
|
|
110
110
|
printerStore.computedPages()
|
|
111
111
|
if (config.autoFillConfig?.checked) {
|
|
112
112
|
this.props.printerStore.setAutofillConfig(
|
package/src/printer/store.js
CHANGED
|
@@ -5,17 +5,14 @@ import {
|
|
|
5
5
|
isMultiTable,
|
|
6
6
|
caclSingleDetailsPageHeight,
|
|
7
7
|
getArrayMid,
|
|
8
|
-
getOverallOrderTrHeight
|
|
8
|
+
getOverallOrderTrHeight,
|
|
9
|
+
price
|
|
9
10
|
} from '../util'
|
|
10
11
|
import _ from 'lodash'
|
|
11
12
|
import Big from 'big.js'
|
|
12
13
|
import { Tip } from '../components'
|
|
13
14
|
|
|
14
15
|
export const TR_BASE_HEIGHT = 23
|
|
15
|
-
const price = (n, f = 2) => {
|
|
16
|
-
if (isNaN(n)) return null
|
|
17
|
-
return Big(n || 0).toFixed(f)
|
|
18
|
-
}
|
|
19
16
|
class PrinterStore {
|
|
20
17
|
@observable ready = false
|
|
21
18
|
|
|
@@ -530,7 +527,7 @@ class PrinterStore {
|
|
|
530
527
|
})({
|
|
531
528
|
...this.data.common,
|
|
532
529
|
[i18next.t('当前页码')]: pageIndex + 1,
|
|
533
|
-
[i18next.t('页码总数')]:
|
|
530
|
+
[i18next.t('页码总数')]: this.pages.length,
|
|
534
531
|
price: price
|
|
535
532
|
})
|
|
536
533
|
} catch (err) {
|
|
@@ -604,7 +601,7 @@ class PrinterStore {
|
|
|
604
601
|
|
|
605
602
|
[i18next.t('列')]: list[index],
|
|
606
603
|
[i18next.t('当前页码')]: pageIndex + 1,
|
|
607
|
-
[i18next.t('页码总数')]:
|
|
604
|
+
[i18next.t('页码总数')]: this.pages.length,
|
|
608
605
|
price: price // 提供一个价格处理函数
|
|
609
606
|
})
|
|
610
607
|
} catch (err) {
|
|
@@ -626,7 +623,7 @@ class PrinterStore {
|
|
|
626
623
|
...this.data.common,
|
|
627
624
|
[i18next.t('列')]: list[index],
|
|
628
625
|
[i18next.t('当前页码')]: pageIndex + 1,
|
|
629
|
-
[i18next.t('页码总数')]:
|
|
626
|
+
[i18next.t('页码总数')]: this.pages.length,
|
|
630
627
|
price: price // 提供一个价格处理函数
|
|
631
628
|
})
|
|
632
629
|
res =
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import _ from 'lodash'
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
coverDigit2Uppercase,
|
|
6
|
+
getDataKey,
|
|
7
|
+
formatSumWithPrecision,
|
|
8
|
+
toSumColTemplate,
|
|
9
|
+
templateSumResult,
|
|
10
|
+
extractSumField
|
|
11
|
+
} from '../util'
|
|
6
12
|
import { observer } from 'mobx-react'
|
|
7
13
|
import classNames from 'classnames'
|
|
8
14
|
import Big from 'big.js'
|
|
@@ -15,20 +21,33 @@ const DiyOverallOrder = props => {
|
|
|
15
21
|
} = props
|
|
16
22
|
const tableData = printerStore.data._table[getDataKey(dataKey)] || []
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
const formatter = printerStore.config?.payAmountFormatter
|
|
25
|
+
const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
|
|
26
|
+
|
|
27
|
+
// 计算合计(逐行取原始列值,内置函数只作用在最终合计结果上)
|
|
19
28
|
const sumData = field => {
|
|
20
|
-
|
|
29
|
+
// 查找高精度字段,有则直接从原始数据取值,避免 templateTable 的精度损失
|
|
30
|
+
// 兼容映射 key 为模板串或字段名两种写法
|
|
31
|
+
const fieldKey = extractSumField(field)
|
|
32
|
+
const hpField =
|
|
33
|
+
highPrecisionMapping?.[field] || highPrecisionMapping?.[fieldKey]
|
|
34
|
+
const sum = _.reduce(
|
|
21
35
|
tableData,
|
|
22
36
|
(a, b, i) => {
|
|
23
37
|
let result = a
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
38
|
+
if (hpField) {
|
|
39
|
+
result = a.plus(b._origin?.[hpField] ?? b[hpField] ?? 0)
|
|
40
|
+
} else {
|
|
41
|
+
const bRes = printerStore
|
|
42
|
+
.templateTable(field, dataKey, i, pageIndex)
|
|
43
|
+
.replace(/\(\)/g, '')
|
|
44
|
+
result = a.plus(+bRes || 0)
|
|
45
|
+
}
|
|
28
46
|
return result
|
|
29
47
|
},
|
|
30
48
|
Big(0)
|
|
31
|
-
)
|
|
49
|
+
)
|
|
50
|
+
return formatSumWithPrecision(sum, formatter)
|
|
32
51
|
}
|
|
33
52
|
|
|
34
53
|
if (!diyOverallOrder?.show || !printerStore?.ready) {
|
|
@@ -45,10 +64,17 @@ const DiyOverallOrder = props => {
|
|
|
45
64
|
const isUpperCaseBefore = diyOverallOrder?.isUpperCaseBefore
|
|
46
65
|
// 大写金额
|
|
47
66
|
const needUpperCase = diyOverallOrder?.needUpperCase
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
const fieldKey = extractSumField(leftField.valueField)
|
|
68
|
+
// 求和用去掉内置函数后的列模板
|
|
69
|
+
const numericValue = sumData(toSumColTemplate(leftField.valueField))
|
|
70
|
+
// 仅对合计结果做模板/内置函数渲染
|
|
71
|
+
const displayValue = templateSumResult(
|
|
72
|
+
leftField.valueField,
|
|
73
|
+
numericValue,
|
|
74
|
+
fieldKey
|
|
75
|
+
)
|
|
50
76
|
// 大写金额
|
|
51
|
-
const upperCaseValue = needUpperCase ? coverDigit2Uppercase(
|
|
77
|
+
const upperCaseValue = needUpperCase ? coverDigit2Uppercase(displayValue) : ''
|
|
52
78
|
|
|
53
79
|
const leftText = () => {
|
|
54
80
|
if (isUpperLowerCaseSeparate) {
|
|
@@ -57,25 +83,25 @@ const DiyOverallOrder = props => {
|
|
|
57
83
|
return upperCaseValue
|
|
58
84
|
}
|
|
59
85
|
// 小写金额在前
|
|
60
|
-
return
|
|
86
|
+
return displayValue
|
|
61
87
|
}
|
|
62
88
|
|
|
63
89
|
// 大写金额在前且需要大写金额
|
|
64
90
|
if (isUpperCaseBefore) {
|
|
65
|
-
return `${upperCaseValue} ${
|
|
91
|
+
return `${upperCaseValue} ${displayValue}`
|
|
66
92
|
}
|
|
67
93
|
|
|
68
94
|
if (needUpperCase) {
|
|
69
|
-
return `${
|
|
95
|
+
return `${displayValue} ${upperCaseValue}`
|
|
70
96
|
}
|
|
71
97
|
|
|
72
|
-
return
|
|
98
|
+
return displayValue
|
|
73
99
|
}
|
|
74
100
|
|
|
75
101
|
const rightText = () => {
|
|
76
102
|
if (isUpperLowerCaseSeparate) {
|
|
77
103
|
if (isUpperCaseBefore) {
|
|
78
|
-
return `${rightName} ${
|
|
104
|
+
return `${rightName} ${displayValue}`
|
|
79
105
|
}
|
|
80
106
|
return `${rightName} ${upperCaseValue}`
|
|
81
107
|
}
|
|
@@ -102,47 +128,6 @@ const DiyOverallOrder = props => {
|
|
|
102
128
|
</td>
|
|
103
129
|
</tr>
|
|
104
130
|
)
|
|
105
|
-
// return (
|
|
106
|
-
// diyOverallOrder?.show &&
|
|
107
|
-
// printerStore?.ready && (
|
|
108
|
-
// <tr>
|
|
109
|
-
// {_.map(diyOverallOrder.fields, (item, index) => {
|
|
110
|
-
// return (
|
|
111
|
-
// <td colSpan={item.colSpan ?? 99} key={index}>
|
|
112
|
-
// <div style={{ ...item.style }} className='gm-flex-page'>
|
|
113
|
-
// {item.name}
|
|
114
|
-
// <div
|
|
115
|
-
// className={classNames('gm-flex-page', {
|
|
116
|
-
// 'gm-flex-justify-between-page':
|
|
117
|
-
// diyOverallOrder?.isUpperLowerCaseSeparate,
|
|
118
|
-
// 'gm-flex-grow-page':
|
|
119
|
-
// diyOverallOrder?.isUpperLowerCaseSeparate
|
|
120
|
-
// })}
|
|
121
|
-
// >
|
|
122
|
-
// <span
|
|
123
|
-
// className={
|
|
124
|
-
// diyOverallOrder?.isUpperCaseBefore
|
|
125
|
-
// ? 'gm-printer-subtotal-isUpperCaseBefore-inter'
|
|
126
|
-
// : ''
|
|
127
|
-
// }
|
|
128
|
-
// >
|
|
129
|
-
// {sumData(item.valueField)}
|
|
130
|
-
// </span>
|
|
131
|
-
// {diyOverallOrder?.needUpperCase && (
|
|
132
|
-
// <span>
|
|
133
|
-
// {coverDigit2Uppercase(sumData(item.valueField))
|
|
134
|
-
// ? coverDigit2Uppercase(sumData(item.valueField))
|
|
135
|
-
// : ''}
|
|
136
|
-
// </span>
|
|
137
|
-
// )}
|
|
138
|
-
// </div>
|
|
139
|
-
// </div>
|
|
140
|
-
// </td>
|
|
141
|
-
// )
|
|
142
|
-
// })}
|
|
143
|
-
// </tr>
|
|
144
|
-
// )
|
|
145
|
-
// )
|
|
146
131
|
}
|
|
147
132
|
DiyOverallOrder.propTypes = {
|
|
148
133
|
config: PropTypes.object.isRequired,
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import _ from 'lodash'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
coverDigit2Uppercase,
|
|
6
|
+
getDataKey,
|
|
7
|
+
isMultiTable,
|
|
8
|
+
formatSumWithPrecision,
|
|
9
|
+
toSumColTemplate,
|
|
10
|
+
templateSumResult,
|
|
11
|
+
extractSumField
|
|
12
|
+
} from '../util'
|
|
5
13
|
import { MULTI_SUFFIX, MULTI_SUFFIX3 } from '../config'
|
|
6
14
|
import { observer } from 'mobx-react'
|
|
7
15
|
import classNames from 'classnames'
|
|
@@ -43,14 +51,23 @@ const DiySummary = props => {
|
|
|
43
51
|
// 判断是否是多栏表格
|
|
44
52
|
const isMulti = isMultiTable(dataKey)
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+
const formatter = printerStore.config?.payAmountFormatter
|
|
55
|
+
const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
|
|
56
|
+
|
|
57
|
+
// 计算合计(逐行取原始列值,内置函数只作用在最终合计结果上)
|
|
47
58
|
const sumData = field => {
|
|
59
|
+
// 查找高精度字段,有则直接从原始数据取值,避免 templateTable 的精度损失
|
|
60
|
+
// 兼容映射 key 为模板串或字段名两种写法
|
|
61
|
+
const fieldKey = extractSumField(field)
|
|
62
|
+
const hpField =
|
|
63
|
+
highPrecisionMapping?.[field] || highPrecisionMapping?.[fieldKey]
|
|
64
|
+
|
|
48
65
|
if (isMulti) {
|
|
49
|
-
|
|
66
|
+
// 多栏表格暂不使用高精度字段,保持原有 templateTable 逻辑
|
|
67
|
+
const sum = _.reduce(
|
|
50
68
|
tableData,
|
|
51
69
|
(a, b, i) => {
|
|
52
70
|
let result = a
|
|
53
|
-
// 先通过 templateTable 获取原始字段的值
|
|
54
71
|
const bRes = getRes(field, i)
|
|
55
72
|
result = a.plus(+bRes || 0)
|
|
56
73
|
|
|
@@ -65,10 +82,24 @@ const DiySummary = props => {
|
|
|
65
82
|
return result
|
|
66
83
|
},
|
|
67
84
|
Big(0)
|
|
68
|
-
)
|
|
85
|
+
)
|
|
86
|
+
return formatSumWithPrecision(sum, formatter)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 单栏:有高精度字段则直接从原始数据取值
|
|
90
|
+
if (hpField) {
|
|
91
|
+
const sum = _.reduce(
|
|
92
|
+
tableData,
|
|
93
|
+
(a, b) => {
|
|
94
|
+
return a.plus(b._origin?.[hpField] ?? b[hpField] ?? 0)
|
|
95
|
+
},
|
|
96
|
+
Big(0)
|
|
97
|
+
)
|
|
98
|
+
return formatSumWithPrecision(sum, formatter)
|
|
69
99
|
}
|
|
70
100
|
|
|
71
|
-
|
|
101
|
+
// 兜底:无高精度字段,使用 templateTable
|
|
102
|
+
const sum = _.reduce(
|
|
72
103
|
tableData,
|
|
73
104
|
(a, b, i) => {
|
|
74
105
|
let result = a
|
|
@@ -77,7 +108,8 @@ const DiySummary = props => {
|
|
|
77
108
|
return result
|
|
78
109
|
},
|
|
79
110
|
Big(0)
|
|
80
|
-
)
|
|
111
|
+
)
|
|
112
|
+
return formatSumWithPrecision(sum, formatter)
|
|
81
113
|
|
|
82
114
|
function getRes(field, i) {
|
|
83
115
|
return printerStore
|
|
@@ -99,8 +131,16 @@ const DiySummary = props => {
|
|
|
99
131
|
const isUpperLowerCaseSeparate = diyConfig?.isUpperLowerCaseSeparate
|
|
100
132
|
const isUpperCaseBefore = diyConfig?.isUpperCaseBefore
|
|
101
133
|
const needUpperCase = diyConfig?.needUpperCase
|
|
102
|
-
const
|
|
103
|
-
|
|
134
|
+
const fieldKey = extractSumField(leftField.valueField)
|
|
135
|
+
// 求和用去掉内置函数后的列模板,多栏/高精度逻辑保持不变
|
|
136
|
+
const numericValue = sumData(toSumColTemplate(leftField.valueField))
|
|
137
|
+
// 仅对合计结果做模板/内置函数渲染
|
|
138
|
+
const displayValue = templateSumResult(
|
|
139
|
+
leftField.valueField,
|
|
140
|
+
numericValue,
|
|
141
|
+
fieldKey
|
|
142
|
+
)
|
|
143
|
+
const upperCaseValue = needUpperCase ? coverDigit2Uppercase(displayValue) : ''
|
|
104
144
|
|
|
105
145
|
const leftText = () => {
|
|
106
146
|
if (isUpperLowerCaseSeparate) {
|
|
@@ -109,25 +149,25 @@ const DiySummary = props => {
|
|
|
109
149
|
return upperCaseValue
|
|
110
150
|
}
|
|
111
151
|
// 小写金额在前
|
|
112
|
-
return
|
|
152
|
+
return displayValue
|
|
113
153
|
}
|
|
114
154
|
|
|
115
155
|
// 大写金额在前且需要大写金额
|
|
116
156
|
if (isUpperCaseBefore) {
|
|
117
|
-
return `${upperCaseValue} ${
|
|
157
|
+
return `${upperCaseValue} ${displayValue}`
|
|
118
158
|
}
|
|
119
159
|
|
|
120
160
|
if (needUpperCase) {
|
|
121
|
-
return `${
|
|
161
|
+
return `${displayValue} ${upperCaseValue}`
|
|
122
162
|
}
|
|
123
163
|
|
|
124
|
-
return
|
|
164
|
+
return displayValue
|
|
125
165
|
}
|
|
126
166
|
|
|
127
167
|
const rightText = () => {
|
|
128
168
|
if (isUpperLowerCaseSeparate) {
|
|
129
169
|
if (isUpperCaseBefore) {
|
|
130
|
-
return `${rightName} ${
|
|
170
|
+
return `${rightName} ${displayValue}`
|
|
131
171
|
}
|
|
132
172
|
return `${rightName} ${upperCaseValue}`
|
|
133
173
|
}
|