하석형 하석형 2023-02-21
230221 하석형 장비 매칭 작업 중
@b94f36c76b1c06b230c6425199eaa8c135c7a3f7
client/views/pages/equipment/EquipmentManagementSelect.jsx
--- client/views/pages/equipment/EquipmentManagementSelect.jsx
+++ client/views/pages/equipment/EquipmentManagementSelect.jsx
@@ -16,26 +16,40 @@
 	const closeModal = () => {
 		setModalOpen(false);
 	};
-	const [modalOpen2, setModalOpen2] = React.useState(false);
-	const openModal2 = () => {
-		setModalOpen2(true);
-	};
-	const closeModal2 = () => {
-		setModalOpen2(false);
-	};
+	
 	const [modalOpen3, setModalOpen3] = React.useState(false);
 	const openModal3 = () => {
+		// equipmentListData();
 		setModalOpen3(true);
 	};
 	const closeModal3 = () => {
 		setModalOpen3(false);
 	};
+
+	// 대상자 매칭 삭제
+	const seniorMatchDelete = () => {
+		if(confirm('등록된 대상자를 삭제하시겠습니까?') == false) {
+			return;
+		}
+		// 대상자 매칭 삭제 함수 사용하기
+	};
+
 	const navigate = useNavigate();
 
-	// 장비 목록 조회
+	// 함수 실행 함수
+	React.useEffect(() => {
+		equipmentSelectList();
+
+		agencyEquipmentSelectList();
+	}, [])
+
+
+
+	/********************************** 관리자 장비 (시작) **********************************/
+	// 관리자 전체 장비 목록
 	const [equipmentList, setEquipmentList] = React.useState([]);
 
-	// 장비 목록 조회 함수
+	// 관리자 전체 장비 목록 조회
 	const equipmentSelectList = () => {
 		console.log('equipmentSelectList Function Run');
 		fetch("/equipment/equipmentSelectList.json", {
@@ -45,16 +59,23 @@
 			},
 		}).then((response) => response.json()).then((data) => {
 			console.log('equipmentSelectList response : ', data);
-			// setEquipmentList(data);
+			setEquipmentList(data);
 		}).catch((error) => {
 			console.log('equipmentSelectList error : ', error);
 		});
 	}
 
-	// 함수 실행 함수
-	React.useEffect(() => {
-		equipmentSelectList();
-	}, [])
+	// 장비 목록 조회 확인
+	const equipmentListData = () => {
+		console.log('equipmentSelectList Function Run', equipmentList);
+		console.log('equipmentSelectList Function Run', equipmentList.length);
+		console.log('content1 before data: ', content1);
+		for(let i = 0; i < equipmentList.length; i++) {
+			content1.equipmentNo = i + 1;
+			content1.equipmentName = equipmentList[i].equipment_name;
+		}
+		console.log('content1 after data: ', content1);
+	}
 
 	const thead1 = [
 		"No",
@@ -62,39 +83,20 @@
 		"시리얼 넘버",
 		"입고 일자",
 		"상태",
-		"보유 기관", //관리기관, 올잇메디
-		"대상자",//시행기관
+		"보유 기관",
+		"대상자",
+		"관리",
 	];
 	const key1 = [
-		"equipmentNo",
-		"equipmentName",
-		"equipmentSerialNumber",
-		"equipmentStockDate",
-		"equipmentState",
-		"equipmentAgency",
-		"equipmentSenior",
+		"equipment_name",
+		"equipment_serial_number",
+		"equipment_stock_date",
+		"equipment_state",
+		"agency_name",
+		"user_name",
 	];
-	const content1 = [
-		{
-			No: 1,
-			equipment: "스마트약상자",
-			serialNumber: "ABCD-1",
-			date: "2022.12.02",
-			use: "사용",
-			agency: "A복지관",
-			protector: "김복지",
-		},
-		{
-			No: 2,
-			equipment: "스마트약상자",
-			serialNumber: "ABCD-1",
-			date: "2022.12.02",
-			use: "미사용",
-			agency: "B복지관",
-			protector: "-"
-		},
-	];
-	const thead3 = [
+
+	const thead2 = [
 		"No",
 		"장비명",
 		"시리얼 넘버",
@@ -102,7 +104,7 @@
 		"납품 기관",//관리기관, 올잇메디
 		"대상자",//시행기관
 	];
-	const key3 = [
+	const key2 = [
 		"No",
 		"equipment",
 		"serialNumber",
@@ -110,7 +112,7 @@
 		"agency",
 		"senior",
 	];
-	const content3 = [
+	const content2 = [
 		{
 			No: 1,
 			equipment: "스마트약상자",
@@ -127,7 +129,7 @@
 				<Button
 					className={"btn-small gray-btn"}
 					btnName={"선택"}
-					onClick={openModal2}
+					// onClick={openModal2}
 				/>
 			),
 		},
@@ -145,12 +147,12 @@
 				<Button
 					className={"btn-small gray-btn"}
 					btnName={"선택"}
-					onClick={openModal2}
+					// onClick={openModal2}
 				/>
 			),
 		},
 	];
-	const thead2 = [
+	const thead3 = [
 		"No",
 		"장비명",
 		"시리얼 넘버",
@@ -159,7 +161,7 @@
 		"보유기관",//관리기관, 올잇메디
 		"담당자",//시행기관
 	];
-	const key2 = [
+	const key3 = [
 		"No",
 		"equipment",
 		"serialNumber",
@@ -168,7 +170,7 @@
 		"agency",
 		"protector",
 	];
-	const content2 = [
+	const content3 = [
 		{
 			No: 1,
 			equipment: "스마트약상자",
@@ -180,6 +182,216 @@
 
 		},
 	];
+	/********************************** 관리자 장비 (끝) **********************************/
+
+
+
+	/********************************** 시행기관 장비 (시작) **********************************/
+	//로그 확인
+	const logCheck = () => {
+		console.log('agencyEquipmentList - change: ', agencyEquipmentList);
+	};
+
+	// 시행기관 전체 장비 목록
+	const [agencyEquipmentList, setAgencyEquipmentList] = React.useState([]);
+
+	// 대상자 장비 등록 모달창
+	const [seniorMatchModal, setSeniorMatchModal] = React.useState(false);
+
+	// 대상자 장비
+	const [seniorEquipment, setSeniorEquipment] = React.useState({});
+
+	// 대상자 장비 등록 모달창 열기
+	const seniorMatchModalOpen = (item) => {
+		setSeniorEquipment(item); // 선택한 장비 데이터 저장
+		setSeniorMatchModal(true);
+	};
+	// 대상자 장비 등록 모달창 닫기
+	const seniorMatchModalClose = () => {
+		setSeniorMatchModal(false);
+	};
+
+	// 대상자 장비 등록 - 대상자
+	const seniorEquipmentSeniorInsert = (e) => {
+		// 원본 데이터 복사 및 수정
+		let data = {
+			...seniorEquipment,
+			senior_id: e.target.value,
+			user_name: null
+		}
+		// 복사 데이터를 원본 데이터에 덮어쓰기
+		setSeniorEquipment(data);
+	};
+
+	// 대상자 장비 등록 - 대여일
+	const seniorEquipmentRentalStartDateInsert = (e) => {
+		// 원본 데이터 복사 및 수정
+		let data = {
+			...seniorEquipment,
+			equipment_rental_start_date: e.target.value
+		}
+		// 복사 데이터를 원본 데이터에 덮어쓰기
+		setSeniorEquipment(data);
+	};
+
+	// 대상자 장비 등록 - 반납예정일
+	const seniorEquipmentRentalEndDateInsert = (e) => {
+		// 원본 데이터 복사 및 수정
+		let data = {
+			...seniorEquipment,
+			equipment_rental_end_date: e.target.value
+		}
+		// 복사 데이터를 원본 데이터에 덮어쓰기
+		setSeniorEquipment(data);
+	};
+
+	// 시행기관 전체 장비 목록 조회
+	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 seniorEquipmentInsert = () => {
+		console.log('seniorEquipmentInsert Function Run');
+		fetch("/equipment/seniorEquipmentInsert.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('seniorEquipmentInsert response : ', data);
+			setSeniorEquipment(data);
+		}).catch((error) => {
+			console.log('seniorEquipmentInsert error : ', error);
+		});
+	}
+
+	const thead11 = [
+		"No",
+		"모델 명",
+		"시리얼 넘버",
+		"상태",
+		"대상자",
+		"대여일",
+		"반납예정일",
+		"반납일",
+		"관리"
+	];
+	const key11 = [
+		"equipment_name",
+		"equipment_serial_number",
+		"equipment_state",
+		"user_name",
+		"equipment_rental_start_date",
+		"equipment_rental_end_date",
+		"equipment_rental_return_date"
+	];
+
+	const thead22 = [
+		"No",
+		"장비명",
+		"시리얼 넘버",
+		"입고일자",
+		"납품 기관",//관리기관, 올잇메디
+		"대상자",//시행기관
+	];
+	const key22 = [
+		"No",
+		"equipment",
+		"serialNumber",
+		"date",
+		"agency",
+		"senior",
+	];
+	const content22 = [
+		{
+			No: 1,
+			equipment: "스마트약상자",
+			serialNumber: "ABCD-1",
+			date: "2022.12.02",
+			agency: (
+				<Button
+					className={"btn-small gray-btn"}
+					btnName={"선택"}
+					onClick={openModal}
+				/>
+			),
+			senior: (
+				<Button
+					className={"btn-small gray-btn"}
+					btnName={"선택"}
+					// onClick={openModal2}
+				/>
+			),
+		},
+		{
+			No: 2,
+			equipment: "스마트약상자",
+			serialNumber: "ABCD-1",
+			date: "2022.12.02",
+			agency: (<Button
+				className={"btn-small gray-btn"}
+				btnName={"선택"}
+				onClick={openModal}
+			/>),
+			senior: (
+				<Button
+					className={"btn-small gray-btn"}
+					btnName={"선택"}
+					// onClick={openModal2}
+				/>
+			),
+		},
+	];
+	const thead33 = [
+		"No",
+		"장비명",
+		"시리얼 넘버",
+		"대여일",
+		"배터리 잔량",
+		"보유기관",//관리기관, 올잇메디
+		"담당자",//시행기관
+	];
+	const key33 = [
+		"No",
+		"equipment",
+		"serialNumber",
+		"date",
+		"battery",
+		"agency",
+		"protector",
+	];
+	const content33 = [
+		{
+			No: 1,
+			equipment: "스마트약상자",
+			serialNumber: "ABCD-1",
+			date: "2022.12.02",
+			battery: "10%",
+			agency: "A복지관",
+			protector: "김복지"
+
+		},
+	];
+	/********************************** 시행기관 장비 (끝) **********************************/
+
 	const thead4 = [
 		"No",
 		"기관명",
@@ -207,13 +419,14 @@
 		},
 	];
 	const thead5 = [
-		"No",
 		"대상자",
-		"선택하기",
+		"대여일",
+		"반납예정일",
+		"선택",
 	];
 	const key5 = [
-		"No",
 		"senior",
+		"date",
 		"choice",
 	];
 	const content5 = [
@@ -243,7 +456,7 @@
 	const data = [
 		{
 			id: 1,
-			title: "장비 전체(205)",
+			title: "전체 장비" + "(" + equipmentList.length + ")",
 			description: (
 				<div>
 					<div className="flex">
@@ -256,46 +469,179 @@
 							/>
 						</div>
 					</div>
-					<Table
+					{/* <Table
 						className={"caregiver-user"}
 						head={thead1}
-						contents={content1}
+						contents={equipmentList}
 						contentKey={key1}
 						onClick={() => {
 							navigate("/EquipmentManagementSelectOne");
 						}}
-					/>
+					/> */}
+					<table class = "caregiver-user">
+						<thead>
+							<tr>
+							{thead1.map((i) => {
+								return <th>{i}</th>;
+							})}
+							</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 green-btn"}
+												btnName={"등록"}
+												onClick={() => seniorMatchModalOpen(item)}
+											/>
+										: <Button
+											className={"btn-small green-btn"}
+											btnName={"삭제"}
+											onClick={seniorMatchDelete}
+										/>
+									}
+									</td>
+								</tr>
+							);
+							})}
+						</tbody>
+					</table>
 				</div>
 			),
 		},
 		{
 			id: 2,
-			title: "재고(미사용) 장비(5)", //에이젼시로 들어가면 미사용 장비(5)로 나와야 함
+			title: "재고 장비" + "(" + ")", //에이젼시로 들어가면 미사용 장비(5)로 나와야 함
 			description: (
 				<div>
 					<Table
 						className={"caregiver-user"}
-						head={thead3}
-						contents={content3}
-						contentKey={key3}
+						head={thead2}
+						contents={content2}
+						contentKey={key2}
 					/>
 				</div>
 			),
 		},
 		{
 			id: 3,
-			title: "납품(내가 사용중인) 장비(200)",//에이젼시로 들어가면 내가 사용중인 장비(5)로 나와야 함
+			title: "납품 장비" + "(" + ")",//에이젼시로 들어가면 내가 사용중인 장비(5)로 나와야 함
 			description: (
 				<Table
 					className={"caregiver-user"}
-					head={thead2}
-					contents={content2}
-					contentKey={key2}
+					head={thead3}
+					contents={content3}
+					contentKey={key3}
+				/>
+			),
+		},
+
+		{
+			id: 4,
+			title: "전체 장비(시행기관)" + "(" + agencyEquipmentList.length + ")",
+			description: (
+				<div>
+					<div className="flex">
+						<SubTitle explanation={"장비 클릭 시 지난 매칭이력을 확인할 수 있습니다."} />
+						<div className="btn-wrap flex-end margin-bottom ">
+							<Button
+								className={"btn-small green-btn"}
+								btnName={"LOG"}
+								onClick={logCheck}
+							/>
+							<Button
+								className={"btn-small green-btn"}
+								btnName={"등록"}
+								onClick={openModal3}
+							/>
+						</div>
+					</div>
+					{/* <Table
+						className={"caregiver-user"}
+						head={thead11}
+						contents={agencyEquipmentList}
+						contentKey={key11}
+						onClick={() => {
+							navigate("/EquipmentManagementSelectOne");
+						}}
+					/> */}
+					<table class = "caregiver-user">
+						<thead>
+							<tr>
+							{thead11.map((i) => {
+								return <th>{i}</th>;
+							})}
+							</tr>
+						</thead>
+						<tbody>
+							{agencyEquipmentList.map((item, index) => {
+							return (
+								<tr key={index}>
+									<td>{agencyEquipmentList.length - index}</td>
+									{key11.map((kes) => {
+										return <td>{item[kes]}</td>
+									})}
+									<td>
+									{
+										item['senior_id'] == null
+										? <Button
+												className={"btn-small green-btn"}
+												btnName={"등록"}
+												onClick={() => seniorMatchModalOpen(item)}
+											/>
+										: <Button
+											className={"btn-small green-btn"}
+											btnName={"삭제"}
+											onClick={seniorMatchDelete}
+										/>
+									}
+									</td>
+								</tr>
+							);
+							})}
+						</tbody>
+					</table>
+				</div>
+			),
+		},
+		{
+			id: 5,
+			title: "재고 장비(시행기관)" + "(" + ")", //에이젼시로 들어가면 미사용 장비(5)로 나와야 함
+			description: (
+				<div>
+					<Table
+						className={"caregiver-user"}
+						head={thead22}
+						contents={content22}
+						contentKey={key22}
+					/>
+				</div>
+			),
+		},
+		{
+			id: 6,
+			title: "납품 장비(시행기관)" + "(" + ")",//에이젼시로 들어가면 내가 사용중인 장비(5)로 나와야 함
+			description: (
+				<Table
+					className={"caregiver-user"}
+					head={thead33}
+					contents={content33}
+					contentKey={key33}
 				/>
 			),
 		},
 	];
-	const [index, setIndex] = React.useState(1);
+
+	//시작 탭 설정
+	const [index, setIndex] = React.useState(4);
 	return (
 		<main>
 			<Modal open={modalOpen} close={closeModal} header="납품 기관 선택">
@@ -317,26 +663,54 @@
 					</div>
 				</div>
 			</Modal>
-			<Modal open={modalOpen2} close={closeModal2} header="대상자 선택">
+			<Modal open={seniorMatchModal} close={seniorMatchModalClose} header="대상자 장비 등록">
 				<div className="board-wrap">
 					<div>
-						<Table
-							className={"caregiver-user"}
-							head={thead5}
-							contents={content5}
-							contentKey={key5}
-						/>
+						<table className={"caregiver-user"}>
+							<thead>
+								<tr>
+								{thead5.map((i) => {
+									return <th>{i}</th>;
+								})}
+								</tr>
+							</thead>
+							<tbody>
+								<tr>
+									<td>
+										<input type="text" list="senior_list" />
+										<datalist id="senior_list">
+											<option value="대상자1(ID)"></option>
+											<option value="대상자2(ID)"></option>
+											<option value="대상자3(ID)"></option>
+										</datalist>
+									</td>
+									<td>
+										<input type="date" onChange={seniorEquipmentRentalStartDateInsert}/>
+									</td>
+									<td>
+										<input type="date" onChange={seniorEquipmentRentalEndDateInsert}/>
+									</td>
+									<td>
+										<Button
+											className={"btn-small gray-btn"}
+											btnName={"선택"}
+											onClick={seniorEquipmentInsert}
+										/>
+									</td>
+								</tr>
+							</tbody>
+						</table>
 					</div>
 					<div>
 						<Button
 							className={"btn-100 green-btn"}
 							btnName={"닫기"}
-							onClick={closeModal2}
+							onClick={seniorMatchModalClose}
 						/>
 					</div>
 				</div>
 			</Modal>
-			<Modal open={modalOpen3} close={closeModal3} header="대상자 선택">
+			<Modal open={modalOpen3} close={closeModal3} header="장비 등록">
 				<div className="board-wrap">
 					<div>
 						<table className="flex70 margin-bottom">
Add a comment
List