박정하 박정하 2023-06-27
230627 박정하 장비관리 작업중
@d951c588f4c6fedf1c00994f008dfa2180a921a0
client/views/component/Modal_Guardian.jsx
--- client/views/component/Modal_Guardian.jsx
+++ client/views/component/Modal_Guardian.jsx
@@ -377,7 +377,7 @@
                   </div>
                 </td>
               </tr>
-              {CommonUtil.isEmpty(guardian['user_phonenumber']) == false && isNewGuardian ? (
+              {isNewGuardian ? (
                 <tr>
                   <th><span style={{ color: "red" }}>*</span>연락처</th>
                   <td colSpan={3}>
client/views/pages/equipment/GovernmentEquipmentSelect.jsx
--- client/views/pages/equipment/GovernmentEquipmentSelect.jsx
+++ client/views/pages/equipment/GovernmentEquipmentSelect.jsx
@@ -198,6 +198,7 @@
     'equipment_update_datetime': null,
     'equipment_update_user_id': null,
     'government_id': defaultGovernmentId,
+    'agency_id': defaultAgencyId,
     'senior_id': null
   }
   //장비
@@ -374,6 +375,81 @@
   };
 
 
+  //장비 대여 모달 여부
+  const [modalRentalIsOpen, setModalRentalIsOpen] = React.useState(false);
+  //장비 대여 오픈
+  const modalRentalOpen = (item) => {
+    setSelectEquipment(item);
+    mySenior['search']['agency_id'] = item['agency_id'];
+    mySeniorSelectList(1);
+    setModalRentalIsOpen(true);
+  };
+  //장비 대여 닫기
+  const modalRentalClose = () => {
+    setModalRentalIsOpen(false);
+  };
+
+  //장비 대여 등록 정보
+  const [selectEquipment, setSelectEquipment] = React.useState()
+
+  //장비 대여 등록
+  const equipmentRentalInsert = (seniorId) => {
+    if (confirm('해당 장비를 추가하시겠습니까?') == false) {
+      return;
+    }
+
+    selectEquipment['senior_id'] = seniorId;
+    selectEquipment['rental_start_date'] = new Date();
+
+    fetch("/equipment/equipmentRentalInsert.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify(selectEquipment),
+    }).then((response) => response.json()).then((data) => {
+      console.log("장비 대여 등록 결과(건수) : ", data);
+      if (data > 0) {
+        alert("추가완료");
+        modalRentalClose();
+      } else {
+        alert("장비추가에 실패하였습니다. 관리자에게 문의바랍니다.");
+      }
+    }).catch((error) => {
+      console.log('seniorSelectOne() /user/seniorSelectOne.json error : ', error);
+    });
+  };
+
+  //보호사(간호사)의 돌봄 대상자(시니어)
+  const [mySenior, setMySenior] = React.useState({
+    seniorList: [],
+    seniorListCount: 0,
+    search: {
+      'government_id': defaultGovernmentId,
+      'agency_id': defaultAgencyId,
+      'currentPage': 1,
+      'perPage': 5,
+    }
+  });
+  //보호사(간호사)의 돌봄 대상자(시니어) 목록 조회
+  const mySeniorSelectList = (currentPage) => {
+    mySenior.search.currentPage = CommonUtil.isEmpty(currentPage) ? 1 : currentPage;
+
+    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);
+    }).catch((error) => {
+      console.log('seniorSelectList() /user/seniorSelectList.json error : ', error);
+    });
+  }
+
   //Mounted
   React.useEffect(() => {
     orgSelectListOfHierarchy();
@@ -422,7 +498,7 @@
           })}
           {CommonUtil.isEmpty(rentalEquipment.equipmentList) ?
             <tr>
-              <td colSpan={9}>조회된 데이터가 없습니다</td>
+              <td colSpan={10}>조회된 데이터가 없습니다</td>
             </tr>
             : null}
         </tbody>
@@ -436,6 +512,8 @@
       />
     </>
   );
+
+
   //현재 탭 Index
   const [tabIndex, setTabIndex] = React.useState(0);
   //탭 초기화
@@ -446,15 +524,6 @@
         <div className="flex equip-tab">
           <SubTitle explanation={"현재 기관에 입고된 장비 중 돌봄 대상자에게 대여하지 않은 장비 목록입니다."} />
           <div className="btn-wrap flex-end margin-bottom ">
-            <button className={"btn-small gray-btn"}
-              onClick={() => navigate("/UserSelect", {
-                state: {
-                  'government_id': defaultGovernmentId,
-                  'agency_id': null,
-                  'tabActiveByRoleType': 'ROLE_SENIOR',
-                }
-              })}>대상자에게 장비대여</button>
-
             <button className={"btn-small gray-btn"} onClick={() => { modalEquipmentOpen() }}>장비 등록</button>
           </div>
         </div>
@@ -466,6 +535,8 @@
               <th>시리얼넘버</th>
               <th>입고일자</th>
               <th>장비상태</th>
+              <th>기관</th>
+              <th>장비대여</th>
               <th>관리</th>
             </tr>
           </thead>
@@ -478,6 +549,24 @@
                   <td data-label="시리얼넘버">{item['equipment_serial_number']}</td>
                   <td data-label="입고일자">{item['equipment_stock_date']}</td>
                   <td data-label="장비상태">{equipmentStates[item['equipment_state']]}</td>
+                  <td data-label="기관">
+                    {orgListOfHierarchy.map((item1, idx1) => {
+                      return (
+                        item1['agencyList'] != undefined && item1['agencyList'] != null ?
+                          item1['agencyList'].map((item2, idx2) => {
+                            return (
+                              item['agency_id'] == item2['agency_id'] ?
+                                item2['agency_name']
+                                : null
+                            )
+                          })
+                          : null
+                      )
+                    })}
+                  </td>
+                  <td cata-label="장비대여">
+                    <button className={"btn-small gray-btn"} onClick={() => modalRentalOpen(item)}>장비 배포</button>
+                  </td>
                   <td data-label="관리">
                     <button className={"btn-small gray-btn"} onClick={() => modalEquipmentOpen(item)}>정보 수정</button>
                   </td>
@@ -486,7 +575,7 @@
             })}
             {CommonUtil.isEmpty(deliveryEquipment.equipmentList) ?
               <tr>
-                <td colSpan={5}>조회된 데이터가 없습니다</td>
+                <td colSpan={8}>조회된 데이터가 없습니다</td>
               </tr>
               : null}
           </tbody>
@@ -498,13 +587,12 @@
           maxRange={5}
           click={deliveryEquipmentSelectList}
         />
-      </div>
+      </div >
     )
   }, {
     title: `사용중인 장비 (${rentalEquipment.equipmentListCount})`,
     content: (
       <div>
-
         <div className="flex-align-start userauthoriylist gap5">
           <div className="left">
             <SubTitle explanation={"기관 리스트"} />
@@ -563,7 +651,6 @@
 
   return (
     <main>
-
       <Modal open={modalEquipmentIsOpen} close={modalEquipmentClose} header="장비 등록">
         <div className="board-wrap">
           <div>
@@ -648,6 +735,30 @@
                     </td>
                   </tr>
                   : null}
+                <tr>
+                  <th>시행기관 선택</th>
+                  <td>
+                    {orgListOfHierarchy.map((item, idx) => {
+                      return (
+                        <select defaultValue={item['agencyList'][0]['agency_id']} onChange={(e) => {
+                          console.log('e.target.value : ', e.target.value);
+                          equipmentValueChange('agency_id', e.target.value);
+                        }}>
+                          {item['agencyList'] != undefined && item['agencyList'] != null ?
+                            item['agencyList'].map((item2, idx2) => {
+                              return (
+                                <option key={idx2} value={item2['agency_id']}
+                                  selected={equipment['agency_id'] == item2['agency_id']}>
+                                  {item2['agency_name']}
+                                </option>
+                              )
+                            })
+                            : null}
+                        </select>
+                      )
+                    })}
+                  </td>
+                </tr>
               </tbody>
             </table>
           </div>
@@ -661,6 +772,51 @@
               </>
             }
           </div>
+        </div>
+      </Modal>
+
+      <Modal open={modalRentalIsOpen} close={modalRentalClose} header="장비 배포 시니어 선택">
+        <div className="board-wrap">
+          <table className={"protector-user"}>
+            <thead>
+              <tr>
+                <th>No</th>
+                <th>소속기관명</th>
+                <th>이름</th>
+                <th>생년월일</th>
+                <th>성별</th>
+                <th>배포</th>
+              </tr>
+            </thead>
+            <tbody>
+              {mySenior.seniorList.map((item, idx) => {
+                return (
+                  <tr key={idx}>
+                    <td data-label="No">{mySenior.seniorListCount - idx - (mySenior.search.currentPage - 1) * mySenior.search.perPage}</td>
+                    <td data-label="소속기관명">{item['agency_name']}</td>
+                    <td data-label="이름">{item['user_name']}</td>
+                    <td data-label="생년월일">{item['user_birth']}</td>
+                    <td data-label="성별">{item['user_gender']}</td>
+                    <td data-label="배포">
+                      <button className="btn-small gray-btn" onClick={() => { equipmentRentalInsert(item['senior_id']) }}>배포하기</button>
+                    </td>
+                  </tr>
+                )
+              })}
+              {CommonUtil.isEmpty(mySenior.seniorList) ?
+                <tr>
+                  <td colSpan={8}>조회된 데이터가 없습니다</td>
+                </tr>
+                : null}
+            </tbody>
+          </table>
+          <Pagination
+            currentPage={mySenior.search.currentPage}
+            perPage={mySenior.search.perPage}
+            totalCount={mySenior.seniorListCount}
+            maxRange={5}
+            click={mySeniorSelectList}
+          />
         </div>
       </Modal>
 
@@ -697,7 +853,6 @@
 				</div>
 			</Modal> */}
 
-
       <div className="search-management flex-end margin-bottom2 margin-top gap">
         <select style={{ maxWidth: '150px' }}
           onChange={(e) => equipmentSearchChange('equipment_state', e.target.value)}>
@@ -724,40 +879,41 @@
         <button className={"btn-small gray-btn"} style={{ maxWidth: '150px' }} onClick={equipmentSearching}>검색</button>
       </div>
 
-      {CommonUtil.isEmpty(state.loginUser) == false && (state.loginUser['authority'] == 'ROLE_ADMIN' || state.loginUser['authority'] == 'ROLE_GOVERNMENT')
-        ? (
-          <div className="tab-container">
-            <ul className="tab-menu flex-start">
-              {tab.map((item, idx) => {
-                return (
-                  <li onClick={() => setTabIndex(idx)} className={idx == tabIndex ? 'active' : null}>
-                    {item.title}
-                  </li>
-                )
-              })}
-            </ul>
-            <div className="content-wrap">
-              <ul className="tab-content">
-                <li>
-                  {tab[tabIndex].content}
-                </li>
+      {
+        CommonUtil.isEmpty(state.loginUser) == false && (state.loginUser['authority'] == 'ROLE_ADMIN' || state.loginUser['authority'] == 'ROLE_GOVERNMENT')
+          ? (
+            <div className="tab-container">
+              <ul className="tab-menu flex-start">
+                {tab.map((item, idx) => {
+                  return (
+                    <li onClick={() => setTabIndex(idx)} className={idx == tabIndex ? 'active' : null}>
+                      {item.title}
+                    </li>
+                  )
+                })}
               </ul>
-            </div>
-          </div>
-        ) : (
-          <div className="content-wrap">
-            <DetailTitle contentTitle={"장비 사용 현황"} />
-            <div className="board-wrap" style={{ marginTop: "3rem" }} >
-              <div className="btn-wrap margin-bottom">
-                <div className="btn-wrap flex-end margin-bottom ">
-                  <button className={"btn-small gray-btn"} onClick={() => (state.loginUser['authority'] == 'ROLE_AGENCYADMIN') ? navigate("/AgencyAdminSeniorSelect") : navigate("/AgencySeniorSelect")}>대상자 관리</button>
-                </div>
-                {rentalContent}
+              <div className="content-wrap">
+                <ul className="tab-content">
+                  <li>
+                    {tab[tabIndex].content}
+                  </li>
+                </ul>
               </div>
             </div>
-          </div>
-        )
+          ) : (
+            <div className="content-wrap">
+              <DetailTitle contentTitle={"장비 사용 현황"} />
+              <div className="board-wrap" style={{ marginTop: "3rem" }} >
+                <div className="btn-wrap margin-bottom">
+                  <div className="btn-wrap flex-end margin-bottom ">
+                    <button className={"btn-small gray-btn"} onClick={() => (state.loginUser['authority'] == 'ROLE_AGENCYADMIN') ? navigate("/AgencyAdminSeniorSelect") : navigate("/AgencySeniorSelect")}>대상자 관리</button>
+                  </div>
+                  {rentalContent}
+                </div>
+              </div>
+            </div>
+          )
       }
-    </main>
+    </main >
   );
 }
client/views/pages/senior_management/SeniorSelectOne.jsx
--- client/views/pages/senior_management/SeniorSelectOne.jsx
+++ client/views/pages/senior_management/SeniorSelectOne.jsx
@@ -7,6 +7,7 @@
 import Pagination from "../../component/Pagination.jsx";
 
 import CommonUtil from "../../../resources/js/CommonUtil.js";
+import { insert } from "@amcharts/amcharts5/.internal/core/util/Array.js";
 
 
 export default function SeniorSelectOne() {
@@ -42,6 +43,56 @@
     });
   }
 
+  // 시스템 코드 - 장비 상태
+  const [equipmentStates, setEquipmentStates] = React.useState({});
+  // 시스템 코드 - 장비 상태 조회
+  const equipmentStatesSelect = () => {
+    console.log('equipmentStatesSelect Function Run');
+
+    //fetch post
+    fetch("/common/systemCode/equipmentStatesSelect.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({})
+    }).then((response) => response.json()).then((data) => {
+      console.log('equipmentStatesSelect response : ', data);
+      setEquipmentStates(data);
+    }).catch((error) => {
+      console.log('equipmentStatesSelect error : ', error);
+    });
+  }
+
+  //입고 및 미대여 장비 검색 정보
+  const [deliveryEquipmentSearch, setDeliveryEquipmentSearch] = React.useState({
+    'government_id': location.state['government_id'],
+    'senior_id': 'IS_NULL',
+    'currentPage': 1,
+    'perPage': 10,
+  });
+  //입고 및 미대여 목록
+  const [deliveryEquipment, setDeliveryEquipment] = React.useState({ equipmentList: [], equipmentListCount: 0 });
+  //입고 및 미대여 목록 조회
+  const deliveryEquipmentSelectList = (currentPage) => {
+    deliveryEquipmentSearch.currentPage = CommonUtil.isEmpty(currentPage) ? 1 : currentPage;
+    setDeliveryEquipmentSearch({ ...deliveryEquipmentSearch });
+ 
+    fetch("/equipment/equipmentSelectList.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify(deliveryEquipmentSearch)
+    }).then((response) => response.json()).then((data) => {
+      console.log('deliveryEquipmentSelectList response : ', data);
+      setDeliveryEquipment(data);
+    }).catch((error) => {
+      console.log('deliveryEquipmentSelectList error : ', error);
+    });
+  }
+
+
 
   //장비 대여 모달 여부
   const [modalRentalIsOpen, setModalRentalIsOpen] = React.useState(false);
@@ -54,78 +105,28 @@
     setModalRentalIsOpen(false);
   };
 
-  // 시스템 코드 - 장비 상태
-	const [equipmentStates, setEquipmentStates] = React.useState({});
-	// 시스템 코드 - 장비 상태 조회
-	const equipmentStatesSelect = () => {
-		console.log('equipmentStatesSelect Function Run');
-
-		//fetch post
-		fetch("/common/systemCode/equipmentStatesSelect.json", {
-			method: "POST",
-			headers: {
-				'Content-Type': 'application/json; charset=UTF-8'
-			},
-			body: JSON.stringify({})
-		}).then((response) => response.json()).then((data) => {
-			console.log('equipmentStatesSelect response : ', data);
-			setEquipmentStates(data);
-		}).catch((error) => {
-			console.log('equipmentStatesSelect error : ', error);
-		});
-	}
-  
-  //입고 및 미대여 장비 검색 정보
-	const [deliveryEquipmentSearch, setDeliveryEquipmentSearch] = React.useState({
-		'government_id': location.state['government_id'],
-		'senior_id': 'IS_NULL',
-		'currentPage': 1,
-		'perPage': 10,
-	});
-	//입고 및 미대여 목록
-	const [deliveryEquipment, setDeliveryEquipment] = React.useState({equipmentList: [], equipmentListCount: 0});
-	//입고 및 미대여 목록 조회
-	const deliveryEquipmentSelectList = (currentPage) => {
-		deliveryEquipmentSearch.currentPage = CommonUtil.isEmpty(currentPage) ? 1 : currentPage;
-		setDeliveryEquipmentSearch({...deliveryEquipmentSearch});
-
-		fetch("/equipment/equipmentSelectList.json", {
-			method: "POST",
-			headers: {
-				'Content-Type': 'application/json; charset=UTF-8'
-			},
-			body: JSON.stringify(deliveryEquipmentSearch)
-		}).then((response) => response.json()).then((data) => {
-			console.log('deliveryEquipmentSelectList response : ', data);
-			setDeliveryEquipment(data);
-		}).catch((error) => {
-			console.log('deliveryEquipmentSelectList error : ', error);
-		});
-	}
-
-
   //장비 대여 등록 정보
   const [equipmentRental, setEquipmentRental] = React.useState({
     'senior_id': location.state['senior_id'],
     'rental_idx': 0,
     'rental_start_date': CommonUtil.getDate(),
     'rental_end_date': null,
-    'rental_return_date': null 
+    'rental_return_date': null
   });
 
   //장비 대여 등록
   const equipmentRentalInsert = (equipment) => {
     if (CommonUtil.isEmpty(equipmentRental['rental_start_date'])) {
-			alert("대여 시작일을 선택해 주세요.");
-			return;
-		}
+      alert("대여 시작일을 선택해 주세요.");
+      return;
+    }
     if (confirm('해당 장비를 추가하시겠습니까?') == false) {
       return;
     }
 
     equipment['senior_id'] = location.state['senior_id'];
     equipment['rental_start_date'] = equipmentRental['rental_start_date'];
-    
+
     fetch("/equipment/equipmentRentalInsert.json", {
       method: "POST",
       headers: {
@@ -134,21 +135,92 @@
       body: JSON.stringify(equipment),
     }).then((response) => response.json()).then((data) => {
       console.log("장비 대여 등록 결과(건수) : ", data);
-			if (data > 0) {
+      if (data > 0) {
         alert("추가완료");
-				modalRentalClose();
+        modalRentalClose();
         equipmentSelectListBySenior();
         deliveryEquipmentSelectList(1);
-			} else {
-				alert("장비추가에 실패하였습니다. 관리자에게 문의바랍니다.");
-			}
+      } else {
+        alert("장비추가에 실패하였습니다. 관리자에게 문의바랍니다.");
+      }
     }).catch((error) => {
       console.log('seniorSelectOne() /user/seniorSelectOne.json error : ', error);
     });
   };
 
+  //대상자 장비 목록
+  const [equipmentBySenior, setEquipmentBySenior] = React.useState({ equipmentList: [], equipmentListCount: 0 });
+  //대상자 장비 목록 조회
+  const equipmentSelectListBySenior = () => {
+    fetch("/equipment/equipmentSelectList.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify(senior)
+    }).then((response) => response.json()).then((data) => {
+      console.log('equipmentSelectListBySenior response : ', data);
+      setEquipmentBySenior(data);
+    }).catch((error) => {
+      console.log('equipmentSelectListBySenior error : ', error);
+    });
+  }
 
 
+  //장비 대여 종료 모달 여부
+  const [modalRentalEndIsOpen, setModalRentalEndIsOpen] = React.useState(false);
+  const [rentalData, setRentalData] = React.useState({});
+  const [rentalEndDate, setRentalEndDate] = React.useState();
+  //장비 대여 종료 오픈
+  const modalRentalEndOpen = (item) => {
+    setModalRentalEndIsOpen(true);
+    setRentalData(item);
+    setRentalEndDate(null);
+  };
+  //장비 대여 종료 닫기
+  const modalRentalEndClose = () => {
+    setModalRentalEndIsOpen(false);
+  };
+  // 장비 대여 종료
+  const equipmentRentalEnd = (item, senior_delete) => {
+    let insertBtn = "";
+    if (!senior_delete) {
+      insertBtn = confirm("대여를 종료하시겠습니까?");
+    } else {
+      insertBtn = true;
+    }
+
+    if (insertBtn) {
+      if (CommonUtil.isEmpty(rentalEndDate) == false) {
+        item['rental_end_date'] = rentalEndDate;
+      } else {
+        item['rental_end_date'] = new Date();
+      }
+
+      fetch("/equipment/equipmentRentalUpdate.json", {
+        method: "POST",
+        headers: {
+          'Content-Type': 'application/json; charset=UTF-8'
+        },
+        body: JSON.stringify(item),
+      }).then((response) => response.json()).then((data) => {
+        console.log("장비 대여 결과(건수) : ", data);
+        if (!senior_delete) {
+          if (data > 0) {
+            alert("대여 종료 되었습니다.");
+          } else {
+            alert("대여 종료에 실패하였습니다.");
+          }
+          equipmentSelectListBySenior();
+          modalRentalEndClose();
+        } else {
+          return;
+        }
+      }).catch((error) => {
+        console.log('equipmentRentalEnd() /equipment/equipmentRentalUpdate.json error : ', error);
+      });
+    }
+  }
 
 
   //시니어 정보
@@ -217,9 +289,8 @@
     modalGuardianOpen();
   }
 
-
   //대상자의 보호사 목록
-  const [agent, setAgent] = React.useState({agentListBySenior: [], agentListCountBySenior: 0});
+  const [agent, setAgent] = React.useState({ agentListBySenior: [], agentListCountBySenior: 0 });
   //대상자의 보호사 목록 조회
   const agentSelectListBySenior = () => {
     fetch("/user/agentSelectListBySenior.json", {
@@ -235,27 +306,6 @@
       console.log('agentSelectListBySenior() /user/agentSelectListBySenior.json error : ', error);
     });
   }
-
-
-	//대상자 장비 목록
-	const [equipmentBySenior, setEquipmentBySenior] = React.useState({equipmentList: [], equipmentListCount: 0});
-	//대상자 장비 목록 조회
-	const equipmentSelectListBySenior = () => {
-		fetch("/equipment/equipmentSelectList.json", {
-			method: "POST",
-			headers: {
-				'Content-Type': 'application/json; charset=UTF-8'
-			},
-			body: JSON.stringify(senior)
-		}).then((response) => response.json()).then((data) => {
-			console.log('equipmentSelectListBySenior response : ', data);
-			setEquipmentBySenior(data);
-		}).catch((error) => {
-			console.log('equipmentSelectListBySenior error : ', error);
-		});
-	}
-
-
 
   //가입승인
   const userUpdate = (user, callback) => {
@@ -280,11 +330,99 @@
     });
   }
 
+  // 시니어 - 담당자 매칭 종료
+  const agentSeniorDelete = (agent_id, agent_match_idx, senior_delete) => {
+    let insertBtn = "";
+    if (!senior_delete) {
+      insertBtn = confirm("담당자 매칭을 종료하시겠습니까?");
+    } else {
+      insertBtn = true;
+    }
+
+    if (insertBtn) {
+      fetch("/user/agentSeniorDelete.json", {
+        method: "POST",
+        headers: {
+          'Content-Type': 'application/json; charset=UTF-8'
+        },
+        body: JSON.stringify({
+          agent_id: agent_id,
+          senior_id: senior['senior_id'],
+          agent_match_idx: agent_match_idx
+        }),
+      }).then((response) => response.json()).then((data) => {
+        console.log("사용자 등록 결과(건수) : ", data);
+
+        if (!senior_delete) {
+          if (data > 0) {
+            alert("담당자 매칭이 종료 되었습니다.");
+            seniorSelectListByAgent();
+          } else {
+            alert("담당자 매칭 종료에 실패하였습니다.");
+          }
+        } else {
+          return;
+        }
+      }).catch((error) => {
+        console.log('agentSeniorDelete() /user/agentSeniorDelete.json error : ', error);
+      });
+    }
+  }
+
+  // 시니어 삭제
+  const seniorDelete = (senior) => {
+    let insertBtn = confirm("삭제하시겠습니까?");
+    if (insertBtn) {
+      // 보호사 매칭 종료
+      let agent_id = "";
+      let agent_match_idx = "";
+      agent.agentListBySenior.map((item, idx) => {
+        if (item['senior_id'] = senior['senior_id'] && item['agent_match_state']) {
+          agent_id = item['agent_id']
+          agent_match_idx = item['agent_match_idx']
+          agentSeniorDelete(agent_id, agent_match_idx, true);
+        }
+      });
+
+      // 장비 대여 종료
+      let equipment = {};
+      equipmentBySenior.equipmentList.map((item, idx) => {
+        if (item['senior_id'] = senior['senior_id']) {
+          equipment = item;
+          equipmentRentalEnd(equipment, true);
+        }
+      });
+
+      senior['user_use'] = false;
+
+      fetch("/user/userUpdate.json", {
+        method: "POST",
+        headers: {
+          'Content-Type': 'application/json; charset=UTF-8'
+        },
+        body: JSON.stringify(senior),
+      }).then((response) => response.json()).then((data) => {
+        console.log("사용자 등록 결과(건수) : ", data);
+        if (data > 0) {
+          alert("삭제 되었습니다.");
+          navigate(-1);
+        } else {
+          alert("삭제에 실패하였습니다.");
+        }
+      }).catch((error) => {
+        console.log('seniorDelete() /user/userInsert.json error : ', error);
+      });
+    } else {
+      return;
+    }
+  }
+
+
   React.useEffect(() => {
     medicationTimeCodeSelectList();
     equipmentStatesSelect();
     deliveryEquipmentSelectList();
-    
+
     seniorSelectOne();
     guardianSelectListBySenior();
     agentSelectListBySenior();
@@ -293,56 +431,59 @@
 
 
   return (
-  <main>
-    <Modal_Guardian open={modalGuardianIsOpen} close={modalGuardianClose} seniorId={location.state['senior_id']}
-      guardianBySenior={guardianBySenior}
-      guardianManagementCallback={() => {guardianSelectListBySenior(); modalGuardianClose(); setGuardianBySenior({})}}/>
+    <main>
+      <Modal_Guardian open={modalGuardianIsOpen} close={modalGuardianClose} seniorId={location.state['senior_id']}
+        guardianBySenior={guardianBySenior}
+        guardianManagementCallback={() => { guardianSelectListBySenior(); modalGuardianClose(); setGuardianBySenior({}) }} />
 
 
-    <Modal open={modalRentalIsOpen} close={modalRentalClose} header="사용가능 장비 선택">
-      <div className="board-wrap">
-        <div>
-          <div className="search-management flex-end margin-bottom2 margin-top">						
-            <div style={{width: '120px', fontWeight: '600', fontSize: '16px'}}>대여 시작일</div>
-            <input type="date"
-              value={equipmentRental['rental_start_date']}
-              onChange={(e) => {
-                equipmentRental['rental_start_date'] = e.target.value;
-                setEquipmentRental({...equipmentRental})}
-              }/>	
-          </div>
-          
-          <table class="caregiver-user protector-user">
-            <thead>
-              <tr>
-                <th>No </th>
-                <th>모델명</th>
-                <th>시리얼넘버</th>
-                <th>입고일자</th>
-                <th>장비상태</th>
-                <th>장비선택</th>
-              </tr>
-            </thead>
-            <tbody>
-              {deliveryEquipment.equipmentList.map((item, idx) => { return (
+      <Modal open={modalRentalIsOpen} close={modalRentalClose} header="사용가능 장비 선택">
+        <div className="board-wrap">
+          <div>
+            <div className="search-management flex-end margin-bottom2 margin-top">
+              <div style={{ width: '120px', fontWeight: '600', fontSize: '16px' }}>대여 시작일</div>
+              <input type="date"
+                value={equipmentRental['rental_start_date']}
+                onChange={(e) => {
+                  equipmentRental['rental_start_date'] = e.target.value;
+                  setEquipmentRental({ ...equipmentRental })
+                }
+                } />
+            </div>
+
+            <table class="caregiver-user protector-user">
+              <thead>
                 <tr>
-                  <td data-label="No">{deliveryEquipment.equipmentListCount - idx - (deliveryEquipmentSearch.currentPage - 1) * deliveryEquipmentSearch.perPage}</td>
-                  <td data-label="모델명">{item['equipment_name']}</td>
-                  <td data-label="시리얼넘버">{item['equipment_serial_number']}</td>
-                  <td data-label="입고일자">{item['equipment_stock_date']}</td>
-                  <td data-label="장비상태">{equipmentStates[item['equipment_state']]}</td>
-                  <td data-label="장비선택">
-                    <button className={"btn-small gray-btn"} onClick={() => {equipmentRentalInsert(item)}}>추가</button>
-                  </td>
-                  
+                  <th>No </th>
+                  <th>모델명</th>
+                  <th>시리얼넘버</th>
+                  <th>입고일자</th>
+                  <th>장비상태</th>
+                  <th>장비선택</th>
                 </tr>
-              )})}
-              {CommonUtil.isEmpty(deliveryEquipment.equipmentList) ?
-                <tr>
-                  <td colSpan={6}>조회된 데이터가 없습니다</td>
-                </tr>
-              : null}
-            </tbody>
+              </thead>
+              <tbody>
+                {deliveryEquipment.equipmentList.map((item, idx) => {
+                  return (
+                    <tr>
+                      <td data-label="No">{deliveryEquipment.equipmentListCount - idx - (deliveryEquipmentSearch.currentPage - 1) * deliveryEquipmentSearch.perPage}</td>
+                      <td data-label="모델명">{item['equipment_name']}</td>
+                      <td data-label="시리얼넘버">{item['equipment_serial_number']}</td>
+                      <td data-label="입고일자">{item['equipment_stock_date']}</td>
+                      <td data-label="장비상태">{equipmentStates[item['equipment_state']]}</td>
+                      <td data-label="장비선택">
+                        <button className={"btn-small gray-btn"} onClick={() => { equipmentRentalInsert(item) }}>추가</button>
+                      </td>
+
+                    </tr>
+                  )
+                })}
+                {CommonUtil.isEmpty(deliveryEquipment.equipmentList) ?
+                  <tr>
+                    <td colSpan={6}>조회된 데이터가 없습니다</td>
+                  </tr>
+                  : null}
+              </tbody>
             </table>
             <Pagination
               currentPage={deliveryEquipmentSearch.currentPage}
@@ -351,230 +492,266 @@
               maxRange={5}
               click={deliveryEquipmentSelectList}
             />
+          </div>
         </div>
-      </div>
-    </Modal>
+      </Modal>
+
+      <Modal open={modalRentalEndIsOpen} close={modalRentalEndClose} header="장비 대여 종료">
+        <div className="board-wrap">
+          <table className="margin-bottom">
+            <tbody>
+              <tr>
+                <th>장비대여종료일</th>
+                <td>
+                  <input type="date" defaultValue={new Date().toLocaleDateString('en-CA')} onChange={(e) => {
+                    console.log('e.target.value : ', e.target.value);
+                    setRentalEndDate(e.target.value);
+                  }} />
+                </td>
+              </tr>
+            </tbody>
+          </table>
+          <div className="flex-center">
+            <button className="btn-small gray-btn" onClick={() => {
+              equipmentRentalEnd(rentalData, false)
+            }}>확인</button>
+          </div>
+        </div>
+      </Modal>
 
 
-    <div className="content-wrap row">
-      <SubTitle explanation={"대상자 상세 프로필"} className="margin-bottom" />
-      <div className="margin-bottom5">
-        <table className="margin-bottom senior-detail">
-          <tbody>
-            <tr>
-              <th>관리기관</th>
-              <td>
-                <span>{senior['government_name']}</span>
-              </td>             
-            </tr>
+      <div className="content-wrap row">
+        <SubTitle explanation={"대상자 상세 프로필"} className="margin-bottom" />
+        <div className="margin-bottom5">
+          <table className="margin-bottom senior-detail">
+            <tbody>
+              <tr>
+                <th>관리기관</th>
+                <td>
+                  <span>{senior['government_name']}</span>
+                </td>
+              </tr>
 
-            <tr>
-              <th>시행기관</th>
-              <td>
-                <span>{senior['agency_name']}</span>
-              </td>              
-            </tr>
+              <tr>
+                <th>시행기관</th>
+                <td>
+                  <span>{senior['agency_name']}</span>
+                </td>
+              </tr>
 
-            <tr>
-              <th>이름(아이디)</th>
-              <td>
-                <span>{senior['user_name']}({senior['user_id']})</span>
-              </td>           
-            </tr>
+              <tr>
+                <th>이름(아이디)</th>
+                <td>
+                  <span>{senior['user_name']}({senior['user_id']})</span>
+                </td>
+              </tr>
 
-            <tr>
-              <th>성별</th>
-              <td>
-                <span>{senior['user_gender']}</span>
-              </td>           
-            </tr>
-            
-            <tr>
-              <th>연락처</th>
-              <td>
-                <span>{senior['user_phonenumber']}</span>
-              </td>
-            </tr>
+              <tr>
+                <th>성별</th>
+                <td>
+                  <span>{senior['user_gender']}</span>
+                </td>
+              </tr>
 
-            <tr>
-              <th>생년월일</th>
-              <td>
-                <span>{senior['user_birth']}</span>
-              </td>
-            </tr>
+              <tr>
+                <th>연락처</th>
+                <td>
+                  <span>{senior['user_phonenumber']}</span>
+                </td>
+              </tr>
 
-            <tr>
-              <th>주소</th>
-              <td>
-                <span>{senior['user_address']}</span>
-              </td>         
-            </tr>
-            
-            <tr>
-              <th>필요복약</th>
-              <td className="flex-start">
-              {medicationTimeCodeList.filter(item => senior.seniorMedicationList.indexOf(item['medication_time_code']) > -1).map((item, idx) => { return (
-                <span>{item['medication_time_code_name']}</span>
-              )})}
-              </td>              
-            </tr>
+              <tr>
+                <th>생년월일</th>
+                <td>
+                  <span>{senior['user_birth']}</span>
+                </td>
+              </tr>
 
-            <tr>
-              <th>복용중인 약</th>
-              <td colSpan={3}>
-                <span className="medicine" cols="30" rows="2">{senior['medication_pill']}</span>
-              </td>
-            </tr>
-            
-            <tr>
-              <th>비고</th>
-              <td colSpan={3}>
-                <span className="note" cols="30" rows="2">{senior['senior_note']}</span>
-              </td>
-            </tr>
-          </tbody>
-        </table>
+              <tr>
+                <th>주소</th>
+                <td>
+                  <span>{senior['user_address']}</span>
+                </td>
+              </tr>
+
+              <tr>
+                <th>필요복약</th>
+                <td className="flex-start">
+                  {medicationTimeCodeList.filter(item => senior.seniorMedicationList.indexOf(item['medication_time_code']) > -1).map((item, idx) => {
+                    return (
+                      <span>{item['medication_time_code_name']}</span>
+                    )
+                  })}
+                </td>
+              </tr>
+
+              <tr>
+                <th>복용중인 약</th>
+                <td colSpan={3}>
+                  <span className="medicine" cols="30" rows="2">{senior['medication_pill']}</span>
+                </td>
+              </tr>
+
+              <tr>
+                <th>비고</th>
+                <td colSpan={3}>
+                  <span className="note" cols="30" rows="2">{senior['senior_note']}</span>
+                </td>
+              </tr>
+            </tbody>
+          </table>
+          <div className="btn-wrap flex-center">
+            <button className={"btn-large gray-btn"} onClick={() => { navigate("/SeniorEdit", { state: { 'senior_id': senior['senior_id'] } }) }}>수정</button>
+            <button className={"btn-large red-btn"} onClick={() => seniorDelete(senior)}>삭제</button>
+          </div>
+        </div>
+
+        <SubTitle explanation={"대상자의 보호자"} className="margin-bottom display-inline-block" />
+        <button className={"btn-small gray-btn display-inline-block float-right"} onClick={() => { setGuardianBySenior({}); modalGuardianOpen() }}>보호자 추가</button>
+        <div className="margin-bottom5">
+          <table className={"protector-user"}>
+            <thead>
+              <tr>
+                <th>No</th>
+                <th>이름</th>
+                <th>관계</th>
+                <th>연락처</th>
+                <th>생년월일</th>
+                <th>주소</th>
+                <th>가입승인</th>
+                <th>관리</th>
+              </tr>
+            </thead>
+            <tbody>
+              {guardianListBySenior.map((item, idx) => {
+                return (
+                  <tr key={idx}>
+                    <td data-label="No">{idx + 1}</td>
+                    <td data-label="이름">{item['user_name']}</td>
+                    <td data-label="관계">{item['senior_relationship']}</td>
+                    <td data-label="연락처">{item['user_phonenumber']}</td>
+                    <td data-label="생년월일">{item['user_birth']}</td>
+                    <td data-label="주소">{item['user_address']}</td>
+                    <td data-label="가입승인">
+                      {item['is_accept'] ? "승인완료" :
+                        <button className={"btn-small red-btn"} onClick={() => { userUpdate(item, guardianSelectListBySenior) }}>가입승인</button>
+                      }
+                    </td>
+                    <td data-label="관리">
+                      <button className={"btn-small lightgray-btn"} onClick={() => guardianBySeniorManagement(item)}>정보 수정</button>
+                    </td>
+                  </tr>
+                )
+              })}
+              {CommonUtil.isEmpty(guardianListBySenior) ?
+                <tr>
+                  <td colSpan={8}>조회된 데이터가 없습니다</td>
+                </tr>
+                : null}
+            </tbody>
+          </table>
+        </div>
+
+
+        <SubTitle explanation={"대상자의 보호사"} className="margin-bottom" />
+        <div className="margin-bottom5">
+          <table className={"senior-user protector-user"}>
+            <thead>
+              <tr>
+                <th>No</th>
+                <th>관리기관명</th>
+                <th>소속기관명</th>
+                <th>이름</th>
+                <th>연락처</th>
+                <th>이메일</th>
+                <th>상태</th>
+                <th>배정시작일</th>
+                <th>배정종료일</th>
+                <th>관리</th>
+                <th>상세보기</th>
+              </tr>
+            </thead>
+            <tbody>
+              {agent.agentListBySenior.map((item, idx) => {
+                return (
+                  <tr key={idx}>
+                    <td data-label="No">{idx + 1}</td>
+                    <td data-label="관리기관명">{item['government_name']}</td>
+                    <td data-label="소속기관명">{item['agency_name']}</td>
+                    <td data-label="이름">{item['user_name']}</td>
+                    <td data-label="연락처">{item['user_phonenumber']}</td>
+                    <td data-label="이메일">{item['user_email']}</td>
+                    <td data-label="상태">{item['agent_match_state'] ? <span className="green">현재 보호사</span> : <span className="grey">이전 보호사</span>}</td>
+                    <td data-label="배정시작일">{item['agent_match_start_date']}</td>
+                    <td data-label="배정종료일">{item['agent_match_end_date']}</td>
+                    <td data-label="관리">
+                      {item['agent_match_state'] ?
+                        <button className="btn-small red-btn" onClick={() => agentSeniorDelete(item['agent_id'], item['agent_match_idx'], false)}>매칭종료</button>
+                        : null}
+                    </td>
+                    <td data-label="상세보기">
+                      <button className={"btn-small lightgray-btn"} onClick={() => { navigate("/AgentSelectOne", { state: { 'agent_id': item['agent_id'] } }) }}>상세 페이지 이동</button>
+                    </td>
+                  </tr>
+                )
+              })}
+              {CommonUtil.isEmpty(agent.agentListBySenior) ?
+                <tr>
+                  <td colSpan={11}>조회된 데이터가 없습니다</td>
+                </tr>
+                : null}
+            </tbody>
+          </table>
+        </div>
+
+
+        <SubTitle explanation={"대상자의 장비"} className="margin-bottom display-inline-block" />
+        <button className={"btn-small gray-btn display-inline-block float-right"} onClick={modalRentalOpen}>장비 추가</button>
+        <div className="margin-bottom5">
+          <table className={"senior-user protector-user"}>
+            <thead>
+              <tr>
+                <th>No </th>
+                <th>모델명</th>
+                <th>시리얼넘버</th>
+                <th>장비상태</th>
+                <th>장비대여여부</th>
+                <th>관리</th>
+              </tr>
+            </thead>
+            <tbody>
+              {equipmentBySenior.equipmentList.map((item, idx) => {
+                return (
+                  <tr key={idx}>
+                    <td data-label="No">{idx + 1}</td>
+                    <td data-label="모델명">{item['equipment_name']}</td>
+                    <td data-label="시리얼넘버">{item['equipment_serial_number']}</td>
+                    <td data-label="장비상태">{equipmentStates[item['equipment_state']]}</td>
+                    <td data-label="장비상태">
+                      {CommonUtil.isEmpty(item['rental_start_date']) == false && CommonUtil.isEmpty(item['rental_end_date']) == true ?
+                        '대여중' : '대여종료'}
+                    </td>
+                    <td data-label="관리">
+                      {
+                        CommonUtil.isEmpty(item['rental_start_date']) == false && CommonUtil.isEmpty(item['rental_end_date']) == true ?
+                          (<button className={"btn-small red-btn"} onClick={() => modalRentalEndOpen(item)}>대여 종료</button>)
+                          : null}
+                    </td>
+                  </tr>
+                )
+              })}
+              {CommonUtil.isEmpty(equipmentBySenior.equipmentList) ?
+                <tr>
+                  <td colSpan={6}>조회된 데이터가 없습니다</td>
+                </tr>
+                : null}
+            </tbody>
+          </table>
+        </div>
         <div className="btn-wrap flex-center">
-          <button className={"btn-large gray-btn"} onClick={() => {navigate("/SeniorEdit", {state: {'senior_id': senior['senior_id']}})}}>수정</button>
-          <button className={"btn-large red-btn"} onClick={() => alert("삭제할 수 없습니다.")}>삭제</button>
+          <button className={"btn-large gray-btn"} onClick={() => navigate(-1)}>이전</button>
         </div>
       </div>
-
-      <SubTitle explanation={"대상자의 보호자"} className="margin-bottom display-inline-block" />
-      <button className={"btn-small gray-btn display-inline-block float-right"} onClick={() => {setGuardianBySenior({}); modalGuardianOpen()}}>보호자 추가</button>
-      <div className="margin-bottom5">
-        <table className={"protector-user"}>
-          <thead>
-            <tr>
-              <th>No</th>
-              <th>이름</th>
-              <th>관계</th>
-              <th>연락처</th>
-              <th>생년월일</th>
-              <th>주소</th>
-              <th>가입승인</th>
-              <th>관리</th>
-            </tr>
-          </thead>
-          <tbody>
-            {guardianListBySenior.map((item, idx) => { return (
-              <tr key={idx}>
-                <td data-label="No">{idx + 1}</td>
-                <td data-label="이름">{item['user_name']}</td>
-                <td data-label="관계">{item['senior_relationship']}</td>
-                <td data-label="연락처">{item['user_phonenumber']}</td>
-                <td data-label="생년월일">{item['user_birth']}</td>
-                <td data-label="주소">{item['user_address']}</td>
-                <td data-label="가입승인">
-                  {item['is_accept'] ? "승인완료" : 
-                    <button className={"btn-small red-btn"} onClick={() => {userUpdate(item, guardianSelectListBySenior)}}>가입승인</button>
-                  }
-                </td>
-                <td data-label="관리">
-                  <button className={"btn-small lightgray-btn"} onClick={() => guardianBySeniorManagement(item)}>정보 수정</button>
-                </td>
-              </tr>
-            )})}
-            {CommonUtil.isEmpty(guardianListBySenior) ?
-              <tr>
-                <td colSpan={8}>조회된 데이터가 없습니다</td>
-              </tr>  
-            : null}
-          </tbody>
-        </table>
-      </div>
-
-
-      <SubTitle explanation={"대상자의 보호사"} className="margin-bottom" />
-      <div className="margin-bottom5">
-        <table className={"senior-user protector-user"}>
-          <thead>
-            <tr>
-              <th>No</th>
-              <th>관리기관명</th>
-              <th>소속기관명</th>
-              <th>이름</th>
-              <th>연락처</th>
-              <th>이메일</th>
-              <th>상태</th>
-              <th>배정시작일</th>
-              <th>배정종료일</th>
-              <th>배정관리</th>
-              <th>상세보기</th>
-            </tr>
-          </thead>
-          <tbody>
-            {agent.agentListBySenior.map((item, idx) => { return (
-              <tr key={idx}>
-                <td data-label="No">{idx + 1}</td>
-                <td data-label="관리기관명">{item['government_name']}</td>
-                <td data-label="소속기관명">{item['agency_name']}</td>
-                <td data-label="이름">{item['user_name']}</td>
-                <td data-label="연락처">{item['user_phonenumber']}</td>
-                <td data-label="이메일">{item['user_email']}</td>
-                <td data-label="상태">{item['agent_match_state'] ? <span className="green">현재 보호사</span> : <span className="grey">이전 보호사</span>}</td>
-                <td data-label="배정시작일">{item['agent_match_start_date']}</td>
-                <td data-label="배정종료일">{item['agent_match_end_date']}</td>
-                <td data-label="배정관리">
-                  <button className="btn-small red-btn" onClick={() => confirm("매칭종료하시겠습니까?")}>매칭종료</button>  
-                </td>
-                <td data-label="상세보기">
-                  <button className={"btn-small lightgray-btn"} onClick={() => {navigate("/AgentSelectOne", {state: {'agent_id': item['agent_id']}})}}>상세 페이지 이동</button>
-                </td>
-              </tr>
-            )})}
-            {CommonUtil.isEmpty(agent.agentListBySenior) ?
-              <tr>
-                <td colSpan={10}>조회된 데이터가 없습니다</td>
-              </tr>
-            : null}
-          </tbody>
-        </table>
-      </div>
-
-
-
-      <SubTitle explanation={"대상자의 장비"} className="margin-bottom display-inline-block" />
-      <button className={"btn-small gray-btn display-inline-block float-right"} onClick={modalRentalOpen}>장비 추가</button>
-      <div className="margin-bottom5">
-        <table className={"senior-user protector-user"}>
-          <thead>
-            <tr>
-              <th>No </th>
-              <th>모델명</th>
-              <th>시리얼넘버</th>
-              <th>장비상태</th>
-              <th>관리</th>
-            </tr>
-          </thead>
-          <tbody>
-            {equipmentBySenior.equipmentList.map((item, idx) => { return (
-              <tr key={idx}>
-                <td data-label="No">{idx + 1}</td>
-                <td data-label="모델명">{item['equipment_name']}</td>
-                <td data-label="시리얼넘버">{item['equipment_serial_number']}</td>
-                <td data-label="장비상태">{equipmentStates[item['equipment_state']]}</td>
-                <td data-label="관리">
-                  <button className={"btn-small red-btn"} onClick={() => guardianBySeniorManagement(item)}>대여 종료</button>
-                </td>
-              </tr>
-            )})}
-            {CommonUtil.isEmpty(equipmentBySenior.equipmentList) ?
-              <tr>
-                <td colSpan={5}>조회된 데이터가 없습니다</td>
-              </tr>
-            : null}
-          </tbody>
-        </table>
-      </div>
-
-
-      <div className="btn-wrap flex-center">
-        <button className={"btn-large gray-btn"} onClick={() => navigate(-1)}>이전</button>
-      </div>
-
-    </div>
-
-  </main>
+    </main>
   );
 }
client/views/pages/user_management/AgencyAdminSeniorSelect.jsx
--- client/views/pages/user_management/AgencyAdminSeniorSelect.jsx
+++ client/views/pages/user_management/AgencyAdminSeniorSelect.jsx
@@ -18,6 +18,10 @@
 
   const [modalOpen, setModalOpen] = React.useState(false);
   const openModal = () => {
+    if (CheckList.length < 0) {
+      alert("대상을 선택해 주세요.");
+      return;
+    }
     setModalOpen(true);
   };
   const closeModal = () => {
@@ -83,49 +87,26 @@
     }
   }
   const searching = () => {
-    mySenior.search['searchType'] = search['searchType'];
-    mySenior.search['searchText'] = search['searchText'];
-    mySenior.search['agent_id'] = state.loginUser['user_id'];
-    setMySenior({ ...mySenior });
-
     agencySenior.search['searchType'] = search['searchType'];
     agencySenior.search['searchText'] = search['searchText'];
     agencySenior.search['agency_id'] = state.loginUser['agency_id'];
     setAgencySenior({ ...agencySenior });
 
-    mySeniorSelectList(1);
+    agencyDeleteSenior.search['searchType'] = search['searchType'];
+    agencyDeleteSenior.search['searchText'] = search['searchText'];
+    agencyDeleteSenior.search['agency_id'] = state.loginUser['agency_id'];
+    setAgencyDeleteSenior({ ...agencyDeleteSenior });
+
     agencySeniorSelectList(1);
+    agencyDeleteSeniorSelectList(1);
   }
-
-
-  //보호사(간호사)의 돌봄 대상자(시니어)
-  const [mySenior, setMySenior] = React.useState({ seniorList: [], seniorListCount: 0, search: JSON.parse(JSON.stringify(search)) });
-  //보호사(간호사)의 돌봄 대상자(시니어) 목록 조회
-  const mySeniorSelectList = (currentPage) => {
-    mySenior.search.currentPage = CommonUtil.isEmpty(currentPage) ? 1 : currentPage;
-
-    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);
-    }).catch((error) => {
-      console.log('seniorSelectList() /user/seniorSelectList.json error : ', error);
-    });
-  }
-
-
 
   //시행기관의 대상자(시니어)
   const [agencySenior, setAgencySenior] = React.useState({ seniorList: [], seniorListCount: 0, search: JSON.parse(JSON.stringify(search)) });
   //시행기관의 대상자(시니어) 목록 조회
   const agencySeniorSelectList = (currentPage) => {
     agencySenior.search.currentPage = CommonUtil.isEmpty(currentPage) ? 1 : currentPage;
+    agencySenior.search.user_use = true;
 
     fetch("/user/seniorSelectList.json", {
       method: "POST",
@@ -157,36 +138,6 @@
     return '보호사';
   }
 
-
-
-  //보호사의 대상자 등록
-  const agentSeniorInsert = (senior, agentId) => {
-    if (confirm(`${senior['user_name']}님을 돌봄 대상자로 추가하시겠습니까?`) == false) {
-      return;
-    } else {
-      senior['agent_id'] = state.loginUser['user_id'];
-    }
-    fetch("/user/agentSeniorInsert.json", {
-      method: "POST",
-      headers: {
-        'Content-Type': 'application/json; charset=UTF-8'
-      },
-      body: JSON.stringify(senior),
-    }).then((response) => response.json()).then((data) => {
-      if (data > 0) {
-        setTabIndex(0);
-        search.searchText = '';
-        search.searchType = '';
-        searching();
-        alert("추가완료");
-      } else {
-        alert("추가에 실패하였습니다. 관리자에게 문의바랍니다.");
-      }
-    }).catch((error) => {
-      console.log('agencySeniorSelectList() /user/seniorSelectList.json error : ', error);
-    });
-  }
-
   const [CheckList, setCheckList] = React.useState([]);
   const [IdList, setIdList] = React.useState([]);
 
@@ -196,18 +147,81 @@
       ids[i] = item['user_id']
     })
     setIdList(ids)
-  }, [agencySenior.seniorList])
+  }, [agencySenior.seniorList,])
 
   const onChangeAll = (e) => {
     setCheckList(e.target.checked ? IdList : [])
   }
 
   const onChangeEach = (e, id) => {
+    console.log('checkList : ', CheckList);
     if (e.target.checked) {
       setCheckList([...CheckList, id]);
     } else {
       setCheckList(CheckList.filter((checkedId) => checkedId !== id));
     }
+  }
+
+  // 시니어 - 담당자 매칭 시도
+  const [workerId, setWorkerId] = React.useState("");
+  // 시니어 - 담당자 매칭 
+  const MatchSeniorAgency = () => {
+    if (workerId == '') {
+      alert("보호사를 선택해 주세요.");
+      return;
+    }
+    var insertBtn = confirm("등록하시겠습니까?");
+    if (insertBtn) {
+      for (let i = 0; i < CheckList.length; i++) {
+        agentSeniorInsert(CheckList[i]);
+      }
+    } else {
+      return;
+    }
+  };
+
+  // 보호사 배정
+  const agentSeniorInsert = (seniorId) => {
+    fetch("/user/agentSeniorInsert.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({
+        agent_id: workerId,
+        senior_id: seniorId,
+        agent_match_insert_user_id: state.loginUser['user_id']
+      }),
+    }).then((response) => response.json()).then((data) => {
+      closeModal();
+      agentSelectList();
+      searching();
+    }).catch((error) => {
+      console.log('MatchSeniorAgency() /user/agentSeniorInsert.json error : ', error);
+    });
+  }
+
+
+  //시행기관의 삭제 대상자(시니어)
+  const [agencyDeleteSenior, setAgencyDeleteSenior] = React.useState({ seniorList: [], seniorListCount: 0, search: JSON.parse(JSON.stringify(search)) });
+  //시행기관의 삭제 대상자(시니어) 목록 조회
+  const agencyDeleteSeniorSelectList = (currentPage) => {
+    agencyDeleteSenior.search.currentPage = CommonUtil.isEmpty(currentPage) ? 1 : currentPage;
+    agencyDeleteSenior.search.user_use = false;
+
+    fetch("/user/seniorSelectList.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify(agencyDeleteSenior.search),
+    }).then((response) => response.json()).then((data) => {
+      data.search = agencyDeleteSenior.search;
+      console.log("시행기관의 삭제 대상자(시니어) 목록 조회 : ", data);
+      setAgencyDeleteSenior(data);
+    }).catch((error) => {
+      console.log('agencyDeleteSeniorSelectList() /user/seniorSelectList.json error : ', error);
+    });
   }
 
   React.useEffect(() => {
@@ -300,7 +314,8 @@
                   return (
                     <tr key={idx}>
                       <td data-label="checkbox">
-                        <input type="checkbox" name="checkSenior" id={"check" + idx} onChange={(e) => onChangeEach(e, item['user_id'])} checked={CheckList.includes(item['user_id'])} />
+                        <input type="checkbox" name="checkSenior" id={"check" + idx} onChange={(e) =>
+                          onChangeEach(e, item['user_id'])} checked={CheckList.includes(item['user_id'])} />
                       </td>
                       <td data-label="No">{agencySenior.seniorListCount - idx - (agencySenior.search.currentPage - 1) * agencySenior.search.perPage}</td>
                       <td data-label="소속기관명">{item['agency_name']}</td>
@@ -347,6 +362,72 @@
             />
           </div>
         </div>
+      </div>
+    )
+  }, {
+    title: `우리기관 삭제된 돌봄 대상자 (${agencyDeleteSenior.seniorListCount})`,
+    content: (
+      <div>
+        <div className="flex equip-tab">
+          <SubTitle explanation={"삭제된 돌봄 대상자 목록입니다."} />
+        </div>
+        <table className={"protector-user"}>
+          <thead>
+            <tr>
+              <th>No</th>
+              <th>소속기관명</th>
+              <th>이름</th>
+              <th>생년월일</th>
+              <th>성별</th>
+              <th>연락처</th>
+              <th>보호자</th>
+              <th>대상자관리</th>
+            </tr>
+          </thead>
+          <tbody>
+            {agencyDeleteSenior.seniorList.map((item, idx) => {
+              return (
+                <tr key={idx}>
+                  <td data-label="No">{agencyDeleteSenior.seniorListCount - idx - (agencyDeleteSenior.search.currentPage - 1) * agencyDeleteSenior.search.perPage}</td>
+                  <td data-label="소속기관명">{item['agency_name']}</td>
+                  <td data-label="이름">{item['user_name']}</td>
+                  <td data-label="생년월일">{item['user_birth']}</td>
+                  <td data-label="성별">{item['user_gender']}</td>
+                  <td data-label="연락처">{item['user_phonenumber']}</td>
+                  <td data-label="보호자">
+                    {CommonUtil.isEmpty(item['guardian_user_names'])
+                      ? '없음'
+                      : item['guardian_user_names']
+                    }
+                  </td>
+                  <td data-label="대상자관리">
+                    <button className="btn-small gray-btn" onClick={() => {
+                      navigate("/SeniorSelectOne", {
+                        state: {
+                          'senior_id': item['senior_id'],
+                          'agency_id': item['agency_id'],
+                          'government_id': item['government_id']
+                        }
+                      })
+                    }}>대상자관리</button>
+                  </td>
+                </tr>
+              )
+            })}
+            {CommonUtil.isEmpty(agencyDeleteSenior.seniorList) ?
+              <tr>
+                <td colSpan={8}>조회된 데이터가 없습니다</td>
+              </tr>
+              : null}
+          </tbody>
+        </table>
+        <Pagination
+          currentPage={agencySenior.search.currentPage}
+          perPage={agencySenior.search.perPage}
+          totalCount={agencySenior.seniorListCount}
+          maxRange={5}
+          click={agencySeniorSelectList}
+        />
       </div>
     )
   }
@@ -409,7 +490,10 @@
               <tr>
                 <th>담당 보호사</th>
                 <td>
-                  <select name="" id="">
+                  <select onChange={(e) => {
+                    console.log('e.target.value : ', e.target.value);
+                    setWorkerId(e.target.value);
+                  }}>
                     <option value="">담당 보호사를 선택해주세요.</option>
                     {agent.userList.map((user, idx) => {
                       return (
@@ -422,8 +506,9 @@
             </tbody>
           </table>
           <div className="flex-center">
-            <button className="btn-small gray-btn">등록</button>
-            <button className="btn-small red-btn">삭제</button>
+            <button className="btn-small gray-btn" onClick={() => {
+              MatchSeniorAgency()
+            }}>등록</button>
           </div>
         </div>
       </Modal>
Add a comment
List