gm-printer 10.29.2 → 10.30.0-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.
- package/build/demo.js +2 -2
- package/locales/en.json +2 -0
- package/locales/th.json +2 -0
- package/locales/zh-HK.json +2 -0
- package/package.json +1 -1
- package/src/common/editor_store.js +50 -0
- package/src/editor_purchase/editor_special_table.js +73 -22
- package/src/printer/store.js +47 -0
- package/src/printer/table.js +22 -1
package/locales/en.json
CHANGED
package/locales/th.json
CHANGED
package/locales/zh-HK.json
CHANGED
package/package.json
CHANGED
|
@@ -1054,6 +1054,24 @@ class EditorStore {
|
|
|
1054
1054
|
const arr = this.selectedRegion.split('.')
|
|
1055
1055
|
const table = this.config.contents[arr[2]]
|
|
1056
1056
|
|
|
1057
|
+
const getDataKey = () => {
|
|
1058
|
+
if (dataKey === 'purchase_detail_one_row') {
|
|
1059
|
+
if (!table.purchaseSettingKey) {
|
|
1060
|
+
this.setPurchasePrintSettingKey()
|
|
1061
|
+
return dataKey
|
|
1062
|
+
}
|
|
1063
|
+
if (table.purchaseSettingKey === 'goods') {
|
|
1064
|
+
return 'purchase_independent_rol_sku'
|
|
1065
|
+
}
|
|
1066
|
+
if (table.purchaseSettingKey === 'address') {
|
|
1067
|
+
return 'purchase_independent_rol_address'
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
return dataKey
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
dataKey = getDataKey()
|
|
1074
|
+
|
|
1057
1075
|
this.selected = null // 清空点中项
|
|
1058
1076
|
table.dataKey = dataKey
|
|
1059
1077
|
// 改变dataKey后做副作用action
|
|
@@ -1062,6 +1080,38 @@ class EditorStore {
|
|
|
1062
1080
|
}
|
|
1063
1081
|
}
|
|
1064
1082
|
|
|
1083
|
+
// 采购明细商品打印设置
|
|
1084
|
+
@action.bound setPurchasePrintSettingKey(dataKey = 'goods') {
|
|
1085
|
+
const arr = this.selectedRegion.split('.')
|
|
1086
|
+
const table = this.config.contents[arr[2]]
|
|
1087
|
+
table.purchaseSettingKey = dataKey
|
|
1088
|
+
|
|
1089
|
+
set(table, {
|
|
1090
|
+
purchaseSettingKey: dataKey,
|
|
1091
|
+
dataKey:
|
|
1092
|
+
dataKey === 'goods'
|
|
1093
|
+
? 'purchase_independent_rol_sku'
|
|
1094
|
+
: 'purchase_independent_rol_address'
|
|
1095
|
+
})
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// 用于 采购明细 select 的显示
|
|
1099
|
+
@computed get computedDataKey() {
|
|
1100
|
+
if (this.selectedRegion) {
|
|
1101
|
+
const arr = this.selectedRegion.split('.')
|
|
1102
|
+
const table = this.config.contents[arr[2]]
|
|
1103
|
+
|
|
1104
|
+
const { dataKey } = table
|
|
1105
|
+
if (
|
|
1106
|
+
dataKey === 'purchase_independent_rol_sku' ||
|
|
1107
|
+
dataKey === 'purchase_independent_rol_address'
|
|
1108
|
+
) {
|
|
1109
|
+
return 'purchase_detail_one_row'
|
|
1110
|
+
}
|
|
1111
|
+
return dataKey
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1065
1115
|
@computed
|
|
1066
1116
|
get computedTableDataKeyOfSelectedRegion() {
|
|
1067
1117
|
if (this.selectedRegion) {
|
|
@@ -24,7 +24,13 @@ const dataKeyList = [
|
|
|
24
24
|
},
|
|
25
25
|
{ value: 'purchase_one_row', text: i18next.t('单列-总表下方一行') },
|
|
26
26
|
{ value: 'purchase_flex_2', text: i18next.t('双栏-总表下方一行两栏') },
|
|
27
|
-
{ value: 'purchase_flex_4', text: i18next.t('四栏-总表下方一行四栏') }
|
|
27
|
+
{ value: 'purchase_flex_4', text: i18next.t('四栏-总表下方一行四栏') },
|
|
28
|
+
{ value: 'purchase_detail_one_row', text: i18next.t('按采购明细单行') }
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
const purchasePrintSettingDataKeyList = [
|
|
32
|
+
{ value: 'goods', text: i18next.t('按商品排序') },
|
|
33
|
+
{ value: 'merchant', text: i18next.t('按商户排序') }
|
|
28
34
|
]
|
|
29
35
|
|
|
30
36
|
@inject('editStore')
|
|
@@ -35,8 +41,30 @@ class TableDetailEditor extends React.Component {
|
|
|
35
41
|
editStore.setPurchaseTableKey(dataKey)
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
handlePurchaseSettingKeyChange = dataKey => {
|
|
39
45
|
const { editStore } = this.props
|
|
46
|
+
|
|
47
|
+
editStore.setPurchasePrintSettingKey(dataKey)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
handleDetailAddField = ({ key, value }) => {
|
|
51
|
+
const { editStore, config } = this.props
|
|
52
|
+
if (editStore.computedDataKey === 'purchase_detail_one_row') {
|
|
53
|
+
// 序号 {{列.序号}}
|
|
54
|
+
const transform = str => {
|
|
55
|
+
return str
|
|
56
|
+
.replace(/{{\s*([^}]+)\s*}}/g, '{{$1}}') // 先标准化(去掉多余空格)
|
|
57
|
+
.replace(/{{([^.\s}]+)}}/g, '{{列.$1}}')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (config.dataKey !== 'purchase_independent_rol_sku') {
|
|
61
|
+
editStore.setPurchaseTableKey('purchase_independent_rol_sku')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
editStore.addFieldToTable({ key, value: transform(value) })
|
|
65
|
+
|
|
66
|
+
return
|
|
67
|
+
}
|
|
40
68
|
editStore.specialTextAddField('*' + value)
|
|
41
69
|
}
|
|
42
70
|
|
|
@@ -52,10 +80,11 @@ class TableDetailEditor extends React.Component {
|
|
|
52
80
|
|
|
53
81
|
render() {
|
|
54
82
|
const {
|
|
55
|
-
addFields: { detailFields }
|
|
83
|
+
addFields: { detailFields },
|
|
84
|
+
editStore
|
|
56
85
|
} = this.props
|
|
57
86
|
const {
|
|
58
|
-
|
|
87
|
+
purchaseSettingKey,
|
|
59
88
|
specialConfig: { template_text, style }
|
|
60
89
|
} = this.props.config
|
|
61
90
|
|
|
@@ -67,7 +96,7 @@ class TableDetailEditor extends React.Component {
|
|
|
67
96
|
<div>{i18next.t('采购明细')}:</div>
|
|
68
97
|
<Select
|
|
69
98
|
className='gm-printer-edit-select'
|
|
70
|
-
value={
|
|
99
|
+
value={editStore.computedDataKey}
|
|
71
100
|
onChange={this.handleDataKeyChange}
|
|
72
101
|
>
|
|
73
102
|
{_.map(dataKeyList, v => (
|
|
@@ -77,7 +106,24 @@ class TableDetailEditor extends React.Component {
|
|
|
77
106
|
))}
|
|
78
107
|
</Select>
|
|
79
108
|
</Flex>
|
|
80
|
-
|
|
109
|
+
|
|
110
|
+
{editStore.computedDataKey === 'purchase_detail_one_row' && (
|
|
111
|
+
<Flex alignCenter className='gm-padding-top-5'>
|
|
112
|
+
<div>{i18next.t('打印设置')}:</div>
|
|
113
|
+
<Select
|
|
114
|
+
className='gm-printer-edit-select'
|
|
115
|
+
value={purchaseSettingKey}
|
|
116
|
+
onChange={this.handlePurchaseSettingKeyChange}
|
|
117
|
+
>
|
|
118
|
+
{_.map(purchasePrintSettingDataKeyList, v => (
|
|
119
|
+
<Option key={v.value} value={v.value}>
|
|
120
|
+
{v.text}
|
|
121
|
+
</Option>
|
|
122
|
+
))}
|
|
123
|
+
</Select>
|
|
124
|
+
</Flex>
|
|
125
|
+
)}
|
|
126
|
+
{editStore.computedDataKey !== 'purchase_no_detail' && (
|
|
81
127
|
<>
|
|
82
128
|
<div className='gm-padding-top-5'>
|
|
83
129
|
<div>{i18next.t('添加字段')}:</div>
|
|
@@ -86,27 +132,32 @@ class TableDetailEditor extends React.Component {
|
|
|
86
132
|
<FieldBtn
|
|
87
133
|
key={o.key}
|
|
88
134
|
name={o.key}
|
|
89
|
-
onClick={this.handleDetailAddField.bind(this, o
|
|
135
|
+
onClick={this.handleDetailAddField.bind(this, o)}
|
|
90
136
|
/>
|
|
91
137
|
))}
|
|
92
138
|
</Flex>
|
|
93
139
|
</div>
|
|
94
140
|
|
|
95
|
-
|
|
96
|
-
<div
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
141
|
+
{editStore.computedDataKey !== 'purchase_detail_one_row' && (
|
|
142
|
+
<div className='gm-padding-top-5'>
|
|
143
|
+
<div>{i18next.t('字段设置')}:</div>
|
|
144
|
+
<Fonter
|
|
145
|
+
style={style}
|
|
146
|
+
onChange={this.handleSpecialStyleChange}
|
|
147
|
+
/>
|
|
148
|
+
<Separator />
|
|
149
|
+
<TextAlign
|
|
150
|
+
style={style}
|
|
151
|
+
onChange={this.handleSpecialStyleChange}
|
|
152
|
+
/>
|
|
153
|
+
<Gap />
|
|
154
|
+
<Textarea
|
|
155
|
+
onChange={this.handleSpecialTextChange}
|
|
156
|
+
value={template_text}
|
|
157
|
+
placeholder={i18next.t('请输入明细字段')}
|
|
158
|
+
/>
|
|
159
|
+
</div>
|
|
160
|
+
)}
|
|
110
161
|
<TipInfo
|
|
111
162
|
text={i18next.t(
|
|
112
163
|
'说明:在字段之间自行设置间隔符号,但谨慎修改{}中的内容,避免出现数据异常'
|
package/src/printer/store.js
CHANGED
|
@@ -524,6 +524,53 @@ class PrinterStore {
|
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
|
|
527
|
+
/**
|
|
528
|
+
*
|
|
529
|
+
* @param text
|
|
530
|
+
* @param dataKey
|
|
531
|
+
* @param index
|
|
532
|
+
* @param begin
|
|
533
|
+
* @returns {number[]|number|*|number|null} -1 需要合并单元格; >1 合并的单元格数量; [] 表示分页需要合并的行数; null 表示不需要合并
|
|
534
|
+
*/
|
|
535
|
+
templateTableRowSpan(text, dataKey, index, begin) {
|
|
536
|
+
try {
|
|
537
|
+
if (
|
|
538
|
+
dataKey !== 'purchase_detail_one_row' &&
|
|
539
|
+
dataKey !== 'purchase_independent_rol_sku' &&
|
|
540
|
+
dataKey !== 'purchase_independent_rol_address'
|
|
541
|
+
) {
|
|
542
|
+
return null
|
|
543
|
+
}
|
|
544
|
+
const list = this.data._table[dataKey] || this.data._table.orders
|
|
545
|
+
|
|
546
|
+
const interpolate = /{{([\s\S]+?)}}/g
|
|
547
|
+
const match = interpolate.exec(text)
|
|
548
|
+
// 显示在表格上的 th 名
|
|
549
|
+
const showFiledText = match[1].split('.')[1]
|
|
550
|
+
|
|
551
|
+
if (list[index]._mergeCell.some(v => v === showFiledText)) {
|
|
552
|
+
// 新的一页,需要重新合并
|
|
553
|
+
if (index && index === begin && list[index]._origin.rowSpan === -1) {
|
|
554
|
+
// 新的一页需要还需要合并的单元格数量
|
|
555
|
+
let newPageCellRowSpan = 1
|
|
556
|
+
for (let i = index - 1; i < list.length; i--) {
|
|
557
|
+
const record = list[i]
|
|
558
|
+
if (record._origin.rowSpan > 1) {
|
|
559
|
+
newPageCellRowSpan = record._origin.rowSpan - (index - i)
|
|
560
|
+
break
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return [newPageCellRowSpan]
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
return list[index]._origin?.rowSpan || 1
|
|
567
|
+
}
|
|
568
|
+
return 1
|
|
569
|
+
} catch (err) {
|
|
570
|
+
return null
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
527
574
|
templateTable(text, dataKey, index, pageIndex) {
|
|
528
575
|
// 做好保护,出错就返回 text
|
|
529
576
|
try {
|
package/src/printer/table.js
CHANGED
|
@@ -19,7 +19,7 @@ import SubtotalTr from './table_subtotal_tr'
|
|
|
19
19
|
import PageSummary from './page_summary'
|
|
20
20
|
import OverallOrder from './table_overallOrder_tr'
|
|
21
21
|
import DiyOverallOrder from './table_diy_overallOrder_tr'
|
|
22
|
-
import { toJS } from 'mobx'
|
|
22
|
+
// import { toJS } from 'mobx'
|
|
23
23
|
|
|
24
24
|
@inject('printerStore')
|
|
25
25
|
@observer
|
|
@@ -280,6 +280,26 @@ class Table extends React.Component {
|
|
|
280
280
|
)
|
|
281
281
|
) : (
|
|
282
282
|
_.map(columns, (col, j) => {
|
|
283
|
+
const rowSpan = printerStore.templateTableRowSpan(
|
|
284
|
+
col.text,
|
|
285
|
+
dataKey,
|
|
286
|
+
i,
|
|
287
|
+
range.begin
|
|
288
|
+
)
|
|
289
|
+
// 说明该单元格不需要显示 已被合并
|
|
290
|
+
if (rowSpan === -1) {
|
|
291
|
+
return null
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// 新的一页如果有需要合并单元格的则不显示数据
|
|
295
|
+
if (
|
|
296
|
+
range.begin &&
|
|
297
|
+
range.begin === i &&
|
|
298
|
+
Array.isArray(rowSpan)
|
|
299
|
+
) {
|
|
300
|
+
return <td rowSpan={rowSpan[0]} />
|
|
301
|
+
}
|
|
302
|
+
|
|
283
303
|
return (
|
|
284
304
|
<td
|
|
285
305
|
key={j}
|
|
@@ -288,6 +308,7 @@ class Table extends React.Component {
|
|
|
288
308
|
...getTdStyle(j, col.style),
|
|
289
309
|
...col.style
|
|
290
310
|
}}
|
|
311
|
+
{...(rowSpan > 1 && { rowSpan: rowSpan })}
|
|
291
312
|
className={classNames({
|
|
292
313
|
active:
|
|
293
314
|
getTableColumnName(name, col.index) ===
|