kts-component-invoice-operate 3.2.246 → 3.2.248

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.
@@ -0,0 +1,155 @@
1
+ import React from 'react';
2
+ import { Modal, Form, Radio, Space } from 'kts-components-antd-x4';
3
+ import { Button, message } from 'kts-xui'
4
+ import Invoice from '../../..';
5
+ import './index.less';
6
+ import LineAttributeType from '@/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType';
7
+
8
+ export default () => {
9
+
10
+ const controller = Invoice.useInvoiceController();
11
+
12
+ const [form] = Form.useForm();
13
+
14
+ const [mainOption, setMainOption] = React.useState(null);
15
+ // 监听煤炭种类变化
16
+ const mtzlDm = Form.useWatch('mtzlDm', form);
17
+
18
+ const visible = controller.useMemo((s) => s.goodsListState.meiTanGoodIndex && s.goodsListState.meiTanGoodIndex.length > 0, []);
19
+
20
+ const onClose = React.useCallback(() => {
21
+ controller.pipeline(async (s) => {
22
+ s.goodsListState.meiTanGoodIndex = [];
23
+ form.setFieldsValue({ mtzlDm: undefined });
24
+ setMainOption(null);
25
+ })();
26
+ }, [controller]);
27
+
28
+ // 提交表单
29
+ const onSubmit = () => {
30
+ form.submit();
31
+ };
32
+
33
+ // 表单
34
+ const onFinish = (values: any) => {
35
+ console.log('煤炭种类:', values);
36
+
37
+ controller.pipeline(async (s) => {
38
+ const mtzl = values.mtzlDm;
39
+ const goods = s.goodsListState.meiTanGoodIndex?.map(e => s.goodsListState.goodsMap.get(e)) || [];
40
+ const editGood = s.goodsListState.editGood;
41
+ const editGoodIndex = editGood?.$index;
42
+ goods.forEach((g) => {
43
+ if (!g) return;
44
+ if (g.lineAttribute === LineAttributeType.被折扣行 || g.lineAttribute === LineAttributeType.正常) {
45
+ g.mtzlDm = mtzl;
46
+ if (editGood && editGoodIndex === g.$index) { // 编辑行
47
+ editGood.mtzlDm = mtzl;
48
+ }
49
+ }
50
+ });
51
+ s.goodsListState.goodsList = s.goodsListState.goodsList.slice();
52
+ onClose();
53
+ })();
54
+
55
+ };
56
+
57
+ // 自定义校验规则
58
+ const validateOption = (_:any, value: any, callback: any) => {
59
+ console.log('自定义校验规则:', value);
60
+ if (!value) {
61
+ return Promise.reject(new Error('请选择选项'));
62
+ // callback('请选择选项');
63
+ }
64
+
65
+ if (value === '0200') {
66
+ return Promise.reject(new Error('请选择长协煤的子选项'));
67
+ }
68
+
69
+ return Promise.resolve();
70
+ };
71
+
72
+ const handleMainOptionChange = (e: any) => {
73
+ const value = e.target.value;
74
+ setMainOption(value);
75
+ if (value === 'A' || value === 'C') {
76
+ form.setFieldsValue({ mtzlDm: value });
77
+ } else if (value === 'B') {
78
+ form.setFieldsValue({ mtzlDm: undefined }); // 清空option,等待选择子选项
79
+ }
80
+ };
81
+
82
+ return (
83
+ <Modal
84
+ title="温馨提示"
85
+ destroyOnClose={true}
86
+ width={700}
87
+ onCancel={onClose}
88
+ visible={visible}
89
+ footer={
90
+ <Space align='end' style={{ paddingRight: 20 }}>
91
+ <Button
92
+ onClick={onClose}
93
+ className='kts-invoice-operate-meitan-button'
94
+ >
95
+ 取消
96
+ </Button>
97
+ <Button type="primary" onClick={onSubmit} className='kts-invoice-operate-meitan-button'>
98
+
99
+ 确定
100
+ </Button>
101
+ </Space>
102
+ }
103
+ >
104
+ <div className='kts-invoice-operate-meitan-modal'>
105
+ <div className='kts-invoice-operate-meitan-title'>
106
+ <div>尊敬的纳税人:</div>
107
+ <div className='kts-invoice-operate-meitan-title2'>您选择了“煤炭”类商品编码,请根据真实业务情况选择
108
+ “煤炭种类”:</div>
109
+ </div>
110
+ <div className='kts-invoice-operate-meitan-content'>
111
+ <Form
112
+ form={form}
113
+ layout="vertical"
114
+ initialValues={{ mtzlDm: null }}
115
+ onFinish={onFinish}
116
+ >
117
+ <Form.Item
118
+ name="mtzlDm"
119
+ label=""
120
+ rules={[
121
+ // { required: true , message: '请选择煤炭种类' },
122
+ { validator: validateOption }
123
+ ]}
124
+ >
125
+ <Radio.Group value={mainOption} onChange={handleMainOptionChange}>
126
+ <Space direction="vertical">
127
+ <Radio value="0100">政府保供煤</Radio>
128
+ <div>
129
+ <Radio value="0200">长协煤</Radio>
130
+ {mainOption === '0200' && (
131
+ <div className='content-item'>
132
+ <div style={{ marginBottom: 8, color: '#666', fontSize: 14 }}>
133
+ <span style={{ color: 'red' }}>*</span>请选择协议期限:
134
+ </div>
135
+ <Radio.Group value={mtzlDm} onChange={(e) => form.setFieldsValue({ mtzlDm: e.target.value })}>
136
+ <Space direction="vertical">
137
+ <Radio value="0201">协议期不足半年</Radio>
138
+ <Radio value="0202">协议期在半年至一年之间</Radio>
139
+ <Radio value="0203">协议期在一年至两年之间</Radio>
140
+ <Radio value="0204">协议期在两年以上</Radio>
141
+ </Space>
142
+ </Radio.Group>
143
+ </div>
144
+ )}
145
+ </div>
146
+ <Radio value="0300">市场煤</Radio>
147
+ </Space>
148
+ </Radio.Group>
149
+ </Form.Item>
150
+ </Form>
151
+ </div>
152
+ </div>
153
+ </Modal>
154
+ );
155
+ };