gm-printer 10.41.1 → 10.41.3-beta.0

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,6 +4,12 @@ import { pageTypeMap } from '../config'
4
4
  import _ from 'lodash'
5
5
  import { dispatchMsg, getBlockName, exchange, getColSpanLength } from '../util'
6
6
  import { accountRadioList } from './util'
7
+ import {
8
+ buildDataKey,
9
+ getDataKeyPrefix,
10
+ isDetailOneRowSelectKey,
11
+ isIndependentRolDataKey
12
+ } from './data_key_util'
7
13
  import React from 'react'
8
14
  import { createDiySummaryStoreMethods } from './diy_summary_helper'
9
15
 
@@ -680,7 +686,6 @@ class EditorStore {
680
686
  // 切换的时候,要把对应table的多余空数据清掉
681
687
  this.clearExtraTableData(table.dataKey)
682
688
 
683
- this.setAutoFillingConfig(!this.isAutoFilling)
684
689
  // 获取td的colSpan
685
690
  const colSpanLength = getColSpanLength(table)
686
691
  set(table.subtotal, {
@@ -773,13 +778,34 @@ class EditorStore {
773
778
  set(table.overallOrder, {
774
779
  show: !table.overallOrder.show
775
780
  })
776
- table.overallOrder.fields[0].colSpan =
777
- colSpanLength - (table.overallOrder.fields?.[1]?.colSpan ?? 0)
781
+ // 老模板补默认:每页展示默认勾选
782
+ if (table.overallOrder.showEachPage === undefined) {
783
+ set(table.overallOrder, { showEachPage: true })
784
+ }
785
+ // 兼容存量/测试模板 overallOrder 只存了 {show:false} 没有 fields,补默认结构,否则 fields[0] 取值崩溃
786
+ if (!table.overallOrder.fields?.length) {
787
+ set(table.overallOrder, {
788
+ fields: [
789
+ {
790
+ name: '整单合计:',
791
+ valueField: '出库金额',
792
+ style: {
793
+ fontWeight: 'bold'
794
+ },
795
+ colSpan: colSpanLength
796
+ }
797
+ ]
798
+ })
799
+ } else {
800
+ table.overallOrder.fields[0].colSpan =
801
+ colSpanLength - (table.overallOrder.fields?.[1]?.colSpan ?? 0)
802
+ }
778
803
  } else {
779
804
  // 兼容已经存在的配送单据,他们的配置存在后端的,没有overallOrder这个配置,给加上
780
805
  set(table, {
781
806
  overallOrder: {
782
807
  show: true,
808
+ showEachPage: true,
783
809
  fields: [
784
810
  {
785
811
  name: '整单合计:',
@@ -796,6 +822,19 @@ class EditorStore {
796
822
  this.config = toJS(this.config)
797
823
  }
798
824
 
825
+ // 整单合计「每页展示」
826
+ @action.bound
827
+ setOverallOrderShowEachPage() {
828
+ if (!this.selectedRegion) return
829
+ const arr = this.selectedRegion.split('.')
830
+ const table = this.config.contents[arr[2]]
831
+ if (!table?.overallOrder) return
832
+ this.overallOrderShow = !this.overallOrderShow
833
+ const next = !(table.overallOrder.showEachPage !== false)
834
+ set(table.overallOrder, { showEachPage: next })
835
+ this.config = toJS(this.config)
836
+ }
837
+
799
838
  @action
800
839
  setDiyOverallOrderShow(name) {
801
840
  const arr = name.split('.')
@@ -898,6 +937,54 @@ class EditorStore {
898
937
  ) {
899
938
  newDataKey = _.without(newDataKey, 'tag', 'tagDiy')
900
939
  }
940
+ // 标签小计和三级分类小计互斥
941
+ if (
942
+ newDataKey.includes('category3') &&
943
+ (key === 'tag' || key === 'tagDiy')
944
+ ) {
945
+ newDataKey = _.without(newDataKey, 'category3')
946
+ } else if (
947
+ (newDataKey.includes('tag') || newDataKey.includes('tagDiy')) &&
948
+ key === 'category3'
949
+ ) {
950
+ newDataKey = _.without(newDataKey, 'tag', 'tagDiy')
951
+ }
952
+ // 标签小计和商品三级分类互斥
953
+ if (
954
+ newDataKey.includes('newCategory3') &&
955
+ (key === 'tag' || key === 'tagDiy')
956
+ ) {
957
+ newDataKey = _.without(newDataKey, 'newCategory3')
958
+ } else if (
959
+ (newDataKey.includes('tag') || newDataKey.includes('tagDiy')) &&
960
+ key === 'newCategory3'
961
+ ) {
962
+ newDataKey = _.without(newDataKey, 'tag', 'tagDiy')
963
+ }
964
+ // 商品三级分类和商品分类互斥(标题维度一级/三级二选一)
965
+ if (newDataKey.includes('newCategory3') && key === 'newCategory') {
966
+ newDataKey = _.without(newDataKey, 'newCategory3')
967
+ } else if (newDataKey.includes('newCategory') && key === 'newCategory3') {
968
+ newDataKey = _.without(newDataKey, 'newCategory')
969
+ }
970
+ // 三级分类小计和分类小计互斥(小计维度一级/三级二选一)
971
+ if (newDataKey.includes('category3') && key === 'category') {
972
+ newDataKey = _.without(newDataKey, 'category3')
973
+ } else if (newDataKey.includes('category') && key === 'category3') {
974
+ newDataKey = _.without(newDataKey, 'category')
975
+ }
976
+ // 跨层级混搭互斥:商品三级分类(三级标题)不配一级分类小计
977
+ if (newDataKey.includes('newCategory3') && key === 'category') {
978
+ newDataKey = _.without(newDataKey, 'newCategory3')
979
+ } else if (newDataKey.includes('category') && key === 'newCategory3') {
980
+ newDataKey = _.without(newDataKey, 'category')
981
+ }
982
+ // 跨层级混搭互斥:三级分类小计(三级小计)不配一级商品分类
983
+ if (newDataKey.includes('category3') && key === 'newCategory') {
984
+ newDataKey = _.without(newDataKey, 'category3')
985
+ } else if (newDataKey.includes('newCategory') && key === 'category3') {
986
+ newDataKey = _.without(newDataKey, 'newCategory')
987
+ }
901
988
 
902
989
  if (newDataKey.includes('categoryDiy')) {
903
990
  if (!diyCategorySubtotal?.show) {
@@ -924,7 +1011,10 @@ class EditorStore {
924
1011
  o => o === 'tag',
925
1012
  o => o === 'multi3',
926
1013
  o => o === 'multi',
1014
+ // 三级 token 紧跟对应一级 token 之后,保证拼串顺序 orders → category → category3 → newCategory → newCategory3 → multi → multi3 → tag → categoryDiy → tagDiy
1015
+ o => o === 'newCategory3',
927
1016
  o => o === 'newCategory',
1017
+ o => o === 'category3',
928
1018
  o => o === 'category',
929
1019
  o => o === 'orders'
930
1020
  ])
@@ -933,12 +1023,33 @@ class EditorStore {
933
1023
 
934
1024
  this.config.contents[arr[2]].dataKey = newDataKey.join('_')
935
1025
 
936
- // 整单合计不显示
937
- if (overallOrder?.show) overallOrder.show = false
938
- // 每页合计不显示
939
- if (subtotal?.show) subtotal.show = false
940
- // 自定义每页合计不显示
941
- if (diyOverallOrder?.show) diyOverallOrder.show = false
1026
+ // 三级分类相关 token(商品三级分类/三级分类小计)是纯分组、标题能力,
1027
+ // 与每页/整单合计可共存,切换时不再强制关闭合计开关;
1028
+ // 其余 token(多栏/一级分类/标签等)保持历史行为:切换时强制关闭
1029
+ if (!['newCategory3', 'category3'].includes(key)) {
1030
+ // 整单合计不显示
1031
+ if (overallOrder?.show) overallOrder.show = false
1032
+ // 每页合计不显示
1033
+ if (subtotal?.show) subtotal.show = false
1034
+ // 自定义每页合计不显示
1035
+ if (diyOverallOrder?.show) diyOverallOrder.show = false
1036
+ }
1037
+
1038
+ // 行数填充开启时切换 token:清掉旧 key 上的空行,并把 autoFillConfig.dataKey
1039
+ // 同步到新 key(printerStore 按两者相等才追加填充高度),交给 Printer 重挂载后重补
1040
+ if (this.isAutoFilling || this.config?.autoFillConfig?.checked) {
1041
+ this.clearAllTableEmptyData()
1042
+ this.setAutoFillingConfig(true)
1043
+ set(this.config, {
1044
+ autoFillConfig: {
1045
+ ...(this.config.autoFillConfig || {}),
1046
+ region: this.selectedRegion || this.config.autoFillConfig?.region,
1047
+ dataKey: newDataKey.join('_'),
1048
+ checked: true,
1049
+ fillIndex: this.fillIndex
1050
+ }
1051
+ })
1052
+ }
942
1053
  }
943
1054
 
944
1055
  @action
@@ -1251,16 +1362,17 @@ class EditorStore {
1251
1362
  const table = this.config.contents[arr[2]]
1252
1363
 
1253
1364
  const getDataKey = () => {
1254
- if (dataKey === 'purchase_detail_one_row') {
1365
+ if (isDetailOneRowSelectKey(dataKey)) {
1255
1366
  if (!table.purchaseSettingKey) {
1256
1367
  this.setPurchasePrintSettingKey()
1257
1368
  return dataKey
1258
1369
  }
1370
+ const prefix = getDataKeyPrefix(dataKey)
1259
1371
  if (table.purchaseSettingKey === 'goods') {
1260
- return 'purchase_independent_rol_sku'
1372
+ return buildDataKey(prefix, 'independent_rol_sku')
1261
1373
  }
1262
1374
  if (table.purchaseSettingKey === 'merchant') {
1263
- return 'purchase_independent_rol_address'
1375
+ return buildDataKey(prefix, 'independent_rol_address')
1264
1376
  }
1265
1377
  }
1266
1378
  return dataKey
@@ -1280,14 +1392,14 @@ class EditorStore {
1280
1392
  @action.bound setPurchasePrintSettingKey(dataKey = 'goods') {
1281
1393
  const arr = this.selectedRegion.split('.')
1282
1394
  const table = this.config.contents[arr[2]]
1395
+ const prefix = getDataKeyPrefix(table.dataKey)
1283
1396
 
1284
1397
  set(table, {
1285
1398
  purchaseSettingKey: dataKey,
1286
1399
  dataKey:
1287
1400
  dataKey === 'goods'
1288
- ? 'purchase_independent_rol_sku'
1289
- : 'purchase_independent_rol_address',
1290
- // 切换打印设置时,重置明细行排序为默认值(候选值列表会变化)
1401
+ ? buildDataKey(prefix, 'independent_rol_sku')
1402
+ : buildDataKey(prefix, 'independent_rol_address'),
1291
1403
  detail_sort_type: 0
1292
1404
  })
1293
1405
  }
@@ -1309,11 +1421,8 @@ class EditorStore {
1309
1421
  const table = this.config.contents[arr[2]]
1310
1422
 
1311
1423
  const { dataKey } = table
1312
- if (
1313
- dataKey === 'purchase_independent_rol_sku' ||
1314
- dataKey === 'purchase_independent_rol_address'
1315
- ) {
1316
- return 'purchase_detail_one_row'
1424
+ if (isIndependentRolDataKey(dataKey)) {
1425
+ return buildDataKey(getDataKeyPrefix(dataKey), 'detail_one_row')
1317
1426
  }
1318
1427
  return dataKey
1319
1428
  }
@@ -1548,6 +1657,42 @@ class EditorStore {
1548
1657
  }
1549
1658
  }
1550
1659
 
1660
+ // 分类/标签 小计 - 显示分类名称(商品分类/商品三级分类小计行是否展示分类名,默认展示)
1661
+ @action.bound setShowCategoryName() {
1662
+ // 作用:触发组件的更新(小计行前缀由渲染层按 specialConfig 实时重拼,需触发预览重渲染)
1663
+ this.overallOrderShow = !this.overallOrderShow
1664
+ if (this.selectedRegion) {
1665
+ const arr = this.selectedRegion.split('.')
1666
+ const tableConfig = this.config.contents[arr[2]]
1667
+
1668
+ set(tableConfig, {
1669
+ specialConfig: {
1670
+ ...tableConfig.specialConfig,
1671
+ showCategoryName: !(
1672
+ tableConfig.specialConfig?.showCategoryName ?? true
1673
+ )
1674
+ }
1675
+ })
1676
+ }
1677
+ }
1678
+
1679
+ // 分类/标签 小计 - 小计文案修改(默认"小计",允许为空;缺失时由数据层兜底默认值)
1680
+ @action.bound setSubtotalText(value) {
1681
+ // 作用:触发组件的更新(小计行前缀由渲染层按 specialConfig 实时重拼,需触发预览重渲染)
1682
+ this.overallOrderShow = !this.overallOrderShow
1683
+ if (this.selectedRegion) {
1684
+ const arr = this.selectedRegion.split('.')
1685
+ const tableConfig = this.config.contents[arr[2]]
1686
+
1687
+ set(tableConfig, {
1688
+ specialConfig: {
1689
+ ...tableConfig.specialConfig,
1690
+ subtotalText: value
1691
+ }
1692
+ })
1693
+ }
1694
+ }
1695
+
1551
1696
  @action.bound
1552
1697
  setSpecialUpperCase() {
1553
1698
  if (this.selectedRegion) {
@@ -1743,6 +1888,8 @@ class EditorStore {
1743
1888
  }
1744
1889
  // 开启自定义单元格
1745
1890
  if (subtotalConfig?.isCustomCells) {
1891
+ // 互斥:开启自定义单元格时关闭单元格拆分展示
1892
+ set(subtotalConfig, { isSplitCells: false })
1746
1893
  // 同时还开启了自定义单元格选项
1747
1894
  if (subtotalConfig?.fields?.length === 2) {
1748
1895
  // fields添加自定义单元格
@@ -1790,6 +1937,8 @@ class EditorStore {
1790
1937
  }
1791
1938
 
1792
1939
  // 每页合计自定义单元格文本输入
1940
+ // Text 组件的 onChange 实际收到事件对象(handleChange 被 spread 覆盖),直接绑定时需防御式取 e.target.value,否则事件对象存进 fields[n].name 会导致页面崩溃
1941
+ // ⚠️ 不能用 `value?.target?.value || value`:清空输入时 e.target.value 为空串(falsy),|| 会错把事件对象存进去(清空即崩),必须用 value?.target 判别
1793
1942
  @action.bound
1794
1943
  setSubtotalFields(value) {
1795
1944
  if (this.selectedRegion) {
@@ -1798,10 +1947,64 @@ class EditorStore {
1798
1947
  const subtotalConfig = table?.subtotal
1799
1948
 
1800
1949
  if (subtotalConfig.isCustomCells) {
1950
+ const text = value?.target ? value.target.value : value ?? ''
1801
1951
  const subtotalConfig = table?.subtotal.fields
1802
1952
  subtotalConfig.length === 3
1803
- ? (subtotalConfig[2].name = value)
1804
- : (subtotalConfig[1].name = value)
1953
+ ? (subtotalConfig[2].name = text)
1954
+ : (subtotalConfig[1].name = text)
1955
+ }
1956
+ }
1957
+ }
1958
+
1959
+ // 每页合计单元格拆分展示("每页合计/数值"拆分为两个单元格,与开启自定义单元格互斥)
1960
+ @action.bound
1961
+ setSubtotalSplitCells() {
1962
+ if (this.selectedRegion) {
1963
+ // 作用:触发组件的更新
1964
+ this.overallOrderShow = !this.overallOrderShow
1965
+ const arr = this.selectedRegion.split('.')
1966
+ const table = this.config.contents[arr[2]]
1967
+ const subtotalConfig = table?.subtotal
1968
+ // 没有显示每页合计的时候不可以设置
1969
+ if (!subtotalConfig?.show) return
1970
+ // 多栏表格情况,计算colSpan
1971
+ const colSpanLength = getColSpanLength(table)
1972
+ const oldSplitCells = subtotalConfig?.isSplitCells
1973
+
1974
+ set(subtotalConfig, {
1975
+ isSplitCells: !oldSplitCells
1976
+ })
1977
+ // 兼容已经存在后端的模板,每页合计配置没有fields,手动补上
1978
+ if (!subtotalConfig.fields) {
1979
+ set(subtotalConfig, {
1980
+ fields: [
1981
+ {
1982
+ name: '每页合计:',
1983
+ valueField: 'real_item_price',
1984
+ colSpan: colSpanLength
1985
+ }
1986
+ ]
1987
+ })
1988
+ }
1989
+ // 互斥:开启拆分展示时关闭自定义单元格(复用其关闭时的 fields 重排逻辑)
1990
+ if (!oldSplitCells && subtotalConfig?.isCustomCells) {
1991
+ this.setSubtotalCustomCells()
1992
+ }
1993
+ }
1994
+ }
1995
+
1996
+ // 每页合计左侧文案修改(默认"每页合计",允许为空,每页合计统一展示输入框内容)
1997
+ @action.bound
1998
+ setSubtotalLeftText(value) {
1999
+ if (this.selectedRegion) {
2000
+ // 作用:触发组件的更新(预览渲染不直接观察 fields[0].name,需强制重渲染)
2001
+ this.overallOrderShow = !this.overallOrderShow
2002
+ const arr = this.selectedRegion.split('.')
2003
+ const table = this.config.contents[arr[2]]
2004
+ const subtotalConfig = table?.subtotal
2005
+
2006
+ if (subtotalConfig?.fields?.[0]) {
2007
+ set(subtotalConfig.fields[0], { name: value })
1805
2008
  }
1806
2009
  }
1807
2010
  }
@@ -1819,6 +2022,7 @@ class EditorStore {
1819
2022
  set(table, {
1820
2023
  overallOrder: {
1821
2024
  show: true,
2025
+ showEachPage: true,
1822
2026
  fields: [
1823
2027
  {
1824
2028
  name: '整单合计:',
@@ -1936,6 +2140,7 @@ class EditorStore {
1936
2140
  }
1937
2141
 
1938
2142
  // 整单合计自定义单元格文本输入
2143
+ // Text 组件直接绑定时收到事件对象(同 setSubtotalFields);⚠️ 不能用 `||` 兜底,清空输入时空串 falsy 会错存事件对象导致页面崩溃,用 value?.target 判别
1939
2144
  @action.bound
1940
2145
  setOverallOrderFields(value) {
1941
2146
  if (this.selectedRegion) {
@@ -1944,8 +2149,9 @@ class EditorStore {
1944
2149
  const overallOrderConfig = table?.overallOrder
1945
2150
 
1946
2151
  if (overallOrderConfig.isCustomCells) {
2152
+ const text = value?.target ? value.target.value : value ?? ''
1947
2153
  const overallOrderConfigFields = table?.overallOrder.fields
1948
- overallOrderConfigFields[1].name = value?.target?.value || value
2154
+ overallOrderConfigFields[1].name = text
1949
2155
  }
1950
2156
  }
1951
2157
  }
@@ -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 }
@@ -166,8 +166,11 @@ class ContextMenu extends React.Component {
166
166
  const isMultiActive = keyArr.includes('multi')
167
167
  const isThreeActive = keyArr.includes('multi3')
168
168
  const isCategoryActive = keyArr.includes('category')
169
+ // 三级分类小计(category3)/ 商品三级分类(newCategory3)token 状态
170
+ const isCategory3Active = keyArr.includes('category3')
169
171
  const isTagActive = keyArr.includes('tag')
170
172
  const isNewCategoryActive = keyArr.includes('newCategory')
173
+ const isNewCategory3Active = keyArr.includes('newCategory3')
171
174
  const isSubtotalActive = subtotal.show
172
175
  const isOverallOrder = overallOrder?.show
173
176
  const isDiyOverallOrder = diyOverallOrder?.show
@@ -208,6 +211,13 @@ class ContextMenu extends React.Component {
208
211
  >
209
212
  {i18next.t('分类小计')}
210
213
  </div>
214
+ {/* 三级分类小计:按三级分类(品类)拆分汇总小计,互斥规则见 changeTableDataKey */}
215
+ <div
216
+ onClick={this.handleChangeTableDataKey.bind(this, 'category3', name)}
217
+ className={isCategory3Active ? 'active' : ''}
218
+ >
219
+ {i18next.t('三级分类小计')}
220
+ </div>
211
221
  <div
212
222
  // onClick={() =>
213
223
  // this.handleDiySummary(
@@ -244,6 +254,13 @@ class ContextMenu extends React.Component {
244
254
  >
245
255
  {i18next.t('商品分类')}
246
256
  </div>
257
+ {/* 商品三级分类:按三级分类(品类)拆分并新增列表标题行,复用 categoryConfig 标题样式配置 */}
258
+ <div
259
+ onClick={this.handleCategoryConfig.bind(this, 'newCategory3', name)}
260
+ className={isNewCategory3Active ? 'active' : ''}
261
+ >
262
+ {i18next.t('商品三级分类')}
263
+ </div>
247
264
  <div
248
265
  onClick={this.handleSubtotal.bind(this, name)}
249
266
  className={isSubtotalActive ? 'active' : ''}
@@ -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]]