하석형 하석형 2023-02-23
230223 하석형 장비 반납 기능
@946c8940ff06d61ba990be37854c5d0a6c752a4d
client/views/pages/equipment/EquipmentManagementSelect.jsx
--- client/views/pages/equipment/EquipmentManagementSelect.jsx
+++ client/views/pages/equipment/EquipmentManagementSelect.jsx
@@ -31,10 +31,48 @@
 		if (confirm('아니다') == false) {
 			return;
 		}
-		// 대상자 매칭 삭제 함수 사용하기
+		// 대상자 매칭 반납 함수 사용하기
 	};
 
 	const navigate = useNavigate();
+
+	// 대상자 목록 조회
+	const seniorSelectList = () => {
+		console.log('seniorSelectList Function Run');
+		fetch("/user/userSeleteList.json", {
+			method: "POST",
+			headers: {
+				'Content-Type': 'application/json; charset=UTF-8'
+			},
+			body: JSON.stringify({
+				user_code: 'SENIOR01'
+			})
+		}).then((response) => response.json()).then((data) => {
+			console.log('seniorSelectList response : ', data);
+			setSeniorList(data);
+		}).catch((error) => {
+			console.log('seniorSelectList error : ', error);
+		});
+	}
+
+	// 담당자 목록 조회
+	const workerSelectList = () => {
+		console.log('workerSelectList Function Run');
+		fetch("/user/userSeleteList.json", {
+			method: "POST",
+			headers: {
+				'Content-Type': 'application/json; charset=UTF-8'
+			},
+			body: JSON.stringify({
+				user_code: 'WORKER01'
+			})
+		}).then((response) => response.json()).then((data) => {
+			console.log('workerSelectList response : ', data);
+			setWorkerList(data);
+		}).catch((error) => {
+			console.log('workerSelectList error : ', error);
+		});
+	}
 
 	/********************************** 관리자 장비 (시작) **********************************/
 	// 관리자 전체 장비 목록
@@ -182,8 +220,8 @@
 	const [seniorEquipment, setSeniorEquipment] = React.useState({});
 	// 대상자 장비 등록 모달창
 	const [seniorMatchInsertModal, setSeniorMatchInsertModal] = React.useState(false);
-	// 대상자 장비 삭제 모달창
-	const [seniorMatchDeleteModal, setSeniorMatchDeleteModal] = React.useState(false);
+	// 대상자 장비 반납 모달창
+	const [seniorMatchReturnModal, setSeniorMatchReturnModal] = React.useState(false);
 
 	// 대상자 목록
 	const [seniorList, setSeniorList] = React.useState([]);
@@ -245,17 +283,21 @@
 		setSeniorEquipment(data);
 	};
 
-	// 대상자 장비 삭제 모달창 열기
-	const seniorMatchDeleteModalOpen = (item) => {
+
+	// 대상자 장비 반납 모달창 열기
+	const seniorMatchReturnModalOpen = (item) => {
 		setSeniorEquipment(item); // 선택한 장비 데이터 저장
-		setSeniorMatchDeleteModal(true);
+		setSeniorMatchReturnModal(true);
 	};
-	// 대상자 장비 삭제 모달창 닫기
-	const seniorMatchDeleteModalClose = () => {
-		setSeniorMatchDeleteModal(false);
+
+	// 대상자 장비 반납 모달창 닫기
+	const seniorMatchReturnModalClose = () => {
+		setSeniorMatchReturnModal(false);
 	};
+
 	// 대상자 장비 - 반납일
 	const seniorEquipmentRentalReturnDateInsert = (e) => {
+		console.log('@@@', e.target.value);
 		// 원본 데이터 복사 및 수정
 		let data = {
 			...seniorEquipment,
@@ -264,8 +306,10 @@
 		// 복사 데이터를 원본 데이터에 덮어쓰기
 		setSeniorEquipment(data);
 	};
-	// 대상자 장비 - 반납 관리자
+
+	// 대상자 장비 - 반납 담당자
 	const seniorEquipmentReturnUserIdInsert = (e) => {
+		console.log('@@@@@', e.target.value);
 		// 원본 데이터 복사 및 수정
 		let data = {
 			...seniorEquipment,
@@ -277,27 +321,8 @@
 
 
 	// 시행기관 전체 장비 목록 조회
-	// const agencyEquipmentSelectList = () => {
-	// 	console.log('agencyEquipmentSelectList Function Run');
-	// 	fetch("/equipment/agencyEquipmentSelectList.json", {
-	// 		method: "POST",
-	// 		headers: {
-	// 			'Content-Type': 'application/json; charset=UTF-8'
-	// 		},
-	// 		body: JSON.stringify({
-	// 			agency_id: 'AGENCY01',
-	// 		}),
-	// 	}).then((response) => response.json()).then((data) => {
-	// 		console.log('agencyEquipmentSelectList response : ', data);
-	// 		setAgencyEquipmentList(data);
-	// 	}).catch((error) => {
-	// 		console.log('agencyEquipmentSelectList error : ', error);
-	// 	});
-	// }
-
-	// 시행기관 전체 장비 목록 조회
 	const agencyEquipmentSelectList = () => {
-		console.log('equipmentSelectList Function Run');
+		console.log('agencyEquipmentSelectList Function Run');
 		fetch("/equipment/equipmentSelectList.json", {
 			method: "POST",
 			headers: {
@@ -308,10 +333,10 @@
 				searchAll: true
 			}),
 		}).then((response) => response.json()).then((data) => {
-			console.log('equipmentSelectList response : ', data);
+			console.log('agencyEquipmentSelectList response : ', data);
 			setAgencyEquipmentList(data);
 		}).catch((error) => {
-			console.log('equipmentSelectList error : ', error);
+			console.log('agencyEquipmentSelectList error : ', error);
 		});
 	}
 
@@ -393,6 +418,12 @@
 			console.log('seniorEquipmentInsert response : ', data);
 			// 대상자 장비 데이터 초기화
 			setSeniorEquipment({});
+
+			// 장비 목록 조회
+			agencyEquipmentSelectList();
+			agencySeniorEquipmentSelectList();
+			agencyStockEquipmentSelectList();
+
 			alert('등록이 완료됐습니다.');
 		}).catch((error) => {
 			console.log('seniorEquipmentInsert error : ', error);
@@ -400,58 +431,64 @@
 		});
 	}
 
-	// 대상자 목록 조회
-	const seniorSelectList = () => {
-		console.log('seniorSelectList Function Run');
-		fetch("/user/selectSubjectList.json", {
+	// 대상자 장비 반납
+	const seniorEquipmentReturn = () => {
+		console.log('seniorEquipmentReturn Function Run');
+
+		// 담당자 아이디 유효성 검사
+		let check = 0;
+		for (let i = 0; i < workerList.length; i++) {
+			// 입력한 데이터가 담당자 목록에 있을 경우
+			if (workerList[i]['user_id'] == seniorEquipment['return_user_id']) {
+				console.log('success: ', workerList[i]['user_id']);
+				check = 1;
+			}
+		}
+		// 입력한 데이터가 담당자 목록에 없을 경우
+		if (check != 1) {
+			console.log('fail: ', workerList, seniorEquipment['return_user_id']);
+			alert('존재하지 않는 담당자입니다.');
+			return;
+		}
+
+		fetch("/equipment/seniorEquipmentReturn.json", {
 			method: "POST",
 			headers: {
 				'Content-Type': 'application/json; charset=UTF-8'
 			},
-			body: JSON.stringify({})
+			body: JSON.stringify(seniorEquipment),
 		}).then((response) => response.json()).then((data) => {
-			console.log('seniorSelectList response : ', data);
-			setSeniorList(data);
+			console.log('seniorEquipmentReturn response : ', data);
+			// 대상자 장비 데이터 초기화
+			setSeniorEquipment({});
+
+			// 장비 목록 조회
+			agencyEquipmentSelectList();
+			agencySeniorEquipmentSelectList();
+			agencyStockEquipmentSelectList();
+
+			alert('반납이 완료됐습니다.');
 		}).catch((error) => {
-			console.log('seniorSelectList error : ', error);
+			console.log('seniorEquipmentReturn error : ', error);
+			alert('반납에 실패했습니다.');
 		});
 	}
 
-	// 담당자 목록 조회
-	const workerSelectList = () => {
-		console.log('workerSelectList Function Run');
-		fetch("/user/selectSubjectList.json", {
-			method: "POST",
-			headers: {
-				'Content-Type': 'application/json; charset=UTF-8'
-			},
-			body: JSON.stringify({})
-		}).then((response) => response.json()).then((data) => {
-			console.log('workerSelectList response : ', data);
-			setSeniorList(data);
-		}).catch((error) => {
-			console.log('workerSelectList error : ', error);
-		});
-	}
 
 	// 시행기관 전체 장비 thead, key
 	const thead11 = [
 		"No",
 		"모델 명",
 		"시리얼 넘버",
-		"상태",
-		"대상자",
-		"대여일",
-		"반납예정일",
-		"관리"
+		"기기 상태",
+		"대여 상태",
+		"대상자 관리",
 	];
 	const key11 = [
 		"equipment_name",
 		"equipment_serial_number",
 		"equipment_state",
-		"senior_name",
-		"equipment_rental_start_date",
-		"equipment_rental_end_date",
+		"equipment_rental_state",
 	];
 
 	// 시행기관 대상자 장비 thead, key
@@ -459,11 +496,11 @@
 		"No",
 		"모델 명",
 		"시리얼 넘버",
-		"상태",
+		"기기 상태",
 		"대상자",
 		"대여일",
 		"반납예정일",
-		"관리"
+		"대상자 관리",
 	];
 	const key22 = [
 		"equipment_name",
@@ -479,19 +516,13 @@
 		"No",
 		"모델 명",
 		"시리얼 넘버",
-		"상태",
-		"대상자",
-		"대여일",
-		"반납예정일",
-		"관리"
+		"기기 상태",
+		"대상자 관리",
 	];
 	const key33 = [
 		"equipment_name",
 		"equipment_serial_number",
 		"equipment_state",
-		"senior_name",
-		"equipment_rental_start_date",
-		"equipment_rental_end_date",
 	];
 
 	// 장비 대상자 등록 모달창 thead
@@ -502,15 +533,18 @@
 		"선택",
 	];
 
-	// 장비 대상자 삭제 모달창 thead
+	// 장비 대상자 반납 모달창 thead
 	const thead55 = [
 		"반납일",
-		"반납자",
+		"반납 담당자",
+		"선택",
 	];
 
 	// 마운트 시 실행 함수
 	React.useEffect(() => {
 		seniorSelectList();
+		workerSelectList();
+
 		//관리자
 		equipmentSelectList();
 
@@ -602,7 +636,7 @@
 													/>
 													: <Button
 														className={"btn-small green-btn"}
-														btnName={"삭제"}
+														btnName={"반납"}
 														onClick={seniorMatchDelete}
 													/>
 											}
@@ -667,6 +701,7 @@
 						</thead>
 						<tbody>
 							{agencyEquipmentList.map((item, index) => {
+								if(item)
 								return (
 									<tr key={index}>
 										<td>{agencyEquipmentList.length - index}</td>
@@ -675,7 +710,7 @@
 										})}
 										<td>
 											{
-												item['senior_id'] == null
+												item['equipment_rental_state'] == false
 													? <Button
 														className={"btn-small green-btn"}
 														btnName={"등록"}
@@ -684,7 +719,7 @@
 													: <Button
 														className={"btn-small green-btn"}
 														btnName={"반납"}
-														onClick={() => seniorMatchDeleteModalOpen(item)}
+														onClick={() => seniorMatchReturnModalOpen(item)}
 													/>
 											}
 										</td>
@@ -725,7 +760,7 @@
 												<Button
 													className={"btn-small green-btn"}
 													btnName={"반납"}
-													onClick={() => seniorMatchDeleteModalOpen(item)}
+													onClick={() => seniorMatchReturnModalOpen(item)}
 												/>
 											}
 										</td>
@@ -891,7 +926,7 @@
 				</div>
 			</Modal>
 
-			<Modal open={seniorMatchDeleteModal} close={seniorMatchDeleteModalClose} header="대상자 장비 반납">
+			<Modal open={seniorMatchReturnModal} close={seniorMatchReturnModalClose} header="대상자 장비 반납">
 				<div className="board-wrap">
 					<div>
 						<table className={"caregiver-user"}>
@@ -908,12 +943,10 @@
 										<input type="date" onChange={seniorEquipmentRentalReturnDateInsert} />
 									</td>
 									<td>
-										<input type="text" list="senior_list" placeholder="반납 관리자를 입력해 주세요" onChange={seniorEquipmentReturnUserIdInsert} />
+										<input type="text" list="senior_list" placeholder="반납 담당자를 입력해 주세요" onChange={seniorEquipmentReturnUserIdInsert} />
 										<datalist id="senior_list">
-											{seniorList.map((item) => {
-												// return <option value={item['user_name'] + " (" + item['user_id'] + ")"}></option>
+											{workerList.map((item) => {
 												return <option value={item['user_id']}>{item['user_name']}</option>
-
 											})}
 										</datalist>
 									</td>
@@ -921,7 +954,7 @@
 										<Button
 											className={"btn-small gray-btn"}
 											btnName={"선택"}
-											onClick={seniorEquipmentInsert}
+											onClick={seniorEquipmentReturn}
 										/>
 									</td>
 								</tr>
Add a comment
List