gm-printer 11.0.0 → 11.0.2-beta.0
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 +37 -2
- package/src/common/editor_title.js +10 -4
- package/src/editor/context_menu_config.js +335 -0
- package/src/editor/editor_menu_config.js +140 -0
- package/src/editor/index.js +2 -0
- package/src/editor_settle/editor.js +2 -1
- package/src/examining_report_editor/context_menu.js +94 -0
- package/src/examining_report_editor/editor.js +85 -0
- package/src/examining_report_editor/index.js +4 -0
- package/src/examining_report_editor/store.js +74 -0
- package/src/index.js +5 -1
- package/src/printer/page_summary.js +9 -32
- package/src/printer/printer.js +3 -3
- package/src/printer/store.js +6 -5
- package/src/printer/table_diy_overallOrder_tr.js +7 -21
- package/src/printer/table_diy_summary_tr.js +6 -32
- package/src/printer/table_subtotal_tr.js +34 -42
- package/src/util.js +1 -24
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import _ from 'lodash'
|
|
4
|
+
import { Flex } from '../components'
|
|
5
|
+
import { Gap, Title } from '../common/component'
|
|
6
|
+
import editStore from './store'
|
|
7
|
+
import { observer, inject } from 'mobx-react'
|
|
8
|
+
import EditorTitle from '../common/editor_title'
|
|
9
|
+
import EditorSelect from '../common/editor_select'
|
|
10
|
+
import EditorField from '../common/editor_edit_field'
|
|
11
|
+
import EditorAddField from '../common/editor_add_field'
|
|
12
|
+
import ContextMenu from './context_menu'
|
|
13
|
+
import i18next from '../../locales'
|
|
14
|
+
import withStore from '../common/hoc_with_store'
|
|
15
|
+
|
|
16
|
+
const tableDataKeyList = [
|
|
17
|
+
{
|
|
18
|
+
value: 'examiningDetail',
|
|
19
|
+
text: i18next.t('检测明细'),
|
|
20
|
+
hasSubtotalBtn: true
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
@withStore(editStore)
|
|
25
|
+
@inject('editStore')
|
|
26
|
+
@observer
|
|
27
|
+
class Editor extends React.Component {
|
|
28
|
+
render() {
|
|
29
|
+
const { onSave, showEditor, addFields, menuConfig } = this.props
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className='gm-printer-edit'>
|
|
33
|
+
<Flex className='gm-printer-edit-title-fixed'>
|
|
34
|
+
<Title
|
|
35
|
+
title={i18next.t('模板预览')}
|
|
36
|
+
text={
|
|
37
|
+
<span className='gm-text-desc gm-padding-left-5'>
|
|
38
|
+
{i18next.t(
|
|
39
|
+
'说明:选中内容进行编辑,可拖动字段移动位置,右键使用更多功能'
|
|
40
|
+
)}
|
|
41
|
+
</span>
|
|
42
|
+
}
|
|
43
|
+
/>
|
|
44
|
+
</Flex>
|
|
45
|
+
|
|
46
|
+
{showEditor && (
|
|
47
|
+
<div className='gm-printer-edit-zone'>
|
|
48
|
+
<EditorTitle onSave={onSave} />
|
|
49
|
+
<Gap height='10px' />
|
|
50
|
+
<EditorSelect />
|
|
51
|
+
<Gap height='5px' />
|
|
52
|
+
<EditorField tableDataKeyList={tableDataKeyList} />
|
|
53
|
+
<Gap height='5px' />
|
|
54
|
+
<EditorAddField addFields={addFields} />
|
|
55
|
+
|
|
56
|
+
<div id='gm-printer-tip' />
|
|
57
|
+
<div id='gm-printer-modal' />
|
|
58
|
+
</div>
|
|
59
|
+
)}
|
|
60
|
+
|
|
61
|
+
<div className='gm-printer-edit-wrap'>
|
|
62
|
+
<ContextMenu menuConfig={menuConfig} />
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Editor.propTypes = {
|
|
70
|
+
config: PropTypes.object.isRequired,
|
|
71
|
+
onSave: PropTypes.func,
|
|
72
|
+
showEditor: PropTypes.bool,
|
|
73
|
+
mockData: PropTypes.object.isRequired,
|
|
74
|
+
addFields: PropTypes.object.isRequired,
|
|
75
|
+
menuConfig: PropTypes.oneOfType([
|
|
76
|
+
PropTypes.arrayOf(PropTypes.string),
|
|
77
|
+
PropTypes.object
|
|
78
|
+
])
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Editor.defaultProps = {
|
|
82
|
+
onSave: _.noop
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default Editor
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import EditorStore from '../common/editor_store'
|
|
2
|
+
import { action, toJS } from 'mobx'
|
|
3
|
+
import i18next from '../../locales'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_TABLE_COLUMNS = [
|
|
6
|
+
{
|
|
7
|
+
head: i18next.t('序号'),
|
|
8
|
+
text: i18next.t('{{列.序号}}'),
|
|
9
|
+
style: { textAlign: 'center' },
|
|
10
|
+
headStyle: { textAlign: 'center' }
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
head: i18next.t('样品名称'),
|
|
14
|
+
text: i18next.t('{{列.样品名称}}'),
|
|
15
|
+
style: { textAlign: 'center' },
|
|
16
|
+
headStyle: { textAlign: 'center' }
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
head: i18next.t('样品编码'),
|
|
20
|
+
text: i18next.t('{{列.样品编码}}'),
|
|
21
|
+
style: { textAlign: 'center' },
|
|
22
|
+
headStyle: { textAlign: 'center' }
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
head: i18next.t('检测结果'),
|
|
26
|
+
text: i18next.t('{{列.检测结果}}'),
|
|
27
|
+
style: { textAlign: 'center' },
|
|
28
|
+
headStyle: { textAlign: 'center' }
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
class Store extends EditorStore {
|
|
33
|
+
constructor({ defaultTableDataKey }) {
|
|
34
|
+
super()
|
|
35
|
+
this.defaultTableDataKey = defaultTableDataKey
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getDefaultTableConfig() {
|
|
39
|
+
return {
|
|
40
|
+
dataKey: this.defaultTableDataKey,
|
|
41
|
+
subtotal: { show: false },
|
|
42
|
+
columns: DEFAULT_TABLE_COLUMNS
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@action
|
|
47
|
+
init(config, data) {
|
|
48
|
+
super.init(config, data)
|
|
49
|
+
this.defaultTableDataKey = 'examiningDetail'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@action.bound
|
|
53
|
+
addContent(name, index, type, tableConfig = null) {
|
|
54
|
+
if (type === 'table' && !tableConfig) {
|
|
55
|
+
tableConfig = this.getDefaultTableConfig()
|
|
56
|
+
}
|
|
57
|
+
super.addContent(name, index, type, tableConfig)
|
|
58
|
+
this.config = toJS(this.config)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@action
|
|
62
|
+
changeTableDataKey(name, key, options = {}) {
|
|
63
|
+
super.changeTableDataKey(name, key, options)
|
|
64
|
+
this.config = toJS(this.config)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@action
|
|
68
|
+
removeContent(name) {
|
|
69
|
+
super.removeContent(name)
|
|
70
|
+
this.config = toJS(this.config)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default new Store({ defaultTableDataKey: 'examiningDetail' })
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// ‼️优先初始化语言设置(必须先初始化语言)
|
|
2
2
|
import '../locales'
|
|
3
|
-
import Editor from './editor'
|
|
3
|
+
import Editor, { Editor2 } from './editor'
|
|
4
|
+
|
|
4
5
|
import EditorPurchase from './editor_purchase'
|
|
6
|
+
import examiningReportEditor from './examining_report_editor'
|
|
5
7
|
import EditorStockIn from './editor_stockin'
|
|
6
8
|
import EditorStockOut from './editor_stockout'
|
|
7
9
|
import EditorSettle from './editor_settle'
|
|
@@ -27,9 +29,11 @@ export { setLocale } from '../locales'
|
|
|
27
29
|
|
|
28
30
|
export {
|
|
29
31
|
Editor,
|
|
32
|
+
Editor2,
|
|
30
33
|
EditorStockIn,
|
|
31
34
|
EditorStockOut,
|
|
32
35
|
EditorPurchase,
|
|
36
|
+
examiningReportEditor,
|
|
33
37
|
EditorSettle,
|
|
34
38
|
EditorStatement,
|
|
35
39
|
EditorAccoutStatement,
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import _ from 'lodash'
|
|
3
|
-
import {
|
|
4
|
-
getDataKey,
|
|
5
|
-
isMultiTable,
|
|
6
|
-
formatSumWithPrecision,
|
|
7
|
-
getHighPrecisionField
|
|
8
|
-
} from '../util'
|
|
3
|
+
import { getDataKey, isMultiTable } from '../util'
|
|
9
4
|
import Big from 'big.js'
|
|
10
5
|
import { observer } from 'mobx-react'
|
|
11
6
|
import { get } from 'mobx'
|
|
@@ -21,27 +16,17 @@ const regExp = text => {
|
|
|
21
16
|
* @param key
|
|
22
17
|
* @param dataList
|
|
23
18
|
* @param summaryFieldsResultToNumber 需要转换为数字的汇总字段
|
|
24
|
-
* @param formatter 精度格式化函数,由 stationv2 传入 AmountPrecisionUtil(precision_control)
|
|
25
|
-
* @param highPrecisionMapping 高精度字段映射,优先用高精度字段求和
|
|
26
19
|
* @returns {*|string}
|
|
27
20
|
*/
|
|
28
|
-
const sumCol = (
|
|
29
|
-
key,
|
|
30
|
-
dataList,
|
|
31
|
-
summaryFieldsResultToNumber = [],
|
|
32
|
-
formatter,
|
|
33
|
-
highPrecisionMapping
|
|
34
|
-
) => {
|
|
21
|
+
const sumCol = (key, dataList, summaryFieldsResultToNumber = []) => {
|
|
35
22
|
let result
|
|
36
23
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}, Big(0))
|
|
44
|
-
result = formatSumWithPrecision(sum, formatter)
|
|
24
|
+
result = dataList
|
|
25
|
+
.reduce((acc, item) => {
|
|
26
|
+
acc = acc.plus(item[key] || 0)
|
|
27
|
+
return acc
|
|
28
|
+
}, Big(0))
|
|
29
|
+
.toFixed(2)
|
|
45
30
|
|
|
46
31
|
if (summaryFieldsResultToNumber.includes(key)) {
|
|
47
32
|
result = Number(result)
|
|
@@ -81,8 +66,6 @@ const PageSummary = props => {
|
|
|
81
66
|
regExp(item)
|
|
82
67
|
)
|
|
83
68
|
}
|
|
84
|
-
const formatter = printerStore.config?.payAmountFormatter
|
|
85
|
-
const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
|
|
86
69
|
return (
|
|
87
70
|
<tr>
|
|
88
71
|
{_.map(columns, (col, index) => {
|
|
@@ -96,13 +79,7 @@ const PageSummary = props => {
|
|
|
96
79
|
summaryConfig.summaryColumns
|
|
97
80
|
.map(text => regExp(text))
|
|
98
81
|
.includes(key) && key
|
|
99
|
-
? sumCol(
|
|
100
|
-
key,
|
|
101
|
-
currentPageTableData,
|
|
102
|
-
summaryFieldsResultToNumber,
|
|
103
|
-
formatter,
|
|
104
|
-
highPrecisionMapping
|
|
105
|
-
)
|
|
82
|
+
? sumCol(key, currentPageTableData, summaryFieldsResultToNumber)
|
|
106
83
|
: ' '
|
|
107
84
|
}
|
|
108
85
|
|
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
|
-
//
|
|
106
|
+
// didMount 代表第一次渲染完成
|
|
107
|
+
printerStore.setReady(true)
|
|
108
|
+
// 连续打印不需要分页计算
|
|
107
109
|
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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import i18next from '../../locales'
|
|
2
|
-
import { action, observable, computed
|
|
2
|
+
import { action, observable, computed } from 'mobx'
|
|
3
3
|
import {
|
|
4
4
|
getSumTrHeight,
|
|
5
5
|
isMultiTable,
|
|
@@ -530,7 +530,7 @@ class PrinterStore {
|
|
|
530
530
|
})({
|
|
531
531
|
...this.data.common,
|
|
532
532
|
[i18next.t('当前页码')]: pageIndex + 1,
|
|
533
|
-
[i18next.t('页码总数')]: this.pages.length,
|
|
533
|
+
[i18next.t('页码总数')]: Math.max(1, this.pages.length),
|
|
534
534
|
price: price
|
|
535
535
|
})
|
|
536
536
|
} catch (err) {
|
|
@@ -552,7 +552,8 @@ class PrinterStore {
|
|
|
552
552
|
dataKey !== 'purchase_detail_one_row' &&
|
|
553
553
|
dataKey !== 'purchase_independent_rol_sku' &&
|
|
554
554
|
dataKey !== 'purchase_independent_rol_address' &&
|
|
555
|
-
dataKey !== 'taxRateSales'
|
|
555
|
+
dataKey !== 'taxRateSales' &&
|
|
556
|
+
dataKey !== 'ordinary'
|
|
556
557
|
) {
|
|
557
558
|
return null
|
|
558
559
|
}
|
|
@@ -604,7 +605,7 @@ class PrinterStore {
|
|
|
604
605
|
|
|
605
606
|
[i18next.t('列')]: list[index],
|
|
606
607
|
[i18next.t('当前页码')]: pageIndex + 1,
|
|
607
|
-
[i18next.t('页码总数')]: this.pages.length,
|
|
608
|
+
[i18next.t('页码总数')]: Math.max(1, this.pages.length),
|
|
608
609
|
price: price // 提供一个价格处理函数
|
|
609
610
|
})
|
|
610
611
|
} catch (err) {
|
|
@@ -626,7 +627,7 @@ class PrinterStore {
|
|
|
626
627
|
...this.data.common,
|
|
627
628
|
[i18next.t('列')]: list[index],
|
|
628
629
|
[i18next.t('当前页码')]: pageIndex + 1,
|
|
629
|
-
[i18next.t('页码总数')]: this.pages.length,
|
|
630
|
+
[i18next.t('页码总数')]: Math.max(1, this.pages.length),
|
|
630
631
|
price: price // 提供一个价格处理函数
|
|
631
632
|
})
|
|
632
633
|
res =
|
|
@@ -2,11 +2,7 @@ import React from 'react'
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import _ from 'lodash'
|
|
4
4
|
// import Big from 'big.js'
|
|
5
|
-
import {
|
|
6
|
-
coverDigit2Uppercase,
|
|
7
|
-
getDataKey,
|
|
8
|
-
formatSumWithPrecision
|
|
9
|
-
} from '../util'
|
|
5
|
+
import { coverDigit2Uppercase, getDataKey } from '../util'
|
|
10
6
|
import { observer } from 'mobx-react'
|
|
11
7
|
import classNames from 'classnames'
|
|
12
8
|
import Big from 'big.js'
|
|
@@ -19,30 +15,20 @@ const DiyOverallOrder = props => {
|
|
|
19
15
|
} = props
|
|
20
16
|
const tableData = printerStore.data._table[getDataKey(dataKey)] || []
|
|
21
17
|
|
|
22
|
-
const formatter = printerStore.config?.payAmountFormatter
|
|
23
|
-
const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
|
|
24
|
-
|
|
25
18
|
// 计算合计
|
|
26
19
|
const sumData = field => {
|
|
27
|
-
|
|
28
|
-
const hpField = highPrecisionMapping?.[field]
|
|
29
|
-
const sum = _.reduce(
|
|
20
|
+
return _.reduce(
|
|
30
21
|
tableData,
|
|
31
22
|
(a, b, i) => {
|
|
32
23
|
let result = a
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.templateTable(field, dataKey, i, pageIndex)
|
|
38
|
-
.replace(/\(\)/g, '')
|
|
39
|
-
result = a.plus(+bRes || 0)
|
|
40
|
-
}
|
|
24
|
+
const bRes = printerStore
|
|
25
|
+
.templateTable(field, dataKey, i, pageIndex)
|
|
26
|
+
.replace(/\(\)/g, '')
|
|
27
|
+
result = a.plus(+bRes || 0)
|
|
41
28
|
return result
|
|
42
29
|
},
|
|
43
30
|
Big(0)
|
|
44
|
-
)
|
|
45
|
-
return formatSumWithPrecision(sum, formatter)
|
|
31
|
+
).toFixed(2)
|
|
46
32
|
}
|
|
47
33
|
|
|
48
34
|
if (!diyOverallOrder?.show || !printerStore?.ready) {
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import _ from 'lodash'
|
|
4
|
-
import {
|
|
5
|
-
coverDigit2Uppercase,
|
|
6
|
-
getDataKey,
|
|
7
|
-
isMultiTable,
|
|
8
|
-
formatSumWithPrecision
|
|
9
|
-
} from '../util'
|
|
4
|
+
import { coverDigit2Uppercase, getDataKey, isMultiTable } from '../util'
|
|
10
5
|
import { MULTI_SUFFIX, MULTI_SUFFIX3 } from '../config'
|
|
11
6
|
import { observer } from 'mobx-react'
|
|
12
7
|
import classNames from 'classnames'
|
|
@@ -48,20 +43,14 @@ const DiySummary = props => {
|
|
|
48
43
|
// 判断是否是多栏表格
|
|
49
44
|
const isMulti = isMultiTable(dataKey)
|
|
50
45
|
|
|
51
|
-
const formatter = printerStore.config?.payAmountFormatter
|
|
52
|
-
const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
|
|
53
|
-
|
|
54
46
|
// 计算合计
|
|
55
47
|
const sumData = field => {
|
|
56
|
-
// 查找高精度字段,有则直接从原始数据取值,避免 templateTable 的精度损失
|
|
57
|
-
const hpField = highPrecisionMapping?.[field]
|
|
58
|
-
|
|
59
48
|
if (isMulti) {
|
|
60
|
-
|
|
61
|
-
const sum = _.reduce(
|
|
49
|
+
return _.reduce(
|
|
62
50
|
tableData,
|
|
63
51
|
(a, b, i) => {
|
|
64
52
|
let result = a
|
|
53
|
+
// 先通过 templateTable 获取原始字段的值
|
|
65
54
|
const bRes = getRes(field, i)
|
|
66
55
|
result = a.plus(+bRes || 0)
|
|
67
56
|
|
|
@@ -76,24 +65,10 @@ const DiySummary = props => {
|
|
|
76
65
|
return result
|
|
77
66
|
},
|
|
78
67
|
Big(0)
|
|
79
|
-
)
|
|
80
|
-
return formatSumWithPrecision(sum, formatter)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 单栏:有高精度字段则直接从原始数据取值
|
|
84
|
-
if (hpField) {
|
|
85
|
-
const sum = _.reduce(
|
|
86
|
-
tableData,
|
|
87
|
-
(a, b, i) => {
|
|
88
|
-
return a.plus(b._origin?.[hpField] ?? b[hpField] ?? 0)
|
|
89
|
-
},
|
|
90
|
-
Big(0)
|
|
91
|
-
)
|
|
92
|
-
return formatSumWithPrecision(sum, formatter)
|
|
68
|
+
).toFixed(2)
|
|
93
69
|
}
|
|
94
70
|
|
|
95
|
-
|
|
96
|
-
const sum = _.reduce(
|
|
71
|
+
return _.reduce(
|
|
97
72
|
tableData,
|
|
98
73
|
(a, b, i) => {
|
|
99
74
|
let result = a
|
|
@@ -102,8 +77,7 @@ const DiySummary = props => {
|
|
|
102
77
|
return result
|
|
103
78
|
},
|
|
104
79
|
Big(0)
|
|
105
|
-
)
|
|
106
|
-
return formatSumWithPrecision(sum, formatter)
|
|
80
|
+
).toFixed(2)
|
|
107
81
|
|
|
108
82
|
function getRes(field, i) {
|
|
109
83
|
return printerStore
|
|
@@ -4,11 +4,7 @@ import PropTypes from 'prop-types'
|
|
|
4
4
|
import _ from 'lodash'
|
|
5
5
|
import { MULTI_SUFFIX, MULTI_SUFFIX3 } from '../config'
|
|
6
6
|
import Big from 'big.js'
|
|
7
|
-
import {
|
|
8
|
-
coverDigit2Uppercase,
|
|
9
|
-
getDataKey,
|
|
10
|
-
formatSumWithPrecision
|
|
11
|
-
} from '../util'
|
|
7
|
+
import { coverDigit2Uppercase, getDataKey } from '../util'
|
|
12
8
|
import { observer } from 'mobx-react'
|
|
13
9
|
import { get } from 'mobx'
|
|
14
10
|
import classNames from 'classnames'
|
|
@@ -49,47 +45,58 @@ const SubtotalTr = props => {
|
|
|
49
45
|
isSomeSubtotalTr
|
|
50
46
|
} = props
|
|
51
47
|
const tableData = printerStore.data._table[getDataKey(dataKey, arrange)] || []
|
|
52
|
-
|
|
53
48
|
// 计算合计
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
const sumData = (list, field) => {
|
|
50
|
+
return _.reduce(
|
|
51
|
+
list,
|
|
52
|
+
(a, b) => {
|
|
53
|
+
let result = a
|
|
54
|
+
|
|
55
|
+
const _origin = b._origin || {}
|
|
56
|
+
const _origin2 = b['_origin' + MULTI_SUFFIX] || {}
|
|
57
|
+
const _origin3 = b['_origin' + MULTI_SUFFIX3] || {}
|
|
58
|
+
|
|
59
|
+
result = a.plus(_origin[field] || 0)
|
|
60
|
+
if (_origin2[field]) {
|
|
61
|
+
result = result.plus(_origin2[field])
|
|
62
|
+
}
|
|
63
|
+
if (_origin3[field]) {
|
|
64
|
+
result = result.plus(_origin3[field])
|
|
65
|
+
}
|
|
66
|
+
return result
|
|
67
|
+
},
|
|
68
|
+
Big(0)
|
|
69
|
+
).toFixed(2)
|
|
70
|
+
}
|
|
57
71
|
|
|
72
|
+
// 计算合计
|
|
73
|
+
const sumData2 = (list, field) => {
|
|
58
74
|
// 兼容之前
|
|
59
75
|
if (field === 'total_item_price') field = '下单金额'
|
|
60
76
|
if (field === 'real_item_price') field = '出库金额'
|
|
61
77
|
if (field === 'settle_money2') field = '结算金额'
|
|
62
78
|
if (field === 'total_money2') field = '金额'
|
|
63
|
-
|
|
64
|
-
const sum = _.reduce(
|
|
79
|
+
return _.reduce(
|
|
65
80
|
list,
|
|
66
81
|
(a, b) => {
|
|
67
82
|
let result = a
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
result = a.plus(b._origin?.[hpField] ?? b[hpField] ?? 0)
|
|
71
|
-
} else {
|
|
72
|
-
result = a.plus(b[field] || 0)
|
|
73
|
-
}
|
|
74
|
-
if (!hpField && b?.[field + MULTI_SUFFIX]) {
|
|
83
|
+
result = a.plus(b[field] || 0)
|
|
84
|
+
if (b?.[field + MULTI_SUFFIX]) {
|
|
75
85
|
result = result.plus(b?.[field + MULTI_SUFFIX])
|
|
76
86
|
}
|
|
77
|
-
if (
|
|
87
|
+
if (b?.[field + MULTI_SUFFIX3]) {
|
|
78
88
|
result = result.plus(b?.[field + MULTI_SUFFIX3])
|
|
79
89
|
}
|
|
80
90
|
return result
|
|
81
91
|
},
|
|
82
92
|
Big(0)
|
|
83
|
-
)
|
|
84
|
-
return formatSumWithPrecision(sum, formatter)
|
|
93
|
+
).toFixed(2)
|
|
85
94
|
}
|
|
86
95
|
|
|
87
96
|
const getData = field => {
|
|
88
97
|
const data = printerStore.data.common
|
|
89
98
|
return data?.[field] ?? ''
|
|
90
99
|
}
|
|
91
|
-
const formatter = printerStore.config?.payAmountFormatter
|
|
92
|
-
const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
|
|
93
100
|
// 每页小计
|
|
94
101
|
// show 是否展示小计,fields<Array> 合计的字段和展现的name,displayName 是否显示名字
|
|
95
102
|
if (show && printerStore.ready) {
|
|
@@ -100,12 +107,7 @@ const SubtotalTr = props => {
|
|
|
100
107
|
const sum = {}
|
|
101
108
|
|
|
102
109
|
_.each(fields, v => {
|
|
103
|
-
sum[v.name] = sumData2(
|
|
104
|
-
list,
|
|
105
|
-
v.valueField,
|
|
106
|
-
formatter,
|
|
107
|
-
highPrecisionMapping
|
|
108
|
-
)
|
|
110
|
+
sum[v.name] = sumData2(list, v.valueField)
|
|
109
111
|
})
|
|
110
112
|
let subtotalStr = ''
|
|
111
113
|
for (const name in sum) {
|
|
@@ -163,14 +165,9 @@ const SubtotalTr = props => {
|
|
|
163
165
|
{item.type === 'useSummarize'
|
|
164
166
|
? getData(item.valueField)
|
|
165
167
|
: index === 0
|
|
166
|
-
? sumData2(
|
|
167
|
-
list,
|
|
168
|
-
item.valueField,
|
|
169
|
-
formatter,
|
|
170
|
-
highPrecisionMapping
|
|
171
|
-
)
|
|
168
|
+
? sumData2(list, item.valueField)
|
|
172
169
|
: ''}
|
|
173
|
-
{/* {index === 0 ? sumData(list, item.valueField
|
|
170
|
+
{/* {index === 0 ? sumData(list, item.valueField) : ''} */}
|
|
174
171
|
</span>
|
|
175
172
|
{subtotal?.needUpperCase && ( // 是否需要大写金额
|
|
176
173
|
<span>
|
|
@@ -180,12 +177,7 @@ const SubtotalTr = props => {
|
|
|
180
177
|
: index === 0
|
|
181
178
|
? '大写:' +
|
|
182
179
|
coverDigit2Uppercase(
|
|
183
|
-
sumData2(
|
|
184
|
-
list,
|
|
185
|
-
item.valueField,
|
|
186
|
-
formatter,
|
|
187
|
-
highPrecisionMapping
|
|
188
|
-
)
|
|
180
|
+
sumData2(list, item.valueField)
|
|
189
181
|
)
|
|
190
182
|
: ''}
|
|
191
183
|
</span>
|
package/src/util.js
CHANGED
|
@@ -353,27 +353,6 @@ const collectGroups = (tableData, range, key = '_collect') => {
|
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
/**
|
|
357
|
-
* 使用精度格式化函数格式化 Big.js 求和结果,无格式化函数时兜底 toFixed(2)
|
|
358
|
-
* @param {Big} sum - Big.js 实例
|
|
359
|
-
* @param {Function} [formatter] - 可选的精度格式化函数
|
|
360
|
-
* @returns {string}
|
|
361
|
-
*/
|
|
362
|
-
const formatSumWithPrecision = (sum, formatter) => {
|
|
363
|
-
return formatter ? formatter(sum).toFixed() : sum.toFixed(2)
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* 根据高精度字段映射,获取求和时应使用的字段名
|
|
368
|
-
* 如果字段有对应的高精度版本,返回高精度字段名,否则返回原字段名
|
|
369
|
-
* @param {string} field - 原始字段名
|
|
370
|
-
* @param {Object} mapping - 高精度字段映射,格式:{ normalField: 'high_precision_field' }
|
|
371
|
-
* @returns {string}
|
|
372
|
-
*/
|
|
373
|
-
const getHighPrecisionField = (field, mapping) => {
|
|
374
|
-
return mapping?.[field] || field
|
|
375
|
-
}
|
|
376
|
-
|
|
377
356
|
export {
|
|
378
357
|
collectGroups,
|
|
379
358
|
getHeight,
|
|
@@ -394,7 +373,5 @@ export {
|
|
|
394
373
|
caclSingleDetailsPageHeight,
|
|
395
374
|
getArrayMid,
|
|
396
375
|
getColSpanLength,
|
|
397
|
-
getOverallOrderTrHeight
|
|
398
|
-
formatSumWithPrecision,
|
|
399
|
-
getHighPrecisionField
|
|
376
|
+
getOverallOrderTrHeight
|
|
400
377
|
}
|