import React, { useEffect } from "react"; import { decorator } from 'grey-react-box'; import { Form, message } from 'kts-components-antd-x3'; import { FormComponentProps } from 'kts-components-antd-x3/lib/form'; import Invoice from '../../..'; import './index.less'; import { Button, Cascader, Col, DatePicker, Input, Row, Select } from "kts-components-antd-x4"; import moment from "moment"; const { RangePicker } = DatePicker; export interface RealEstateInfoProps { /** * 不动产地址数据 */ realEstateAddressOptions?: any[]; /** * 不动产地址数据字段名 */ realEstateAddressFieldNames?: any; } /** 特殊信息-不动产经营租赁服务 */ export default decorator(Form.create())(props => { /** 控制器 */ const controller = Invoice.useInvoiceController(); const editGood = controller.useMemo(s => s.goodsListState.editGood, []); const { form } = props; const { getFieldDecorator } = form; const model = controller.useMemo(s => s.model, []); const readOnly = React.useMemo(() => model === 'readOnly', [model]); const goodsList = controller.useMemo(s => s.goodsListState.goodsList, []); //outcome-104 任务 https://wiki.dev.kingxunlian.com/pages/viewpage.action?pageId=180355189 //商品和服务税收分类合并编码为“3040502020200000000”时,视为停车费业务,针对停车费业务,蓝字发票增加以下判断: // 单位必须为“平方米”; // 项目名称必须为“车辆停放服务”; // 车牌号必填,最多支持填写3个车牌号;除该场景车牌号必须为空; // 租赁期起止格式必须为“yyyy-MM-dd HH:mm(租赁期起)”+“空格”+“yyyy-MM-dd HH:mm(租赁期止)。 const isParkFee = React.useCallback((taxClassificationCode?: string) => { if (taxClassificationCode === '3040502020200000000') { return true } else { return false; } }, []) const indexRef = React.useRef([]); useEffect(() => { const dd = goodsList?.reduce((acc: any, cur: any) => { if (cur.lineAttribute !== 1) { acc.push(cur.$index) } return acc }, []) indexRef.current = dd; }, [goodsList, indexRef]) // 注册 form controller.useForm('realEstateInfo', form); const getList = () => { const decrease = indexRef.current.length > goodsList.length if (decrease) { //已删行列表 const diff = indexRef.current.filter((item: any) => !goodsList.find(i => i.$index === item)); const formData: any[] = form.getFieldValue('realEstateDataDto'); if (Array.isArray(formData) && diff.length > 0) { const newForm = formData?.filter(item => !diff.find((i: any) => i === item.$index)); form.setFieldsValue({ realEstateDataDto: newForm }); } else { form.setFieldsValue({ realEstateDataDto: undefined }); } } return goodsList.filter(item => item.lineAttribute !== 1).map((item, index) => { if (item.lineAttribute !== 1) { const isParkFeeItem = editGood?.$index === item.$index ? isParkFee(editGood.taxClassificationCode) : isParkFee(item.taxClassificationCode) return {getFieldDecorator(`realEstateDataDto[${index}].$index`, { initialValue: item.$index, })( )} {getFieldDecorator(`realEstateDataDto[${index}].realEstateAddress`, { rules: readOnly ? [] : [{ required: true, message: '请选择不动产地址' }] })( readOnly ? () : () )} {getFieldDecorator(`realEstateDataDto[${index}].realEstateDetailedAddress`, { rules: readOnly ? [] : [ { required: true, message: '请输入详细地址' }, { max: 120, message: '详细地址最多120个字符' }, { validator: async (_, value, callback) => { const pattern = /街|路|村|乡|镇|道|巷|号/; if (pattern.test(value)) { callback() } else { callback('地址必须包含“街”、“路”、“村”、“乡”、“镇”、“道”、“巷”、“号”等任意一个关键词') } } } ] })( readOnly ? : )} {!isParkFeeItem && {getFieldDecorator(`realEstateDataDto[${index}].leaseTerm`, { rules: readOnly ? [] : [{ required: true, message: '请输入租赁期' }] })( readOnly ? : )} } {isParkFeeItem && {getFieldDecorator(`realEstateDataDto[${index}].leaseTerm`, { rules: readOnly ? [] : [{ required: true, message: '请输入租赁期' }] })( readOnly ? : )} } {getFieldDecorator(`realEstateDataDto[${index}].crossCitiesSign`, { rules: readOnly ? [] : [ { required: true, message: '请选择跨地(市)标志' } ] })( readOnly ? : )} {getFieldDecorator(`realEstateDataDto[${index}].realEstateNumber`, { rules: readOnly ? [] : [ { required: true, message: '请输入证书编号,若没有证书填写“无”' }, { max: 40, message: '证书编号最多40个字符' }, ] })( readOnly ? : )} {!isParkFeeItem && {getFieldDecorator(`realEstateDataDto[${index}].realEstateUnit`, { rules: readOnly ? [] : [{ required: true, message: '请选择面积单位' }] })( readOnly ? : )} } {isParkFeeItem && {getFieldDecorator(`realEstateDataDto[${index}].realEstateUnit`, { rules: readOnly ? [] : [{ required: true, message: '请选择面积单位' }] })( readOnly ? : )} } {isParkFeeItem && // // // {getFieldDecorator(`realEstateDataDto[${index}].licensePlateNumber`, { // rules: readOnly ? [] : [{ required: true, message: '请选择面积单位' }] // })( // readOnly // ? // : // )} // // } } }) } return (
特定信息-不动产经营租赁服务
{getList()}
) }) class MyDiv extends React.Component<{ value?: string, style?: React.CSSProperties }> { render(): React.ReactNode { return (
{this.props.value}
) } } class MyArrString extends React.Component<{ value?: string[], style?: React.CSSProperties }> { render(): React.ReactNode { return (
{ this.props.value?.filter(e => !!e) .join(',') }
) } } class MyArrMoment extends React.Component<{ value?: moment.Moment[], style?: React.CSSProperties }> { render(): React.ReactNode { const { value = [] } = this.props return (
{moment.isMoment(value[0]) && value[0].format('YYYY-MM-DD')} - {moment.isMoment(value[1]) && value[1].format('YYYY-MM-DD')}
) } } class MyArrMomentTime extends React.Component<{ value?: moment.Moment[], style?: React.CSSProperties }> { render(): React.ReactNode { const { value = [] } = this.props return (
{moment.isMoment(value[0]) && value[0].format('YYYY-MM-DD HH:mm')} - {moment.isMoment(value[1]) && value[1].format('YYYY-MM-DD HH:mm')}
) } } class MyNY extends React.Component<{ value?: 'Y' | 'N', style?: React.CSSProperties }> { render(): React.ReactNode { return (
{ this.props.value === 'Y' ? '是' : '否' }
) } } interface PriceInputProps { // value?: string[]; // style?: React.CSSProperties // onChange?: (value: string[]) => void; form: any, index: number cd?: number readOnly: boolean } const LicensePlateNumber: React.FC = (props) => { const { form, readOnly } = props; const { getFieldDecorator } = form; const licenceLimit = 3; // 最多支持填写3个车牌号 const formData: any[] = form.getFieldValue('realEstateDataDto'); const [value, setVal] = React.useState(new Array(props.cd || 1).fill('')); const cd = React.useMemo(() => formData[props.index]?.cd, [formData[props.index]?.cd]) // useEffect(() => { // if (cd) { // const dd = value.concat(new Array(cd.length-1).fill('')) // setVal(dd); // } // }, [cd]) const onAdd = () => { if (value.length < licenceLimit) { setVal([...value, '']); } else { message.warn('最多支持填写3个车牌号') } } // 删除车牌号 const onDelete = () => { if (value.length > 0) { const dd = value.slice(0, -1) setVal(dd); } } return <> { value.length > 0 && value.map((item: string[], key: number) => { return {getFieldDecorator(`realEstateDataDto[${props.index}].cphList[${key}]`, { rules: readOnly ? [] : [{ required: true, message: '请输入车牌号,最多20位' }] })( readOnly ? : )} }) } {/* {getFieldDecorator(`realEstateDataDto[${props.index}].cd`, { })( { onInputChange(e, index) }} key={index} style={{ width: '100%' }} autoComplete='off' placeholder="请输入车牌号" /> // )} // // // // // { onInputChange(e, index) }} key={index} style={{ width: '100%' }} autoComplete='off' placeholder="请输入车牌号" /> // // // })} // // {newArrLength > 1 && } // // ) // }