From 7d8017fcbbe275cc5689347fcecf0507c3217e1b Mon Sep 17 00:00:00 2001 From: inmake Date: Tue, 11 Apr 2023 20:28:17 +0500 Subject: [PATCH] upd --- src/components/Calc.tsx | 51 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/components/Calc.tsx b/src/components/Calc.tsx index 36fa3f9..0ac2092 100644 --- a/src/components/Calc.tsx +++ b/src/components/Calc.tsx @@ -7,16 +7,14 @@ function Calc() { const [regions, setRegions] = useState([]); const [consultsPerMonth, setConsultsPerMonth] = useState(100); // Консультации в месяц const [totalHousingAreaInComplex, setTotalAreaHousingInComplex] = - useState("10000"); // Общая площадь жилья в комплексе (м2) + useState(10000); // Общая площадь жилья в комплексе (м2) const [averageApartmentArea, setAverageApartmentArea] = useState(50); // Средняя площадь квартиры const [averagePrice, setAveragePrice] = useState(100000); // Средняя стоиомость за 1 м2 - const [consultsInBooking, setConsultsInBooking] = useState( - Math.round(consultsPerMonth * 0.3) - ); - const [consultsInSales, setConsultsInSales] = useState( - Math.round(consultsPerMonth * 0.1) - ); + const [consultsInBooking, setConsultsInBooking] = useState(); + const [consultsInSales, setConsultsInSales] = useState(100); const [isEnabled, setIsEnabled] = useState(false); + const [profitPerMonth, setProfitPerMonth] = useState(); + const [implementationTime, setImplementationTime] = useState(); async function getRegions() { const result: [] = await ky.get("http://localhost:3000/regions").json(); @@ -40,9 +38,32 @@ function Calc() { setConsultsInBooking( Math.round(consultsPerMonth * (!isEnabled ? 0.3 : 0.45)) ); + setConsultsInSales(Math.round(consultsPerMonth * (!isEnabled ? 0.1 : 0.2))); }, [consultsPerMonth, isEnabled]); + useEffect(() => { + setProfitPerMonth( + Math.round( + (consultsInSales * averageApartmentArea * averagePrice) / 1000000 + ) + ); + + setImplementationTime( + Math.round( + totalHousingAreaInComplex / (consultsInSales * averageApartmentArea) + ) + ); + + console.log(averageApartmentArea, averagePrice, totalHousingAreaInComplex); + }, [ + totalHousingAreaInComplex, + consultsInSales, + isEnabled, + averageApartmentArea, + averagePrice, + ]); + useEffect(() => { getRegions(); }, []); @@ -52,12 +73,6 @@ function Calc() { if (pattern.test(e.target.value)) { setConsultsPerMonth(+e.target.value); - // setConsultsInBooking( - // Math.round(+e.target.value * (!isEnabled ? 0.3 : 0.45)) - // ); - // setConsultsInSales( - // Math.round(+e.target.value * (!isEnabled ? 0.1 : 0.2)) - // ); } } @@ -69,7 +84,7 @@ function Calc() { const pattern = new RegExp(e.target.pattern); if (pattern.test(e.target.value)) { - setTotalAreaHousingInComplex(e.target.value); + setTotalAreaHousingInComplex(+e.target.value); } } @@ -124,7 +139,7 @@ function Calc() { min={1} max={100} defaultValue={averageApartmentArea} - onChange={(value) => console.log(value)} + onChange={(value) => setAverageApartmentArea(value)} />
@@ -135,7 +150,7 @@ function Calc() { min={30000} max={300000} defaultValue={averagePrice} - onChange={(value) => console.log(value)} + onChange={(value) => setAveragePrice(value)} />
@@ -192,7 +207,7 @@ function Calc() {

- 16 + {implementationTime} месяцев

@@ -208,7 +223,7 @@ function Calc() {

- 180,2 + {profitPerMonth} млн. руб.