gm-printer 10.11.5-beta2 → 10.11.5
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/.eslintcache +1 -1
- package/README.md +102 -7
- package/build/demo.js +54 -0
- package/locales/en.json +1 -0
- package/locales/th.json +1 -0
- package/locales/zh-HK.json +1 -0
- package/package.json +10 -8
- package/src/common/editor_edit_field.js +82 -16
- package/src/common/editor_store.js +58 -0
- package/src/components/index.js +3 -1
- package/src/components/index.less +1 -0
- package/src/components/tip/index.js +19 -35
- package/src/components/tooltip/index.js +26 -0
- package/src/components/tooltip/style.less +16 -0
- package/src/editor/context_menu.js +16 -16
- package/src/editor/editor.js +16 -9
- package/src/editor/store.js +97 -12
- package/src/{editor_cannibalize → editor_account}/context_menu.js +42 -16
- package/src/{editor_cannibalize → editor_account}/editor.js +24 -9
- package/src/editor_account/index.js +4 -0
- package/src/editor_account/store.js +263 -0
- package/src/editor_purchase/context_menu.js +0 -1
- package/src/editor_purchase/editor_special_table.js +5 -2
- package/src/editor_purchase/store.js +27 -5
- package/src/index.js +2 -2
- package/src/printer/block.js +18 -10
- package/src/printer/printer.js +2 -2
- package/src/printer/qrcode.js +5 -2
- package/src/printer/store.js +116 -30
- package/src/printer/style.lesss +13 -3
- package/src/printer/table.js +57 -16
- package/src/printer/table_special_tr.js +1 -0
- package/src/printer/table_subtotal_tr.js +47 -7
- package/src/svg/question-circle-o.svg +1 -0
- package/src/util.js +53 -2
- package/webpack.config.js +19 -1
- package/global.d.ts +0 -67
- package/src/editor_cannibalize/index.js +0 -4
- package/src/editor_cannibalize/store.js +0 -29
- package/yarn-error.log +0 -9770
|
@@ -23,17 +23,30 @@ class Store extends EditorStore {
|
|
|
23
23
|
tableConfig.columns.replace(newCols)
|
|
24
24
|
|
|
25
25
|
// 单列-总表最后一列,在columns上修改
|
|
26
|
-
if (
|
|
26
|
+
if (
|
|
27
|
+
dataKey === 'purchase_last_col' ||
|
|
28
|
+
dataKey === 'purchase_last_col_noLineBreak'
|
|
29
|
+
) {
|
|
27
30
|
tableConfig.columns.push({
|
|
28
31
|
head: i18next.t('明细'),
|
|
29
32
|
headStyle: { textAlign: 'center' },
|
|
30
33
|
style: { textAlign: 'left' },
|
|
31
34
|
isSpecialColumn: true,
|
|
35
|
+
separator: '+',
|
|
36
|
+
// detailsType: 'purchase_last_col',
|
|
32
37
|
specialDetailsKey: '__details',
|
|
33
38
|
text: i18next.t(
|
|
34
|
-
'{{采购数量_
|
|
39
|
+
'{{采购数量_采购单位}}{{采购单位}}*{{商户名}}*{{商品备注}}'
|
|
35
40
|
)
|
|
36
41
|
})
|
|
42
|
+
// 通过detailsType属性区分单列-总表最后一列的数据是否换行展示
|
|
43
|
+
dataKey === 'purchase_last_col'
|
|
44
|
+
? (tableConfig.columns[
|
|
45
|
+
tableConfig.columns.length - 1
|
|
46
|
+
].detailLastColType = 'purchase_last_col')
|
|
47
|
+
: (tableConfig.columns[
|
|
48
|
+
tableConfig.columns.length - 1
|
|
49
|
+
].detailLastColType = 'purchase_last_col_noLineBreak')
|
|
37
50
|
}
|
|
38
51
|
}
|
|
39
52
|
|
|
@@ -44,7 +57,10 @@ class Store extends EditorStore {
|
|
|
44
57
|
|
|
45
58
|
tableConfig.specialConfig.template_text = value
|
|
46
59
|
// 单列-总表最后一列,在columns上修改
|
|
47
|
-
if (
|
|
60
|
+
if (
|
|
61
|
+
tableConfig.dataKey === 'purchase_last_col' ||
|
|
62
|
+
tableConfig.dataKey === 'purchase_last_col_noLineBreak'
|
|
63
|
+
) {
|
|
48
64
|
const specialCol = tableConfig.columns.find(o => o.isSpecialColumn)
|
|
49
65
|
specialCol.text = value
|
|
50
66
|
}
|
|
@@ -57,7 +73,10 @@ class Store extends EditorStore {
|
|
|
57
73
|
|
|
58
74
|
tableConfig.specialConfig.style = value
|
|
59
75
|
// 单列-总表最后一列,在columns上修改
|
|
60
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
tableConfig.dataKey === 'purchase_last_col' ||
|
|
78
|
+
tableConfig.dataKey === 'purchase_last_col_noLineBreak'
|
|
79
|
+
) {
|
|
61
80
|
const specialCol = tableConfig.columns.find(o => o.isSpecialColumn)
|
|
62
81
|
specialCol.style = value
|
|
63
82
|
}
|
|
@@ -70,7 +89,10 @@ class Store extends EditorStore {
|
|
|
70
89
|
|
|
71
90
|
tableConfig.specialConfig.template_text += fieldText
|
|
72
91
|
// 单列-总表最后一列,在columns上修改
|
|
73
|
-
if (
|
|
92
|
+
if (
|
|
93
|
+
tableConfig.dataKey === 'purchase_last_col' ||
|
|
94
|
+
tableConfig.dataKey === 'purchase_last_col_noLineBreak'
|
|
95
|
+
) {
|
|
74
96
|
const specialCol = tableConfig.columns.find(o => o.isSpecialColumn)
|
|
75
97
|
specialCol.text += fieldText
|
|
76
98
|
}
|
package/src/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import EditorStatement from './editor_statement'
|
|
|
9
9
|
import EditorAccoutStatement from './editor_account_statement'
|
|
10
10
|
import EditorBoxLabel from './editor_box_label'
|
|
11
11
|
import EditorSaleMenus from './editor_salemenus'
|
|
12
|
-
import
|
|
12
|
+
import EditorAccount from './editor_account'
|
|
13
13
|
import { BatchPrinter, doBatchPrint, doPrint, Printer, getCSS } from './printer'
|
|
14
14
|
import { MULTI_SUFFIX } from './config'
|
|
15
15
|
|
|
@@ -26,7 +26,7 @@ export {
|
|
|
26
26
|
EditorAccoutStatement,
|
|
27
27
|
EditorBoxLabel,
|
|
28
28
|
EditorSaleMenus,
|
|
29
|
-
|
|
29
|
+
EditorAccount,
|
|
30
30
|
Printer,
|
|
31
31
|
BatchPrinter,
|
|
32
32
|
doPrint,
|
package/src/printer/block.js
CHANGED
|
@@ -155,20 +155,28 @@ class Block extends React.Component {
|
|
|
155
155
|
</div>
|
|
156
156
|
)
|
|
157
157
|
} else if (type === 'barcode') {
|
|
158
|
+
// sid 合并打印没有订单id值,所以不渲染条形码
|
|
159
|
+
if (printerStore.template(text)) {
|
|
160
|
+
content = (
|
|
161
|
+
<BarCode
|
|
162
|
+
value={printerStore.template(text)}
|
|
163
|
+
textMargin={0}
|
|
164
|
+
margin={0}
|
|
165
|
+
height={35}
|
|
166
|
+
width={2}
|
|
167
|
+
displayValue={false}
|
|
168
|
+
dataName={name}
|
|
169
|
+
background='transparent'
|
|
170
|
+
/>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
} else if (type === 'qrcode') {
|
|
158
174
|
content = (
|
|
159
|
-
<
|
|
175
|
+
<QrCode
|
|
160
176
|
value={printerStore.template(text)}
|
|
161
|
-
|
|
162
|
-
margin={0}
|
|
163
|
-
height={35}
|
|
164
|
-
width={2}
|
|
165
|
-
displayValue={false}
|
|
166
|
-
dataName={name}
|
|
167
|
-
background='transparent'
|
|
177
|
+
size={parseInt(style.height)}
|
|
168
178
|
/>
|
|
169
179
|
)
|
|
170
|
-
} else if (type === 'qrcode') {
|
|
171
|
-
content = <QrCode value={printerStore.template(text)} />
|
|
172
180
|
}
|
|
173
181
|
|
|
174
182
|
const active = name === printerStore.selected
|
package/src/printer/printer.js
CHANGED
|
@@ -110,7 +110,7 @@ class Printer extends React.Component {
|
|
|
110
110
|
key={`contents.table.${index}`}
|
|
111
111
|
name={`contents.table.${index}`}
|
|
112
112
|
config={content}
|
|
113
|
-
range={{ begin: 0, end: list
|
|
113
|
+
range={{ begin: 0, end: list?.length || 0 }}
|
|
114
114
|
pageIndex={0}
|
|
115
115
|
placeholder={`${i18next.t('区域')} ${index}`}
|
|
116
116
|
/>
|
|
@@ -208,7 +208,7 @@ class Printer extends React.Component {
|
|
|
208
208
|
key={`contents.table.${index}`}
|
|
209
209
|
name={`contents.table.${index}`}
|
|
210
210
|
config={content}
|
|
211
|
-
range={{ begin: 0, end: list
|
|
211
|
+
range={{ begin: 0, end: list?.length || 0 }}
|
|
212
212
|
pageIndex={0}
|
|
213
213
|
placeholder={`${i18next.t('区域')} ${index}`}
|
|
214
214
|
/>
|
package/src/printer/qrcode.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import QRCode from 'qrcode.react'
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
|
+
import _ from 'lodash'
|
|
4
5
|
|
|
5
6
|
const QrCode = props => {
|
|
6
|
-
const { value } = props
|
|
7
|
-
return
|
|
7
|
+
const { value, size } = props
|
|
8
|
+
return (
|
|
9
|
+
<QRCode renderAs='svg' value={value} size={_.isFinite(size) ? size : 75} />
|
|
10
|
+
)
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
QrCode.propTypes = {
|
package/src/printer/store.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import i18next from '../../locales'
|
|
2
2
|
import { action, observable } from 'mobx'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getSumTrHeight,
|
|
5
|
+
isMultiTable,
|
|
6
|
+
caclSingleDetailsPageHeight
|
|
7
|
+
} from '../util'
|
|
4
8
|
import _ from 'lodash'
|
|
5
9
|
import Big from 'big.js'
|
|
6
10
|
|
|
@@ -84,17 +88,22 @@ class PrinterStore {
|
|
|
84
88
|
|
|
85
89
|
// 某一page的累计高度
|
|
86
90
|
let currentPageHeight = allPagesHaveThisHeight
|
|
91
|
+
/** 区域1的高度 */
|
|
92
|
+
let firstPagePanel0Height = 0
|
|
87
93
|
// 当前在处理 contents 的索引
|
|
88
94
|
let index = 0
|
|
89
95
|
// 一页承载的内容. [object, object, ...]
|
|
90
96
|
let page = []
|
|
91
|
-
|
|
97
|
+
// 处理配送单有多个表格的情况
|
|
98
|
+
let tableCount = 0
|
|
92
99
|
/* --- 遍历 contents,将内容动态分配到page --- */
|
|
93
100
|
while (index < this.config.contents.length) {
|
|
94
101
|
const content = this.config.contents[index]
|
|
95
102
|
|
|
96
103
|
/* 表格内容处理 */
|
|
97
104
|
if (content.type === 'table') {
|
|
105
|
+
// 是表格就++
|
|
106
|
+
tableCount++
|
|
98
107
|
// 表格原始的高度和宽度信息
|
|
99
108
|
const table = this.tablesInfo[`contents.table.${index}`]
|
|
100
109
|
|
|
@@ -113,21 +122,15 @@ class PrinterStore {
|
|
|
113
122
|
const currentPageMinimumHeight =
|
|
114
123
|
allPagesHaveThisHeight + allTableHaveThisHeight
|
|
115
124
|
|
|
125
|
+
// 当前数据
|
|
126
|
+
const tableData = this.data._table[dataKey] || []
|
|
127
|
+
|
|
116
128
|
// 表格行的索引,用于table.slice(begin, end), 分割到不同页面中
|
|
117
129
|
let begin = 0
|
|
118
130
|
let end = 0
|
|
119
131
|
|
|
120
132
|
// 如果表格没有数据,那么轮一下个content
|
|
121
|
-
if (
|
|
122
|
-
table.body.heights.length === 0 || // 没有数据,不渲染此table
|
|
123
|
-
table.body.heights[0] + currentPageMinimumHeight > this.pageHeight // 页面无法容纳此table,不渲染这个table了
|
|
124
|
-
) {
|
|
125
|
-
if (
|
|
126
|
-
table.body.heights[0] + currentPageMinimumHeight >
|
|
127
|
-
this.pageHeight
|
|
128
|
-
) {
|
|
129
|
-
window.alert('表格明细内容过多,无法打印,请更换其他打印模板') // 例如: 采购明细放在单列-最后一列,造成一列高度大于页面高度
|
|
130
|
-
}
|
|
133
|
+
if (table.body.heights.length === 0) {
|
|
131
134
|
index++
|
|
132
135
|
} else {
|
|
133
136
|
// 表格有数据,添加[每个表格都具有的高度]
|
|
@@ -137,36 +140,82 @@ class PrinterStore {
|
|
|
137
140
|
while (end < table.body.heights.length) {
|
|
138
141
|
currentPageHeight += table.body.heights[end]
|
|
139
142
|
|
|
140
|
-
//
|
|
143
|
+
// 当前页没有多余空间
|
|
141
144
|
if (currentPageHeight > this.pageHeight) {
|
|
145
|
+
// 第一条数据计算时,不能加上header的高度
|
|
146
|
+
const calcHeight = this.pageHeight - firstPagePanel0Height
|
|
147
|
+
// 第一条就极端会有问题
|
|
142
148
|
if (end !== 0) {
|
|
143
|
-
// ‼️‼️‼️ 极端情况: 如果一行的高度 大于 页面高度, 那么就做下一行
|
|
144
|
-
if (
|
|
145
|
-
table.body.heights[end] + currentPageMinimumHeight >
|
|
146
|
-
this.pageHeight
|
|
147
|
-
) {
|
|
148
|
-
end++
|
|
149
|
-
}
|
|
150
149
|
page.push({
|
|
151
150
|
type: 'table',
|
|
152
151
|
index,
|
|
153
152
|
begin,
|
|
154
153
|
end
|
|
155
154
|
})
|
|
155
|
+
// 此页完成任务
|
|
156
|
+
this.pages.push(page)
|
|
157
|
+
page = []
|
|
158
|
+
}
|
|
159
|
+
// 页面有多个表格时,当同一页的第二个表格的第一行高度加上第一个表格的高度大于页面的高度,需要生成新的一页
|
|
160
|
+
// 因为是第二个表格,重新走了遍历,end重置0,没有进入到上面的判断(end !== 0),不会生成新的一页
|
|
161
|
+
if (tableCount > 1 && end === 0) {
|
|
162
|
+
this.pages.push(page)
|
|
163
|
+
page = []
|
|
156
164
|
}
|
|
157
165
|
|
|
158
|
-
|
|
166
|
+
// ‼️‼️‼️ 极端情况: 如果一行的高度 大于 页面高度, 那么就对明细进行分页
|
|
167
|
+
if (
|
|
168
|
+
table.body.heights[end] + currentPageMinimumHeight >
|
|
169
|
+
this.pageHeight
|
|
170
|
+
) {
|
|
171
|
+
/** 明细data */
|
|
172
|
+
const detailsData = tableData[end]?.__details || []
|
|
173
|
+
const heightParams = {
|
|
174
|
+
currentPageMinimumHeight: currentPageMinimumHeight,
|
|
175
|
+
calcHeight: calcHeight,
|
|
176
|
+
pageHeight: this.pageHeight
|
|
177
|
+
}
|
|
178
|
+
const {
|
|
179
|
+
ranges,
|
|
180
|
+
detailsPageHeight
|
|
181
|
+
} = caclSingleDetailsPageHeight(
|
|
182
|
+
end,
|
|
183
|
+
table,
|
|
184
|
+
detailsData,
|
|
185
|
+
heightParams
|
|
186
|
+
)
|
|
187
|
+
// 分局明细拆分后的数据
|
|
188
|
+
const splitTableData = _.map(ranges, range => {
|
|
189
|
+
// 当前行的table数据
|
|
190
|
+
const _tableData = Object.assign({}, tableData[end])
|
|
191
|
+
_tableData.__details = detailsData.slice(...range)
|
|
192
|
+
return _tableData
|
|
193
|
+
})
|
|
194
|
+
// 插入原table数据中
|
|
195
|
+
tableData.splice(end, 1, ...splitTableData)
|
|
196
|
+
// 更新
|
|
197
|
+
this.data._table[dataKey] = tableData
|
|
198
|
+
|
|
199
|
+
// 同时也要更新body.heights 不能影响后续计算
|
|
200
|
+
table.body.heights.splice(end, 1, ...detailsPageHeight)
|
|
159
201
|
|
|
160
|
-
|
|
161
|
-
|
|
202
|
+
page.push({
|
|
203
|
+
type: 'table',
|
|
204
|
+
index,
|
|
205
|
+
begin: end,
|
|
206
|
+
end: ++end
|
|
207
|
+
})
|
|
208
|
+
// 此页完成任务
|
|
209
|
+
this.pages.push(page)
|
|
210
|
+
page = []
|
|
211
|
+
}
|
|
162
212
|
|
|
213
|
+
begin = end
|
|
163
214
|
// 开启新一页,重置页面高度
|
|
164
|
-
page = []
|
|
165
215
|
currentPageHeight = currentPageMinimumHeight
|
|
166
216
|
} else {
|
|
167
217
|
// 有空间,继续做下行
|
|
168
218
|
end++
|
|
169
|
-
|
|
170
219
|
// 最后一行,把信息加入 page,并轮下一个contents
|
|
171
220
|
if (end === table.body.heights.length) {
|
|
172
221
|
page.push({
|
|
@@ -190,6 +239,11 @@ class PrinterStore {
|
|
|
190
239
|
break
|
|
191
240
|
}
|
|
192
241
|
|
|
242
|
+
if (index === 0) {
|
|
243
|
+
// 针对极端情况下,保存区域1的高度
|
|
244
|
+
firstPagePanel0Height = panelHeight
|
|
245
|
+
}
|
|
246
|
+
|
|
193
247
|
if (currentPageHeight <= this.pageHeight) {
|
|
194
248
|
// 空间充足,把信息加入 page,并轮下一个contents
|
|
195
249
|
page.push({
|
|
@@ -208,7 +262,6 @@ class PrinterStore {
|
|
|
208
262
|
}
|
|
209
263
|
}
|
|
210
264
|
}
|
|
211
|
-
|
|
212
265
|
this.pages.push(page)
|
|
213
266
|
}
|
|
214
267
|
|
|
@@ -224,7 +277,6 @@ class PrinterStore {
|
|
|
224
277
|
price: price
|
|
225
278
|
})
|
|
226
279
|
} catch (err) {
|
|
227
|
-
// console.warn(err)
|
|
228
280
|
return text
|
|
229
281
|
}
|
|
230
282
|
}
|
|
@@ -250,13 +302,47 @@ class PrinterStore {
|
|
|
250
302
|
|
|
251
303
|
templateSpecialDetails(col, dataKey, index) {
|
|
252
304
|
// 做好保护,出错就返回 text
|
|
253
|
-
const { specialDetailsKey, text } = col
|
|
305
|
+
const { specialDetailsKey, text, detailLastColType, separator } = col
|
|
254
306
|
try {
|
|
255
307
|
const row = this.data._table[dataKey][index]
|
|
256
308
|
const compiled = _.template(text, { interpolate: /{{([\s\S]+?)}}/g })
|
|
257
|
-
|
|
309
|
+
let detailsList = row[specialDetailsKey] || []
|
|
310
|
+
|
|
311
|
+
/** 简单处理下数据 */
|
|
312
|
+
const filterList = (list, type = '') => {
|
|
313
|
+
if (type === 'noLineBreak') {
|
|
314
|
+
return list.map(d => `${compiled(d)}`).join(separator)
|
|
315
|
+
}
|
|
316
|
+
return list
|
|
317
|
+
.map(d => `<div class='b-table-details'> ${compiled(d)} </div>`)
|
|
318
|
+
.join('')
|
|
319
|
+
}
|
|
258
320
|
|
|
259
|
-
|
|
321
|
+
/** 明细换行和不换行处理 */
|
|
322
|
+
detailsList =
|
|
323
|
+
!detailLastColType || detailLastColType === 'purchase_last_col'
|
|
324
|
+
? filterList(detailsList)
|
|
325
|
+
: filterList(detailsList, 'noLineBreak')
|
|
326
|
+
|
|
327
|
+
// 兼容之前已经添加上最后一列的模板
|
|
328
|
+
// if (!detailLastColType) {
|
|
329
|
+
// detailsList = detailsList
|
|
330
|
+
// ? detailsList.map(d => `<div> ${compiled(d)} </div>`).join('')
|
|
331
|
+
// : []
|
|
332
|
+
// } else {
|
|
333
|
+
// // 多栏商品时,同一行仅有一个商品,后面空余部分显示空白
|
|
334
|
+
// if (detailsList) {
|
|
335
|
+
// // detailLastColType ---> 区分采购明细单列——最后一列是否换行
|
|
336
|
+
// detailsList =
|
|
337
|
+
// detailLastColType === 'purchase_last_col'
|
|
338
|
+
// ? detailsList.map(d => `<div> ${compiled(d)} </div>`).join('')
|
|
339
|
+
// : detailsList.map(d => `${compiled(d)}`).join(separator)
|
|
340
|
+
// } else {
|
|
341
|
+
// detailsList = []
|
|
342
|
+
// }
|
|
343
|
+
// }
|
|
344
|
+
|
|
345
|
+
return detailsList
|
|
260
346
|
} catch (err) {
|
|
261
347
|
return text
|
|
262
348
|
}
|
package/src/printer/style.lesss
CHANGED
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
td,
|
|
97
97
|
th {
|
|
98
98
|
border: 1px solid black;
|
|
99
|
-
padding: 2px;
|
|
99
|
+
padding: 2px 0;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
td,
|
|
107
107
|
th {
|
|
108
108
|
border: 1px solid #ddd;
|
|
109
|
-
padding: 2px;
|
|
109
|
+
padding: 2px 0;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -116,6 +116,7 @@
|
|
|
116
116
|
td,
|
|
117
117
|
th {
|
|
118
118
|
border: 1px solid transparent;
|
|
119
|
+
padding: 2px 0;
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
th {
|
|
@@ -130,7 +131,7 @@
|
|
|
130
131
|
td,
|
|
131
132
|
th {
|
|
132
133
|
border: none;
|
|
133
|
-
padding: 2px;
|
|
134
|
+
padding: 2px 0;
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
}
|
|
@@ -152,3 +153,12 @@
|
|
|
152
153
|
@page {
|
|
153
154
|
margin: 0;
|
|
154
155
|
}
|
|
156
|
+
|
|
157
|
+
.gm-printer-subtotal-UpperLowerCaseSeparate-outer{
|
|
158
|
+
display:flex;
|
|
159
|
+
}
|
|
160
|
+
.gm-printer-subtotal-UpperLowerCaseSeparate-inter{
|
|
161
|
+
display: flex;
|
|
162
|
+
flex-grow: 1;
|
|
163
|
+
justify-content: space-between;
|
|
164
|
+
}
|
package/src/printer/table.js
CHANGED
|
@@ -36,6 +36,7 @@ class Table extends React.Component {
|
|
|
36
36
|
const tHead = $table.querySelector('thead')
|
|
37
37
|
const ths = tHead.querySelectorAll('th') || []
|
|
38
38
|
const trs = $table.querySelectorAll('tbody tr') || []
|
|
39
|
+
const detailsDiv = $table.querySelectorAll('tr td .b-table-details')
|
|
39
40
|
|
|
40
41
|
printerStore.setHeight(name, getHeight($table))
|
|
41
42
|
|
|
@@ -45,7 +46,8 @@ class Table extends React.Component {
|
|
|
45
46
|
widths: _.map(ths, th => getWidth(th))
|
|
46
47
|
},
|
|
47
48
|
body: {
|
|
48
|
-
heights: _.map(trs, tr => getHeight(tr))
|
|
49
|
+
heights: _.map(trs, tr => getHeight(tr)),
|
|
50
|
+
children: _.map(detailsDiv, div => getHeight(div))
|
|
49
51
|
}
|
|
50
52
|
})
|
|
51
53
|
}
|
|
@@ -107,14 +109,27 @@ class Table extends React.Component {
|
|
|
107
109
|
for (let i = 2; i <= colNumber; i++) {
|
|
108
110
|
const colNum = i > 2 ? i : '' // 栏数
|
|
109
111
|
const columnsI = columns.map((val, index) => {
|
|
110
|
-
|
|
112
|
+
const data = {
|
|
111
113
|
...val,
|
|
112
114
|
index,
|
|
113
115
|
text: val.text.replace(
|
|
114
|
-
/{{
|
|
115
|
-
(s, s1) =>
|
|
116
|
+
/{{(price\()?列\.([^{{]+)}}/g,
|
|
117
|
+
(s, s1, s2) => {
|
|
118
|
+
if (s1) {
|
|
119
|
+
// 有price函数插进来
|
|
120
|
+
const mix_suffix = s2.replace(/\*/, () => `${MULTI_SUFFIX}*`)
|
|
121
|
+
return `{{${s1}列.${mix_suffix}${colNum}}}`
|
|
122
|
+
} else {
|
|
123
|
+
return `{{列.${s2}${MULTI_SUFFIX}${colNum}}}`
|
|
124
|
+
}
|
|
125
|
+
}
|
|
116
126
|
) // {{列.xx}} => {{列.xxMULTI_SUFFIXi}}
|
|
117
127
|
}
|
|
128
|
+
// 多栏商品的明细取 __details_MULTI_SUFFIX
|
|
129
|
+
if (val.specialDetailsKey)
|
|
130
|
+
data.specialDetailsKey =
|
|
131
|
+
val.specialDetailsKey + `${MULTI_SUFFIX}${colNum}`
|
|
132
|
+
return data
|
|
118
133
|
})
|
|
119
134
|
res = res.concat(columnsI)
|
|
120
135
|
}
|
|
@@ -140,9 +155,34 @@ class Table extends React.Component {
|
|
|
140
155
|
|
|
141
156
|
// 列
|
|
142
157
|
const columns = this.getColumns()
|
|
143
|
-
|
|
144
158
|
// 列宽固定(避免跳页bug)
|
|
145
159
|
const thWidths = printerStore.tablesInfo[name]?.head.widths || []
|
|
160
|
+
// 每页合计在前
|
|
161
|
+
const subtotalTrPageSummary = () => {
|
|
162
|
+
return (
|
|
163
|
+
<>
|
|
164
|
+
<SubtotalTr
|
|
165
|
+
range={range}
|
|
166
|
+
config={config}
|
|
167
|
+
printerStore={printerStore}
|
|
168
|
+
/>
|
|
169
|
+
<PageSummary {...this.props} />
|
|
170
|
+
</>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
// 合计在前
|
|
174
|
+
const PageSummarySubtotalTr = () => {
|
|
175
|
+
return (
|
|
176
|
+
<>
|
|
177
|
+
<PageSummary {...this.props} />
|
|
178
|
+
<SubtotalTr
|
|
179
|
+
range={range}
|
|
180
|
+
config={config}
|
|
181
|
+
printerStore={printerStore}
|
|
182
|
+
/>
|
|
183
|
+
</>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
146
186
|
|
|
147
187
|
return (
|
|
148
188
|
<table>
|
|
@@ -155,7 +195,7 @@ class Table extends React.Component {
|
|
|
155
195
|
data-name={getTableColumnName(name, col.index)}
|
|
156
196
|
draggable
|
|
157
197
|
style={{
|
|
158
|
-
|
|
198
|
+
maxWidth: thWidths[i],
|
|
159
199
|
...col.headStyle
|
|
160
200
|
}}
|
|
161
201
|
className={classNames({
|
|
@@ -178,7 +218,6 @@ class Table extends React.Component {
|
|
|
178
218
|
const _special = tableData[i] && tableData[i]._special
|
|
179
219
|
if (_special)
|
|
180
220
|
return <SpecialTr key={i} config={config} data={_special} />
|
|
181
|
-
|
|
182
221
|
// 如果项为空对象展现一个占满一行的td
|
|
183
222
|
const isItemNone = !_.keys(tableData[i]).length
|
|
184
223
|
|
|
@@ -192,7 +231,11 @@ class Table extends React.Component {
|
|
|
192
231
|
<td
|
|
193
232
|
key={j}
|
|
194
233
|
data-name={getTableColumnName(name, col.index)}
|
|
195
|
-
style={
|
|
234
|
+
style={{
|
|
235
|
+
minWidth: '24px',
|
|
236
|
+
maxWidth: thWidths[j],
|
|
237
|
+
...col.style
|
|
238
|
+
}}
|
|
196
239
|
className={classNames({
|
|
197
240
|
active:
|
|
198
241
|
getTableColumnName(name, col.index) ===
|
|
@@ -205,12 +248,9 @@ class Table extends React.Component {
|
|
|
205
248
|
dataKey,
|
|
206
249
|
i
|
|
207
250
|
)
|
|
208
|
-
: printerStore
|
|
209
|
-
col.text,
|
|
210
|
-
|
|
211
|
-
i,
|
|
212
|
-
pageIndex
|
|
213
|
-
)
|
|
251
|
+
: printerStore
|
|
252
|
+
.templateTable(col.text, dataKey, i, pageIndex)
|
|
253
|
+
.replace(/\(\)/g, '')
|
|
214
254
|
}}
|
|
215
255
|
/>
|
|
216
256
|
)
|
|
@@ -219,8 +259,9 @@ class Table extends React.Component {
|
|
|
219
259
|
</tr>
|
|
220
260
|
)
|
|
221
261
|
})}
|
|
222
|
-
|
|
223
|
-
|
|
262
|
+
{this.props.config.subtotal.isCommutationPlace
|
|
263
|
+
? PageSummarySubtotalTr()
|
|
264
|
+
: subtotalTrPageSummary()}
|
|
224
265
|
</tbody>
|
|
225
266
|
</table>
|
|
226
267
|
)
|
|
@@ -7,6 +7,7 @@ import Big from 'big.js'
|
|
|
7
7
|
import { coverDigit2Uppercase, getDataKey } from '../util'
|
|
8
8
|
import { observer } from 'mobx-react'
|
|
9
9
|
import { get } from 'mobx'
|
|
10
|
+
import { Flex } from '../components'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* 每页合计组件,分页计算后,根据range来统计每页合计数据
|
|
@@ -21,6 +22,8 @@ const SubtotalTr = props => {
|
|
|
21
22
|
subtotal,
|
|
22
23
|
subtotal: {
|
|
23
24
|
show,
|
|
25
|
+
isUpperCaseBefore, // 决定小写金额是否在前
|
|
26
|
+
isUpperLowerCaseSeparate, // 决定大小写金额是否分开在两端
|
|
24
27
|
style,
|
|
25
28
|
fields = [
|
|
26
29
|
{
|
|
@@ -62,21 +65,37 @@ const SubtotalTr = props => {
|
|
|
62
65
|
const list = tableData.slice(range.begin, range.end)
|
|
63
66
|
|
|
64
67
|
const sum = {}
|
|
65
|
-
let subtotalStr = ''
|
|
66
68
|
|
|
67
69
|
_.each(fields, v => {
|
|
68
70
|
sum[v.name] = sumData(list, v.valueField)
|
|
69
71
|
})
|
|
70
72
|
|
|
73
|
+
// 定义每页小记的左右两侧内容
|
|
74
|
+
let subtotalLeftContent
|
|
75
|
+
let subtotalRightContent
|
|
76
|
+
|
|
71
77
|
for (const name in sum) {
|
|
72
78
|
const price = sum[name]
|
|
73
79
|
const priceUpperCase = get(subtotal, 'needUpperCase') // needUpperCase在初始模板中undefined,所以必须用这个方法
|
|
74
80
|
? '大写:' + coverDigit2Uppercase(price)
|
|
75
81
|
: ''
|
|
76
82
|
if (displayName) {
|
|
77
|
-
|
|
83
|
+
// 大写金额是否在前
|
|
84
|
+
if (isUpperCaseBefore) {
|
|
85
|
+
subtotalLeftContent = `${name}${priceUpperCase}`
|
|
86
|
+
subtotalRightContent = `${price}`
|
|
87
|
+
} else {
|
|
88
|
+
subtotalLeftContent = `${price}`
|
|
89
|
+
subtotalRightContent = `${name} ${priceUpperCase}`
|
|
90
|
+
}
|
|
78
91
|
} else {
|
|
79
|
-
|
|
92
|
+
if (isUpperCaseBefore) {
|
|
93
|
+
subtotalLeftContent = `${priceUpperCase}`
|
|
94
|
+
subtotalRightContent = `${price}`
|
|
95
|
+
} else {
|
|
96
|
+
subtotalLeftContent = `${price}`
|
|
97
|
+
subtotalRightContent = `${priceUpperCase}`
|
|
98
|
+
}
|
|
80
99
|
}
|
|
81
100
|
}
|
|
82
101
|
|
|
@@ -85,10 +104,31 @@ const SubtotalTr = props => {
|
|
|
85
104
|
<td
|
|
86
105
|
colSpan={99}
|
|
87
106
|
style={{ fontWeight: 'bold', ...style }}
|
|
88
|
-
dangerouslySetInnerHTML={{
|
|
89
|
-
|
|
90
|
-
}}
|
|
91
|
-
|
|
107
|
+
// dangerouslySetInnerHTML={{
|
|
108
|
+
// __html: `${i18next.t('每页合计')}:${subtotalStr}`
|
|
109
|
+
// }}flex-grow: 1
|
|
110
|
+
>
|
|
111
|
+
{/* 大写金额和小写金额分开在表格的两侧,通过控制类名实现,添加类名后,覆盖原来的居中、靠右靠左 */}
|
|
112
|
+
<div
|
|
113
|
+
className={
|
|
114
|
+
isUpperLowerCaseSeparate
|
|
115
|
+
? 'gm-printer-subtotal-UpperLowerCaseSeparate-outer'
|
|
116
|
+
: ''
|
|
117
|
+
}
|
|
118
|
+
>
|
|
119
|
+
{i18next.t('每页合计')}:
|
|
120
|
+
<span
|
|
121
|
+
className={
|
|
122
|
+
isUpperLowerCaseSeparate
|
|
123
|
+
? 'gm-printer-subtotal-UpperLowerCaseSeparate-inter'
|
|
124
|
+
: ''
|
|
125
|
+
}
|
|
126
|
+
>
|
|
127
|
+
<span> {subtotalLeftContent} </span>
|
|
128
|
+
<span> {subtotalRightContent} </span>
|
|
129
|
+
</span>
|
|
130
|
+
</div>
|
|
131
|
+
</td>
|
|
92
132
|
</tr>
|
|
93
133
|
)
|
|
94
134
|
} else {
|