gm-printer 10.42.3-beta.1 → 10.42.3
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/locales/en.json +0 -3
- package/locales/th.json +0 -3
- package/locales/zh-HK.json +0 -3
- package/package.json +1 -1
- package/src/common/common_context_menu.js +4 -6
- package/src/common/component.js +8 -64
- package/src/common/editor_edit_field.js +1 -6
- package/src/common/editor_store.js +32 -34
- package/src/common/hoc_with_store.js +0 -9
- package/src/common/style.lesss +0 -43
- package/src/editor/store.js +0 -13
- package/src/finance_voucher/components/table_subtotal_tr.js +18 -12
- package/src/index.js +0 -2
- package/src/printer/block.js +4 -154
- package/src/printer/compute_pages.js +1 -2
- package/src/printer/multi_column.js +0 -1
- package/src/printer/page_summary.js +1 -3
- package/src/printer/printer.js +1 -8
- package/src/printer/store.js +38 -129
- package/src/printer/table_diy_overallOrder_tr.js +15 -8
- package/src/printer/table_diy_summary_tr.js +35 -18
- package/src/printer/table_subtotal_tr.js +16 -13
- package/src/util.js +1 -20
- package/yarn-error.log +152 -372
package/src/printer/block.js
CHANGED
|
@@ -8,12 +8,7 @@ import BarCode from './barcode'
|
|
|
8
8
|
import QrCode from './qrcode'
|
|
9
9
|
import Tag from './tag'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
// 字符串形式的 inject 会直接抛错,这里降级为 null 关闭编辑能力
|
|
13
|
-
@inject(({ printerStore, editStore }) => ({
|
|
14
|
-
printerStore,
|
|
15
|
-
editStore: editStore || null
|
|
16
|
-
}))
|
|
11
|
+
@inject('printerStore')
|
|
17
12
|
@observer
|
|
18
13
|
class Block extends React.Component {
|
|
19
14
|
constructor(props) {
|
|
@@ -21,10 +16,8 @@ class Block extends React.Component {
|
|
|
21
16
|
this.state = {
|
|
22
17
|
clientX: null,
|
|
23
18
|
clientY: null,
|
|
24
|
-
isEdit: false
|
|
25
|
-
isResizing: false
|
|
19
|
+
isEdit: false
|
|
26
20
|
}
|
|
27
|
-
this.resizeState = null
|
|
28
21
|
}
|
|
29
22
|
|
|
30
23
|
componentDidMount() {
|
|
@@ -39,7 +32,6 @@ class Block extends React.Component {
|
|
|
39
32
|
'gm-printer-block-edit',
|
|
40
33
|
this.handleBlockEdit
|
|
41
34
|
)
|
|
42
|
-
this.teardownResize()
|
|
43
35
|
}
|
|
44
36
|
|
|
45
37
|
handleBlockEdit = e => {
|
|
@@ -120,118 +112,6 @@ class Block extends React.Component {
|
|
|
120
112
|
})
|
|
121
113
|
}
|
|
122
114
|
|
|
123
|
-
// 电子签章:图片四角等比例拖拽缩放
|
|
124
|
-
handleResizeStart = (direction, e) => {
|
|
125
|
-
// 阻止触发块的选中/拖动
|
|
126
|
-
e.stopPropagation()
|
|
127
|
-
e.preventDefault()
|
|
128
|
-
|
|
129
|
-
const {
|
|
130
|
-
config: { style, ratio }
|
|
131
|
-
} = this.props
|
|
132
|
-
|
|
133
|
-
const initW = parseFloat(style.width) || 0
|
|
134
|
-
const initH = parseFloat(style.height) || 0
|
|
135
|
-
// 旧模板无 ratio 时按当前显示宽高锁定;宽或高缺失(存量块无 width)时退回 1,
|
|
136
|
-
// 避免比例算出 0 导致高度 Infinity
|
|
137
|
-
const fallbackRatio = initW > 0 && initH > 0 ? initW / initH : 1
|
|
138
|
-
this.resizeState = {
|
|
139
|
-
direction,
|
|
140
|
-
startX: e.clientX,
|
|
141
|
-
startY: e.clientY,
|
|
142
|
-
initW,
|
|
143
|
-
initH,
|
|
144
|
-
initL: parseFloat(style.left) || 0,
|
|
145
|
-
initT: parseFloat(style.top) || 0,
|
|
146
|
-
// ratio = 原始宽/高
|
|
147
|
-
ratio: ratio || fallbackRatio,
|
|
148
|
-
baseStyle: style
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
this.setState({
|
|
152
|
-
isResizing: true
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
window.addEventListener('mousemove', this.handleResizeMove)
|
|
156
|
-
window.addEventListener('mouseup', this.handleResizeEnd)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
handleResizeMove = e => {
|
|
160
|
-
if (!this.resizeState) return
|
|
161
|
-
|
|
162
|
-
// rAF 节流,避免高频 mousemove 打爆渲染
|
|
163
|
-
if (this.resizePending) return
|
|
164
|
-
this.resizePending = e
|
|
165
|
-
window.requestAnimationFrame(() => {
|
|
166
|
-
const evt = this.resizePending
|
|
167
|
-
this.resizePending = null
|
|
168
|
-
if (!evt || !this.resizeState) return
|
|
169
|
-
this.doResize(evt)
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
doResize = e => {
|
|
174
|
-
const {
|
|
175
|
-
direction,
|
|
176
|
-
startX,
|
|
177
|
-
initW,
|
|
178
|
-
initH,
|
|
179
|
-
initL,
|
|
180
|
-
initT,
|
|
181
|
-
ratio,
|
|
182
|
-
baseStyle
|
|
183
|
-
} = this.resizeState
|
|
184
|
-
const dx = e.clientX - startX
|
|
185
|
-
|
|
186
|
-
// 右侧角向右放大,左侧角向左放大
|
|
187
|
-
let width =
|
|
188
|
-
direction === 'rb' || direction === 'rt' ? initW + dx : initW - dx
|
|
189
|
-
// 最小尺寸兜底,防止翻转
|
|
190
|
-
width = Math.max(width, 10)
|
|
191
|
-
const height = Math.round(width / ratio)
|
|
192
|
-
width = Math.round(width)
|
|
193
|
-
|
|
194
|
-
// 锚定对角:左向角拖拽时右/下边不动,上向角拖拽时下边不动
|
|
195
|
-
let left = initL
|
|
196
|
-
let top = initT
|
|
197
|
-
if (direction === 'lb' || direction === 'lt') {
|
|
198
|
-
left = initL + initW - width
|
|
199
|
-
}
|
|
200
|
-
if (direction === 'rt' || direction === 'lt') {
|
|
201
|
-
top = initT + initH - height
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
dispatchMsg('gm-printer-block-style-set', {
|
|
205
|
-
style: {
|
|
206
|
-
...baseStyle,
|
|
207
|
-
width: width + 'px',
|
|
208
|
-
height: height + 'px',
|
|
209
|
-
left: left + 'px',
|
|
210
|
-
top: top + 'px'
|
|
211
|
-
}
|
|
212
|
-
})
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
handleResizeEnd = () => {
|
|
216
|
-
// 先 flush 掉节流里排队中的最后一帧,避免松手回退
|
|
217
|
-
if (this.resizePending) {
|
|
218
|
-
const evt = this.resizePending
|
|
219
|
-
this.resizePending = null
|
|
220
|
-
this.doResize(evt)
|
|
221
|
-
}
|
|
222
|
-
this.teardownResize()
|
|
223
|
-
this.setState({
|
|
224
|
-
isResizing: false
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
teardownResize = () => {
|
|
229
|
-
window.removeEventListener('mousemove', this.handleResizeMove)
|
|
230
|
-
window.removeEventListener('mouseup', this.handleResizeEnd)
|
|
231
|
-
this.resizeState = null
|
|
232
|
-
this.resizePending = null
|
|
233
|
-
}
|
|
234
|
-
|
|
235
115
|
render() {
|
|
236
116
|
let {
|
|
237
117
|
name,
|
|
@@ -239,7 +119,6 @@ class Block extends React.Component {
|
|
|
239
119
|
pageIndex,
|
|
240
120
|
className,
|
|
241
121
|
printerStore,
|
|
242
|
-
editStore,
|
|
243
122
|
...rest
|
|
244
123
|
} = this.props
|
|
245
124
|
const { isEdit } = this.state
|
|
@@ -307,14 +186,6 @@ class Block extends React.Component {
|
|
|
307
186
|
}
|
|
308
187
|
|
|
309
188
|
const active = name === printerStore.selected
|
|
310
|
-
const { isResizing } = this.state
|
|
311
|
-
const showResizeHandles = !!(
|
|
312
|
-
active &&
|
|
313
|
-
type === 'image' &&
|
|
314
|
-
editStore &&
|
|
315
|
-
editStore.imageConfig &&
|
|
316
|
-
editStore.imageConfig.resizable
|
|
317
|
-
)
|
|
318
189
|
|
|
319
190
|
return (
|
|
320
191
|
<div
|
|
@@ -322,7 +193,7 @@ class Block extends React.Component {
|
|
|
322
193
|
className={classNames('gm-printer-block', className, {
|
|
323
194
|
active
|
|
324
195
|
})}
|
|
325
|
-
draggable
|
|
196
|
+
draggable
|
|
326
197
|
onDragStart={this.handleDragStart}
|
|
327
198
|
onDragEnd={this.handleDragEnd}
|
|
328
199
|
onClick={this.handleClick}
|
|
@@ -350,26 +221,6 @@ class Block extends React.Component {
|
|
|
350
221
|
/>
|
|
351
222
|
)}
|
|
352
223
|
{content}
|
|
353
|
-
{showResizeHandles && (
|
|
354
|
-
<>
|
|
355
|
-
<div
|
|
356
|
-
className='gm-printer-resize-handle gm-printer-resize-lt'
|
|
357
|
-
onMouseDown={this.handleResizeStart.bind(this, 'lt')}
|
|
358
|
-
/>
|
|
359
|
-
<div
|
|
360
|
-
className='gm-printer-resize-handle gm-printer-resize-rt'
|
|
361
|
-
onMouseDown={this.handleResizeStart.bind(this, 'rt')}
|
|
362
|
-
/>
|
|
363
|
-
<div
|
|
364
|
-
className='gm-printer-resize-handle gm-printer-resize-lb'
|
|
365
|
-
onMouseDown={this.handleResizeStart.bind(this, 'lb')}
|
|
366
|
-
/>
|
|
367
|
-
<div
|
|
368
|
-
className='gm-printer-resize-handle gm-printer-resize-rb'
|
|
369
|
-
onMouseDown={this.handleResizeStart.bind(this, 'rb')}
|
|
370
|
-
/>
|
|
371
|
-
</>
|
|
372
|
-
)}
|
|
373
224
|
</div>
|
|
374
225
|
)
|
|
375
226
|
}
|
|
@@ -380,8 +231,7 @@ Block.propTypes = {
|
|
|
380
231
|
config: PropTypes.object.isRequired,
|
|
381
232
|
pageIndex: PropTypes.number.isRequired,
|
|
382
233
|
className: PropTypes.string,
|
|
383
|
-
printerStore: PropTypes.object
|
|
384
|
-
editStore: PropTypes.object
|
|
234
|
+
printerStore: PropTypes.object
|
|
385
235
|
}
|
|
386
236
|
|
|
387
237
|
export default Block
|
|
@@ -62,8 +62,7 @@ function init() {
|
|
|
62
62
|
* 影响合计行渲染与行高,进而影响分页边界)
|
|
63
63
|
* @returns {Promise<{pages: Array, remainPageHeight: number, tableCustomerRowHeight: number}>}
|
|
64
64
|
* pages: [[{type, index, begin, end}, ...], ...] 对 data._table[contents[i].dataKey] 行号的切片
|
|
65
|
-
* remainPageHeight:
|
|
66
|
-
* 无填充表格时为末页剩余;供行数填充换算)
|
|
65
|
+
* remainPageHeight: 最后一页剩余高度(供行数填充换算)
|
|
67
66
|
* tableCustomerRowHeight: 表格行高(供行数填充换算)
|
|
68
67
|
*/
|
|
69
68
|
function computePages({ data, config, isSomeSubtotalTr }) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import _ from 'lodash'
|
|
3
|
-
import { getDataKey, isMultiTable
|
|
3
|
+
import { getDataKey, isMultiTable } from '../util'
|
|
4
4
|
import Big from 'big.js'
|
|
5
5
|
import { observer } from 'mobx-react'
|
|
6
6
|
import { get } from 'mobx'
|
|
@@ -19,8 +19,6 @@ const regExp = text => {
|
|
|
19
19
|
* @returns {*|string}
|
|
20
20
|
*/
|
|
21
21
|
const sumCol = (key, dataList, summaryFieldsResultToNumber = []) => {
|
|
22
|
-
// 任一值脱敏 '***' 则合计显 '***'(原逻辑 Big('***') 抛异常被 catch,合计显空串)
|
|
23
|
-
if (dataList.some(item => isMaskedValue(item[key]))) return MASKED_VALUE
|
|
24
22
|
let result
|
|
25
23
|
try {
|
|
26
24
|
result = dataList
|
package/src/printer/printer.js
CHANGED
|
@@ -100,13 +100,6 @@ class Printer extends React.Component {
|
|
|
100
100
|
await this.props.printerStore.setFillIndex(nextProps.fillIndex)
|
|
101
101
|
await this.props.printerStore.setData(nextProps.data)
|
|
102
102
|
await this.props.printerStore.setReady(true)
|
|
103
|
-
// 与 componentDidMount 同序:先按当前数据分页拿到行数填充基准,再补空行、
|
|
104
|
-
// 按补空后的数据重新分页。缺前置分页时 changeTableData 只能用上一轮
|
|
105
|
-
// (可能已含空行)的 remainPageHeight 换算行数,开关填充时行数会偏小或偏大
|
|
106
|
-
await this.props.printerStore.computedPages()
|
|
107
|
-
// 把「未补空」基准回报给编辑器,与挂载流程同口径
|
|
108
|
-
this.props.getremainpageHeight &&
|
|
109
|
-
this.props.getremainpageHeight(this.props.printerStore.remainPageHeight)
|
|
110
103
|
await this.props.printerStore.changeTableData()
|
|
111
104
|
await this.props.printerStore.computedPages()
|
|
112
105
|
}
|
|
@@ -139,7 +132,7 @@ class Printer extends React.Component {
|
|
|
139
132
|
printerStore.changeTableData()
|
|
140
133
|
printerStore.computedPages()
|
|
141
134
|
}
|
|
142
|
-
// 获取剩余空白高度,传到
|
|
135
|
+
// 获取剩余空白高度,传到editor
|
|
143
136
|
getremainpageHeight && getremainpageHeight(printerStore.remainPageHeight)
|
|
144
137
|
}
|
|
145
138
|
printerStore.setReady(true)
|
package/src/printer/store.js
CHANGED
|
@@ -7,8 +7,7 @@ import {
|
|
|
7
7
|
getDataKey,
|
|
8
8
|
caclSingleDetailsPageHeight,
|
|
9
9
|
getArrayMid,
|
|
10
|
-
getOverallOrderTrHeight
|
|
11
|
-
isMaskedValue
|
|
10
|
+
getOverallOrderTrHeight
|
|
12
11
|
} from '../util'
|
|
13
12
|
import {
|
|
14
13
|
isDetailOneRowSelectKey,
|
|
@@ -47,8 +46,6 @@ const canSplitRowDetails = (dataKey, row) => {
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
const price = (n, f = 2) => {
|
|
50
|
-
// 脱敏值 '***' 原样返回(不能走 isNaN 判空,空单元格仍需显空)
|
|
51
|
-
if (isMaskedValue(n)) return n
|
|
52
49
|
if (isNaN(n)) return null
|
|
53
50
|
return Big(n || 0).toFixed(f)
|
|
54
51
|
}
|
|
@@ -68,7 +65,7 @@ class PrinterStore {
|
|
|
68
65
|
|
|
69
66
|
@observable pages = [] // [{type, index, begin, end}]
|
|
70
67
|
|
|
71
|
-
/**
|
|
68
|
+
/** 当前页剩余空白高度 */
|
|
72
69
|
@observable remainPageHeight = 0
|
|
73
70
|
@observable isSave = false
|
|
74
71
|
/** data._table 非 observable,变更后递增以驱动预览重渲 */
|
|
@@ -327,8 +324,6 @@ class PrinterStore {
|
|
|
327
324
|
|
|
328
325
|
// 使用本地数组累积分页结果,避免循环中反复触发 observable 更新
|
|
329
326
|
const pages = []
|
|
330
|
-
// 各表格的行高数组(含明细拆分 splice 后的结果),供行数填充基准按同一口径复算
|
|
331
|
-
const splicedHeightsMap = {}
|
|
332
327
|
// 每页必有 页眉header, 页脚footer , 签名
|
|
333
328
|
const allPagesHaveThisHeight = heightMap.header + heightMap.footer
|
|
334
329
|
// 退出计算! 因为页眉 + 页脚 > currentPageHeight,页面装不下其他东西
|
|
@@ -364,15 +359,43 @@ class PrinterStore {
|
|
|
364
359
|
index++
|
|
365
360
|
continue
|
|
366
361
|
}
|
|
367
|
-
const {
|
|
368
|
-
|
|
369
|
-
|
|
362
|
+
const {
|
|
363
|
+
subtotal,
|
|
364
|
+
dataKey,
|
|
365
|
+
summaryConfig,
|
|
366
|
+
overallOrder,
|
|
367
|
+
diySubtotal
|
|
368
|
+
} = content
|
|
369
|
+
// 如果显示每页合计,那么table高度多预留一行高度
|
|
370
|
+
const subtotalTrHeight = subtotal.show ? getSumTrHeight(subtotal) : 0
|
|
371
|
+
// 如果显示整单合计,那么table高度多预留一行高度
|
|
372
|
+
const overallOrderTrHeight = overallOrder?.show
|
|
373
|
+
? getOverallOrderTrHeight(overallOrder)
|
|
374
|
+
: 0
|
|
375
|
+
// 如果每页合计(新的),那么table高度多预留一行高度
|
|
376
|
+
const pageSummaryTrHeight =
|
|
377
|
+
summaryConfig?.pageSummaryShow && !isMultiTable(dataKey) // 双栏table没有每页合计
|
|
378
|
+
? getSumTrHeight(summaryConfig)
|
|
379
|
+
: 0
|
|
380
|
+
|
|
381
|
+
// 如果显示自定义每页合计,那么table高度多预留一行高度
|
|
382
|
+
const diySubtotalTrHeight = diySubtotal?.show
|
|
383
|
+
? getOverallOrderTrHeight(diySubtotal) // 使用相同的计算方式
|
|
384
|
+
: 0
|
|
385
|
+
|
|
386
|
+
// 每个表格都具有的高度
|
|
387
|
+
const allTableHaveThisHeight =
|
|
388
|
+
table.head.height +
|
|
389
|
+
subtotalTrHeight +
|
|
390
|
+
pageSummaryTrHeight +
|
|
391
|
+
overallOrderTrHeight +
|
|
392
|
+
diySubtotalTrHeight
|
|
370
393
|
|
|
371
394
|
/** 当前page页面的最小高度 */
|
|
372
395
|
const currentPageMinimumHeight =
|
|
373
396
|
allPagesHaveThisHeight + allTableHaveThisHeight
|
|
374
397
|
// 最后一项是表格时,末页仍要渲染签名:装行可用高度预留签名,避免空行顶进签名区
|
|
375
|
-
const isLastContent = index ===
|
|
398
|
+
const isLastContent = index === this.config.contents.length - 1
|
|
376
399
|
const signReserve = isLastContent ? this.getSignHeight() : 0
|
|
377
400
|
/** 当前page可容纳的table高度 */
|
|
378
401
|
let pageAccomodateTableHeight = roundHeight(
|
|
@@ -382,8 +405,6 @@ class PrinterStore {
|
|
|
382
405
|
const heights = [
|
|
383
406
|
...this.getNormalTableBodyHeights(table.body.heights, dataKey)
|
|
384
407
|
]
|
|
385
|
-
// 保留引用:该数组会被明细拆分 splice,填充基准需要用拆分后的行高
|
|
386
|
-
splicedHeightsMap[index] = heights
|
|
387
408
|
const tableData = tableDataMap[dataKey] || []
|
|
388
409
|
// 表格行的索引,用于table.slice(begin, end), 分割到不同页面中
|
|
389
410
|
let begin = 0
|
|
@@ -466,7 +487,7 @@ class PrinterStore {
|
|
|
466
487
|
)
|
|
467
488
|
break
|
|
468
489
|
}
|
|
469
|
-
//
|
|
490
|
+
// 行无法拆分(普通长文本列)或拆分失败
|
|
470
491
|
if (end === begin) {
|
|
471
492
|
// 新一页可容纳的 table 高度(页高 - 页眉页脚)
|
|
472
493
|
const fullPageAccomodateTableHeight = roundHeight(
|
|
@@ -585,127 +606,15 @@ class PrinterStore {
|
|
|
585
606
|
currentPageHeight += this.getSignHeight()
|
|
586
607
|
}
|
|
587
608
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
// 下一页渲染成空表格,或把同页后续表格挤到下一页。
|
|
592
|
-
// 填充基准不做 Math.round 向上取整,避免整行边界多算 ≤1px 导致重分页时溢出
|
|
593
|
-
const fillRemainHeight = this.computeFillTableRemainHeight(
|
|
594
|
-
pages,
|
|
595
|
-
pageHeight,
|
|
596
|
-
heightMap,
|
|
597
|
-
splicedHeightsMap
|
|
609
|
+
this.remainPageHeight = Math.max(
|
|
610
|
+
0,
|
|
611
|
+
Math.round(pageHeight - currentPageHeight)
|
|
598
612
|
)
|
|
599
|
-
this.remainPageHeight =
|
|
600
|
-
fillRemainHeight != null
|
|
601
|
-
? Math.max(0, fillRemainHeight)
|
|
602
|
-
: Math.max(0, Math.round(pageHeight - currentPageHeight))
|
|
603
613
|
this.isSave = false
|
|
604
614
|
this.config.isSave = false
|
|
605
615
|
this.repackVerticalMultiByPages()
|
|
606
616
|
}
|
|
607
617
|
|
|
608
|
-
/** 表格固定高度:表头 + 每页/整单/自定义合计行(不含数据行),与 computedPages 分页口径一致 */
|
|
609
|
-
getTableAllHaveHeight(contentIndex) {
|
|
610
|
-
const table = this.tablesInfo[`contents.table.${contentIndex}`]
|
|
611
|
-
if (!table?.head) return 0
|
|
612
|
-
const content = this.config.contents[contentIndex]
|
|
613
|
-
const {
|
|
614
|
-
subtotal,
|
|
615
|
-
dataKey,
|
|
616
|
-
summaryConfig,
|
|
617
|
-
overallOrder,
|
|
618
|
-
diySubtotal
|
|
619
|
-
} = content
|
|
620
|
-
// 如果显示每页合计,那么table高度多预留一行高度
|
|
621
|
-
const subtotalTrHeight = subtotal.show ? getSumTrHeight(subtotal) : 0
|
|
622
|
-
// 如果显示整单合计,那么table高度多预留一行高度
|
|
623
|
-
const overallOrderTrHeight = overallOrder?.show
|
|
624
|
-
? getOverallOrderTrHeight(overallOrder)
|
|
625
|
-
: 0
|
|
626
|
-
// 如果每页合计(新的),那么table高度多预留一行高度
|
|
627
|
-
const pageSummaryTrHeight =
|
|
628
|
-
summaryConfig?.pageSummaryShow && !isMultiTable(dataKey) // 双栏table没有每页合计
|
|
629
|
-
? getSumTrHeight(summaryConfig)
|
|
630
|
-
: 0
|
|
631
|
-
// 如果显示自定义每页合计,那么table高度多预留一行高度
|
|
632
|
-
const diySubtotalTrHeight = diySubtotal?.show
|
|
633
|
-
? getOverallOrderTrHeight(diySubtotal) // 使用相同的计算方式
|
|
634
|
-
: 0
|
|
635
|
-
|
|
636
|
-
return (
|
|
637
|
-
table.head.height +
|
|
638
|
-
subtotalTrHeight +
|
|
639
|
-
pageSummaryTrHeight +
|
|
640
|
-
overallOrderTrHeight +
|
|
641
|
-
diySubtotalTrHeight
|
|
642
|
-
)
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
/** 行数填充目标表格在 contents 中的索引(对齐 tableConfig 的解析口径),无法解析返回 null */
|
|
646
|
-
getFillTableContentIndex() {
|
|
647
|
-
const { autoFillConfig } = this.config
|
|
648
|
-
// checked 为 false 时 region 也保留着(编辑器开关来回切),此时同样能定位,
|
|
649
|
-
// 让基准在「未开启填充」的分页里也保持正确口径
|
|
650
|
-
if (!this.selectedRegion && !autoFillConfig?.region) return null
|
|
651
|
-
const region = this.selectedRegion || autoFillConfig.region
|
|
652
|
-
const contentIndex = Number(region.split('.')[2])
|
|
653
|
-
const content = this.config.contents[contentIndex]
|
|
654
|
-
if (!content || !_.has(content, 'dataKey')) return null
|
|
655
|
-
return contentIndex
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* 填充表格最后一段所在页的剩余高度(表格底部到该页可用底边的空白)。
|
|
660
|
-
* 高度口径与 computedPages 一致:页眉页脚 + 该页各内容
|
|
661
|
-
* (表格固定高度 + 分段行高 / panel 实测高),所在页为末页时再扣签名区。
|
|
662
|
-
* 定位不到填充表格(未配置 / 表格无数据被跳过)时返回 null,由调用方退回旧口径。
|
|
663
|
-
*/
|
|
664
|
-
computeFillTableRemainHeight(
|
|
665
|
-
pages,
|
|
666
|
-
pageHeight,
|
|
667
|
-
heightMap,
|
|
668
|
-
splicedHeightsMap
|
|
669
|
-
) {
|
|
670
|
-
const fillIndex = this.getFillTableContentIndex()
|
|
671
|
-
if (fillIndex == null || !pages?.length) return null
|
|
672
|
-
|
|
673
|
-
// 定位填充表格最后一个分段所在的页(一个表格每页至多一个分段)
|
|
674
|
-
let pageIndex = -1
|
|
675
|
-
for (let i = pages.length - 1; i >= 0; i--) {
|
|
676
|
-
if (
|
|
677
|
-
(pages[i] || []).some(
|
|
678
|
-
panel => panel?.type === 'table' && panel.index === fillIndex
|
|
679
|
-
)
|
|
680
|
-
) {
|
|
681
|
-
pageIndex = i
|
|
682
|
-
break
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
if (pageIndex < 0) return null
|
|
686
|
-
|
|
687
|
-
// 按分页同一套口径累计该页已用高度:表格下方还有内容时一并计入,
|
|
688
|
-
// 填充就只会补「表格与后续内容之间」的空隙,不会把它们挤到下一页
|
|
689
|
-
let used = heightMap.header + heightMap.footer
|
|
690
|
-
;(pages[pageIndex] || []).forEach(panel => {
|
|
691
|
-
if (panel.type === 'table') {
|
|
692
|
-
const heights = splicedHeightsMap[panel.index] || []
|
|
693
|
-
used += this.getTableAllHaveHeight(panel.index)
|
|
694
|
-
for (let r = panel.begin; r < panel.end; r++) {
|
|
695
|
-
used += heights[r] || 0
|
|
696
|
-
}
|
|
697
|
-
} else {
|
|
698
|
-
used += heightMap[`contents.panel.${panel.index}`] || 0
|
|
699
|
-
}
|
|
700
|
-
})
|
|
701
|
-
|
|
702
|
-
// 签名只渲染在最后一页,填充所在页为末页时同样要预留
|
|
703
|
-
const signReserve =
|
|
704
|
-
pageIndex === pages.length - 1 ? this.getSignHeight() : 0
|
|
705
|
-
const remain = pageHeight - used - signReserve
|
|
706
|
-
return Number.isFinite(remain) ? remain : null
|
|
707
|
-
}
|
|
708
|
-
|
|
709
618
|
getTablePageRanges(contentIndex, rows) {
|
|
710
619
|
const ranges = []
|
|
711
620
|
this.pages.forEach(page => {
|
|
@@ -2,9 +2,10 @@ 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 { coverDigit2Uppercase, getDataKey
|
|
5
|
+
import { coverDigit2Uppercase, getDataKey } from '../util'
|
|
6
6
|
import { observer } from 'mobx-react'
|
|
7
7
|
import classNames from 'classnames'
|
|
8
|
+
import Big from 'big.js'
|
|
8
9
|
|
|
9
10
|
const DiyOverallOrder = props => {
|
|
10
11
|
const {
|
|
@@ -14,14 +15,20 @@ const DiyOverallOrder = props => {
|
|
|
14
15
|
} = props
|
|
15
16
|
const tableData = printerStore.data._table[getDataKey(dataKey)] || []
|
|
16
17
|
|
|
17
|
-
//
|
|
18
|
+
// 计算合计
|
|
18
19
|
const sumData = field => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
return _.reduce(
|
|
21
|
+
tableData,
|
|
22
|
+
(a, b, i) => {
|
|
23
|
+
let result = a
|
|
24
|
+
const bRes = printerStore
|
|
25
|
+
.templateTable(field, dataKey, i, pageIndex)
|
|
26
|
+
.replace(/\(\)/g, '')
|
|
27
|
+
result = a.plus(+bRes || 0)
|
|
28
|
+
return result
|
|
29
|
+
},
|
|
30
|
+
Big(0)
|
|
31
|
+
).toFixed(2)
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
if (!diyOverallOrder?.show || !printerStore?.ready) {
|
|
@@ -1,15 +1,11 @@
|
|
|
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
|
-
maskedSum
|
|
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'
|
|
8
|
+
import Big from 'big.js'
|
|
13
9
|
|
|
14
10
|
function buildTemplateField(fieldStr, suffix) {
|
|
15
11
|
// 如果 field 是 "{{列.下单数}}",提取出 "下单数"
|
|
@@ -49,18 +45,39 @@ const DiySummary = props => {
|
|
|
49
45
|
|
|
50
46
|
// 计算合计
|
|
51
47
|
const sumData = field => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
|
|
71
|
+
return _.reduce(
|
|
72
|
+
tableData,
|
|
73
|
+
(a, b, i) => {
|
|
74
|
+
let result = a
|
|
75
|
+
const bRes = getRes(field, i)
|
|
76
|
+
result = a.plus(+bRes || 0)
|
|
77
|
+
return result
|
|
78
|
+
},
|
|
79
|
+
Big(0)
|
|
80
|
+
).toFixed(2)
|
|
64
81
|
|
|
65
82
|
function getRes(field, i) {
|
|
66
83
|
return printerStore
|
|
@@ -4,7 +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 { coverDigit2Uppercase, getDataKey
|
|
7
|
+
import { coverDigit2Uppercase, getDataKey } from '../util'
|
|
8
8
|
import { observer } from 'mobx-react'
|
|
9
9
|
import { get } from 'mobx'
|
|
10
10
|
import classNames from 'classnames'
|
|
@@ -76,18 +76,21 @@ const SubtotalTr = props => {
|
|
|
76
76
|
if (field === 'real_item_price') field = '出库金额'
|
|
77
77
|
if (field === 'settle_money2') field = '结算金额'
|
|
78
78
|
if (field === 'total_money2') field = '金额'
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
79
|
+
return _.reduce(
|
|
80
|
+
list,
|
|
81
|
+
(a, b) => {
|
|
82
|
+
let result = a
|
|
83
|
+
result = a.plus(b[field] || 0)
|
|
84
|
+
if (b?.[field + MULTI_SUFFIX]) {
|
|
85
|
+
result = result.plus(b?.[field + MULTI_SUFFIX])
|
|
86
|
+
}
|
|
87
|
+
if (b?.[field + MULTI_SUFFIX3]) {
|
|
88
|
+
result = result.plus(b?.[field + MULTI_SUFFIX3])
|
|
89
|
+
}
|
|
90
|
+
return result
|
|
91
|
+
},
|
|
92
|
+
Big(0)
|
|
93
|
+
).toFixed(2)
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
const getData = field => {
|