gm-printer 10.14.2 → 10.14.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.
@@ -4,7 +4,8 @@ import {
4
4
  getSumTrHeight,
5
5
  isMultiTable,
6
6
  caclSingleDetailsPageHeight,
7
- getArrayMid
7
+ getArrayMid,
8
+ getOverallOrderTrHeight
8
9
  } from '../util'
9
10
  import _ from 'lodash'
10
11
  import Big from 'big.js'
@@ -172,6 +173,11 @@ class PrinterStore {
172
173
  }
173
174
  }
174
175
 
176
+ @action
177
+ setOverallOrder(config) {
178
+ this.config = config || {}
179
+ }
180
+
175
181
  @action
176
182
  computedData(dataKey, table, end, currentRemainTableHeight) {
177
183
  /** 当前数据 */
@@ -243,9 +249,13 @@ class PrinterStore {
243
249
  tableCount++
244
250
  // 表格原始的高度和宽度信息
245
251
  const table = this.tablesInfo[`contents.table.${index}`]
246
- const { subtotal, dataKey, summaryConfig } = content
252
+ const { subtotal, dataKey, summaryConfig, overallOrder } = content
247
253
  // 如果显示每页合计,那么table高度多预留一行高度
248
254
  const subtotalTrHeight = subtotal.show ? getSumTrHeight(subtotal) : 0
255
+ // 如果显示整单合计,那么table高度多预留一行高度
256
+ const overallOrderTrHeight = overallOrder?.show
257
+ ? getOverallOrderTrHeight(overallOrder)
258
+ : 0
249
259
  // 如果每页合计(新的),那么table高度多预留一行高度
250
260
  const pageSummaryTrHeight =
251
261
  summaryConfig?.pageSummaryShow && !isMultiTable(dataKey) // 双栏table没有每页合计
@@ -253,7 +263,10 @@ class PrinterStore {
253
263
  : 0
254
264
  // 每个表格都具有的高度
255
265
  const allTableHaveThisHeight =
256
- table.head.height + subtotalTrHeight + pageSummaryTrHeight
266
+ table.head.height +
267
+ subtotalTrHeight +
268
+ pageSummaryTrHeight +
269
+ overallOrderTrHeight
257
270
  /** 当前page页面的最小高度 */
258
271
  const currentPageMinimumHeight =
259
272
  allPagesHaveThisHeight + allTableHaveThisHeight
@@ -166,3 +166,15 @@
166
166
  flex-grow: 1;
167
167
  justify-content: space-between;
168
168
  }
169
+ .gm-printer-subtotal-isUpperCaseBefore-inter{
170
+ order:2;
171
+ }
172
+ .gm-flex-justify-between-page{
173
+ justify-content: space-between;
174
+ }
175
+ .gm-flex-grow-page{
176
+ flex-grow: 1;
177
+ }
178
+ .gm-flex-page{
179
+ display:flex
180
+ }
@@ -16,6 +16,7 @@ import { MULTI_SUFFIX } from '../config'
16
16
  import SpecialTr from './table_special_tr'
17
17
  import SubtotalTr from './table_subtotal_tr'
18
18
  import PageSummary from './page_summary'
19
+ import OverallOrder from './table_overallOrder_tr'
19
20
 
20
21
  @inject('printerStore')
21
22
  @observer
@@ -293,6 +294,11 @@ class Table extends React.Component {
293
294
  {this.props.config.subtotal.isCommutationPlace
294
295
  ? PageSummarySubtotalTr()
295
296
  : subtotalTrPageSummary()}
297
+ <OverallOrder
298
+ range={range}
299
+ config={config}
300
+ printerStore={printerStore}
301
+ />
296
302
  </tbody>
297
303
  </table>
298
304
  )
@@ -0,0 +1,65 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import _ from 'lodash'
4
+ // import Big from 'big.js'
5
+ import { coverDigit2Uppercase } from '../util'
6
+ import { observer } from 'mobx-react'
7
+ import classNames from 'classnames'
8
+
9
+ const OverallOrder = props => {
10
+ const {
11
+ config: { overallOrder },
12
+ printerStore,
13
+ printerStore: {
14
+ data: { common }
15
+ }
16
+ } = props
17
+
18
+ return (
19
+ overallOrder?.show &&
20
+ printerStore?.ready && (
21
+ <tr>
22
+ {_.map(overallOrder.fields, (item, index) => {
23
+ return (
24
+ <td colSpan={item.colSpan} key={index}>
25
+ <div style={{ ...item.style }} className='gm-flex-page'>
26
+ {item.name}
27
+ <div
28
+ className={classNames('gm-flex-page', {
29
+ 'gm-flex-justify-between-page':
30
+ overallOrder?.isUpperLowerCaseSeparate,
31
+ 'gm-flex-grow-page': overallOrder?.isUpperLowerCaseSeparate
32
+ })}
33
+ >
34
+ <span
35
+ className={
36
+ overallOrder?.isUpperCaseBefore
37
+ ? 'gm-printer-subtotal-isUpperCaseBefore-inter'
38
+ : ''
39
+ }
40
+ >
41
+ {common?.[item.valueField] ?? ''}
42
+ </span>
43
+ {overallOrder?.needUpperCase && (
44
+ <span>
45
+ {common?.[item.valueField]
46
+ ? coverDigit2Uppercase(common[item.valueField])
47
+ : ''}
48
+ </span>
49
+ )}
50
+ </div>
51
+ </div>
52
+ </td>
53
+ )
54
+ })}
55
+ </tr>
56
+ )
57
+ )
58
+ }
59
+ OverallOrder.propTypes = {
60
+ config: PropTypes.object.isRequired,
61
+ range: PropTypes.object.isRequired,
62
+ printerStore: PropTypes.object
63
+ }
64
+
65
+ export default observer(OverallOrder)
@@ -7,11 +7,18 @@ 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 classNames from 'classnames'
11
+
10
12
  /**
11
13
  * 每页合计组件,分页计算后,根据range来统计每页合计数据
12
14
  * @param props
13
15
  * @returns {*}
14
16
  */
17
+ const flexStyle = {
18
+ left: 'flex-start',
19
+ center: 'center',
20
+ right: 'flex-end'
21
+ }
15
22
  const SubtotalTr = props => {
16
23
  const {
17
24
  config: {
@@ -25,7 +32,7 @@ const SubtotalTr = props => {
25
32
  style,
26
33
  fields = [
27
34
  {
28
- name: i18next.t('出库金额'),
35
+ name: i18next.t('每页合计:'),
29
36
  valueField: 'real_item_price'
30
37
  }
31
38
  ],
@@ -36,7 +43,6 @@ const SubtotalTr = props => {
36
43
  printerStore,
37
44
  isSomeSubtotalTr
38
45
  } = props
39
-
40
46
  const tableData = printerStore.data._table[getDataKey(dataKey, arrange)] || []
41
47
  // 计算合计
42
48
  const sumData = (list, field) => {
@@ -67,18 +73,14 @@ const SubtotalTr = props => {
67
73
  if (show && printerStore.ready) {
68
74
  const list = tableData.slice(range.begin, range.end)
69
75
 
70
- const sum = {}
71
-
72
- _.each(fields, v => {
73
- sum[v.name] = sumData(list, v.valueField)
74
- })
75
-
76
- // 定义每页小记的左右两侧内容
77
- let subtotalLeftContent
78
- let subtotalRightContent
79
- let subtotalStr = ''
80
- // 结款单
76
+ // 针对结款单的
81
77
  if (isSomeSubtotalTr) {
78
+ const sum = {}
79
+
80
+ _.each(fields, v => {
81
+ sum[v.name] = sumData(list, v.valueField)
82
+ })
83
+ let subtotalStr = ''
82
84
  for (const name in sum) {
83
85
  const price = sum[name]
84
86
  const priceUpperCase = get(subtotal, 'needUpperCase') // needUpperCase在初始模板中undefined,所以必须用这个方法
@@ -103,61 +105,49 @@ const SubtotalTr = props => {
103
105
  </tr>
104
106
  )
105
107
  } else {
106
- for (const name in sum) {
107
- const price = sum[name]
108
- const priceUpperCase = get(subtotal, 'needUpperCase') // needUpperCase在初始模板中undefined,所以必须用这个方法
109
- ? '大写:' + coverDigit2Uppercase(price)
110
- : ''
111
- if (displayName) {
112
- // 大写金额是否在前
113
- if (isUpperCaseBefore) {
114
- subtotalLeftContent = `${name}${priceUpperCase}`
115
- subtotalRightContent = `${price}`
116
- } else {
117
- subtotalLeftContent = `${price}`
118
- subtotalRightContent = `${name} ${priceUpperCase}`
119
- }
120
- } else {
121
- if (isUpperCaseBefore) {
122
- subtotalLeftContent = `${priceUpperCase}`
123
- subtotalRightContent = `${price}`
124
- } else {
125
- subtotalLeftContent = `${price}`
126
- subtotalRightContent = `${priceUpperCase}`
127
- }
128
- }
129
- }
130
-
131
108
  return (
132
109
  <tr>
133
- <td
134
- colSpan={99}
135
- style={{ fontWeight: 'bold', ...style }}
136
- // dangerouslySetInnerHTML={{
137
- // __html: `${i18next.t('每页合计')}:${subtotalStr}`
138
- // }}flex-grow: 1
139
- >
140
- {/* 大写金额和小写金额分开在表格的两侧,通过控制类名实现,添加类名后,覆盖原来的居中、靠右靠左 */}
141
- <div
142
- className={
143
- isUpperLowerCaseSeparate
144
- ? 'gm-printer-subtotal-UpperLowerCaseSeparate-outer'
145
- : ''
146
- }
147
- >
148
- {i18next.t('每页合计')}:
149
- <span
150
- className={
151
- isUpperLowerCaseSeparate
152
- ? 'gm-printer-subtotal-UpperLowerCaseSeparate-inter'
153
- : ''
154
- }
155
- >
156
- <span>&nbsp;&nbsp;{subtotalLeftContent}&nbsp;&nbsp;</span>
157
- <span>&nbsp;&nbsp;{subtotalRightContent}&nbsp;&nbsp;</span>
158
- </span>
159
- </div>
160
- </td>
110
+ {_.map(fields, (item, index) => {
111
+ return (
112
+ <td colSpan={item.colSpan ?? 99} key={index}>
113
+ <div
114
+ style={{
115
+ fontWeight: 'bold',
116
+ 'justify-content': flexStyle[subtotal.style?.textAlign], // flex布局中textAlign不生效,改使用justify-content
117
+ ...subtotal.style
118
+ }}
119
+ className='gm-flex-page'
120
+ >
121
+ {item.name}
122
+ <div
123
+ className={classNames('gm-flex-page', {
124
+ 'gm-flex-justify-between-page': isUpperLowerCaseSeparate, // 决定大小写金额是否分开在两端
125
+ 'gm-flex-grow-page': isUpperLowerCaseSeparate
126
+ })}
127
+ >
128
+ <span
129
+ className={
130
+ isUpperCaseBefore // 决定小写金额是否在前
131
+ ? 'gm-printer-subtotal-isUpperCaseBefore-inter'
132
+ : ''
133
+ }
134
+ >
135
+ {/* 这样写是为了支持自定义单元,index = 1时是自定义单元格 */}
136
+ {index === 0 ? sumData(list, item.valueField) : ''}
137
+ </span>
138
+ {subtotal?.needUpperCase && ( // 是否需要大写金额
139
+ <span>
140
+ {index === 0
141
+ ? '大写:' +
142
+ coverDigit2Uppercase(sumData(list, item.valueField))
143
+ : ''}
144
+ </span>
145
+ )}
146
+ </div>
147
+ </div>
148
+ </td>
149
+ )
150
+ })}
161
151
  </tr>
162
152
  )
163
153
  }
package/src/util.js CHANGED
@@ -108,6 +108,14 @@ function getSumTrHeight(SumTr) {
108
108
  return (parseInt(fontSize) - 12) * 1.5 + 26
109
109
  }
110
110
 
111
+ function getOverallOrderTrHeight(overallOrder) {
112
+ const { fields = [] } = overallOrder
113
+ const fontSize = fields?.[0]?.style?.fontSize || '12px'
114
+
115
+ // 12px => 26, 14px => 29, 16px => 33, ...
116
+ return (parseInt(fontSize) - 12) * 1.5 + 26
117
+ }
118
+
111
119
  // eslint-disable-next-line
112
120
  const coverDigit2Uppercase = n => {
113
121
  if (_.isNil(n) || _.isNaN(n)) {
@@ -274,6 +282,17 @@ const getArrayMid = arr => {
274
282
  return majority
275
283
  }
276
284
 
285
+ /**
286
+ * 获取整单合计colSpan合并的个数
287
+ * @param {*} table
288
+ * @returns number
289
+ */
290
+ const getColSpanLength = table => {
291
+ return /multi/.test(table.dataKey)
292
+ ? getMultiNumber(table.dataKey) * table.columns.length
293
+ : table.columns.length
294
+ }
295
+
277
296
  export {
278
297
  getHeight,
279
298
  getWidth,
@@ -291,5 +310,7 @@ export {
291
310
  isMultiTable,
292
311
  getMultiNumber,
293
312
  caclSingleDetailsPageHeight,
294
- getArrayMid
313
+ getArrayMid,
314
+ getColSpanLength,
315
+ getOverallOrderTrHeight
295
316
  }