kts-component-invoice-operate 3.2.21 → 3.2.24

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 (23) hide show
  1. package/dist/Invoice/InvoiceController/InvoiceControllerState/AutoComplete/index.d.ts +4 -0
  2. package/dist/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/index.d.ts +2 -0
  3. package/dist/Invoice/InvoiceController/fns/importGoodsDrawer.d.ts +6 -0
  4. package/dist/Invoice/InvoiceController/fns/mergeDiscount.d.ts +2 -0
  5. package/dist/Invoice/InvoiceController/index.d.ts +4 -0
  6. package/dist/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemNameInput/index.d.ts +1 -0
  7. package/dist/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useMergeDiscount/index.d.ts +6 -0
  8. package/dist/Invoice/ui/digtal/Stakeholder/index.d.ts +1 -1
  9. package/dist/index.esm.js +7097 -6733
  10. package/dist/index.js +7097 -6733
  11. package/package.json +1 -1
  12. package/src/Invoice/Invoice-digtal/_test/header/index.tsx +68 -0
  13. package/src/Invoice/InvoiceController/InvoiceControllerState/AutoComplete/index.ts +7 -1
  14. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/index.ts +3 -0
  15. package/src/Invoice/InvoiceController/fns/importGoodsDrawer.ts +68 -0
  16. package/src/Invoice/InvoiceController/fns/mergeDiscount.ts +29 -0
  17. package/src/Invoice/InvoiceController/index.ts +9 -1
  18. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +61 -61
  19. package/src/Invoice/ui/default/GoodsList/index.tsx +7 -0
  20. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useMergeDetails/index.tsx +1 -1
  21. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useMergeDiscount/index.tsx +37 -0
  22. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +33 -7
  23. package/src/Invoice/ui/digtal/Stakeholder/index.tsx +88 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kts-component-invoice-operate",
3
- "version": "3.2.21",
3
+ "version": "3.2.24",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -1,10 +1,15 @@
1
1
  import React from 'react';
2
2
  import Invoice from '../../..';
3
3
  import 'antd/dist/antd.css';
4
+ import InvoiceController from '../../../InvoiceController';
4
5
 
5
6
  export default () => {
7
+
8
+ const invoiceController = React.useMemo(() => new MyInvoiceController(), []);
9
+
6
10
  return (
7
11
  <Invoice
12
+ controller={invoiceController}
8
13
  invoiceType='digtal'
9
14
  invoiceHeader={
10
15
  <Invoice.InvoiceHeaderDigtal
@@ -15,3 +20,66 @@ export default () => {
15
20
  />
16
21
  )
17
22
  };
23
+
24
+ class MyInvoiceController extends InvoiceController {
25
+
26
+ constructor() {
27
+ super();
28
+ this.state.autoComplete.onItemNameSearch = async text => {
29
+ return [
30
+ {
31
+ "itemName": "呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵",
32
+ "taxClassificationCode": "1010112070000000000",
33
+ "itemModelName": null,
34
+ "shorthand": "蔬菜",
35
+ "taxRate": undefined
36
+ },
37
+ {
38
+ "itemName": "稻谷",
39
+ "taxClassificationCode": "1010101040000000000",
40
+ "itemModelName": null,
41
+ "shorthand": "谷物",
42
+ "taxRate": 3
43
+ },
44
+ {
45
+ "itemName": "苹果",
46
+ "taxClassificationCode": "1090111090000000000",
47
+ "itemModelName": null,
48
+ "shorthand": "小型起重设备",
49
+ "taxRate": null
50
+ },
51
+ {
52
+ "itemName": "银丝",
53
+ "taxClassificationCode": "1080411120000000000",
54
+ "itemModelName": null,
55
+ "shorthand": "金属制品",
56
+ "taxRate": 3
57
+ },
58
+ {
59
+ "itemName": "布料",
60
+ "taxClassificationCode": "1100101011100000000",
61
+ "itemModelName": null,
62
+ "shorthand": "发电",
63
+ "taxRate": 2
64
+ },
65
+ {
66
+ "itemName": "苹果",
67
+ "taxClassificationCode": "1010115010100000000",
68
+ "itemModelName": null,
69
+ "shorthand": "水果",
70
+ "taxRate": 3
71
+ }
72
+ ] as any
73
+ }
74
+
75
+ this.state.autoComplete.onBuyerTaxIdSearch = this.state.autoComplete.onBuyerNameSearch = async test => {
76
+ return [
77
+ { buyerName: '测试1', buyerTaxId: 'xxxxx1', buyerPhone:'xxxx1' },
78
+ { buyerName: '测试2', buyerTaxId: 'xxxxx2', buyerPhone:'xxxx2' },
79
+ { buyerName: '测试4', buyerTaxId: 'xxxxx4', buyerPhone:'xxxx4' },
80
+ { buyerName: '测试5', buyerTaxId: 'xxxxx5', buyerPhone:'xxxx5' },
81
+ { buyerName: '测试6', buyerTaxId: 'xxxxx6', buyerPhone:'xxxx6' },
82
+ ]
83
+ }
84
+ }
85
+ }
@@ -4,5 +4,11 @@ import IGood from "../GoodsListState/IGood";
4
4
  export default class AutoComplete {
5
5
 
6
6
  /** 商品名称自动补全 */
7
- onItemNameSearch?: (searchText: string) => Promise<IGood[]>
7
+ onItemNameSearch?: (searchText: string) => Promise<IGood[]>;
8
+
9
+ /** 购方名称自动补全 */
10
+ onBuyerNameSearch?: (searchText: string) => Promise<any[]>;
11
+
12
+ /** 统一社会信用代码/纳税人识别号 */
13
+ onBuyerTaxIdSearch?: (searchText: string) => Promise<any[]>;
8
14
  }
@@ -92,6 +92,9 @@ export default class GoodsListState {
92
92
  /** 是否可以合并明细 */
93
93
  isMergeDetails = false;
94
94
 
95
+ /** 是否可以合并折扣 */
96
+ isMergeDiscount = false;
97
+
95
98
  /** 正在 添加商品对照 的货物 */
96
99
  addComparisonIndex?: string;
97
100
  }
@@ -0,0 +1,68 @@
1
+ import { dutyFree, format15, updateUnitPriceExcludingTax, updateUnitPriceTax } from '../../ui/default/GoodsList/hook/useColumns/autoFillFn';
2
+ import { InvoiceControllerState, IGood } from '../';
3
+ import evaluate from '../../tools/evaluate';
4
+ import { countAmountIncludeTax } from '../../tools/calculate';
5
+
6
+ /**
7
+ * 删除一个货物
8
+ */
9
+ export default async (s: InvoiceControllerState, record: any, controller:any) => {
10
+ Object.keys(record).filter(e => !record[e] && record[e] !== 0).forEach(e => { delete record[e] });
11
+
12
+ // 没用 被编辑的货物 和 form 就退出
13
+ if (!s.goodsListState.editGood || !s.goodsListState.form) return;
14
+
15
+ // 导入时清空之前输入的值,使用导入的单价和税率(参考税局系统)
16
+ record.quantity = undefined;
17
+ record.lineAmountExcludeTax = undefined;
18
+ record.lineAmountIncludeTax = undefined;
19
+
20
+ // 中间数据
21
+ const between = { ...record };
22
+ between.itemName = record.itemName;
23
+ between.itemNameOther = record.itemName;
24
+
25
+ // 设置编辑货物
26
+ const editGood: IGood = s.goodsListState.editGood = { ...s.goodsListState.editGood, ...between };
27
+
28
+ if (editGood.taxRate) {
29
+ editGood.taxRate = dutyFree(controller, editGood.taxRate, s.goodsListState.form, editGood)
30
+ }
31
+
32
+ if (`${editGood.priceIncludeTax}` === '0') {
33
+ editGood.priceIncludeTax = undefined;
34
+ editGood.priceExcludeTax = undefined;
35
+ } else {
36
+ editGood.priceExcludeTax = getPriceExcludeTax(editGood, record, s.calculatingDigits) as number;
37
+ }
38
+
39
+ if (editGood.quantity && editGood.priceIncludeTax) {
40
+ editGood.lineAmountIncludeTax = countAmountIncludeTax(editGood.quantity, editGood.priceIncludeTax, s.calculatingDigits);
41
+ }
42
+
43
+ // 导入FORM里
44
+ if (s.goodsListState.isMyShow) {
45
+ s.goodsListState.form.setFieldsValue({
46
+ ...editGood,
47
+ itemName: editGood.itemNameSelf,
48
+ itemModelName: editGood.itemModelNameSelf,
49
+ });
50
+ } else {
51
+ s.goodsListState.form.setFieldsValue({
52
+ ...editGood,
53
+ });
54
+ }
55
+
56
+ s.goodsListState.importGoods.isVisibleDrawer = false;
57
+ s.goodsListState.isTaxIncluded
58
+ ? await updateUnitPriceExcludingTax(controller, s.goodsListState.form, record)
59
+ : await updateUnitPriceTax(controller, s.goodsListState.form, record)
60
+ }
61
+
62
+ /** 货物单价,不含税 */
63
+ const getPriceExcludeTax = (s: IGood, record: any, calculatingDigits?: number) => {
64
+ if ((!s.taxRate && s.taxRate !== 0) || (!record.priceIncludeTax && record.priceIncludeTax !== 0)) return;
65
+
66
+ // 单价(含税)/(1+税率) = 单价(不含税)
67
+ return format15(evaluate(`${record.priceIncludeTax} / (1+${s.taxRate}/100)`), calculatingDigits);
68
+ };
@@ -0,0 +1,29 @@
1
+
2
+
3
+ import { IGood, InvoiceControllerState, LineAttributeType } from '..';
4
+ import { chain, bignumber } from 'mathjs';
5
+ import idGenerator from '../../tools/idGenerator';
6
+
7
+ export default async function mergeDiscount(state: InvoiceControllerState) {
8
+ if (state.goodsListState.goodsList.length <= 1 || state.goodsListState.editGood) return;
9
+
10
+ const goodsList = state.goodsListState.goodsList.slice();
11
+ for (let i = 0; i < goodsList.length; i++) {
12
+ const good = goodsList[i];
13
+ if (good.lineAttribute * 1 === LineAttributeType.被折扣行) {
14
+ const sum: IGood = { ...good, $index: idGenerator(), lineAttribute: LineAttributeType.正常, discountGroup: undefined };
15
+ const zk = goodsList[i + 1];
16
+
17
+ sum.lineAmountExcludeTax = chain(bignumber(good.lineAmountExcludeTax)).subtract(bignumber(Math.abs(zk.lineAmountExcludeTax || 0))).done().toNumber();
18
+ sum.lineAmountIncludeTax = chain(bignumber(good.lineAmountIncludeTax)).subtract(bignumber(Math.abs(zk.lineAmountIncludeTax || 0))).done().toNumber();
19
+ sum.quantity = good.quantity;
20
+ if (sum.quantity) {
21
+ sum.priceExcludeTax = chain(bignumber(good.lineAmountExcludeTax)).divide(bignumber(good.quantity)).done().toNumber();
22
+ sum.priceIncludeTax = chain(bignumber(good.lineAmountIncludeTax)).divide(bignumber(good.quantity)).done().toNumber();
23
+ }
24
+
25
+ goodsList.splice(i, 2, sum);
26
+ }
27
+ }
28
+ state.goodsListState.goodsList = goodsList;
29
+ }
@@ -12,7 +12,9 @@ import addGood from './fns/addGood';
12
12
  import saveEditGood from './fns/saveEditGood';
13
13
  import getGoodsSearch from './fns/getGoodsSearch';
14
14
  import mergeDetails from './fns/mergeDetails';
15
-
15
+ import mergeDiscount from './fns/mergeDiscount';
16
+ import importGoodsDrawer from './fns/importGoodsDrawer';
17
+ 0
16
18
  export { default as InvoiceControllerState } from './InvoiceControllerState';
17
19
  export { default as IGood } from './InvoiceControllerState/GoodsListState/IGood';
18
20
  export { default as LineAttributeType } from './InvoiceControllerState/GoodsListState/LineAttributeType';
@@ -52,12 +54,18 @@ export default class InvoiceController extends InvoiceControllerForm {
52
54
  /** 全单合并明细 */
53
55
  mergeDetails = this.pipeline<any>(mergeDetails);
54
56
 
57
+ /** 全单合并折扣 */
58
+ mergeDiscount = this.pipeline<any>(mergeDiscount);
59
+
55
60
  /** 给一组货物添加折扣行 */
56
61
  addGoodDiscount = this.pipeline(addGoodDiscount);
57
62
 
58
63
  /** 给一组货物添加折扣行 */
59
64
  addGoodDiscountV2 = this.pipeline(addGoodDiscountV2);
60
65
 
66
+ /** 导入商品 */
67
+ importGoodsDrawer = this.pipeline(importGoodsDrawer);
68
+
61
69
  /** 获取 商品 列表 */
62
70
  getGoodsList?: (option?: IGetGoodsListOption | undefined) => Promise<any>;
63
71
 
@@ -2,11 +2,11 @@
2
2
  import { Input } from 'kts-components-antd-x3';
3
3
  import React, { ChangeEvent } from 'react';
4
4
  import { AutoComplete } from 'kts-xui';
5
- import { countAmountIncludeTax } from '../../../../../../../tools/calculate'
5
+ // import { countAmountIncludeTax } from '../../../../../../../tools/calculate'
6
6
  import { IGood, Invoice } from '../../../../../../../..';
7
7
  import './index.less';
8
- import { dutyFree, format15, updateUnitPriceExcludingTax, updateUnitPriceTax } from '../../autoFillFn';
9
- import evaluate from '../../../../../../../tools/evaluate';
8
+ // import { dutyFree, format15, updateUnitPriceExcludingTax, updateUnitPriceTax } from '../../autoFillFn';
9
+ // import evaluate from '../../../../../../../tools/evaluate';
10
10
 
11
11
  export default function ItemNameInput(props: { onChange?: (e: ChangeEvent<HTMLInputElement>) => void, value?: string, shorthand?: string }) {
12
12
 
@@ -37,60 +37,60 @@ export default function ItemNameInput(props: { onChange?: (e: ChangeEvent<HTMLIn
37
37
  // good && controller.state.goodsListState.form?.setFieldsValue(removeNullUndefined(good));
38
38
 
39
39
  const record = options.filter(e => e.itemName === itemName)[0] as any;
40
- debugger;
41
40
  if (!record) return;
42
- controller.run(async s => {
43
- Object.keys(record).filter(e => !record[e] && record[e] !== 0).forEach(e => { delete record[e] });
44
-
45
- // 没用 被编辑的货物 和 form 就退出
46
- if (!s.goodsListState.editGood || !s.goodsListState.form) return;
47
-
48
- // 导入时清空之前输入的值,使用导入的单价和税率(参考税局系统)
49
- record.quantity = undefined;
50
- record.lineAmountExcludeTax = undefined;
51
- record.lineAmountIncludeTax = undefined;
52
-
53
- // 中间数据
54
- const between = { ...record };
55
- between.itemName = record.itemName;
56
- between.itemNameOther = record.itemName;
57
-
58
- // 设置编辑货物
59
- const editGood: IGood = s.goodsListState.editGood = { ...s.goodsListState.editGood, ...between };
60
-
61
- if (editGood.taxRate) {
62
- editGood.taxRate = dutyFree(controller, editGood.taxRate, s.goodsListState.form, editGood)
63
- }
64
-
65
- if (`${editGood.priceIncludeTax}` === '0') {
66
- editGood.priceIncludeTax = undefined;
67
- editGood.priceExcludeTax = undefined;
68
- } else {
69
- editGood.priceExcludeTax = getPriceExcludeTax(editGood, record, s.calculatingDigits) as number;
70
- }
71
-
72
- if (editGood.quantity && editGood.priceIncludeTax) {
73
- editGood.lineAmountIncludeTax = countAmountIncludeTax(editGood.quantity, editGood.priceIncludeTax, s.calculatingDigits);
74
- }
75
-
76
- // 导入FORM里
77
- if (s.goodsListState.isMyShow) {
78
- s.goodsListState.form.setFieldsValue({
79
- ...editGood,
80
- itemName: editGood.itemNameSelf,
81
- itemModelName: editGood.itemModelNameSelf,
82
- });
83
- } else {
84
- s.goodsListState.form.setFieldsValue({
85
- ...editGood,
86
- });
87
- }
88
-
89
- s.goodsListState.importGoods.isVisibleDrawer = false;
90
- s.goodsListState.isTaxIncluded
91
- ? await updateUnitPriceExcludingTax(controller, s.goodsListState.form, record)
92
- : await updateUnitPriceTax(controller, s.goodsListState.form, record)
93
- })
41
+ controller.importGoodsDrawer(record);
42
+ // controller.run(async s => {
43
+ // Object.keys(record).filter(e => !record[e] && record[e] !== 0).forEach(e => { delete record[e] });
44
+
45
+ // // 没用 被编辑的货物 form 就退出
46
+ // if (!s.goodsListState.editGood || !s.goodsListState.form) return;
47
+
48
+ // // 导入时清空之前输入的值,使用导入的单价和税率(参考税局系统)
49
+ // record.quantity = undefined;
50
+ // record.lineAmountExcludeTax = undefined;
51
+ // record.lineAmountIncludeTax = undefined;
52
+
53
+ // // 中间数据
54
+ // const between = { ...record };
55
+ // between.itemName = record.itemName;
56
+ // between.itemNameOther = record.itemName;
57
+
58
+ // // 设置编辑货物
59
+ // const editGood: IGood = s.goodsListState.editGood = { ...s.goodsListState.editGood, ...between };
60
+
61
+ // if (editGood.taxRate) {
62
+ // editGood.taxRate = dutyFree(controller, editGood.taxRate, s.goodsListState.form, editGood)
63
+ // }
64
+
65
+ // if (`${editGood.priceIncludeTax}` === '0') {
66
+ // editGood.priceIncludeTax = undefined;
67
+ // editGood.priceExcludeTax = undefined;
68
+ // } else {
69
+ // editGood.priceExcludeTax = getPriceExcludeTax(editGood, record, s.calculatingDigits) as number;
70
+ // }
71
+
72
+ // if (editGood.quantity && editGood.priceIncludeTax) {
73
+ // editGood.lineAmountIncludeTax = countAmountIncludeTax(editGood.quantity, editGood.priceIncludeTax, s.calculatingDigits);
74
+ // }
75
+
76
+ // // 导入FORM里
77
+ // if (s.goodsListState.isMyShow) {
78
+ // s.goodsListState.form.setFieldsValue({
79
+ // ...editGood,
80
+ // itemName: editGood.itemNameSelf,
81
+ // itemModelName: editGood.itemModelNameSelf,
82
+ // });
83
+ // } else {
84
+ // s.goodsListState.form.setFieldsValue({
85
+ // ...editGood,
86
+ // });
87
+ // }
88
+
89
+ // s.goodsListState.importGoods.isVisibleDrawer = false;
90
+ // s.goodsListState.isTaxIncluded
91
+ // ? await updateUnitPriceExcludingTax(controller, s.goodsListState.form, record)
92
+ // : await updateUnitPriceTax(controller, s.goodsListState.form, record)
93
+ // })
94
94
  }, [options, controller])
95
95
 
96
96
  return (
@@ -117,9 +117,9 @@ export default function ItemNameInput(props: { onChange?: (e: ChangeEvent<HTMLIn
117
117
  // }
118
118
 
119
119
  /** 货物单价,不含税 */
120
- const getPriceExcludeTax = (s: IGood, record: any, calculatingDigits?: number) => {
121
- if ((!s.taxRate && s.taxRate !== 0) || (!record.priceIncludeTax && record.priceIncludeTax !== 0)) return;
120
+ // const getPriceExcludeTax = (s: IGood, record: any, calculatingDigits?: number) => {
121
+ // if ((!s.taxRate && s.taxRate !== 0) || (!record.priceIncludeTax && record.priceIncludeTax !== 0)) return;
122
122
 
123
- // 单价(含税)/(1+税率) = 单价(不含税)
124
- return format15(evaluate(`${record.priceIncludeTax} / (1+${s.taxRate}/100)`), calculatingDigits);
125
- };
123
+ // // 单价(含税)/(1+税率) = 单价(不含税)
124
+ // return format15(evaluate(`${record.priceIncludeTax} / (1+${s.taxRate}/100)`), calculatingDigits);
125
+ // };
@@ -28,6 +28,7 @@ import useEndowCodeButton from './ui/BulkMenu/hooks/useEndowCodeButton';
28
28
  import useDelRowButton from './ui/BulkMenu/hooks/useDelRowButton';
29
29
  import useAddDiscountRowButton from './ui/BulkMenu/hooks/useAddDiscountRowButton';
30
30
  import useMergeDetails from './ui/BulkMenu/hooks/useMergeDetails';
31
+ import useMergeDiscount from './ui/BulkMenu/hooks/useMergeDiscount';
31
32
 
32
33
  export interface IGoodsListProps {
33
34
  /** 扩展部分 */
@@ -87,6 +88,9 @@ const Main = decorator<IGoodsListProps, FormComponentProps & IGoodsListProps>(Fo
87
88
  /** 全单合并明细 */
88
89
  const mergeDetails = useMergeDetails()
89
90
 
91
+ /** 全单合并折扣 */
92
+ const mergeDiscount = useMergeDiscount()
93
+
90
94
  /** 清空自动赋码缓存 */
91
95
  React.useEffect(() => {
92
96
  controller.run(async s => { s.goodsListState.endowCode.cache = {} });
@@ -139,6 +143,9 @@ const Main = decorator<IGoodsListProps, FormComponentProps & IGoodsListProps>(Fo
139
143
  {/* 全单合并明细 */}
140
144
  {mergeDetails.button}
141
145
 
146
+ {/* 全单合并折扣 */}
147
+ {mergeDiscount.button}
148
+
142
149
  {/* 添加折扣行 */}
143
150
  {addDiscountRowButton.drawer}
144
151
 
@@ -16,7 +16,7 @@ export default function useMergeDetails() {
16
16
  await controller.saveEditGood();
17
17
  await controller.wait();
18
18
  await controller.mergeDetails();
19
- }, [])
19
+ }, [controller])
20
20
 
21
21
  const button = React.useMemo(() => {
22
22
  if (!isMergeDetails) return <></>;
@@ -0,0 +1,37 @@
1
+
2
+ import React from "react"
3
+ import { Button } from "kts-components-antd-x3"
4
+ import Invoice from '../../../../../../..'
5
+
6
+ /** 全单合并折扣 */
7
+ export default function useMergeDiscount() {
8
+
9
+ const controller = Invoice.useInvoiceController();
10
+
11
+ const goodsList = controller.useMemo(s => s.goodsListState.goodsList, []);
12
+
13
+ const isMergeDiscount = controller.useMemo(s => s.goodsListState.isMergeDiscount, []);
14
+
15
+ const onClick = React.useCallback(async () => {
16
+ await controller.saveEditGood();
17
+ await controller.wait();
18
+ await controller.mergeDiscount();
19
+ }, [controller])
20
+
21
+ const button = React.useMemo(() => {
22
+ if (!isMergeDiscount) return <></>;
23
+ return (
24
+ <Button
25
+ onClick={onClick}
26
+ disabled={goodsList.length <= 1}
27
+ >
28
+ 合并折扣
29
+ </Button>
30
+ )
31
+ }, [goodsList.length])
32
+
33
+ return {
34
+ /** 按钮 */
35
+ button,
36
+ }
37
+ }
@@ -1,24 +1,50 @@
1
1
 
2
- import { Input } from 'kts-xui';
2
+ import { AutoComplete, Input } from 'kts-xui';
3
3
  import React, { ChangeEvent } from 'react';
4
+ import { IGood, Invoice } from '../../../../../../../..';
4
5
  import './index.less';
5
6
 
6
- export default function ItemNameInput(props: {
7
- onChange?: (e: ChangeEvent<HTMLInputElement>) => void,
8
- suffix?: React.ReactNode,
9
- value?: string,
10
- shorthand?: string
7
+ export default function ItemNameInput(props: {
8
+ onChange?: (e: ChangeEvent<HTMLInputElement>) => void,
9
+ suffix?: React.ReactNode,
10
+ value?: string,
11
+ shorthand?: string
11
12
  }) {
12
13
 
14
+ const controller = Invoice.useInvoiceController();
15
+
16
+ const autoComplete = controller.useMemo(s => s.autoComplete, [])
17
+
18
+ const [options, setOptions] = React.useState<IGood[]>([])
19
+
13
20
  const onChange = React.useCallback((e: ChangeEvent<HTMLInputElement>) => {
14
21
  const event = { ...e };
15
22
  props.onChange && props.onChange(event);
16
23
  }, [])
17
24
 
25
+ const onChangeAutoComplete = React.useCallback(itemName => {
26
+ const record = options.filter(e => e.itemName === itemName)[0] as any;
27
+ if (!record) return;
28
+ controller.importGoodsDrawer(record);
29
+ }, [options, controller])
30
+
31
+ const onSearch = React.useCallback(async (searchText: string) => {
32
+ try {
33
+ if (autoComplete.onItemNameSearch) {
34
+ setOptions(await autoComplete.onItemNameSearch(searchText));
35
+ }
36
+ } catch (error) {
37
+ setOptions([]);
38
+ throw error;
39
+ }
40
+ }, [autoComplete.onItemNameSearch])
41
+
18
42
  return (
19
43
  <div className='kts-invoice-operate-goods-list-itemName-input'>
20
44
  {props.shorthand && <span style={{ alignSelf: 'center', fontSize: 12 }} >*{props.shorthand}*</span>}
21
- <Input style={{ height: '100%' }} value={props.value} onChange={onChange} suffix={props.suffix} />
45
+ <AutoComplete onSearch={onSearch} options={options.map(e => ({ value: e.itemName }))} onChange={onChangeAutoComplete} >
46
+ <Input style={{ height: '100%' }} value={props.value} onChange={onChange} suffix={props.suffix} />
47
+ </AutoComplete>
22
48
  </div>
23
49
  )
24
50
  }