최정임 최정임 2023-02-21
Merge branch 'admin' of http://210.180.118.83/yjryu/senior_care_system into admin
@e8e3b22cd620d358501333fa861deb7a73102984
client/views/pages/user_management/UserAuthoriySelect_agency.jsx
--- client/views/pages/user_management/UserAuthoriySelect_agency.jsx
+++ client/views/pages/user_management/UserAuthoriySelect_agency.jsx
@@ -6,23 +6,24 @@
 import { useNavigate } from "react-router";
 
 export default function UserAuthoriySelect_agency() {
+  // 화면 진입 시 탭 별 노출될ㄹ 리스트 초기화 
   const [subjectList, setSubjectList] = React.useState([]);
-  //초기값 세팅
-  const [regiNumber, setRegiNumber] = React.useState("");
+  const [subjectMyList, setSubjectMyList] = React.useState([]);
+  
+  // ------ 등록 버튼 클릭 시 노출되는 모달 데이터 ------//
+  // 사용자 등록 시 초기값 세팅
   const [userName, setUserName] = React.useState("");
   const [gender, setGender] = React.useState("");
-  const [brithday, setBrithday] = React.useState("");
+  const [brith, setBrith] = React.useState("");
   const [telNum, setTelNum] = React.useState("");
   const [homeAddress, setHomeAddress] = React.useState("");
   const [medicineM, setMedicineM] = React.useState(false);
   const [medicineL, setMedicineL] = React.useState(false);
   const [medicineD, setMedicineD] = React.useState(false);
+  const [medication, setMedication] = React.useState("");
   const [note, setNote] = React.useState("");
 
   // 변경되는 데이터 Handler
-  const handleRegiNumber = (e) => {
-    setRegiNumber(e.target.value);
-  };
   const handleUserName = (e) => {
     setUserName(e.target.value);
   };
@@ -30,9 +31,10 @@
     setGender(e.target.value);
   };
   const handleBrithday = (e) => {
-    setBrithday(e.target.value);
+    setBrith(e.target.value);
   };
   const handleTelNum = (e) => {
+    e.target.value =  e.target.value.replace(/[^0-9]/g, '').replace(/^(\d{2,3})(\d{3,4})(\d{4})$/, `$1-$2-$3`);
     setTelNum(e.target.value);
   };
   const handleHomeAddress = (e) => {
@@ -47,49 +49,92 @@
   const handleMedicineD = (e) => {
     setMedicineD(e.target.checked);
   };
+  const handleMedication = (e) => {
+    setMedication(e.target.value);
+  };
   const handleNote = (e) => {
     setNote(e.target.value);
   };
 
+  // 대상자 등록 함수 
   const seniorInsert = () => {
-    console.log("userName : ", userName);
-    console.log("gender : ", gender);
-    console.log("brithday : ", brithday);
-    console.log("telNum : ", telNum);
-    console.log("homeAddress : ", homeAddress);
-    console.log("note : ", note);
-    console.log("medicineM : ", medicineM);
-    console.log("medicineL : ", medicineL);
-    console.log("medicineD : ", medicineD);
-  //   fetch("", {
-  //     method: "POST",
-  //     headers: {
-  //       'Content-Type': 'application/json; charset=UTF-8'
-  //     },
-  //     body: JSON.stringify({
-  //       category: selectCategory,
-  //       title: inputTitle,
-  //       writer: writer,
-  //     }),
-  //   }).then((response) => response.json()).then((data) => {
-  //     alert("등록 되었습니다.");
-  //   }).catch((error) => {
-  //     console.log('selectNotice() /Notice/selectNotice.json error : ', error);
-  //   });
+    // userName,gender,brith, telNum, homeAddress, note, medicineM, medicineL, medicineD
+    // console.log("userName : ",userName);
+    // console.log("gender : ",gender);
+    // console.log("brith : ",brith);
+    // console.log("telNum : ",telNum);
+    // console.log("homeAddress : ",homeAddress);
+    // console.log("note : ",note);
+    // console.log("medicineM : ",medicineM);
+    // console.log("medicineL : ",medicineL);
+    // console.log("medicineD : ",medicineD);
+    var insertBtn = confirm("등록하시겠습니까?");
+    if(insertBtn){
+      fetch("/user/userInsert_userMadicationInsert.json", {
+        method: "POST",
+        headers: {
+          'Content-Type': 'application/json; charset=UTF-8'
+        },
+        body: JSON.stringify({
+          userName:userName,
+          gender:gender,
+          brith :brith,
+          userTel :telNum,
+          homeAddress:homeAddress,
+          medicineM:medicineM,
+          medicineL:medicineL,
+          medicineD:medicineD,
+          medication:medication,
+          note:note,
+          agancyId:'agency1',
+          govId:'government1',
+          userCode : '4'
+        }),
+      }).then((response) => response.json()).then((data) => {
+        alert("등록 되었습니다.");
+      }).catch((error) => {
+        console.log('selectNotice() /Notice/selectNotice.json error : ', error);
+      });
+    }else{
+        return;
+    }
+    
   };
-  const getSubjectSelect = () => {
-    fetch("/user/subjectList.json", {
+
+  const getSelectSubjectList = () => {
+    fetch("/user/selectSubjectList.json", {
           method: "POST",
           headers: {
             'Content-Type': 'application/json; charset=UTF-8'
           },
         }).then((response) => response.json()).then((data) => {
+          const rowData = data;
           console.log(data);
-          // setSubjectList(data.rows);
+          setSubjectList(rowData)
+
         }).catch((error) => {
-          console.log('getSubjectSelect() /user/subjectList.json error : ', error);
+          console.log('getSelectSubjectList() /user/selectSubjectList.json error : ', error);
         });
   };
+
+  const getSelectMySubjectList = () => {
+    fetch("/user/selectMySubjectList.json", {
+          method: "POST",
+          headers: {
+            'Content-Type': 'application/json; charset=UTF-8'
+          },
+          body: JSON.stringify({
+            agancyId: 'agency1',
+          }),
+        }).then((response) => response.json()).then((data) => {
+          const rowData = data;
+          console.log(data);
+          setSubjectMyList(rowData)
+        }).catch((error) => {
+          console.log('getSubjectMySelect() /user/selectMySubjectList.json error : ', error);
+        });
+  };
+
   const navigate = useNavigate();
   const [modalOpen, setModalOpen] = React.useState(false);
   const openModal = () => {
@@ -131,37 +176,26 @@
   const thead1 = [
     "No",
     "대상자 이름",
-    "대상자 등록번호",
     "대상자 연락처",
     "성별",
     "생년월일",
     "주소",
     "보호자",
+    
   ];
-  const key1 = ["No", "name", "Id", "call", "gender", "birth", "address", "management"];
-  const content1 = [
-    {
-      No: 1,
-      name: "김복남",
-      Id: "20230131",
-      call: "010-1234-1234",
-      gender: "여",
-      birth: "1948.11.15",
-      address: "경상북도 군위군 삼국유사면",
-      management: (
-        <Button
-          className={"btn-small gray-btn"}
-          btnName={"보기"}
-          onClick={openModal}
-        />
-      ),
-    },
+  const key1 = [
+    // "No", "name", "Id", "call", "gender", "birth", "address", "management"
+    "rn",
+    "user_name",
+    "user_phonenumber",
+    "user_gender",
+    "user_birth",
+    "user_address",
   ];
 
   const thead2 = [
     "No",
     "대상자 이름",
-    "대상자 등록번호",
     "대상자 연락처",
     "성별",
     "생년월일",
@@ -170,13 +204,17 @@
     "보호자",
   ];
   const key2 = [
-    "No", "name", "Id", "call", "gender", "birth", "address", "worker", "guardian"
+    "rn",
+    "user_name",
+    "user_phonenumber",
+    "user_gender",
+    "user_birth",
+    "user_address",
   ];
   const content2 = [
     {
       No: 2,
       name: "송창덕",
-      Id: "20230202",
       call: "010-5555-3573",
       gender: "남",
       birth: "1951.08.12",
@@ -199,7 +237,6 @@
     {
       No: 1,
       name: "김복남",
-      Id: "20230131",
       call: "010-1234-1234",
       gender: "여",
       birth: "1948.11.15",
@@ -302,10 +339,11 @@
       id: 1,
       title: "내가 관리하는 대상자",
       description: (
+        
         <Table
           className={"protector-user"}
           head={thead1}
-          contents={subjectList}
+          contents={subjectMyList}
           contentKey={key1}
         />
       ),
@@ -317,7 +355,7 @@
         <Table
           className={"caregiver-user"}
           head={thead2}
-          contents={content2}
+          contents={subjectList}
           contentKey={key2}
         />
       ),
@@ -327,7 +365,8 @@
   const [index, setIndex] = React.useState(1);
 
   React.useEffect(() => {
-    getSubjectSelect();
+    getSelectSubjectList();
+    getSelectMySubjectList();
 
   }, [])
   return (
@@ -359,7 +398,7 @@
             <tr>
               <th>연락처</th>
               <td colSpan={3}>
-                <input type="text" />
+                <input type="input" maxLength="11" />
               </td>
             </tr>
             <tr>
@@ -419,7 +458,7 @@
         <div className="board-wrap">
           <SubTitle explanation={"회원 등록 시 ID는 연락처, 패스워드는 생년월일 8자리입니다."} className="margin-bottom"/>
           <table className="margin-bottom2 senior-insert">
-          <tr>
+          {/* <tr>
               <th>대상자등록번호</th>
               <td colSpan={3} className="flex">
                 <input type="text" placeholder="생성하기 버튼 클릭 시 자동으로 생성됩니다."/>
@@ -428,7 +467,7 @@
               btnName={"생성하기"}
             />
               </td>
-            </tr>
+            </tr> */}
             <tr>
               <th>이름</th>
               <td>
@@ -450,7 +489,7 @@
             <th>생년월일</th>
               <td>
                 <div className="flex">
-                  <input type='date' value={brithday} onChange={handleBrithday} />
+                  <input type='date' value={brith} onChange={handleBrithday} />
                 </div>
               </td>
               {/* <th>요양등급</th>
@@ -462,7 +501,7 @@
             <tr>
               <th>연락처</th>
               <td colSpan={3}>
-                <input type="text" value={telNum} onChange={handleTelNum}/>
+                <input type="text" value={telNum} onChange={handleTelNum} />
               </td>
             </tr>
             <tr>
@@ -482,18 +521,19 @@
               </td>
             </tr>
             <tr>
-              <th>비고</th>
-              <td colSpan={3}>
-                <textarea className="medicine" cols="30" rows="2" value={note} onChange={handleNote}></textarea>
-              </td>
-            </tr>
-            {/* <tr>
               <th>복용중인 약</th>
               <td colSpan={3}>
-                <textarea className="medicine" cols="30" rows="2"></textarea>
+                <textarea className="medicine" cols="30" rows="2" value={medication} onChange={handleMedication}></textarea>
               </td>
             </tr>
             <tr>
+              <th>비고</th>
+              <td colSpan={3}>
+                <textarea className="note" cols="30" rows="2" value={note} onChange={handleNote}></textarea>
+              </td>
+            </tr>
+            
+            {/* <tr>
               <th>기저질환</th>
               <td colSpan={3}>
                 <textarea cols="30" rows="10"></textarea>
@@ -505,7 +545,7 @@
                 className={"btn-small green-btn"}
                 btnName={"등록"}
                 onClick={() => {
-                  seniorInsert(userName,gender,brithday, telNum, homeAddress, note, medicineM, medicineL, medicineD)
+                  seniorInsert(userName,gender,brith, telNum, homeAddress, note, medicineM, medicineL, medicineD)
                 }}
               />
             </div>
Add a comment
List