kts-component-invoice-operate 3.1.12 → 3.1.13

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.
Files changed (115) hide show
  1. package/.dumi/theme/builtins/API.tsx +66 -66
  2. package/.editorconfig +16 -16
  3. package/.fatherrc.ts +4 -4
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +8 -8
  7. package/README.md +5 -5
  8. package/dist/Invoice/ui/GoodsList/hook/useColumns/autoFillFn/index.d.ts +2 -0
  9. package/dist/index.esm.js +2754 -3920
  10. package/dist/index.js +2754 -3920
  11. package/docs/index.md +5 -5
  12. package/index.html +12 -12
  13. package/package.json +59 -59
  14. package/src/Invoice/InvoiceController/InvoiceControllerForm/index.ts +94 -94
  15. package/src/Invoice/InvoiceController/InvoiceControllerState/BuyerState/index.tsx +88 -88
  16. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/EndowCode/index.tsx +93 -93
  17. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IColumnsReplenish/index.ts +10 -10
  18. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IGood/index.ts +72 -72
  19. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ImportGoods/index.ts +80 -80
  20. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType/index.ts +5 -5
  21. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ProductComparison/index.ts +9 -9
  22. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/index.ts +88 -88
  23. package/src/Invoice/InvoiceController/InvoiceControllerState/index.ts +48 -48
  24. package/src/Invoice/InvoiceController/fns/addGood.ts +11 -11
  25. package/src/Invoice/InvoiceController/fns/addGoodDiscount.ts +125 -125
  26. package/src/Invoice/InvoiceController/fns/delGood.ts +43 -43
  27. package/src/Invoice/InvoiceController/fns/getGoodsSearch.ts +23 -23
  28. package/src/Invoice/InvoiceController/fns/saveEditGood.ts +23 -23
  29. package/src/Invoice/InvoiceController/fns/setEditGood.ts +16 -16
  30. package/src/Invoice/InvoiceController/fns/setGoods.ts +10 -10
  31. package/src/Invoice/InvoiceController/fns/updateInvoiceNo.ts +8 -8
  32. package/src/Invoice/InvoiceController/index.ts +61 -61
  33. package/src/Invoice/_test/buyerNameSearch/index.tsx +41 -41
  34. package/src/Invoice/_test/deduction/index.tsx +935 -935
  35. package/src/Invoice/_test/draft/index.tsx +40 -40
  36. package/src/Invoice/_test/easiest/index.tsx +5 -5
  37. package/src/Invoice/_test/endowCode/index.tsx +1095 -1095
  38. package/src/Invoice/_test/goodsMenuExpand/index.tsx +32 -32
  39. package/src/Invoice/_test/importBuyer/index.tsx +74 -74
  40. package/src/Invoice/_test/importGoods/index.tsx +515 -515
  41. package/src/Invoice/_test/invoiceType/index.tsx +59 -59
  42. package/src/Invoice/_test/isInvoiceNo/index.tsx +12 -12
  43. package/src/Invoice/_test/replaceHead/index.tsx +22 -22
  44. package/src/Invoice/_test/retrieveData/index.tsx +22 -22
  45. package/src/Invoice/_test/seller/index.tsx +28 -28
  46. package/src/Invoice/_test/setDataSource/index.tsx +22 -22
  47. package/src/Invoice/_test/unit/index.tsx +19 -19
  48. package/src/Invoice/index.less +12 -12
  49. package/src/Invoice/index.md +53 -53
  50. package/src/Invoice/index.tsx +104 -104
  51. package/src/Invoice/tools/calculate/index.ts +97 -97
  52. package/src/Invoice/tools/coolingFn/index.ts +17 -17
  53. package/src/Invoice/tools/evaluate/index.ts +7 -7
  54. package/src/Invoice/tools/idGenerator/index.ts +2 -2
  55. package/src/Invoice/tools/itemName/index.ts +46 -46
  56. package/src/Invoice/tools/lazyFn/index.ts +19 -19
  57. package/src/Invoice/tools/strringFn/index.ts +40 -40
  58. package/src/Invoice/ui/AddComparisonDrawer/index.tsx +149 -149
  59. package/src/Invoice/ui/Buyer/index.less +219 -219
  60. package/src/Invoice/ui/Buyer/index.tsx +114 -114
  61. package/src/Invoice/ui/Buyer/ui/BuyerNameInput/index.tsx +166 -166
  62. package/src/Invoice/ui/Buyer/ui/ImportBuyerButton/index.tsx +21 -21
  63. package/src/Invoice/ui/EndowCodeDrawer/index.less +8 -8
  64. package/src/Invoice/ui/EndowCodeDrawer/index.tsx +445 -445
  65. package/src/Invoice/ui/GoodsList/hook/useColumns/autoFillFn/index.ts +513 -496
  66. package/src/Invoice/ui/GoodsList/hook/useColumns/index.tsx +618 -606
  67. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/ItemNameInput/index.less +9 -9
  68. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +34 -34
  69. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowEditButton/index.tsx +30 -30
  70. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/_useAddComparison/index.tsx +43 -43
  71. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/useAddDiscount/index.tsx +76 -76
  72. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/useDelItem/index.tsx +35 -35
  73. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/useEndowCode/index.tsx +34 -34
  74. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/index.less +13 -13
  75. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/index.tsx +98 -98
  76. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowSaveButton/index.tsx +14 -14
  77. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/TitleText/index.tsx +20 -20
  78. package/src/Invoice/ui/GoodsList/hook/useDeduction/index.tsx +24 -24
  79. package/src/Invoice/ui/GoodsList/hook/useOnRow/index.tsx +39 -39
  80. package/src/Invoice/ui/GoodsList/hook/useRowSelection/index.tsx +111 -111
  81. package/src/Invoice/ui/GoodsList/hook/useToGenerateId/index.ts +8 -8
  82. package/src/Invoice/ui/GoodsList/hook/useWindowClick/index.tsx +23 -23
  83. package/src/Invoice/ui/GoodsList/index.less +177 -177
  84. package/src/Invoice/ui/GoodsList/index.tsx +177 -177
  85. package/src/Invoice/ui/GoodsList/ui/AddRowButton/index.tsx +61 -61
  86. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.less +21 -21
  87. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.tsx +244 -244
  88. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useCommodityComparisonButton/index.tsx +75 -75
  89. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +66 -66
  90. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useEndowCodeButton/index.tsx +58 -58
  91. package/src/Invoice/ui/GoodsList/ui/BulkMenu/index.tsx +37 -37
  92. package/src/Invoice/ui/GoodsList/ui/DescribeSwitch/index.tsx +36 -36
  93. package/src/Invoice/ui/GoodsList/ui/Search/index.less +10 -10
  94. package/src/Invoice/ui/GoodsList/ui/Search/index.tsx +50 -50
  95. package/src/Invoice/ui/GoodsList/ui/Statistics/index.less +18 -18
  96. package/src/Invoice/ui/GoodsList/ui/Statistics/index.tsx +109 -109
  97. package/src/Invoice/ui/GoodsList/ui/TableRow/index.tsx +29 -29
  98. package/src/Invoice/ui/GoodsList/ui/TableVirtual/index.less +38 -38
  99. package/src/Invoice/ui/GoodsList/ui/TableVirtual/index.tsx +105 -105
  100. package/src/Invoice/ui/GoodsList/ui/TableVirtual.o/index.less +44 -44
  101. package/src/Invoice/ui/GoodsList/ui/TableVirtual.o/index.tsx +96 -96
  102. package/src/Invoice/ui/GoodsList/ui/TaxIncludedSwitch/index.tsx +30 -30
  103. package/src/Invoice/ui/ImportBuyerDrawer/index.tsx +75 -75
  104. package/src/Invoice/ui/ImportGoodsDrawer/index.tsx +174 -174
  105. package/src/Invoice/ui/InvoiceHeader/index.less +68 -68
  106. package/src/Invoice/ui/InvoiceHeader/index.tsx +246 -246
  107. package/src/Invoice/ui/Seller/index.less +113 -113
  108. package/src/Invoice/ui/Seller/index.tsx +98 -98
  109. package/src/Invoice/ui/Sign/index.less +14 -14
  110. package/src/Invoice/ui/Sign/index.tsx +71 -71
  111. package/src/index.ts +6 -6
  112. package/tsconfig.json +31 -31
  113. package/typings.d.ts +3 -3
  114. package/yarn.e.lock +14331 -14331
  115. package/yarn.o.lock +14800 -14800
@@ -1,445 +1,445 @@
1
- import React from 'react';
2
- import Invoice from '../../';
3
- import { Button, Drawer, Select, Modal, Input as InputAntd, Form, Tree, message } from 'kts-components-antd-x3';
4
- import { chain, bignumber } from 'mathjs';
5
- import { Input, NumberPicker } from '@formily/antd-components';
6
- import { format15 } from '../GoodsList/hook/useColumns/autoFillFn';
7
- import { LineAttributeType } from '../../InvoiceController';
8
- import IGood from '../../InvoiceController/InvoiceControllerState/GoodsListState/IGood';
9
- import { countTaxAmount } from '../../tools/calculate';
10
- import { bytesLnegth, cutStr } from '../../tools/strringFn';
11
- import { setShorthand } from '../../tools/itemName';
12
- import {
13
- SchemaForm,
14
- FormButtonGroup,
15
- createAsyncFormActions,
16
- SchemaMarkupField as Field,
17
- FormEffectHooks,
18
- } from '@formily/antd';
19
- import './index.less';
20
-
21
- const { TreeNode } = Tree;
22
- const { confirm } = Modal;
23
-
24
- export default () => {
25
- const controller = Invoice.useInvoiceController();
26
-
27
- const visible = controller.useMemo(s => s.goodsListState.endowCode.endowcodeGoodIndex.length > 0, []);
28
-
29
- const [defaultValue, setDefaultValue] = React.useState<IGood>();
30
-
31
- const onClose = React.useCallback(() => {
32
- controller.pipeline(async (s) => {
33
- s.goodsListState.endowCode.endowcodeGoodIndex = [];
34
- })();
35
- }, [controller]);
36
-
37
- // 计算赋码默认值
38
- React.useEffect(() => {
39
- if (visible) {
40
- controller.pipeline(async s => {
41
- const endowcodeGoodIndex = s.goodsListState.endowCode.endowcodeGoodIndex.filter(i => {
42
- const good = s.goodsListState.goodsMap.get(i);
43
- if (!good) return false;
44
-
45
- return good.lineAttribute !== LineAttributeType.折扣行;
46
- })
47
-
48
- const good = s.goodsListState.goodsMap.get(s.goodsListState.endowCode.endowcodeGoodIndex[0]);
49
- if (!good) return;
50
-
51
- const getDefaultValue = s.goodsListState.endowCode.getDefaultValue;
52
- if (getDefaultValue) {
53
- setDefaultValue(await getDefaultValue({ ...good }, endowcodeGoodIndex.length));
54
- } else {
55
- if (endowcodeGoodIndex.length === 1) {
56
- setDefaultValue(good);
57
- } else {
58
- setDefaultValue({ taxRate: good.taxRate } as any);
59
- }
60
- }
61
- })()
62
- } else {
63
- setDefaultValue(undefined);
64
- }
65
- }, [visible])
66
-
67
- return (
68
- <Drawer
69
- title="赋码"
70
- placement="right"
71
- destroyOnClose={true}
72
- closable={false}
73
- width={383}
74
- onClose={onClose}
75
- visible={visible}
76
- >
77
- {defaultValue && <DrawerBody defaultValue={defaultValue} />}
78
- </Drawer>
79
- );
80
- };
81
-
82
- const DrawerBody = (props: { defaultValue: IGood }) => {
83
-
84
- const controller = Invoice.useInvoiceController();
85
-
86
- const { defaultValue } = props;
87
-
88
- const actions = React.useMemo(() => createAsyncFormActions(), []);
89
-
90
- /** 免税类型 是否需要 */
91
- const isTaxFreeTypeNeeded = controller.useMemo(s => s.goodsListState.endowCode.isTaxFreeTypeNeeded, []);
92
-
93
- /** 税率 是否禁用 */
94
- const readOnlyTaxRate = controller.useMemo(s => {
95
- if (s.goodsListState.endowCode.getReadOnlyTaxRate) {
96
- return s.goodsListState.endowCode.getReadOnlyTaxRate(s.goodsListState);
97
- } else {
98
- return false;
99
- }
100
- }, [])
101
-
102
- /** 优惠政策 是否禁用 */
103
- const readOnlyFavouredPolicy = controller.useMemo(s => {
104
- if (s.goodsListState.endowCode.getReadOnlyFavouredPolicy) {
105
- return s.goodsListState.endowCode.getReadOnlyFavouredPolicy(s.goodsListState);
106
- } else {
107
- return false;
108
- }
109
- }, [])
110
-
111
- /** 税率列表 */
112
- const taxRateList = controller.useMemo(s => s.goodsListState.taxRateList.map((e) => ({ label: `${e}%`, value: e })), []);
113
-
114
- /** 免税类型 列表 */
115
- const taxFreeTypeList = controller.useMemo(s => s.goodsListState.endowCode.taxFreeTypeList, []);
116
-
117
- /** 优惠政策类型列表 */
118
- const favouredPolicyNameList = controller.useMemo(s => s.goodsListState.endowCode.favouredPolicyNameList, []);
119
-
120
- /** 优惠政策类型列表 */
121
- // const getTaxCategoryCodeTree = controller.useMemo(s => s.goodsListState.endowCode.getTaxCategoryCodeTree, []);
122
-
123
- /** 税率 */
124
- const [taxRate, setTaxRate] = React.useState<number>(0);
125
-
126
- /** 税收分类编码 选择组件 */
127
- const ShowSearch = React.useCallback(props => {
128
-
129
- const [dataSource, setDataSource] = React.useState<any[]>([]);
130
-
131
- const onSearch = React.useCallback(async e => {
132
- const arr = await controller.state.goodsListState.endowCode.getTaxCategoryCodeList(e);
133
- setDataSource(arr);
134
- }, [])
135
-
136
- const onChange = React.useCallback((value: string) => {
137
- if (props.onChange) {
138
- props.onChange(value);
139
- }
140
-
141
- const info = dataSource.filter(i => i.value === value)[0];
142
- if (!info) return;
143
-
144
- !readOnlyTaxRate && actions.setFieldState('taxRate', async s => {
145
- if (info.taxRate || info.taxRate === 0) {
146
- s.value = info.taxRate
147
- }
148
- });
149
-
150
- actions.setFieldState('shorthand', async (s) => {
151
- if (info.shorthand) {
152
- s.value = info.shorthand
153
- }
154
- });
155
- }, [actions, dataSource, readOnlyTaxRate])
156
-
157
- return (
158
- <Select
159
- {...props}
160
- showSearch
161
- showArrow={false}
162
- notFoundContent={null}
163
- filterOption={false}
164
- onSearch={onSearch}
165
- onChange={onChange}
166
- >
167
- {dataSource.map(e => <Select.Option key={e.value} value={e.value}>{e.label}</Select.Option>)}
168
- </Select>
169
- )
170
- }, [controller, actions])
171
-
172
- /** 税收分类编码 选择组件2 */
173
- const ShowSearch2 = React.useCallback(props => {
174
-
175
- // 是否显示
176
- const [visible, setVisible] = React.useState(false);
177
-
178
- // 税收分类编码树
179
- const [list, setList] = React.useState<any[]>();
180
-
181
- // 搜索条件
182
- const [filter, setFilter] = React.useState<{
183
- /** 税收分类编码 */
184
- taxCategoryCode?: string,
185
-
186
- /** 货物和劳务名称/简称 */
187
- val?: string
188
- }>();
189
-
190
- /** 创建 树节点 */
191
- const createTreeNode = React.useCallback(() => {
192
- if (!list) return <></>;
193
-
194
- return ctn(list);
195
-
196
- function title(label: string) {
197
- if (!filter) return label;
198
- label = (filter.taxCategoryCode ? label.split(new RegExp(filter.taxCategoryCode, 'g')) : [label]).join(`<span style="color: #1890ff;">${filter.taxCategoryCode}</span>`);
199
- label = (filter.val ? label.split(new RegExp(filter.val, 'g')) : [label]).join(`<span style="color: #1890ff;">${filter.val}</span>`);
200
- return <span dangerouslySetInnerHTML={{ __html: label }} />
201
- }
202
-
203
- function ctn(l: any[], p = '0') {
204
- if (!l || !l.length) return [<></>];
205
- return l.filter(e => e.pid === p).map(e => {
206
- return (
207
- <TreeNode title={title(e.label)} key={e.id}>
208
- {ctn(l, e.id)}
209
- </TreeNode>
210
- )
211
- })
212
- }
213
- }, [list, filter])
214
-
215
- /** 点击了节点 */
216
- const onSelect = React.useCallback((e: string[]) => {
217
- const id = e[0];
218
-
219
- // 是否叶子节点
220
- if (list?.filter(e => e.pid === id).length !== 0) { return; }
221
-
222
- const info = list?.filter(e => e.id === id)[0];
223
-
224
- !readOnlyTaxRate && actions.setFieldState('taxRate', async s => {
225
- if (info.taxRate || info.taxRate === 0) {
226
- s.value = info.taxRate
227
- }
228
- });
229
-
230
- actions.setFieldState('taxClassificationCode', async s => {
231
- if (info.id) {
232
- s.value = info.id
233
- }
234
- });
235
-
236
- actions.setFieldState('shorthand', async (s) => {
237
- if (info.shorthand) {
238
- s.value = info.shorthand
239
- }
240
- });
241
-
242
- setVisible(false);
243
- }, [list, actions, readOnlyTaxRate])
244
-
245
- React.useEffect(() => {
246
- (async () => {
247
- const fn = controller.state.goodsListState.endowCode.getTaxCategoryCodeTree || (async () => []);
248
- const list = await fn(filter?.taxCategoryCode, filter?.val);
249
- setList(list || []);
250
- })()
251
- }, [filter])
252
-
253
- React.useEffect(() => {
254
- if (visible) {
255
- setList([])
256
- }
257
- }, [visible])
258
-
259
- return (
260
- <>
261
- <InputAntd readOnly value={props.value} addonAfter={<Button size="small" type="link" onClick={() => { setVisible(true) }} >点击选择</Button>} />
262
- <Drawer
263
- title="税收分类编码"
264
- visible={visible}
265
- width={500}
266
- onClose={() => { setVisible(false) }}
267
- >
268
- <Form key={`${visible}`} >
269
- <Form.Item label="产品或服务简称" >
270
- <InputAntd onChange={e => { setFilter({ ...filter, val: e.target.value }) }} />
271
- </Form.Item>
272
- <Form.Item label="税收分类编码">
273
- <InputAntd onChange={e => { setFilter({ ...filter, taxCategoryCode: e.target.value }) }} />
274
- </Form.Item>
275
- </Form>
276
- {
277
- (list && list.length > 0)
278
- ? <Tree
279
- defaultExpandAll
280
- selectedKeys={[]}
281
- onSelect={onSelect}
282
- >
283
- {createTreeNode()}
284
- </Tree>
285
- : <span style={{ color: '#00000073' }} >请输入“产品或服务简称”或“税收分类编码”查找数据。</span>
286
- }
287
- </Drawer>
288
- </>
289
- )
290
- }, [controller, actions])
291
-
292
- // 是否享受优惠政策
293
- const [favouredPolicyMark, setFavouredPolicyMark] = React.useState<number>(0);
294
-
295
- // 确定
296
- const onSubmit = React.useCallback(values => {
297
- controller.pipeline(async s => {
298
-
299
- const endowCodeGood = s.goodsListState.endowCode.endowcodeGoodIndex.map(e => s.goodsListState.goodsMap.get(e));
300
-
301
- // 赋码
302
- endowCodeGood.forEach(good => {
303
- if (!good) return;
304
-
305
- good.itemName = setShorthand(good.itemName, values.shorthand);
306
- good.itemNameSelf = setShorthand(good.itemNameSelf, values.shorthand);
307
-
308
- good.taxClassificationCode = values.taxClassificationCode;
309
- good.taxRate = values.taxRate;
310
- good.taxFreeType = values.taxFreeType;
311
- good.favouredPolicyMark = values.favouredPolicyMark;
312
- good.favouredPolicyName = values.favouredPolicyName;
313
-
314
- const taxRate = chain(bignumber(values.taxRate)).dotDivide(bignumber(100)).add(bignumber(1)).done();
315
-
316
- // 是否含税
317
- const lineAmountExcludeTax = chain(bignumber(good.lineAmountIncludeTax)).dotDivide(taxRate).done();
318
- const priceExcludeTax = good.priceIncludeTax ? chain(bignumber(good.priceIncludeTax)).dotDivide(taxRate).done() : undefined
319
-
320
- good.lineAmountExcludeTax = lineAmountExcludeTax.toNumber().toFixed(2);
321
- good.priceExcludeTax = (priceExcludeTax ? format15(priceExcludeTax.toNumber(), s.calculatingDigits) : undefined) || undefined;
322
-
323
- good.taxAmount = countTaxAmount(good.lineAmountIncludeTax || 0, s.goodsListState.deduction, values.taxRate);
324
- });
325
-
326
- s.goodsListState.goodsList = s.goodsListState.goodsList.slice();
327
- s.goodsListState.endowCode.endowcodeGoodIndex = [];
328
- })();
329
- }, [controller]);
330
-
331
- const effects = React.useCallback(() => {
332
- // 税率变化
333
- FormEffectHooks.onFieldValueChange$('taxRate').subscribe((e) => {
334
- setTaxRate(e.value);
335
- actions.setFieldState('taxFreeType', async (s) => {
336
- if (e.value !== 0)
337
- s.value = undefined;
338
- });
339
- });
340
-
341
- // 是否享受优惠政策
342
- FormEffectHooks.onFieldValueChange$('favouredPolicyMark').subscribe((e) => {
343
- setFavouredPolicyMark(e.value);
344
- actions.setFieldState('favouredPolicyName', async (s) => {
345
- if (e.value === 0)
346
- s.value = undefined;
347
- });
348
- });
349
- }, [actions]);
350
-
351
- // 更新 税收分类编码列表
352
- React.useEffect(() => {
353
- if (controller.getTaxCategoryCodeList) controller.getTaxCategoryCodeList();
354
- }, [controller]);
355
-
356
- return (
357
- <SchemaForm actions={actions} components={{ ...components, showSearch: !!controller.state.goodsListState.endowCode.getTaxCategoryCodeTree ? ShowSearch2 : ShowSearch }} effects={effects}>
358
- <FormButtonGroup>
359
- <Field
360
- name="taxClassificationCode"
361
- type="showSearch"
362
- title="税收分类编码"
363
- // enum={taxCategoryCodeList}
364
- default={defaultValue?.taxClassificationCode}
365
- x-rules={[{ message: '请选择税收分类编码', required: true }]}
366
- />
367
- <Field
368
- name="shorthand"
369
- type="string"
370
- readOnly
371
- default={getShorthand(defaultValue?.itemName)}
372
- title="商品和服务分类简称"
373
- />
374
- <Field
375
- name="taxRate"
376
- type="string"
377
- title="税率"
378
- x-component-props={{ disabled: readOnlyTaxRate }}
379
- default={defaultValue?.taxRate ?? 0}
380
- enum={taxRateList}
381
- x-rules={[{ message: '请选择税率', required: true }]}
382
- />
383
- {taxRate === 0 && isTaxFreeTypeNeeded &&
384
- <Field
385
- name="taxFreeType"
386
- type="string"
387
- title="免税类型"
388
- x-component-props={{ disabled: readOnlyTaxRate }}
389
- default={defaultValue?.taxFreeType}
390
- enum={taxFreeTypeList}
391
- x-rules={[{ message: '请选择免税类型', required: true }]}
392
- />
393
- }
394
- <Field
395
- name="favouredPolicyMark"
396
- type="number"
397
- title="是否享受优惠政策"
398
- x-component-props={{ disabled: readOnlyFavouredPolicy }}
399
- enum={[
400
- { label: '是', value: 1 },
401
- { label: '否', value: 0 },
402
- ]}
403
- default={defaultValue?.favouredPolicyMark ?? 0}
404
- x-rules={[{ message: '请选择是否享受优惠政策', required: true }]}
405
- />
406
- {favouredPolicyMark === 1 &&
407
- <Field
408
- name="favouredPolicyName"
409
- type="string"
410
- title="优惠政策类型"
411
- x-component-props={{ disabled: readOnlyFavouredPolicy }}
412
- enum={favouredPolicyNameList}
413
- default={defaultValue?.favouredPolicyName}
414
- x-rules={[{ message: '请选择是否享受优惠政策', required: true }]}
415
- />
416
- }
417
- </FormButtonGroup>
418
-
419
- <span className="kts-invoice-operate-goods-endow-code-button-list">
420
- <Button onClick={() => { actions.submit(onSubmit) }} type="primary">
421
- 确定
422
- </Button>
423
- <Button onClick={() => { controller.pipeline(async s => (s.goodsListState.endowCode.endowcodeGoodIndex = []))() }}>
424
- 取消
425
- </Button>
426
- </span>
427
- </SchemaForm>
428
- );
429
- };
430
-
431
- const components = {
432
- string: Input,
433
- number: NumberPicker,
434
- };
435
-
436
- /** 提取简称 */
437
- const getShorthand = (value?: string) => {
438
- if (!value) return ' ';
439
- const arr = value.match(/\*[^*]+\*/);
440
- if (arr) {
441
- return arr[0].split('*')[1];
442
- } else {
443
- return ' ';
444
- }
445
- };
1
+ import React from 'react';
2
+ import Invoice from '../../';
3
+ import { Button, Drawer, Select, Modal, Input as InputAntd, Form, Tree, message } from 'kts-components-antd-x3';
4
+ import { chain, bignumber } from 'mathjs';
5
+ import { Input, NumberPicker } from '@formily/antd-components';
6
+ import { format15 } from '../GoodsList/hook/useColumns/autoFillFn';
7
+ import { LineAttributeType } from '../../InvoiceController';
8
+ import IGood from '../../InvoiceController/InvoiceControllerState/GoodsListState/IGood';
9
+ import { countTaxAmount } from '../../tools/calculate';
10
+ import { bytesLnegth, cutStr } from '../../tools/strringFn';
11
+ import { setShorthand } from '../../tools/itemName';
12
+ import {
13
+ SchemaForm,
14
+ FormButtonGroup,
15
+ createAsyncFormActions,
16
+ SchemaMarkupField as Field,
17
+ FormEffectHooks,
18
+ } from '@formily/antd';
19
+ import './index.less';
20
+
21
+ const { TreeNode } = Tree;
22
+ const { confirm } = Modal;
23
+
24
+ export default () => {
25
+ const controller = Invoice.useInvoiceController();
26
+
27
+ const visible = controller.useMemo(s => s.goodsListState.endowCode.endowcodeGoodIndex.length > 0, []);
28
+
29
+ const [defaultValue, setDefaultValue] = React.useState<IGood>();
30
+
31
+ const onClose = React.useCallback(() => {
32
+ controller.pipeline(async (s) => {
33
+ s.goodsListState.endowCode.endowcodeGoodIndex = [];
34
+ })();
35
+ }, [controller]);
36
+
37
+ // 计算赋码默认值
38
+ React.useEffect(() => {
39
+ if (visible) {
40
+ controller.pipeline(async s => {
41
+ const endowcodeGoodIndex = s.goodsListState.endowCode.endowcodeGoodIndex.filter(i => {
42
+ const good = s.goodsListState.goodsMap.get(i);
43
+ if (!good) return false;
44
+
45
+ return good.lineAttribute !== LineAttributeType.折扣行;
46
+ })
47
+
48
+ const good = s.goodsListState.goodsMap.get(s.goodsListState.endowCode.endowcodeGoodIndex[0]);
49
+ if (!good) return;
50
+
51
+ const getDefaultValue = s.goodsListState.endowCode.getDefaultValue;
52
+ if (getDefaultValue) {
53
+ setDefaultValue(await getDefaultValue({ ...good }, endowcodeGoodIndex.length));
54
+ } else {
55
+ if (endowcodeGoodIndex.length === 1) {
56
+ setDefaultValue(good);
57
+ } else {
58
+ setDefaultValue({ taxRate: good.taxRate } as any);
59
+ }
60
+ }
61
+ })()
62
+ } else {
63
+ setDefaultValue(undefined);
64
+ }
65
+ }, [visible])
66
+
67
+ return (
68
+ <Drawer
69
+ title="赋码"
70
+ placement="right"
71
+ destroyOnClose={true}
72
+ closable={false}
73
+ width={383}
74
+ onClose={onClose}
75
+ visible={visible}
76
+ >
77
+ {defaultValue && <DrawerBody defaultValue={defaultValue} />}
78
+ </Drawer>
79
+ );
80
+ };
81
+
82
+ const DrawerBody = (props: { defaultValue: IGood }) => {
83
+
84
+ const controller = Invoice.useInvoiceController();
85
+
86
+ const { defaultValue } = props;
87
+
88
+ const actions = React.useMemo(() => createAsyncFormActions(), []);
89
+
90
+ /** 免税类型 是否需要 */
91
+ const isTaxFreeTypeNeeded = controller.useMemo(s => s.goodsListState.endowCode.isTaxFreeTypeNeeded, []);
92
+
93
+ /** 税率 是否禁用 */
94
+ const readOnlyTaxRate = controller.useMemo(s => {
95
+ if (s.goodsListState.endowCode.getReadOnlyTaxRate) {
96
+ return s.goodsListState.endowCode.getReadOnlyTaxRate(s.goodsListState);
97
+ } else {
98
+ return false;
99
+ }
100
+ }, [])
101
+
102
+ /** 优惠政策 是否禁用 */
103
+ const readOnlyFavouredPolicy = controller.useMemo(s => {
104
+ if (s.goodsListState.endowCode.getReadOnlyFavouredPolicy) {
105
+ return s.goodsListState.endowCode.getReadOnlyFavouredPolicy(s.goodsListState);
106
+ } else {
107
+ return false;
108
+ }
109
+ }, [])
110
+
111
+ /** 税率列表 */
112
+ const taxRateList = controller.useMemo(s => s.goodsListState.taxRateList.map((e) => ({ label: `${e}%`, value: e })), []);
113
+
114
+ /** 免税类型 列表 */
115
+ const taxFreeTypeList = controller.useMemo(s => s.goodsListState.endowCode.taxFreeTypeList, []);
116
+
117
+ /** 优惠政策类型列表 */
118
+ const favouredPolicyNameList = controller.useMemo(s => s.goodsListState.endowCode.favouredPolicyNameList, []);
119
+
120
+ /** 优惠政策类型列表 */
121
+ // const getTaxCategoryCodeTree = controller.useMemo(s => s.goodsListState.endowCode.getTaxCategoryCodeTree, []);
122
+
123
+ /** 税率 */
124
+ const [taxRate, setTaxRate] = React.useState<number>(0);
125
+
126
+ /** 税收分类编码 选择组件 */
127
+ const ShowSearch = React.useCallback(props => {
128
+
129
+ const [dataSource, setDataSource] = React.useState<any[]>([]);
130
+
131
+ const onSearch = React.useCallback(async e => {
132
+ const arr = await controller.state.goodsListState.endowCode.getTaxCategoryCodeList(e);
133
+ setDataSource(arr);
134
+ }, [])
135
+
136
+ const onChange = React.useCallback((value: string) => {
137
+ if (props.onChange) {
138
+ props.onChange(value);
139
+ }
140
+
141
+ const info = dataSource.filter(i => i.value === value)[0];
142
+ if (!info) return;
143
+
144
+ !readOnlyTaxRate && actions.setFieldState('taxRate', async s => {
145
+ if (info.taxRate || info.taxRate === 0) {
146
+ s.value = info.taxRate
147
+ }
148
+ });
149
+
150
+ actions.setFieldState('shorthand', async (s) => {
151
+ if (info.shorthand) {
152
+ s.value = info.shorthand
153
+ }
154
+ });
155
+ }, [actions, dataSource, readOnlyTaxRate])
156
+
157
+ return (
158
+ <Select
159
+ {...props}
160
+ showSearch
161
+ showArrow={false}
162
+ notFoundContent={null}
163
+ filterOption={false}
164
+ onSearch={onSearch}
165
+ onChange={onChange}
166
+ >
167
+ {dataSource.map(e => <Select.Option key={e.value} value={e.value}>{e.label}</Select.Option>)}
168
+ </Select>
169
+ )
170
+ }, [controller, actions])
171
+
172
+ /** 税收分类编码 选择组件2 */
173
+ const ShowSearch2 = React.useCallback(props => {
174
+
175
+ // 是否显示
176
+ const [visible, setVisible] = React.useState(false);
177
+
178
+ // 税收分类编码树
179
+ const [list, setList] = React.useState<any[]>();
180
+
181
+ // 搜索条件
182
+ const [filter, setFilter] = React.useState<{
183
+ /** 税收分类编码 */
184
+ taxCategoryCode?: string,
185
+
186
+ /** 货物和劳务名称/简称 */
187
+ val?: string
188
+ }>();
189
+
190
+ /** 创建 树节点 */
191
+ const createTreeNode = React.useCallback(() => {
192
+ if (!list) return <></>;
193
+
194
+ return ctn(list);
195
+
196
+ function title(label: string) {
197
+ if (!filter) return label;
198
+ label = (filter.taxCategoryCode ? label.split(new RegExp(filter.taxCategoryCode, 'g')) : [label]).join(`<span style="color: #1890ff;">${filter.taxCategoryCode}</span>`);
199
+ label = (filter.val ? label.split(new RegExp(filter.val, 'g')) : [label]).join(`<span style="color: #1890ff;">${filter.val}</span>`);
200
+ return <span dangerouslySetInnerHTML={{ __html: label }} />
201
+ }
202
+
203
+ function ctn(l: any[], p = '0') {
204
+ if (!l || !l.length) return [<></>];
205
+ return l.filter(e => e.pid === p).map(e => {
206
+ return (
207
+ <TreeNode title={title(e.label)} key={e.id}>
208
+ {ctn(l, e.id)}
209
+ </TreeNode>
210
+ )
211
+ })
212
+ }
213
+ }, [list, filter])
214
+
215
+ /** 点击了节点 */
216
+ const onSelect = React.useCallback((e: string[]) => {
217
+ const id = e[0];
218
+
219
+ // 是否叶子节点
220
+ if (list?.filter(e => e.pid === id).length !== 0) { return; }
221
+
222
+ const info = list?.filter(e => e.id === id)[0];
223
+
224
+ !readOnlyTaxRate && actions.setFieldState('taxRate', async s => {
225
+ if (info.taxRate || info.taxRate === 0) {
226
+ s.value = info.taxRate
227
+ }
228
+ });
229
+
230
+ actions.setFieldState('taxClassificationCode', async s => {
231
+ if (info.id) {
232
+ s.value = info.id
233
+ }
234
+ });
235
+
236
+ actions.setFieldState('shorthand', async (s) => {
237
+ if (info.shorthand) {
238
+ s.value = info.shorthand
239
+ }
240
+ });
241
+
242
+ setVisible(false);
243
+ }, [list, actions, readOnlyTaxRate])
244
+
245
+ React.useEffect(() => {
246
+ (async () => {
247
+ const fn = controller.state.goodsListState.endowCode.getTaxCategoryCodeTree || (async () => []);
248
+ const list = await fn(filter?.taxCategoryCode, filter?.val);
249
+ setList(list || []);
250
+ })()
251
+ }, [filter])
252
+
253
+ React.useEffect(() => {
254
+ if (visible) {
255
+ setList([])
256
+ }
257
+ }, [visible])
258
+
259
+ return (
260
+ <>
261
+ <InputAntd readOnly value={props.value} addonAfter={<Button size="small" type="link" onClick={() => { setVisible(true) }} >点击选择</Button>} />
262
+ <Drawer
263
+ title="税收分类编码"
264
+ visible={visible}
265
+ width={500}
266
+ onClose={() => { setVisible(false) }}
267
+ >
268
+ <Form key={`${visible}`} >
269
+ <Form.Item label="产品或服务简称" >
270
+ <InputAntd onChange={e => { setFilter({ ...filter, val: e.target.value }) }} />
271
+ </Form.Item>
272
+ <Form.Item label="税收分类编码">
273
+ <InputAntd onChange={e => { setFilter({ ...filter, taxCategoryCode: e.target.value }) }} />
274
+ </Form.Item>
275
+ </Form>
276
+ {
277
+ (list && list.length > 0)
278
+ ? <Tree
279
+ defaultExpandAll
280
+ selectedKeys={[]}
281
+ onSelect={onSelect}
282
+ >
283
+ {createTreeNode()}
284
+ </Tree>
285
+ : <span style={{ color: '#00000073' }} >请输入“产品或服务简称”或“税收分类编码”查找数据。</span>
286
+ }
287
+ </Drawer>
288
+ </>
289
+ )
290
+ }, [controller, actions])
291
+
292
+ // 是否享受优惠政策
293
+ const [favouredPolicyMark, setFavouredPolicyMark] = React.useState<number>(0);
294
+
295
+ // 确定
296
+ const onSubmit = React.useCallback(values => {
297
+ controller.pipeline(async s => {
298
+
299
+ const endowCodeGood = s.goodsListState.endowCode.endowcodeGoodIndex.map(e => s.goodsListState.goodsMap.get(e));
300
+
301
+ // 赋码
302
+ endowCodeGood.forEach(good => {
303
+ if (!good) return;
304
+
305
+ good.itemName = setShorthand(good.itemName, values.shorthand);
306
+ good.itemNameSelf = setShorthand(good.itemNameSelf, values.shorthand);
307
+
308
+ good.taxClassificationCode = values.taxClassificationCode;
309
+ good.taxRate = values.taxRate;
310
+ good.taxFreeType = values.taxFreeType;
311
+ good.favouredPolicyMark = values.favouredPolicyMark;
312
+ good.favouredPolicyName = values.favouredPolicyName;
313
+
314
+ const taxRate = chain(bignumber(values.taxRate)).dotDivide(bignumber(100)).add(bignumber(1)).done();
315
+
316
+ // 是否含税
317
+ const lineAmountExcludeTax = chain(bignumber(good.lineAmountIncludeTax)).dotDivide(taxRate).done();
318
+ const priceExcludeTax = good.priceIncludeTax ? chain(bignumber(good.priceIncludeTax)).dotDivide(taxRate).done() : undefined
319
+
320
+ good.lineAmountExcludeTax = lineAmountExcludeTax.toNumber().toFixed(2);
321
+ good.priceExcludeTax = (priceExcludeTax ? format15(priceExcludeTax.toNumber(), s.calculatingDigits) : undefined) || undefined;
322
+
323
+ good.taxAmount = countTaxAmount(good.lineAmountIncludeTax || 0, s.goodsListState.deduction, values.taxRate);
324
+ });
325
+
326
+ s.goodsListState.goodsList = s.goodsListState.goodsList.slice();
327
+ s.goodsListState.endowCode.endowcodeGoodIndex = [];
328
+ })();
329
+ }, [controller]);
330
+
331
+ const effects = React.useCallback(() => {
332
+ // 税率变化
333
+ FormEffectHooks.onFieldValueChange$('taxRate').subscribe((e) => {
334
+ setTaxRate(e.value);
335
+ actions.setFieldState('taxFreeType', async (s) => {
336
+ if (e.value !== 0)
337
+ s.value = undefined;
338
+ });
339
+ });
340
+
341
+ // 是否享受优惠政策
342
+ FormEffectHooks.onFieldValueChange$('favouredPolicyMark').subscribe((e) => {
343
+ setFavouredPolicyMark(e.value);
344
+ actions.setFieldState('favouredPolicyName', async (s) => {
345
+ if (e.value === 0)
346
+ s.value = undefined;
347
+ });
348
+ });
349
+ }, [actions]);
350
+
351
+ // 更新 税收分类编码列表
352
+ React.useEffect(() => {
353
+ if (controller.getTaxCategoryCodeList) controller.getTaxCategoryCodeList();
354
+ }, [controller]);
355
+
356
+ return (
357
+ <SchemaForm actions={actions} components={{ ...components, showSearch: !!controller.state.goodsListState.endowCode.getTaxCategoryCodeTree ? ShowSearch2 : ShowSearch }} effects={effects}>
358
+ <FormButtonGroup>
359
+ <Field
360
+ name="taxClassificationCode"
361
+ type="showSearch"
362
+ title="税收分类编码"
363
+ // enum={taxCategoryCodeList}
364
+ default={defaultValue?.taxClassificationCode}
365
+ x-rules={[{ message: '请选择税收分类编码', required: true }]}
366
+ />
367
+ <Field
368
+ name="shorthand"
369
+ type="string"
370
+ readOnly
371
+ default={getShorthand(defaultValue?.itemName)}
372
+ title="商品和服务分类简称"
373
+ />
374
+ <Field
375
+ name="taxRate"
376
+ type="string"
377
+ title="税率"
378
+ x-component-props={{ disabled: readOnlyTaxRate }}
379
+ default={defaultValue?.taxRate ?? 0}
380
+ enum={taxRateList}
381
+ x-rules={[{ message: '请选择税率', required: true }]}
382
+ />
383
+ {taxRate === 0 && isTaxFreeTypeNeeded &&
384
+ <Field
385
+ name="taxFreeType"
386
+ type="string"
387
+ title="免税类型"
388
+ x-component-props={{ disabled: readOnlyTaxRate }}
389
+ default={defaultValue?.taxFreeType}
390
+ enum={taxFreeTypeList}
391
+ x-rules={[{ message: '请选择免税类型', required: true }]}
392
+ />
393
+ }
394
+ <Field
395
+ name="favouredPolicyMark"
396
+ type="number"
397
+ title="是否享受优惠政策"
398
+ x-component-props={{ disabled: readOnlyFavouredPolicy }}
399
+ enum={[
400
+ { label: '是', value: 1 },
401
+ { label: '否', value: 0 },
402
+ ]}
403
+ default={defaultValue?.favouredPolicyMark ?? 0}
404
+ x-rules={[{ message: '请选择是否享受优惠政策', required: true }]}
405
+ />
406
+ {favouredPolicyMark === 1 &&
407
+ <Field
408
+ name="favouredPolicyName"
409
+ type="string"
410
+ title="优惠政策类型"
411
+ x-component-props={{ disabled: readOnlyFavouredPolicy }}
412
+ enum={favouredPolicyNameList}
413
+ default={defaultValue?.favouredPolicyName}
414
+ x-rules={[{ message: '请选择是否享受优惠政策', required: true }]}
415
+ />
416
+ }
417
+ </FormButtonGroup>
418
+
419
+ <span className="kts-invoice-operate-goods-endow-code-button-list">
420
+ <Button onClick={() => { actions.submit(onSubmit) }} type="primary">
421
+ 确定
422
+ </Button>
423
+ <Button onClick={() => { controller.pipeline(async s => (s.goodsListState.endowCode.endowcodeGoodIndex = []))() }}>
424
+ 取消
425
+ </Button>
426
+ </span>
427
+ </SchemaForm>
428
+ );
429
+ };
430
+
431
+ const components = {
432
+ string: Input,
433
+ number: NumberPicker,
434
+ };
435
+
436
+ /** 提取简称 */
437
+ const getShorthand = (value?: string) => {
438
+ if (!value) return ' ';
439
+ const arr = value.match(/\*[^*]+\*/);
440
+ if (arr) {
441
+ return arr[0].split('*')[1];
442
+ } else {
443
+ return ' ';
444
+ }
445
+ };