const POSVAT=(props)=>{
const {Row, Col} = ReactBootstrap
const { baskets, setBaskets, handleClose, member, config } = props;
const [buyerLegalName, setBuyerLegalName] = useState('');
const [buyerTaxCode, setBuyerTaxCode] = useState('');
const [buyerName, setBuyerName] = useState(`${member?.family_name ||''} ${member?.given_name || ''} `);
const [buyerMobile, setBuyerMobile] = useState(member?.mobile);
const [buyerAddress, setBuyerAddress] = useState(`${member?.district || ''} ${member?.city || ''}`);
const [buyerEmail, setBuyerEmail] = useState(member?.email);
useEffect(()=>{
if(baskets?.basket?.invoice_info){
const info = baskets.basket.invoice_info;
setBuyerTaxCode( info.buyerTaxCode || '');
setBuyerName( info.buyerName || '');
setBuyerLegalName( info.buyerLegalName || '');
setBuyerMobile( info.buyerMobile || '');
setBuyerAddress( info.buyerAddress || '');
setBuyerEmail( info.buyerEmail || '');
}
},[])
const handleSaveToBasket = async () => {
// Kiểm tra sự tồn tại của basket
const currentBaskets = baskets || { items: [], basket: {} };
// Kế thừa thông tin đã có và thêm invoice_info
const updatedBaskets = {
...currentBaskets,
basket: {
...currentBaskets.basket,
invoice_info: {
buyerTaxCode: buyerTaxCode,
buyerName: buyerName,
buyerLegalName: buyerLegalName,
buyerMobile: buyerMobile,
buyerAddress: buyerAddress,
buyerEmail: buyerEmail,
}
}
};
// Cập nhật giỏ hàng
setBaskets(updatedBaskets);
handleClose()
};
return (
<>
setBuyerTaxCode(e.target.value)}
type='text'
required={false}
feedback={null}
onEnter={null}
size="sm"
autoFocus={false}
onFocus={null}
style={{ textAlign: 'left' }}
styleInput={{ textAlign: 'left' }}
disabled={false}
tabIndex="0"
/>
setBuyerMobile( e.target.value)}
type='text'
required={false}
feedback={null}
onEnter={null}
size="sm"
autoFocus={false}
onFocus={null}
style={{ textAlign: 'left' }}
styleInput={{ textAlign: 'left' }}
disabled={false}
tabIndex="0"
/>
setBuyerName(e.target.value)}
type='text'
required={false}
feedback={null}
onEnter={null}
size="sm"
autoFocus={false}
onFocus={null}
style={{ textAlign: 'left' }}
styleInput={{ textAlign: 'left' }}
disabled={false}
tabIndex="0"
/>
setBuyerEmail(e.target.value)}
type='text'
required={false}
feedback={null}
onEnter={null}
size="sm"
autoFocus={false}
onFocus={null}
style={{ textAlign: 'left' }}
styleInput={{ textAlign: 'left' }}
disabled={false}
tabIndex="0"
/>
setBuyerLegalName(e.target.value)}
type='text'
required={false}
feedback={null}
onEnter={null}
size="sm"
autoFocus={false}
onFocus={null}
style={{ textAlign: 'left' }}
styleInput={{ textAlign: 'left' }}
disabled={false}
tabIndex="0"
/>
setBuyerAddress(e.target.value)}
type='text'
required={false}
feedback={null}
onEnter={null}
size="sm"
autoFocus={false}
onFocus={null}
style={{ textAlign: 'left' }}
styleInput={{ textAlign: 'left' }}
disabled={false}
tabIndex="0"
/>
{config?.lang=='vi'?"Đóng":"Close"}}
onClick={handleClose}
variant='secondary'
type='button'
style={{ float:'right', margin:10}}
visible={true}
tabIndex={0}
/>
{config?.lang=='vi'?"Lưu":"Save"}}
onClick={handleSaveToBasket}
variant='primary'
type='button'
style={{ float:'right', margin:10}}
visible={true}
tabIndex={0}
/>
>
);
};