kts-component-invoice-operate 3.1.1 → 3.1.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": "kts-component-invoice-operate",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -36,4 +36,7 @@ export default class InvoiceControllerState {
36
36
 
37
37
  /** 计算中启动字段 */
38
38
  calculating?: string;
39
+
40
+ /** 组件根结构 */
41
+ rootElement?: HTMLDivElement | null = null;
39
42
  }
@@ -1,4 +1,4 @@
1
- import { InvoiceControllerState, IGood } from '../';
1
+ import { InvoiceControllerState } from '../';
2
2
 
3
3
  /**
4
4
  * 保存正在编辑的货物
@@ -84,7 +84,7 @@ const Main = (props: IInvoiceProps) => {
84
84
  return (
85
85
  <InvoiceContext.Provider key={key} value={controller}>
86
86
 
87
- <div className="kts-invoice-operate">
87
+ <div className="kts-invoice-operate" ref={controller.pipeline<HTMLDivElement | null>(async (s, e) => { s.rootElement = e })} >
88
88
  {props.invoiceHeader || <InvoiceHeader /> /** 发票头 */}
89
89
  {props.buyer || <Buyer /> /** 购买方 */}
90
90
  {props.goodsList || <GoodsList /> /** 货物列表 */}
@@ -1,13 +1,15 @@
1
1
  import React from 'react';
2
2
  import Invoice from '../../../../';
3
3
  import { Button, message } from 'kts-components-antd-x3';
4
- import { LineAttributeType } from '../../../../InvoiceController';
4
+ import InvoiceController, { LineAttributeType } from '../../../../InvoiceController';
5
5
 
6
6
  export default () => {
7
7
  const controller = Invoice.useInvoiceController();
8
8
 
9
9
  const model = controller.useMemo(s => s.model, []);
10
10
 
11
+ const rootElement = controller.useMemo(s => s.rootElement, []);
12
+
11
13
  /** 产品数据量 */
12
14
  const goodsNum = controller.useMemo(s => s.goodsListState.goodsList.length, []);
13
15
 
@@ -18,25 +20,12 @@ export default () => {
18
20
  const goodMax = controller.useMemo(s => s.goodsListState.goodMax, []);
19
21
 
20
22
  /** 按钮是否禁用 */
21
- const disabled = React.useMemo(() => {
22
- return typeof goodMax === 'number' ? goodsNum >= goodMax : !!searchValue;
23
- }, [goodMax, goodsNum, searchValue])
23
+ const disabled = React.useMemo(() => typeof goodMax === 'number' ? goodsNum >= goodMax : !!searchValue, [goodMax, goodsNum, searchValue])
24
24
 
25
25
  const onClick = React.useCallback(async () => {
26
- await controller.saveEditGood();
27
- await controller.wait();
28
- await controller.pipeline(async (s) => {
29
- if (s.goodsListState.editGood) {
30
- message.error({
31
- content: '你正在编辑一个货物',
32
- key: '你正在编辑一个货物',
33
- });
34
- return;
35
- }
36
-
37
- s.goodsListState.editGood = await controller.addGood({ taxRate: s.goodsListState.defaultRate, lineAttribute: LineAttributeType.正常 });
38
- })();
39
- }, [controller]);
26
+ await addGood(controller);
27
+ await rollBottom(controller, rootElement);
28
+ }, [controller, rootElement]);
40
29
 
41
30
  if (model === 'prefab') return <></>;
42
31
  if (model === 'readOnly') return <></>;
@@ -47,3 +36,27 @@ export default () => {
47
36
  </Button>
48
37
  );
49
38
  };
39
+
40
+ /** 添加一个空货物 */
41
+ async function addGood(controller: InvoiceController) {
42
+ await controller.saveEditGood();
43
+ await controller.wait();
44
+ await controller.run(async (s) => {
45
+ if (s.goodsListState.editGood) {
46
+ message.error({
47
+ content: '你正在编辑一个货物',
48
+ key: '你正在编辑一个货物',
49
+ });
50
+ return;
51
+ }
52
+ s.goodsListState.editGood = await controller.addGood({ taxRate: s.goodsListState.defaultRate, lineAttribute: LineAttributeType.正常 });
53
+ });
54
+ }
55
+
56
+ /** 货物列表,滚动到底部 */
57
+ async function rollBottom(controller: InvoiceController, rootElement: HTMLDivElement | null | undefined) {
58
+ await controller.wait();
59
+ const cont = rootElement?.querySelector('.ktsAntX-table-body');
60
+ if (!cont) return;
61
+ cont.scrollTop = cont.scrollHeight;
62
+ }