gm-printer 10.35.2 → 10.35.4
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/package.json
CHANGED
package/src/common/component.js
CHANGED
|
@@ -132,6 +132,10 @@ Textarea.propTypes = {
|
|
|
132
132
|
class TextPX extends React.Component {
|
|
133
133
|
handleChange = value => {
|
|
134
134
|
const { onChange } = this.props
|
|
135
|
+
// 理论上这里只会有字符串和 event 两种类型
|
|
136
|
+
if (Object.prototype.toString.call(value) === '[object Object]') {
|
|
137
|
+
value = value?.target?.value
|
|
138
|
+
}
|
|
135
139
|
if (value === '') {
|
|
136
140
|
onChange('')
|
|
137
141
|
} else if (value.endsWith('%')) {
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import _ from 'lodash'
|
|
4
|
-
import { coverDigit2Uppercase, getDataKey } from '../util'
|
|
4
|
+
import { coverDigit2Uppercase, getDataKey, isMultiTable } from '../util'
|
|
5
|
+
import { MULTI_SUFFIX, MULTI_SUFFIX3 } from '../config'
|
|
5
6
|
import { observer } from 'mobx-react'
|
|
6
7
|
import classNames from 'classnames'
|
|
7
8
|
import Big from 'big.js'
|
|
8
9
|
|
|
10
|
+
function buildTemplateField(fieldStr, suffix) {
|
|
11
|
+
// 如果 field 是 "{{列.下单数}}",提取出 "下单数"
|
|
12
|
+
const match = fieldStr.match(/\{\{列\.([^}]+)\}\}/)
|
|
13
|
+
if (match) {
|
|
14
|
+
// 构造新的模板字符串:{{列.下单数_MULTI_SUFFIX}}
|
|
15
|
+
return `{{列.${match[1]}${suffix}}}`
|
|
16
|
+
}
|
|
17
|
+
// 如果 field 不是模板格式,直接返回(这种情况应该不会发生)
|
|
18
|
+
return fieldStr + suffix
|
|
19
|
+
}
|
|
20
|
+
|
|
9
21
|
/**
|
|
10
22
|
* 通用的自定义合计组件
|
|
11
23
|
* @param {string} configKey - 配置键名
|
|
@@ -28,20 +40,50 @@ const DiySummary = props => {
|
|
|
28
40
|
? getTableData(printerStore, dataKey, arrange, range)
|
|
29
41
|
: printerStore.data._table[getDataKey(dataKey, arrange)] || []
|
|
30
42
|
|
|
43
|
+
// 判断是否是多栏表格
|
|
44
|
+
const isMulti = isMultiTable(dataKey)
|
|
45
|
+
|
|
31
46
|
// 计算合计
|
|
32
47
|
const sumData = field => {
|
|
48
|
+
if (isMulti) {
|
|
49
|
+
return _.reduce(
|
|
50
|
+
tableData,
|
|
51
|
+
(a, b, i) => {
|
|
52
|
+
let result = a
|
|
53
|
+
// 先通过 templateTable 获取原始字段的值
|
|
54
|
+
const bRes = getRes(field, i)
|
|
55
|
+
result = a.plus(+bRes || 0)
|
|
56
|
+
|
|
57
|
+
// 双栏
|
|
58
|
+
const multiField = buildTemplateField(field, MULTI_SUFFIX)
|
|
59
|
+
result = result.plus(+getRes(multiField, i) || 0)
|
|
60
|
+
|
|
61
|
+
// 三栏
|
|
62
|
+
const multiField3 = buildTemplateField(field, MULTI_SUFFIX3)
|
|
63
|
+
result = result.plus(+getRes(multiField3, i) || 0)
|
|
64
|
+
|
|
65
|
+
return result
|
|
66
|
+
},
|
|
67
|
+
Big(0)
|
|
68
|
+
).toFixed(2)
|
|
69
|
+
}
|
|
70
|
+
|
|
33
71
|
return _.reduce(
|
|
34
72
|
tableData,
|
|
35
73
|
(a, b, i) => {
|
|
36
74
|
let result = a
|
|
37
|
-
const bRes =
|
|
38
|
-
.templateTable(field, dataKey, range ? range.begin + i : i, pageIndex)
|
|
39
|
-
.replace(/\(\)/g, '')
|
|
75
|
+
const bRes = getRes(field, i)
|
|
40
76
|
result = a.plus(+bRes || 0)
|
|
41
77
|
return result
|
|
42
78
|
},
|
|
43
79
|
Big(0)
|
|
44
80
|
).toFixed(2)
|
|
81
|
+
|
|
82
|
+
function getRes(field, i) {
|
|
83
|
+
return printerStore
|
|
84
|
+
.templateTable(field, dataKey, range ? range.begin + i : i, pageIndex)
|
|
85
|
+
.replace(/\(\)/g, '')
|
|
86
|
+
}
|
|
45
87
|
}
|
|
46
88
|
|
|
47
89
|
if (!diyConfig?.show || !printerStore?.ready) {
|