최정임 최정임 2023-02-28
Merge branch 'admin' of http://210.180.118.83/yjryu/senior_care_system into admin
@16cd96b29f405c051278acdcb6fccb7920102bb9
client/views/pages/equipment/EquipmentManagementSelect.jsx
--- client/views/pages/equipment/EquipmentManagementSelect.jsx
+++ client/views/pages/equipment/EquipmentManagementSelect.jsx
@@ -176,7 +176,6 @@
 		"입고 일자",
 		"상태",
 		"보유 기관",
-		"대상자",
 		"관리",
 	];
 	const key1 = [
@@ -185,7 +184,6 @@
 		"equipment_stock_date",
 		"equipment_state",
 		"agency_name",
-		"senior_name",
 	];
 
 	const thead2 = [
@@ -281,7 +279,7 @@
 	/********************************** 시행기관 장비 (시작) **********************************/
 	//로그 확인
 	const logCheck = () => {
-		console.log('equipmentNotMatchSeniorList - change: ', equipmentNotMatchSeniorList);
+		console.log('seniorMatchListByEquipment - change: ', seniorMatchListByEquipment.length);
 	};
 
 	// 시행기관 전체 장비 목록
@@ -298,6 +296,8 @@
 	const [seniorMatchReturnModal, setSeniorMatchReturnModal] = React.useState(false);
 	// 시행기관 장비 상세 조회 모달창
 	const [agencyEquipmentOneModal, setAgencyEquipmentOneModal] = React.useState(false);
+	// 장비별 대상자 매칭 목록 조회
+	const [seniorMatchListByEquipment, setSeniorMatchListByEquipment] = React.useState([]);
 
 	// 장비 비매칭 대상자 목록
 	const [equipmentNotMatchSeniorList, setEquipmentNotMatchSeniorList] = React.useState([]);
@@ -395,16 +395,18 @@
 		setSeniorEquipment(data);
 	};
 
-
-	// 대상자 장비 등록 모달창 열기
+	// 시행기관 장비 상세 조회 모달창 열기
 	const agencyEquipmentOneModalOpen = (item) => {
-		setSeniorEquipment(item); // 선택한 장비 데이터 저장
+		agencyEquipmentSelectOne(item);
+		// setSeniorEquipment(item); // 선택한 장비 데이터 저장
 		setAgencyEquipmentOneModal(true);
 	};
-	// 대상자 장비 등록 모달창 닫기
+
+	// 시행기관 장비 상세 조회 모달창 닫기
 	const agencyEquipmentOneModalClose = () => {
 		setAgencyEquipmentOneModal(false);
 	};
+
 
 	// 시행기관 전체 장비 목록 조회
 	const agencyEquipmentSelectList = () => {
@@ -466,6 +468,28 @@
 		});
 	}
 
+	// 시행기관 장비 상세 조회
+	const agencyEquipmentSelectOne = (item) => {
+		console.log('agencyEquipmentSelectOne Function Run: ', item);
+		
+		// 대상자 장비 반납 구분 조건 data
+		item['matchTarget'] = 'equipment';
+
+		fetch("/equipment/equipmentMatchSelectList.json", {
+			method: "POST",
+			headers: {
+				'Content-Type': 'application/json; charset=UTF-8'
+			},
+			body: JSON.stringify(item),
+		}).then((response) => response.json()).then((data) => {
+			console.log('agencyEquipmentSelectOne response : ', data);
+			// 장비별 대상자 매칭 목록
+			setSeniorMatchListByEquipment(data);
+		}).catch((error) => {
+			console.log('agencyEquipmentSelectOne error : ', error);
+		});
+	}
+
 	// 대상자 장비 등록
 	const seniorEquipmentInsert = () => {
 		console.log('seniorEquipmentInsert Function Run');
@@ -495,16 +519,21 @@
 		}
 
 		// 대여일 유효성 검사
-		/* if(seniorEquipment['equipment_rental_start_date'] == null) {
+		if(seniorEquipment['equipment_rental_start_date'] == null) {
 			alert('대여일을 입력해 주세요');
 			return;
-		} */
+		}
 
 		// 반납 예정일 유효성 검사
-		/* if(seniorEquipment['equipment_rental_end_date'] == null) {
+		if(seniorEquipment['equipment_rental_end_date'] == null) {
 			alert('반납 예정일 입력해 주세요');
 			return;
-		} */
+		}
+		
+		// 이전 매칭 기록 확인 조건 data
+		// console.log('insert seniorEquipment before: ', seniorEquipment);
+		seniorEquipment['matchTarget'] = 'senior';
+		// console.log('insert seniorEquipment after: ', seniorEquipment);
 
 		fetch("/equipment/seniorEquipmentInsert.json", {
 			method: "POST",
@@ -553,10 +582,10 @@
 		}
 
 		// 반납 예정일 유효성 검사
-		/* if(seniorEquipment['equipment_rental_return_date'] == null) {
-			alert('반납일 입력해 주세요');
+		if(seniorEquipment['equipment_rental_return_date'] == null) {
+			alert('반납일을 입력해 주세요');
 			return;
-		} */
+		}
 
 		fetch("/equipment/seniorEquipmentReturn.json", {
 			method: "POST",
@@ -653,6 +682,20 @@
 		"선택",
 	];
 
+	const thead66 = [
+		"대상자",
+		"대여일",
+		"반납일",
+		"반납 담당자",
+	];
+
+	const key66 = [
+		"senior_name",
+		"equipment_rental_start_date",
+		"equipment_rental_return_date",
+		"return_user_name",
+	];
+
 	// 마운트 시 실행 함수
 	React.useEffect(() => {
 		equipmentStatesSelect();
@@ -734,31 +777,34 @@
 							</tr>
 						</thead>
 						<tbody>
-							{equipmentList.map((item, index) => {
-								return (
-									<tr key={index}>
-										<td>{equipmentList.length - index}</td>
-										{key1.map((kes) => {
-											return <td>{item[kes]}</td>
-										})}
-										<td>
-											{
-												item['senior_id'] == null
-													? <Button
-														className={"btn-small gray-btn"}
-														btnName={"등록"}
-														onClick={() => seniorMatchInsertModalOpen(item)}
-													/>
-													: <Button
-														className={"btn-small gray-btn"}
-														btnName={"반납"}
-														onClick={seniorMatchDelete}
-													/>
-											}
-										</td>
-									</tr>
-								);
-							})}
+							{equipmentList.length > 0
+								? equipmentList.map((item, index) => {
+									return (
+										<tr key={index}>
+											<td>{equipmentList.length - index}</td>
+											{key1.map((kes) => {
+												return <td>{item[kes]}</td>
+											})}
+											<td>
+												{
+													item['senior_id'] == null
+														? <Button
+															className={"btn-small gray-btn"}
+															btnName={"등록"}
+															onClick={() => seniorMatchInsertModalOpen(item)}
+														/>
+														: <Button
+															className={"btn-small gray-btn"}
+															btnName={"반납"}
+															onClick={seniorMatchDelete}
+														/>
+												}
+											</td>
+										</tr>
+									);
+								})
+								: <td colSpan={7}>조회된 데이터가 없습니다.</td>
+							}
 						</tbody>
 					</table>
 				</div>
@@ -818,7 +864,7 @@
 							{agencyEquipmentList.map((item, index) => {
 								if(item)
 								return (
-									<tr key={index} onclick={agencyEquipmentOneModalOpen}>
+									<tr key={index} onClick={() => agencyEquipmentOneModalOpen(item)}>
 										<td>{agencyEquipmentList.length - index}</td>
 										{/* {key11.map((kes) => {
 											if(kes == "equipment_rental_state") {
@@ -841,7 +887,7 @@
 											return <td>{Object.values(equipmentRentalStates)[idx]}</td>
 										})}
 										<td>{item['equipment_match_idx']}</td>
-										<td onClick={event.stopPropagation()}>
+										<td onClick={(e) => e.stopPropagation()}>
 											{
 												item['equipment_rental_state'] == 'RENTABLE'
 													? <Button
@@ -881,25 +927,28 @@
 							</tr>
 						</thead>
 						<tbody>
-							{agencySeniorEquipmentList.map((item, index) => {
-								return (
-									<tr key={index}>
-										<td>{agencySeniorEquipmentList.length - index}</td>
-										{key22.map((kes) => {
-											return <td>{item[kes]}</td>
-										})}
-										<td>
-											{
-												<Button
-													className={"btn-small gray-btn"}
-													btnName={"반납"}
-													onClick={() => seniorMatchReturnModalOpen(item)}
-												/>
-											}
-										</td>
-									</tr>
-								);
-							})}
+							{agencySeniorEquipmentList.length > 0
+								? agencySeniorEquipmentList.map((item, index) => {
+									return (
+										<tr key={index}>
+											<td>{agencySeniorEquipmentList.length - index}</td>
+											{key22.map((kes) => {
+												return <td>{item[kes]}</td>
+											})}
+											<td>
+												{
+													<Button
+														className={"btn-small gray-btn"}
+														btnName={"반납"}
+														onClick={() => seniorMatchReturnModalOpen(item)}
+													/>
+												}
+											</td>
+										</tr>
+									);
+								})
+								: <td colSpan={9}>조회된 데이터가 없습니다.</td>
+							}
 						</tbody>
 					</table>
 				</div>
@@ -922,25 +971,28 @@
 							</tr>
 						</thead>
 						<tbody>
-							{agencyStockEquipmentList.map((item, index) => {
-								return (
-									<tr key={index}>
-										<td>{agencyStockEquipmentList.length - index}</td>
-										{key33.map((kes) => {
-											return <td>{item[kes]}</td>
-										})}
-										<td>
-											{
-												<Button
-													className={"btn-small gray-btn"}
-													btnName={"등록"}
-													onClick={() => seniorMatchInsertModalOpen(item)}
-												/>
-											}
-										</td>
-									</tr>
-								);
-							})}
+							{agencyStockEquipmentList.length > 0
+								? agencyStockEquipmentList.map((item, index) => {
+									return (
+										<tr key={index}>
+											<td>{agencyStockEquipmentList.length - index}</td>
+											{key33.map((kes) => {
+												return <td>{item[kes]}</td>
+											})}
+											<td>
+												{
+													<Button
+														className={"btn-small gray-btn"}
+														btnName={"등록"}
+														onClick={() => seniorMatchInsertModalOpen(item)}
+													/>
+												}
+											</td>
+										</tr>
+									);
+								})
+								: <td colSpan={5}>조회된 데이터가 없습니다.</td>
+							}
 						</tbody>
 					</table>
 				</div>
@@ -1110,32 +1162,24 @@
 						<table className={"caregiver-user"}>
 							<thead>
 								<tr>
-									{thead55.map((i) => {
+									{thead66.map((i) => {
 										return <th>{i}</th>;
 									})}
 								</tr>
 							</thead>
 							<tbody>
-								<tr>
-									<td>
-										<input type="date" onChange={seniorEquipmentRentalReturnDateInsert} />
-									</td>
-									<td>
-										<input type="text" list="senior_list" placeholder="반납 담당자를 입력해 주세요" onChange={seniorEquipmentReturnUserIdInsert} />
-										<datalist id="senior_list">
-											{workerList.map((item) => {
-												return <option value={item['user_id']}>{item['user_name']}</option>
-											})}
-										</datalist>
-									</td>
-									<td>
-										<Button
-											className={"btn-small gray-btn"}
-											btnName={"선택"}
-											onClick={seniorEquipmentReturn}
-										/>
-									</td>
-								</tr>
+								{seniorMatchListByEquipment.length > 0
+									? seniorMatchListByEquipment.map((item, index) => {
+										return (
+											<tr>
+												{key66.map((kes) => {
+													return <td>{item[kes]}</td>
+												})}
+											</tr>
+										);
+									})
+									: <td colSpan={4}>조회된 데이터가 없습니다.</td>
+								}
 							</tbody>
 						</table>
 					</div>
Add a comment
List