gm-printer 10.41.1 → 10.41.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.
@@ -1,10 +1,9 @@
1
1
  import i18next from '../../locales'
2
2
 
3
3
  /**
4
- * 每页合计设置单选按钮
5
- * id的值是用来计算每页的金额总数,不要轻易随便改
4
+ * 每页合计金额单选
5
+ * id 与 data_to_key 中文 key 对齐,用于对本页行求和,不要轻易改 id
6
6
  */
7
- // 整单合计和每页合计栏都使用的这个
8
7
  const subtotalRadioList = [
9
8
  {
10
9
  value: i18next.t('下单金额'),
@@ -17,6 +16,61 @@ const subtotalRadioList = [
17
16
  {
18
17
  value: i18next.t('实际金额'),
19
18
  id: '实际金额'
19
+ },
20
+ {
21
+ value: i18next.t('变化前金额'),
22
+ id: '变化前金额'
23
+ },
24
+ {
25
+ value: i18next.t('下单金额(不含税)'),
26
+ id: '下单金额_不含税'
27
+ },
28
+ {
29
+ value: i18next.t('实收金额'),
30
+ id: '实收金额'
31
+ },
32
+ {
33
+ value: i18next.t('实收金额(不含税)'),
34
+ id: '实收金额_不含税'
35
+ }
36
+ ]
37
+
38
+ /**
39
+ * 整单合计金额单选(比每页合计多「出库金额(不含税)」)
40
+ * id 与 data.common 中文 key 对齐,取订单已算金额,不重算
41
+ */
42
+ const overallOrderRadioList = [
43
+ {
44
+ value: i18next.t('下单金额'),
45
+ id: '下单金额'
46
+ },
47
+ {
48
+ value: i18next.t('出库金额'),
49
+ id: '出库金额'
50
+ },
51
+ {
52
+ value: i18next.t('实际金额'),
53
+ id: '实际金额'
54
+ },
55
+ {
56
+ value: i18next.t('变化前金额'),
57
+ id: '变化前金额'
58
+ },
59
+ {
60
+ value: i18next.t('下单金额(不含税)'),
61
+ id: '下单金额_不含税'
62
+ },
63
+ {
64
+ value: i18next.t('出库金额(不含税)'),
65
+ id: '出库金额_不含税'
66
+ },
67
+ {
68
+ value: i18next.t('实收金额'),
69
+ id: '实收金额'
70
+ },
71
+ {
72
+ value: i18next.t('实收金额(不含税)'),
73
+ id: '实收金额_不含税'
20
74
  }
21
75
  ]
22
76
 
@@ -26,4 +80,4 @@ const accountRadioList = {
26
80
  实际金额: i18next.t('实际金额')
27
81
  }
28
82
 
29
- export { subtotalRadioList, accountRadioList }
83
+ export { subtotalRadioList, overallOrderRadioList, accountRadioList }
@@ -21,6 +21,7 @@ import withStore from '../common/hoc_with_store'
21
21
  class Editor extends React.Component {
22
22
  render() {
23
23
  const { onSave, showEditor, addFields, isPurchase } = this.props
24
+ const editFieldConfig = addFields?.editFieldConfig
24
25
 
25
26
  return (
26
27
  <div className='gm-printer-edit'>
@@ -43,7 +44,7 @@ class Editor extends React.Component {
43
44
  <Gap height='10px' />
44
45
  <EditorSelect isPurchase={isPurchase} />
45
46
  <Gap height='5px' />
46
- <EditorField />
47
+ <EditorField editFieldConfig={editFieldConfig} />
47
48
  <Gap height='5px' />
48
49
  <EditorAddField addFields={addFields} />
49
50
  <Gap height='5px' />
@@ -14,6 +14,11 @@ import {
14
14
  } from '../common/component'
15
15
  import _ from 'lodash'
16
16
  import { inject, observer } from 'mobx-react'
17
+ import {
18
+ buildDataKey,
19
+ getDataKeyPrefix,
20
+ isDetailOneRowSelectKey,
21
+ } from '../common/data_key_util'
17
22
 
18
23
  const dataKeyList = [
19
24
  { value: 'purchase_no_detail', text: i18next.t('不打印明细') },
@@ -57,8 +62,11 @@ const detailSortOptionsForMerchant = [
57
62
  @observer
58
63
  class TableDetailEditor extends React.Component {
59
64
  handleDataKeyChange = dataKey => {
60
- const { editStore } = this.props
61
- editStore.setPurchaseTableKey(dataKey)
65
+ const { editStore, addFields } = this.props
66
+ editStore.setPurchaseTableKey(
67
+ dataKey,
68
+ addFields.specialTableConfig
69
+ )
62
70
  }
63
71
 
64
72
  handlePurchaseSettingKeyChange = dataKey => {
@@ -74,28 +82,32 @@ class TableDetailEditor extends React.Component {
74
82
  }
75
83
 
76
84
  handleDetailAddField = ({ key, value }) => {
77
- const { editStore, config } = this.props
78
- if (editStore.computedDataKey === 'purchase_detail_one_row') {
79
- // 序号 {{列.序号}}
85
+ const { editStore, config, addFields } = this.props
86
+ if (isDetailOneRowSelectKey(editStore.computedDataKey)) {
80
87
  const transform = str => {
81
88
  return str
82
- .replace(/{{\s*([^}]+)\s*}}/g, '{{$1}}') // 先标准化(去掉多余空格)
89
+ .replace(/{{\s*([^}]+)\s*}}/g, '{{$1}}')
83
90
  .replace(/{{([^.\s}]+)}}/g, '{{列.$1}}')
84
91
  }
92
+ const prefix = getDataKeyPrefix(config.dataKey)
93
+ const rolSkuKey = buildDataKey(prefix, 'independent_rol_sku')
94
+ const rolAddressKey = buildDataKey(prefix, 'independent_rol_address')
85
95
  if (
86
96
  config.purchaseSettingKey === 'goods' &&
87
- config.dataKey !== 'purchase_independent_rol_sku'
97
+ config.dataKey !== rolSkuKey
88
98
  ) {
89
- editStore.setPurchaseTableKey('purchase_independent_rol_sku')
99
+ editStore.setPurchaseTableKey(rolSkuKey, addFields.specialTableConfig)
90
100
  } else if (
91
101
  config.purchaseSettingKey === 'merchant' &&
92
- config.dataKey !== 'purchase_independent_rol_address'
102
+ config.dataKey !== rolAddressKey
93
103
  ) {
94
- editStore.setPurchaseTableKey('purchase_independent_rol_address')
104
+ editStore.setPurchaseTableKey(
105
+ rolAddressKey,
106
+ addFields.specialTableConfig
107
+ )
95
108
  }
96
109
 
97
110
  editStore.addFieldToTable({ key, value: transform(value) })
98
-
99
111
  return
100
112
  }
101
113
  editStore.specialTextAddField('*' + value)
@@ -113,7 +125,7 @@ class TableDetailEditor extends React.Component {
113
125
 
114
126
  render() {
115
127
  const {
116
- addFields: { detailFields },
128
+ addFields: { detailFields, specialTableConfig = {} },
117
129
  editStore
118
130
  } = this.props
119
131
  const {
@@ -123,18 +135,28 @@ class TableDetailEditor extends React.Component {
123
135
  specialConfig: { template_text, style }
124
136
  } = this.props.config
125
137
 
138
+ const title = specialTableConfig.title || i18next.t('设置采购明细')
139
+ const label = specialTableConfig.label || i18next.t('采购明细')
140
+ // 外部可整体覆盖下拉选项(dataKeyList),否则按 hideDataKeys 过滤默认列表
141
+ const baseDataKeyList = specialTableConfig.dataKeyList || dataKeyList
142
+ const hideDataKeys = specialTableConfig.hideDataKeys || []
143
+ const visibleDataKeyList = _.filter(
144
+ baseDataKeyList,
145
+ v => !hideDataKeys.includes(v.value)
146
+ )
147
+
126
148
  return (
127
149
  <div>
128
- <Title title={i18next.t('设置采购明细')} />
150
+ <Title title={title} />
129
151
  <Gap />
130
152
  <Flex alignCenter className='gm-padding-top-5'>
131
- <div>{i18next.t('采购明细')}:</div>
153
+ <div>{label}:</div>
132
154
  <Select
133
155
  className='gm-printer-edit-select'
134
156
  value={editStore.computedDataKey}
135
157
  onChange={this.handleDataKeyChange}
136
158
  >
137
- {_.map(dataKeyList, v => (
159
+ {_.map(visibleDataKeyList, v => (
138
160
  <Option key={v.value} value={v.value}>
139
161
  {v.text}
140
162
  </Option>
@@ -142,7 +164,7 @@ class TableDetailEditor extends React.Component {
142
164
  </Select>
143
165
  </Flex>
144
166
 
145
- {editStore.computedDataKey === 'purchase_detail_one_row' && (
167
+ {isDetailOneRowSelectKey(editStore.computedDataKey) && (
146
168
  <>
147
169
  <Flex alignCenter className='gm-padding-top-5'>
148
170
  <div>{i18next.t('打印设置')}:</div>
@@ -210,7 +232,7 @@ class TableDetailEditor extends React.Component {
210
232
  </Flex>
211
233
  </div>
212
234
 
213
- {editStore.computedDataKey !== 'purchase_detail_one_row' && (
235
+ {!isDetailOneRowSelectKey(editStore.computedDataKey) && (
214
236
  <>
215
237
  <div className='gm-padding-top-5'>
216
238
  <div>{i18next.t('字段设置')}:</div>
@@ -16,10 +16,14 @@ class TableDetailEditor extends Component {
16
16
  }
17
17
 
18
18
  render() {
19
- const { editStore } = this.props
20
19
  const {
21
20
  addFields: { sumTableConfig }
22
21
  } = this.props
22
+ // 业务侧可传 sumTableConfig.hide=true 隐藏「汇总表」开关;默认展示
23
+ if (sumTableConfig?.hide) {
24
+ return null
25
+ }
26
+ const { editStore } = this.props
23
27
  if (editStore.computedRegionIsTable) {
24
28
  const arr = editStore.selectedRegion.split('.')
25
29
  const tableConfig = editStore.config.contents[arr[2]]
@@ -1,55 +1,71 @@
1
1
  import EditorStore from '../common/editor_store'
2
2
  import { action, observable } from 'mobx'
3
3
  import i18next from '../../locales'
4
+ import { getDataKeySuffix, isLastColDataKey } from '../common/data_key_util'
5
+
6
+ const getPurchaseDefaultDetailText = () =>
7
+ i18next.t('{{采购数量_采购单位}}{{采购单位}}*{{商户名}}*{{商品备注}}')
8
+
9
+ /** 创建/切换「单列-最后一列」时,明细列 text 应与 template_text 一致 */
10
+ const resolveDetailTemplateText = (tableConfig, specialTableConfig) => {
11
+ const existing = tableConfig.specialConfig?.template_text
12
+ if (existing) return existing
13
+ if (specialTableConfig && specialTableConfig.defaultDetailText !== undefined) {
14
+ return specialTableConfig.defaultDetailText
15
+ }
16
+ return getPurchaseDefaultDetailText()
17
+ }
18
+
19
+ const syncLastColColumnText = (tableConfig) => {
20
+ if (!isLastColDataKey(tableConfig.dataKey)) return
21
+ const templateText = tableConfig.specialConfig?.template_text
22
+ if (!templateText) return
23
+ const specialCol = tableConfig.columns?.find((o) => o.isSpecialColumn)
24
+ if (specialCol) specialCol.text = templateText
25
+ }
4
26
 
5
27
  class Store extends EditorStore {
6
28
  constructor({ defaultTableDataKey }) {
7
29
  super()
8
- this.defaultTableDataKey = defaultTableDataKey // 修改默认dataKey
30
+ this.defaultTableDataKey = defaultTableDataKey
9
31
  }
10
32
 
11
33
  @observable
12
34
  customerTag = false
13
35
 
14
- /* start---------设置采购明细相关--------- */
15
36
  @action.bound
16
- setPurchaseTableKey(dataKey) {
17
- // 先移除选中项,安全第一
37
+ init(config, data) {
38
+ super.init(config, data)
39
+ config?.contents?.forEach((tableConfig) => {
40
+ if (tableConfig?.type === 'table') syncLastColColumnText(tableConfig)
41
+ })
42
+ }
43
+
44
+ @action.bound
45
+ setPurchaseTableKey(dataKey, specialTableConfig) {
18
46
  this.selected = null
19
47
  this.setTableDataKey(dataKey)
20
48
 
21
49
  const arr = this.selectedRegion.split('.')
22
50
  const tableConfig = this.config.contents[arr[2]]
23
51
 
24
- // 先去掉所有明细列
25
- const newCols = tableConfig.columns.filter(o => !o.isSpecialColumn)
52
+ const newCols = tableConfig.columns.filter((o) => !o.isSpecialColumn)
26
53
  tableConfig.columns.replace(newCols)
27
54
 
28
- // 单列-总表最后一列,在columns上修改
29
- if (
30
- dataKey === 'purchase_last_col' ||
31
- dataKey === 'purchase_last_col_noLineBreak'
32
- ) {
55
+ if (isLastColDataKey(dataKey)) {
56
+ const templateText = resolveDetailTemplateText(tableConfig, specialTableConfig)
33
57
  tableConfig.columns.push({
34
58
  head: i18next.t('明细'),
35
59
  headStyle: { textAlign: 'center' },
36
60
  style: { textAlign: 'left' },
37
61
  isSpecialColumn: true,
38
62
  separator: '+',
39
- // detailsType: 'purchase_last_col',
40
63
  specialDetailsKey: '__details',
41
- text: i18next.t(
42
- '{{采购数量_采购单位}}{{采购单位}}*{{商户名}}*{{商品备注}}'
43
- )
64
+ text: templateText,
44
65
  })
45
- // 通过detailsType属性区分单列-总表最后一列的数据是否换行展示
46
- dataKey === 'purchase_last_col'
47
- ? (tableConfig.columns[
48
- tableConfig.columns.length - 1
49
- ].detailLastColType = 'purchase_last_col')
50
- : (tableConfig.columns[
51
- tableConfig.columns.length - 1
52
- ].detailLastColType = 'purchase_last_col_noLineBreak')
66
+ const suffix = getDataKeySuffix(dataKey)
67
+ tableConfig.columns[tableConfig.columns.length - 1].detailLastColType =
68
+ suffix === 'last_col' ? 'purchase_last_col' : 'purchase_last_col_noLineBreak'
53
69
  }
54
70
  }
55
71
 
@@ -59,13 +75,9 @@ class Store extends EditorStore {
59
75
  const tableConfig = this.config.contents[arr[2]]
60
76
 
61
77
  tableConfig.specialConfig.template_text = value
62
- // 单列-总表最后一列,在columns上修改
63
- if (
64
- tableConfig.dataKey === 'purchase_last_col' ||
65
- tableConfig.dataKey === 'purchase_last_col_noLineBreak'
66
- ) {
67
- const specialCol = tableConfig.columns.find(o => o.isSpecialColumn)
68
- specialCol.text = value
78
+ if (isLastColDataKey(tableConfig.dataKey)) {
79
+ const specialCol = tableConfig.columns.find((o) => o.isSpecialColumn)
80
+ if (specialCol) specialCol.text = value
69
81
  }
70
82
  }
71
83
 
@@ -75,13 +87,9 @@ class Store extends EditorStore {
75
87
  const tableConfig = this.config.contents[arr[2]]
76
88
 
77
89
  tableConfig.specialConfig.style = value
78
- // 单列-总表最后一列,在columns上修改
79
- if (
80
- tableConfig.dataKey === 'purchase_last_col' ||
81
- tableConfig.dataKey === 'purchase_last_col_noLineBreak'
82
- ) {
83
- const specialCol = tableConfig.columns.find(o => o.isSpecialColumn)
84
- specialCol.style = value
90
+ if (isLastColDataKey(tableConfig.dataKey)) {
91
+ const specialCol = tableConfig.columns.find((o) => o.isSpecialColumn)
92
+ if (specialCol) specialCol.style = value
85
93
  }
86
94
  }
87
95
 
@@ -91,17 +99,12 @@ class Store extends EditorStore {
91
99
  const tableConfig = this.config.contents[arr[2]]
92
100
 
93
101
  tableConfig.specialConfig.template_text += fieldText
94
- // 单列-总表最后一列,在columns上修改
95
- if (
96
- tableConfig.dataKey === 'purchase_last_col' ||
97
- tableConfig.dataKey === 'purchase_last_col_noLineBreak'
98
- ) {
99
- const specialCol = tableConfig.columns.find(o => o.isSpecialColumn)
100
- specialCol.text += fieldText
102
+ if (isLastColDataKey(tableConfig.dataKey)) {
103
+ const specialCol = tableConfig.columns.find((o) => o.isSpecialColumn)
104
+ if (specialCol) specialCol.text += fieldText
101
105
  }
102
106
  }
103
107
 
104
- /* end---------设置采购明细相关--------- */
105
108
  @action.bound
106
109
  switchCustomerTag(val) {
107
110
  const arr = this.selectedRegion.split('.')
@@ -111,7 +111,8 @@ class Table extends React.Component {
111
111
  range,
112
112
  pageIndex,
113
113
  printerStore,
114
- isSomeSubtotalTr
114
+ isSomeSubtotalTr,
115
+ isLastTablePage
115
116
  } = this.props
116
117
  // 数据
117
118
  dataKey = getDataKey(dataKey, arrange)
@@ -202,7 +203,8 @@ class Table extends React.Component {
202
203
  ? printerStore.templateSpecialDetails(
203
204
  col,
204
205
  dataKey,
205
- i
206
+ i,
207
+ config.specialConfig?.template_text
206
208
  )
207
209
  : printerStore
208
210
  .templateTable(
@@ -227,6 +229,7 @@ class Table extends React.Component {
227
229
  range={range}
228
230
  config={config}
229
231
  printerStore={printerStore}
232
+ isLastTablePage={isLastTablePage}
230
233
  />
231
234
  <DiyOverallOrder
232
235
  range={range}
@@ -307,7 +310,8 @@ class Table extends React.Component {
307
310
  ? printerStore.templateSpecialDetails(
308
311
  col,
309
312
  dataKey,
310
- i
313
+ i,
314
+ config.specialConfig?.template_text
311
315
  )
312
316
  : printerStore
313
317
  .templateTable(col.text, dataKey, i, pageIndex)
@@ -327,6 +331,7 @@ class Table extends React.Component {
327
331
  range={range}
328
332
  config={config}
329
333
  printerStore={printerStore}
334
+ isLastTablePage={isLastTablePage}
330
335
  />
331
336
  <DiyOverallOrder
332
337
  range={range}
@@ -385,7 +390,12 @@ Table.propTypes = {
385
390
  pageIndex: PropTypes.number.isRequired,
386
391
  placeholder: PropTypes.string,
387
392
  printerStore: PropTypes.object,
388
- isSomeSubtotalTr: PropTypes.bool
393
+ isSomeSubtotalTr: PropTypes.bool,
394
+ isLastTablePage: PropTypes.bool
395
+ }
396
+
397
+ Table.defaultProps = {
398
+ isLastTablePage: true
389
399
  }
390
400
 
391
401
  export default Table
@@ -13,6 +13,20 @@ import MergePage from './merge_page'
13
13
  import { LONG_PRINT } from '../config'
14
14
  import Big from 'big.js'
15
15
 
16
+ /** 当前 panel 是否为该表格 content 在全部分页中的最后一次出现 */
17
+ const isLastTablePanel = (pages, pageIndex, panelIndexInPage, tableIndex) => {
18
+ for (let pi = pages.length - 1; pi >= 0; pi--) {
19
+ const page = pages[pi] || []
20
+ for (let pji = page.length - 1; pji >= 0; pji--) {
21
+ const p = page[pji]
22
+ if (p?.type === 'table' && p.index === tableIndex) {
23
+ return pi === pageIndex && pji === panelIndexInPage
24
+ }
25
+ }
26
+ }
27
+ return true
28
+ }
29
+
16
30
  // Header Sign Footer 相对特殊,要单独处理
17
31
  const Header = props => (
18
32
  <Panel {...props} name='header' placeholder={i18next.t('页眉')} />
@@ -272,6 +286,12 @@ class Printer extends React.Component {
272
286
  placeholder={`${i18next.t('区域')} ${panel.index}`}
273
287
  pageIndex={i}
274
288
  isSomeSubtotalTr={isSomeSubtotalTr}
289
+ isLastTablePage={isLastTablePanel(
290
+ printerStore.pages,
291
+ i,
292
+ ii,
293
+ panel.index
294
+ )}
275
295
  />
276
296
  )
277
297
 
@@ -7,6 +7,7 @@ import {
7
7
  getArrayMid,
8
8
  getOverallOrderTrHeight
9
9
  } from '../util'
10
+ import { isIndependentRolDataKey } from '../common/data_key_util'
10
11
  import _ from 'lodash'
11
12
  import Big from 'big.js'
12
13
  import { Tip } from '../components'
@@ -604,13 +605,14 @@ class PrinterStore {
604
605
  */
605
606
  templateTableRowSpan(text, dataKey, index, begin) {
606
607
  try {
607
- if (
608
- dataKey !== 'purchase_detail_one_row' &&
609
- dataKey !== 'purchase_independent_rol_sku' &&
610
- dataKey !== 'purchase_independent_rol_address' &&
611
- dataKey !== 'taxRateSales' &&
612
- dataKey !== 'ordinary'
613
- ) {
608
+ // 采购 / 分拣「按明细单行」展开后才做合并单元格(后缀 independent_rol_*)
609
+ const canMerge =
610
+ isIndependentRolDataKey(dataKey) ||
611
+ dataKey === 'taxRateSales' ||
612
+ dataKey === 'ordinary' ||
613
+ dataKey === 'purchase_detail_one_row' ||
614
+ dataKey === 'sorting_detail_detail_one_row'
615
+ if (!canMerge) {
614
616
  return null
615
617
  }
616
618
  const list = this.data._table[dataKey] || this.data._table.orders
@@ -696,12 +698,15 @@ class PrinterStore {
696
698
  }
697
699
  }
698
700
 
699
- templateSpecialDetails(col, dataKey, index) {
700
- // 做好保护,出错就返回 text
701
+ templateSpecialDetails(col, dataKey, index, fallbackText = '') {
701
702
  const { specialDetailsKey, text, detailLastColType, separator } = col
703
+ const templateText = text || fallbackText
704
+ if (!templateText) return ''
702
705
  try {
703
706
  const row = this.data._table[dataKey][index]
704
- const compiled = _.template(text, { interpolate: /{{([\s\S]+?)}}/g })
707
+ const compiled = _.template(templateText, {
708
+ interpolate: /{{([\s\S]+?)}}/g,
709
+ })
705
710
  let detailsList = row[specialDetailsKey] || []
706
711
 
707
712
  /** 简单处理下数据 */
@@ -724,7 +729,7 @@ class PrinterStore {
724
729
 
725
730
  return detailsList
726
731
  } catch (err) {
727
- return text
732
+ return templateText
728
733
  }
729
734
  }
730
735
 
@@ -169,7 +169,8 @@ class Table extends React.Component {
169
169
  range,
170
170
  pageIndex,
171
171
  printerStore,
172
- isSomeSubtotalTr
172
+ isSomeSubtotalTr,
173
+ isLastTablePage
173
174
  } = this.props
174
175
  // 数据
175
176
  dataKey = getDataKey(dataKey, arrange)
@@ -411,7 +412,8 @@ class Table extends React.Component {
411
412
  ? printerStore.templateSpecialDetails(
412
413
  col,
413
414
  dataKey,
414
- i
415
+ i,
416
+ config.specialConfig?.template_text
415
417
  )
416
418
  : printerStore
417
419
  .templateTable(col.text, dataKey, i, pageIndex)
@@ -445,6 +447,7 @@ class Table extends React.Component {
445
447
  range={range}
446
448
  config={config}
447
449
  printerStore={printerStore}
450
+ isLastTablePage={isLastTablePage}
448
451
  />
449
452
  <DiyOverallOrder
450
453
  range={range}
@@ -503,7 +506,12 @@ Table.propTypes = {
503
506
  pageIndex: PropTypes.number.isRequired,
504
507
  placeholder: PropTypes.string,
505
508
  printerStore: PropTypes.object,
506
- isSomeSubtotalTr: PropTypes.bool
509
+ isSomeSubtotalTr: PropTypes.bool,
510
+ isLastTablePage: PropTypes.bool
511
+ }
512
+
513
+ Table.defaultProps = {
514
+ isLastTablePage: true
507
515
  }
508
516
 
509
517
  export default Table