import React from 'react'; import { Modal, Form, Radio, Space } from 'kts-components-antd-x4'; import { Button, message } from 'kts-xui' import Invoice from '../../..'; import './index.less'; import LineAttributeType from '@/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType'; export default () => { const controller = Invoice.useInvoiceController(); const [form] = Form.useForm(); const [mainOption, setMainOption] = React.useState(null); const [subOption, setSubOption] = React.useState(null); // 监听煤炭种类变化 const mtzlDm = Form.useWatch('mtzlDm', form); const visible = controller.useMemo((s) => s.goodsListState.meiTanGoodIndex && s.goodsListState.meiTanGoodIndex.length > 0, []); const onClose = React.useCallback(() => { controller.pipeline(async (s) => { s.goodsListState.meiTanGoodIndex = []; form.setFieldsValue({ mtzlDm: undefined }); setMainOption(null); setSubOption(null); })(); }, [controller]); // 提交表单 const onSubmit = () => { form.submit(); }; // 表单 const onFinish = (values: any) => { // console.log('煤炭种类:', values); controller.pipeline(async (s) => { const mtzl = subOption || mainOption || undefined; //values.mtzlDm; console.log('煤炭种类', mtzl) const goods = s.goodsListState.meiTanGoodIndex?.map(e => s.goodsListState.goodsMap.get(e)) || []; const editGood = s.goodsListState.editGood; const editGoodIndex = editGood?.$index; goods.forEach((g) => { if (!g) return; if (g.lineAttribute === LineAttributeType.被折扣行 || g.lineAttribute === LineAttributeType.正常) { g.mtzlDm = mtzl; if (editGood && editGoodIndex === g.$index) { // 编辑行 editGood.mtzlDm = mtzl; } } }); s.goodsListState.goodsList = s.goodsListState.goodsList.slice(); onClose(); })(); }; // 自定义校验规则 const validateOption = (_: any, value: any, callback: any) => { console.log('自定义校验规则:', value); if (!value) { return Promise.reject(new Error('请选择选项')); // callback('请选择选项'); } if (value === '0200' && !subOption) { return Promise.reject(new Error('请选择长协煤的子选项')); } return Promise.resolve(); }; const handleMainOptionChange = (e: any) => { const value = e.target.value; setMainOption(value); if (value === '0100' || value === '0300') { //form.setFieldsValue({ mtzlDm: value }); setSubOption(null); } else if (value === '0200') { //form.setFieldsValue({ mtzlDm: undefined }); // 清空option,等待选择子选项 // setSubOption(null); } }; const handleSubOptionChange = (e: any) => { const value = e.target.value; setSubOption(value); form.validateFields(); }; return ( } >
尊敬的纳税人:
您选择了“煤炭”类商品编码,请根据真实业务情况选择 “煤炭种类”:
政府保供煤
长协煤 {mainOption === '0200' && (
*请选择协议期限:
协议期不足半年 协议期在半年至一年之间 协议期在一年至两年之间 协议期在两年以上
)}
市场煤
); };