gm-printer 10.14.2-alpha.1 → 10.14.2-alpha.2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-printer",
3
- "version": "10.14.2-alpha.1",
3
+ "version": "10.14.2-alpha.2",
4
4
  "description": "diy printer",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -184,7 +184,7 @@ class EditorField extends React.Component {
184
184
  }
185
185
 
186
186
  renderTable() {
187
- const { tableDataKeyList, editStore } = this.props
187
+ const { tableDataKeyList, editStore, isSomeSubtotalTr } = this.props
188
188
  const { head, headStyle, text, style } = editStore.computedSelectedInfo
189
189
 
190
190
  const {
@@ -219,6 +219,11 @@ class EditorField extends React.Component {
219
219
  // 每页合计样式
220
220
  const overallOrderStyle =
221
221
  (overallOrder && overallOrder?.fields[0].style) || {}
222
+ // 每页合计自定义单元格
223
+ const subtotalUpperCustomCell =
224
+ (editStore.computedTableSpecialConfig?.subtotal &&
225
+ get(subtotal, 'isCustomCells')) ||
226
+ false
222
227
  // 整单合计是否大写
223
228
  const overallOrderNeedUpperCase =
224
229
  (editStore.computedTableSpecialConfig?.overallOrder &&
@@ -411,18 +416,38 @@ class EditorField extends React.Component {
411
416
  subtotalCheckOnChange={editStore.setSubtotalUpperCase}
412
417
  subtotalCheckText='显示大写金额'
413
418
  />
414
- <EditorSubtotalCheck
415
- subtotalCheckDisabled={subtotalNeedUpperCase}
416
- subtotalChecked={subtotalUpperCaseBefore}
417
- subtotalCheckOnChange={editStore.setSubtotalUpperCaseBefore}
418
- subtotalCheckText='大写金额在前'
419
- />
420
- <EditorSubtotalCheck
421
- subtotalCheckDisabled={subtotalNeedUpperCase}
422
- subtotalChecked={subtotalUpperLowerCaseSeparate}
423
- subtotalCheckOnChange={editStore.setSubtotalUpperLowerCaseSeparate}
424
- subtotalCheckText='大、小写金额分左右两边展示'
425
- />
419
+ {/* 结款单不需要这些配置 */}
420
+ {!isSomeSubtotalTr && (
421
+ <>
422
+ <EditorSubtotalCheck
423
+ subtotalCheckDisabled={subtotalNeedUpperCase}
424
+ subtotalChecked={subtotalUpperCaseBefore}
425
+ subtotalCheckOnChange={editStore.setSubtotalUpperCaseBefore}
426
+ subtotalCheckText='大写金额在前'
427
+ />
428
+ <EditorSubtotalCheck
429
+ subtotalCheckDisabled={subtotalNeedUpperCase}
430
+ subtotalChecked={subtotalUpperLowerCaseSeparate}
431
+ subtotalCheckOnChange={
432
+ editStore.setSubtotalUpperLowerCaseSeparate
433
+ }
434
+ subtotalCheckText='大、小写金额分左右两边展示'
435
+ />
436
+ <EditorSubtotalCheck
437
+ subtotalCheckDisabled
438
+ subtotalChecked={subtotalUpperCustomCell}
439
+ subtotalCheckOnChange={editStore.setSubtotalCustomCells}
440
+ subtotalCheckText='开启自定义单元格'
441
+ />
442
+ <Text
443
+ value={
444
+ subtotal && subtotal?.fields?.[1] ? subtotal.fields[1].name : ''
445
+ }
446
+ onChange={editStore.setSubtotalFields}
447
+ style={{ width: '65px', margin: '5px 0 5px 80px' }}
448
+ />
449
+ </>
450
+ )}
426
451
  <Flex>
427
452
  <Flex>{i18next.t('整单合计')}:</Flex>
428
453
  <Fonter
@@ -490,7 +515,8 @@ class EditorField extends React.Component {
490
515
  EditorField.propTypes = {
491
516
  editStore: PropTypes.object,
492
517
  tableDataKeyList: PropTypes.array,
493
- showNewDate: PropTypes.bool
518
+ showNewDate: PropTypes.bool,
519
+ isSomeSubtotalTr: PropTypes.bool
494
520
  }
495
521
  EditorField.defaultProps = {
496
522
  showNewDate: false
@@ -74,7 +74,15 @@ class EditorStore {
74
74
  fontWeight: 'bold'
75
75
  }
76
76
  }
77
-
77
+
78
+ // 每页合计自定义合并单元格
79
+ @observable
80
+ subtotalConfigFields = {
81
+ name: '',
82
+ valueField: '',
83
+ colSpan: 3 // 产品说3个,开启自定义单元格
84
+ }
85
+
78
86
  @computed
79
87
  get computedPrinterKey() {
80
88
  return _.map(this.config, (v, k) => {
@@ -525,11 +533,28 @@ class EditorStore {
525
533
  setSubtotalShow(name) {
526
534
  const arr = name.split('.')
527
535
  const table = this.config.contents[arr[2]]
528
-
536
+ this.overallOrderShow = !this.overallOrderShow
529
537
  // 切换的时候,要把对应table的多余空数据清掉
530
538
  this.clearExtraTableData(table.dataKey)
531
- table.subtotal.show = !table.subtotal.show
539
+
532
540
  this.setAutoFillingConfig(!this.isAutoFilling)
541
+ // 获取td的colSpan
542
+ const colSpanLength = getColSpanLength(table)
543
+ set(table.subtotal, {
544
+ show: !table.subtotal.show
545
+ })
546
+ // 兼容存在后端的模板,subtotal配置没有fields
547
+ if (!table.subtotal?.fields) {
548
+ set(table.subtotal, {
549
+ fields: [
550
+ {
551
+ name: '每页合计:',
552
+ valueField: 'real_item_price',
553
+ colSpan: colSpanLength
554
+ }
555
+ ]
556
+ })
557
+ }
533
558
  }
534
559
 
535
560
  @action
@@ -577,7 +602,7 @@ class EditorStore {
577
602
  @action
578
603
  changeTableDataKey(name, key) {
579
604
  const arr = name.split('.')
580
- const { dataKey, overallOrder } = this.config.contents[arr[2]]
605
+ const { dataKey, overallOrder, subtotal } = this.config.contents[arr[2]]
581
606
  const keyArr = dataKey.split('_')
582
607
  let newDataKey
583
608
  // 当前有这个key则去掉
@@ -601,10 +626,10 @@ class EditorStore {
601
626
  ])
602
627
 
603
628
  this.config.contents[arr[2]].dataKey = newDataKey.join('_')
604
- // 整单合计的单元格要修改
605
- if (overallOrder?.show) {
606
- overallOrder.show = false
607
- }
629
+ // 整单合计不显示
630
+ if (overallOrder?.show) overallOrder.show = false
631
+ // 每页合计不显示
632
+ if (subtotal?.show) subtotal.show = false
608
633
  }
609
634
 
610
635
  @action
@@ -992,6 +1017,7 @@ class EditorStore {
992
1017
  @action.bound
993
1018
  setSubtotalUpperCase() {
994
1019
  if (this.selectedRegion) {
1020
+ this.overallOrderShow = !this.overallOrderShow
995
1021
  const arr = this.selectedRegion.split('.')
996
1022
  const subtotalConfig = this.config.contents[arr[2]].subtotal
997
1023
 
@@ -1011,6 +1037,7 @@ class EditorStore {
1011
1037
  @action.bound
1012
1038
  setSubtotalUpperCaseBefore() {
1013
1039
  if (this.selectedRegion) {
1040
+ this.overallOrderShow = !this.overallOrderShow
1014
1041
  const arr = this.selectedRegion.split('.')
1015
1042
  const subtotalConfig = this.config.contents[arr[2]].subtotal
1016
1043
 
@@ -1023,6 +1050,7 @@ class EditorStore {
1023
1050
  @action.bound
1024
1051
  setSubtotalUpperLowerCaseSeparate() {
1025
1052
  if (this.selectedRegion) {
1053
+ this.overallOrderShow = !this.overallOrderShow
1026
1054
  const arr = this.selectedRegion.split('.')
1027
1055
  const subtotalConfig = this.config.contents[arr[2]].subtotal
1028
1056
 
@@ -1033,6 +1061,72 @@ class EditorStore {
1033
1061
  }
1034
1062
  }
1035
1063
 
1064
+ // 每页合计开启自定义单元格
1065
+ @action.bound
1066
+ setSubtotalCustomCells() {
1067
+ if (this.selectedRegion) {
1068
+ // 作用:触发组件的更新
1069
+ this.overallOrderShow = !this.overallOrderShow
1070
+ const arr = this.selectedRegion.split('.')
1071
+ const table = this.config.contents[arr[2]]
1072
+ const subtotalConfig = table?.subtotal
1073
+ // 没有显示每页合计的时候不可以设置自定义单元格
1074
+ if (!subtotalConfig?.show) return
1075
+ // 多栏表格情况,计算colSpan
1076
+ const colSpanLength = getColSpanLength(table)
1077
+ const oldCustomCells = subtotalConfig?.isCustomCells
1078
+
1079
+ set(subtotalConfig, {
1080
+ isCustomCells: !oldCustomCells
1081
+ })
1082
+ // 兼容已经存在后端的模板,每页合计直接是显示的,导致每页合计配置没有fields,isCustomCells,手动添加上
1083
+ if (oldCustomCells === undefined && !subtotalConfig.fields) {
1084
+ set(subtotalConfig, {
1085
+ fields: [
1086
+ {
1087
+ name: '每页合计:',
1088
+ valueField: 'real_item_price',
1089
+ colSpan: colSpanLength
1090
+ }
1091
+ ]
1092
+ })
1093
+ }
1094
+ // 开启自定义单元格
1095
+ if (subtotalConfig?.isCustomCells) {
1096
+ // fields添加自定义单元格
1097
+ subtotalConfig.fields = [
1098
+ subtotalConfig.fields[0],
1099
+ {
1100
+ ...this.subtotalConfigFields
1101
+ }
1102
+ ]
1103
+ // 重新计算合并单元格的个数
1104
+ subtotalConfig.fields[0].colSpan =
1105
+ colSpanLength - subtotalConfig.fields[1].colSpan
1106
+ } else {
1107
+ // 关闭自定义单元格,fields只有一个
1108
+ subtotalConfig.fields = [subtotalConfig.fields[0]]
1109
+ // 重新计算合并单元格的个数
1110
+ subtotalConfig.fields[0].colSpan = colSpanLength
1111
+ }
1112
+ }
1113
+ }
1114
+
1115
+ // 每页合计自定义单元格文本输入
1116
+ @action.bound
1117
+ setSubtotalFields(value) {
1118
+ if (this.selectedRegion) {
1119
+ const arr = this.selectedRegion.split('.')
1120
+ const table = this.config.contents[arr[2]]
1121
+ const subtotalConfig = table?.subtotal
1122
+
1123
+ if (subtotalConfig.isCustomCells) {
1124
+ const subtotalConfig = table?.subtotal.fields
1125
+ subtotalConfig[1].name = value
1126
+ }
1127
+ }
1128
+ }
1129
+
1036
1130
  // 整单合计设置大写金额
1037
1131
  @action.bound
1038
1132
  setOverallOrderUpperCase() {
@@ -23,7 +23,7 @@ const tableDataKeyList = [
23
23
  @observer
24
24
  class Editor extends React.Component {
25
25
  render() {
26
- const { onSave, showEditor, addFields } = this.props
26
+ const { onSave, showEditor, addFields, isSomeSubtotalTr } = this.props
27
27
 
28
28
  return (
29
29
  <div className='gm-printer-edit'>
@@ -46,7 +46,10 @@ class Editor extends React.Component {
46
46
  <Gap height='10px' />
47
47
  <EditorSelect />
48
48
  <Gap height='5px' />
49
- <EditorField tableDataKeyList={tableDataKeyList} />
49
+ <EditorField
50
+ tableDataKeyList={tableDataKeyList}
51
+ isSomeSubtotalTr={isSomeSubtotalTr}
52
+ />
50
53
  <Gap height='5px' />
51
54
  <EditorAddField addFields={addFields} />
52
55
 
@@ -69,7 +72,8 @@ Editor.propTypes = {
69
72
  onSave: PropTypes.func,
70
73
  showEditor: PropTypes.bool,
71
74
  mockData: PropTypes.object.isRequired,
72
- addFields: PropTypes.object.isRequired
75
+ addFields: PropTypes.object.isRequired,
76
+ isSomeSubtotalTr: PropTypes.bool
73
77
  }
74
78
 
75
79
  Editor.defaultProps = {
@@ -9,7 +9,6 @@ import classNames from 'classnames'
9
9
  const OverallOrder = props => {
10
10
  const {
11
11
  config: { overallOrder },
12
- // range,
13
12
  printerStore,
14
13
  printerStore: {
15
14
  data: { common }
@@ -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
  ],
@@ -66,18 +73,14 @@ const SubtotalTr = props => {
66
73
  if (show && printerStore.ready) {
67
74
  const list = tableData.slice(range.begin, range.end)
68
75
 
69
- const sum = {}
70
-
71
- _.each(fields, v => {
72
- sum[v.name] = sumData(list, v.valueField)
73
- })
74
-
75
- // 定义每页小记的左右两侧内容
76
- let subtotalLeftContent
77
- let subtotalRightContent
78
- let subtotalStr = ''
79
- // 结款单
76
+ // 针对结款单的
80
77
  if (isSomeSubtotalTr) {
78
+ const sum = {}
79
+
80
+ _.each(fields, v => {
81
+ sum[v.name] = sumData(list, v.valueField)
82
+ })
83
+ let subtotalStr = ''
81
84
  for (const name in sum) {
82
85
  const price = sum[name]
83
86
  const priceUpperCase = get(subtotal, 'needUpperCase') // needUpperCase在初始模板中undefined,所以必须用这个方法
@@ -102,61 +105,49 @@ const SubtotalTr = props => {
102
105
  </tr>
103
106
  )
104
107
  } else {
105
- for (const name in sum) {
106
- const price = sum[name]
107
- const priceUpperCase = get(subtotal, 'needUpperCase') // needUpperCase在初始模板中undefined,所以必须用这个方法
108
- ? '大写:' + coverDigit2Uppercase(price)
109
- : ''
110
- if (displayName) {
111
- // 大写金额是否在前
112
- if (isUpperCaseBefore) {
113
- subtotalLeftContent = `${name}${priceUpperCase}`
114
- subtotalRightContent = `${price}`
115
- } else {
116
- subtotalLeftContent = `${price}`
117
- subtotalRightContent = `${name} ${priceUpperCase}`
118
- }
119
- } else {
120
- if (isUpperCaseBefore) {
121
- subtotalLeftContent = `${priceUpperCase}`
122
- subtotalRightContent = `${price}`
123
- } else {
124
- subtotalLeftContent = `${price}`
125
- subtotalRightContent = `${priceUpperCase}`
126
- }
127
- }
128
- }
129
-
130
108
  return (
131
109
  <tr>
132
- <td
133
- colSpan={99}
134
- style={{ fontWeight: 'bold', ...style }}
135
- // dangerouslySetInnerHTML={{
136
- // __html: `${i18next.t('每页合计')}:${subtotalStr}`
137
- // }}flex-grow: 1
138
- >
139
- {/* 大写金额和小写金额分开在表格的两侧,通过控制类名实现,添加类名后,覆盖原来的居中、靠右靠左 */}
140
- <div
141
- className={
142
- isUpperLowerCaseSeparate
143
- ? 'gm-printer-subtotal-UpperLowerCaseSeparate-outer'
144
- : ''
145
- }
146
- >
147
- {i18next.t('每页合计')}:
148
- <span
149
- className={
150
- isUpperLowerCaseSeparate
151
- ? 'gm-printer-subtotal-UpperLowerCaseSeparate-inter'
152
- : ''
153
- }
154
- >
155
- <span>&nbsp;&nbsp;{subtotalLeftContent}&nbsp;&nbsp;</span>
156
- <span>&nbsp;&nbsp;{subtotalRightContent}&nbsp;&nbsp;</span>
157
- </span>
158
- </div>
159
- </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
+ })}
160
151
  </tr>
161
152
  )
162
153
  }