в процессе

This commit is contained in:
Nikolai 2022-11-01 15:59:44 +06:00
parent e434d1c1c2
commit 571ad5731c

@ -112,6 +112,10 @@ const DataGridElement: React.FC<MWProps> = ({ openModal }) => {
let price = 0; let price = 0;
let prices = 0; let prices = 0;
const [ refreshX, setRefreshX ] = React.useState(1);
const refresh = () => { setRefreshX( refreshX + 1 ); }
console.log("RENDER")
const { discountsArray, discountsArraySet } = useStore<StoreState>((state) => state); const { discountsArray, discountsArraySet } = useStore<StoreState>((state) => state);
const { discountsActiveArray, discountsActiveArraySet } = useStore<StoreState>((state) => state); const { discountsActiveArray, discountsActiveArraySet } = useStore<StoreState>((state) => state);
@ -190,6 +194,8 @@ const DataGridElement: React.FC<MWProps> = ({ openModal }) => {
setSelectedPromocode( codeNumber ); setSelectedPromocode( codeNumber );
} }
const fieldAdded = React.useRef<HTMLInputElement | null>(null);
return ( return (
<Box style={{ width: "100%" }}> <Box style={{ width: "100%" }}>
<Box style={{ height: 400 }}> <Box style={{ height: 400 }}>
@ -405,7 +411,8 @@ const DataGridElement: React.FC<MWProps> = ({ openModal }) => {
style: { style: {
color: theme.palette.secondary.main color: theme.palette.secondary.main
} }} } }}
//inputRef={ fieldPromocode } inputRef={ fieldAdded }
onChange={ () => refresh() }
/> />
</Box> </Box>
@ -450,7 +457,7 @@ const DataGridElement: React.FC<MWProps> = ({ openModal }) => {
if( selectedPromocode >= 0 && checkboxStates == 1 ) { if( selectedPromocode >= 0 && checkboxStates == 1 ) {
promocodeArray[ selectedPromocode ].privileges.forEach( (privilege) => { promocodeArray[ selectedPromocode ].privileges.forEach( (privilege) => {
if( tariff.service == privilege.good ) { if( tariff.service == privilege.good ) {
tariffPrice = tariffPrice * privilege.discount; tariffPrice = tariffPrice - (tariffPrice * privilege.discount);
} }
} ) } )
} }
@ -463,7 +470,7 @@ const DataGridElement: React.FC<MWProps> = ({ openModal }) => {
discount.privileges.forEach( (privilege) => { discount.privileges.forEach( (privilege) => {
if( tariff.service == privilege.good ) { if( tariff.service == privilege.good ) {
if( privilege.discount != 0 ) { if( privilege.discount != 0 ) {
tariffPrice = tariffPrice * privilege.discount; tariffPrice = tariffPrice - (tariffPrice * privilege.discount);
} }
} }
}); });
@ -484,7 +491,7 @@ const DataGridElement: React.FC<MWProps> = ({ openModal }) => {
if( selectedPromocode >= 0 && checkboxStates == 1 ) { if( selectedPromocode >= 0 && checkboxStates == 1 ) {
promocodeArray[ selectedPromocode ].privileges.forEach( (privilege) => { promocodeArray[ selectedPromocode ].privileges.forEach( (privilege) => {
if( item.service == privilege.good ) { if( item.service == privilege.good ) {
price = price * privilege.discount; price = price - (price * privilege.discount);
} }
} ) } )
} }
@ -497,7 +504,36 @@ const DataGridElement: React.FC<MWProps> = ({ openModal }) => {
discount.privileges.forEach( (privilege) => { discount.privileges.forEach( (privilege) => {
if( item.service == privilege.good ) { if( item.service == privilege.good ) {
if( privilege.discount != 0 ) { if( privilege.discount != 0 ) {
price = price * privilege.discount;
if( fieldAdded.current != null ) { // внесено
if( fieldAdded.current.value ) {
const f = Number(fieldAdded.current.value);
let minDiscount = 0;
let minI = -1;
discountsArray.forEach( (x, ii) => {
discount.privileges.forEach( (y) => {
if( item.service == y.good ) {
if( x.active && f - y.discount * 100 >= minDiscount ) {
minDiscount = y.discount;
minI = ii;
}
}
});
});
discountsArray[ minI ].privileges.forEach( (y) => {
price = price - (price * y.discount);
});
} else {
price = price - (price * privilege.discount);
}
} else { // не внесено
price = price - (price * privilege.discount);
}
} }
} }
}); });