import React from "react"; import { useNavigate, useLocation } from "react-router"; import { useSelector } from "react-redux"; import Title from "../../component/Title.jsx"; import Table from "../../component/Table.jsx"; import Map from "../../component/chart/Map.jsx"; import Chart from "../../component/chart/Chart.jsx"; import Chart5_agency from "../../component/chart/Chart5_agency.jsx"; import Chart2_agency from "../../component/chart/Chart2_agency.jsx"; import AddCircleIcon from "@mui/icons-material/AddCircle"; import Calendar_agency from "../../component/Calendar_agency.jsx"; import Chart10 from "../../component/chart/Chart10.jsx"; import Chart7 from "../../component/chart/Chart7.jsx"; import Chart8 from "../../component/chart/Chart8.jsx"; import tool from "../../../resources/files/images/tool.png"; import medicinebox from "../../../resources/files/images/medicinebox.png"; import box from "../../../resources/files/images/box.png"; import exchange from "../../../resources/files/images/exchange.png"; import error from "../../../resources/files/images/error.png"; import batteryAgency from "../../../resources/files/images/batteryAgency.png"; import medicineAgency from "../../../resources/files/images/medicineAgency.png"; import temperatureAgency from "../../../resources/files/images/temperatureAgency.png"; import wifioff from "../../../resources/files/images/wifioff.png"; import TitleSmall from "../../component/TitleSmall.jsx"; import CommonUtil from "../../../resources/js/CommonUtil.js"; export default function Main2() { const navigate = useNavigate(); const location = useLocation(); //전역 변수 저장 객체 const state = useSelector((state) => { return state; }); const thead = ["No", "계약업체명", "구분", "담당자 연락처", "주소"]; const key = ["No", "agency", "division", "phone", "address"]; const content = [ { No: (

{thead[0]} 1948.11.15

), agency: (

{thead[1]} A복지관

), division: (

{thead[2]}교환

), phone: (

{thead[3]}010-1234-5678

), address: (

{thead[4]}경상북도 군위군 삼국유사면

), }, ]; // 내 시니어 const [mySenior, setMySenior] = React.useState({ seniorList: [], seniorListCount: 0, search: { agent_id: state.loginUser["user_id"], user_use: true, }, }); // 내 시니어 목록 조회 const [seniorGenderData, setSeniorGenderData] = React.useState([]); const mySeniorSelectList = () => { fetch("/user/seniorSelectList.json", { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8", }, body: JSON.stringify(mySenior.search), }) .then((response) => response.json()) .then((data) => { data.search = mySenior.search; console.log("내 시니어 목록 조회 : ", data); setMySenior(data); let seniorGenderArr = []; const today = new Date(); data["seniorList"].map((item, idx) => { const birth = new Date(item["user_birth"]); let age = today.getFullYear() - birth.getFullYear() + 1; seniorGenderArr.push({ gender: item["user_gender"], age: age }); }); console.log("seniorGenderArr: ", seniorGenderArr); let genderData = []; for (let i = 0; i < 18; i++) { let age = i * 5; let age1 = (i + 1) * 5 - 1; if (i == 17) { genderData.push({ age: age + "+", male: 0, female: 0 }); } else { genderData.push({ age: age + "-" + age1, male: 0, female: 0 }); } } console.log("genderData: ", genderData); seniorGenderArr.map((item, idx) => { for (let i = 0; i < 18; i++) { if (item["age"] >= i * 5 && item["age"] <= (i + 1) * 5 - 1) { if (item["gender"] == "남") { genderData[i]["male"]--; } else if (item["gender"] == "여") { genderData[i]["female"]++; } } } }); setSeniorGenderData(genderData); console.log("genderData: ", genderData); }) .catch((error) => { console.log( "seniorSelectList() /user/seniorSelectList.json error : ", error ); }); }; //온도 위험 대상자(시니어) 수 조회 const [temperatureCount, setTemperatureCount] = React.useState(0); const temperatureRiskCount = () => { fetch("/stats/temperatureRisk.json", { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8", }, body: JSON.stringify({ agent_id: state.loginUser["user_id"], }), }) .then((response) => response.json()) .then((data) => { console.log("온도 위험 대상자(시니어) 수 조회 : ", data); setTemperatureCount(data); }) .catch((error) => { console.log( "temperatureRiskCount() /stats/temperatureRisk.json error : ", error ); }); }; //배터리 부족 대상자(시니어) 수 조회 const [batteryCount, setbatteryCount] = React.useState(0); const batteryRiskCount = () => { fetch("/stats/batteryRisk.json", { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8", }, body: JSON.stringify({ agent_id: state.loginUser["user_id"], }), }) .then((response) => response.json()) .then((data) => { console.log("배터리 부족 대상자(시니어) 수 조회 : ", data); setbatteryCount(data); }) .catch((error) => { console.log( "batteryRiskCount() /stats/batteryRisk.json error : ", error ); }); }; //데이터 미확인 대상자(시니어) 수 조회 const [receiveDataMissCount, setReceiveDataMissCount] = React.useState(0); const receiveDataMissRiskCount = () => { fetch("/stats/receiveDataMissCount.json", { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8", }, body: JSON.stringify({ agent_id: state.loginUser["user_id"], }), }) .then((response) => response.json()) .then((data) => { console.log("데이터 미확인 대상자(시니어) 수 조회 : ", data); setReceiveDataMissCount(data); }) .catch((error) => { console.log( "receiveDataMissRiskCount() /stats/receiveDataMissCount.json error : ", error ); }); }; // 최근 복약률 const [medicationSelectListByNew, setMedicationSelectListByNew] = React.useState([]); // 최근 복약률 조회 const seniorMedicationSelectListByNew = () => { fetch("/user/seniorMedicationSelectListByNew.json", { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8", }, body: JSON.stringify({ agent_id: state.loginUser["user_id"], }), }) .then((response) => response.json()) .then((data) => { console.log("seniorMedicationSelectListByNew : ", data); setMedicationSelectListByNew(data); }) .catch((error) => { console.log( "seniorMedicationSelectListByNew() /user/seniorMedicationSelectListByNew.json error : ", error ); }); }; // 복약률 목록 const [medicationSelectListByMonth, setMedicationSelectListByMonth] = React.useState([]); const [medicationSelectListByYear, setMedicationSelectListByYear] = React.useState([]); // 복약률 목록 조회 const seniorMedicationSelectListByMonth = () => { let totalYearArr = []; let yearArr = []; fetch("/user/seniorMedicationSelectListByMonth.json", { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8", }, body: JSON.stringify({ agency_id: state.loginUser["agency_id"] }), }) .then((response) => response.json()) .then((data) => { data.map((item, idx) => { item["year"] = item["medication_default_date"].substr(0, 4); item["month"] = item["medication_default_date"].substr(5, 2); totalYearArr.push(item["medication_default_date"].substr(0, 4)); item["date"] = new Date(item["medication_default_date"]).getTime(); }); const setYearArr = [...new Set(totalYearArr)]; console.log("totalYearArr: ", setYearArr); setYearArr.map((year, yearIdx) => { let sum = 0; let count = 0; let avg = 0; let monthArr = [ "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", ]; data.map((item, idx) => { if (item["year"] == year) { sum += item["average"]; count++; monthArr[Number(item["month"]) - 1] = item["average"]; } }); avg = parseInt(sum / count); yearArr.push({ year: [year], average: avg, data: monthArr }); }); console.log("yearArr : ", yearArr); setMedicationSelectListByYear(yearArr); console.log("seniorMedicationSelectListByMonth : ", data); setMedicationSelectListByMonth(data); }) .catch((error) => { console.log( "seniorMedicationSelectListByMonth() /user/seniorMedicationSelectListByMonth.json error : ", error ); }); }; React.useEffect(() => { temperatureRiskCount(); batteryRiskCount(); receiveDataMissRiskCount(); seniorMedicationSelectListByNew(); seniorMedicationSelectListByMonth(); mySeniorSelectList(); }, []); return (
{medicationSelectListByNew.length > 0 ? ( ) : (

데이터가 없습니다.

)}
{medicationSelectListByYear.length > 0 ? ( medicationSelectListByYear.map((item, idx) => { return ( {CommonUtil.isEmpty(item["data"]) == false ? item["data"].map((item1, idx1) => { return ( <> ); }) : null} ); }) ) : ( )}
년도 총계 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
{item["year"]} {item["average"] == "-" ? "-" : item["average"] + "%"} {item1 == "-" ? "-" : item1 + "%"}
데이터가 없습니다.
{/*
*/}
{medicationSelectListByNew.length > 0 ? ( ) : (

데이터가 없습니다.

)}
{seniorGenderData.length > 0 ? ( ) : (

데이터가 없습니다.

)}
); }