kcscDev/egovframe-template-simple-r.../src/pages/admin/config/baseCode/ParentCodeDiv.jsx

153 lines
5.7 KiB
React
Raw Normal View History

2024-01-02 09:02:31 +00:00
import React, { useState, useEffect, useCallback } from 'react';
2024-01-03 08:59:14 +00:00
import * as EgovNet from "api/egovFetch";
2023-12-29 02:56:04 +00:00
import {Container} from "react-bootstrap";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Form from 'react-bootstrap/Form'
import Button from "react-bootstrap/Button";
2024-01-03 08:59:14 +00:00
import { FaRegHandPointRight } from "react-icons/fa";
import CODE from "../../../../constants/code";
2024-01-02 09:02:31 +00:00
2024-01-03 08:59:14 +00:00
function ParentCodeDiv({getCodeItem}){
2024-01-02 09:02:31 +00:00
const [codeGrpRow, setCodeGrpRow] = useState();
2024-01-03 08:59:14 +00:00
const getCodeGrp = useCallback(()=>{
2024-01-02 09:02:31 +00:00
EgovNet.requestFetch(
'/admin/config/base-code-mgt/code-grp',
2024-01-02 09:02:31 +00:00
{
2024-01-03 08:59:14 +00:00
method: "GET"
2024-01-02 09:02:31 +00:00
},
(resp) => {
2024-01-03 08:59:14 +00:00
const codeGrpList = resp.result.codeGrpList;
const grpTag = [];
codeGrpList.forEach(function (item, index){
grpTag.push(
<Row className={"py-2 border-bottom"}>
<Form.Control type={"hidden"} className={"grpCd"} defaultValue={item.grpCd}/>
2024-01-03 08:59:14 +00:00
<Col xs={3}>
<FaRegHandPointRight className={"selectIcon d-none"}/>&nbsp;
<a href={"#"} onClick={(e)=>{codeGrpChoose(e, item.grpCd)}} data-grpcd={item.grpCd}>{item.grpCd}</a>
</Col>
<Col xs={5}><Form.Control type={"text"} size={"sm"} className={"grpCdNm"} defaultValue={item.grpCdNm}/></Col>
<Col xs={2}><Button variant={"danger"} size={"sm"} onClick={(e)=>{modifyCodeGrp(e, "remove")}}>삭제</Button></Col>
<Col xs={2}><Button variant={"primary"} size={"sm"} onClick={(e)=>{modifyCodeGrp(e, "modify")}}>수정</Button></Col>
2024-01-03 08:59:14 +00:00
</Row>
)
})
setCodeGrpRow(grpTag);
2024-01-02 09:02:31 +00:00
},
function (resp) {
console.log("err response : ", resp);
}
);
2024-01-03 08:59:14 +00:00
});
2024-01-02 09:02:31 +00:00
useEffect(() => {
getCodeGrp();
}, []);
2023-12-29 02:56:04 +00:00
2024-01-03 08:59:14 +00:00
function codeGrpChoose(e, grpCd){
document.querySelectorAll(".selectIcon").forEach(function (item){
item.classList.value = 'selectIcon d-none'
})
e.target.parentElement.querySelector(".selectIcon").classList.value = "selectIcon"
getCodeItem(grpCd)
}
function addCodeGrp(){
const grpCd = document.querySelector("#grpCd");
const grpCdNm = document.querySelector("#grpCdNm");
if(!grpCd.value){
alert("코드 그룹을 입력해주세요.")
}else{
EgovNet.requestFetch(
'/admin/config/base-code-mgt/code-grp',
{
method: "POST",
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify({
grpCd: grpCd.value,
grpCdNm: grpCdNm.value
})
},
(resp) => {
switch (resp.resultCode) {
case Number(CODE.RCV_SUCCESS):
grpCd.value = "";
grpCdNm.value = "";
getCodeGrp();
2024-01-04 07:43:56 +00:00
getCodeItem();
break;
case Number(CODE.RCV_ERROR_SAVE)||Number(CODE.RCV_ERROR_AUTH):
alert(resp.resultMessage);
break;
}
},
function (resp) {
console.log("err response : ", resp);
}
);
}
}
function modifyCodeGrp(e, action){
const row = e.target.parentElement.parentElement;
const codeGrp = {
grpCd: row.querySelector(".grpCd").value,
grpCdNm: row.querySelector(".grpCdNm").value,
useYn: action==="modify"?'Y':'N'
}
2024-01-03 08:59:14 +00:00
EgovNet.requestFetch(
'/admin/config/base-code-mgt/code-grp',
2024-01-03 08:59:14 +00:00
{
method: "PUT",
2024-01-03 08:59:14 +00:00
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify(codeGrp)
2024-01-03 08:59:14 +00:00
},
(resp) => {
switch (resp.resultCode) {
case Number(CODE.RCV_SUCCESS):
getCodeGrp();
2024-01-04 07:43:56 +00:00
getCodeItem();
break;
case Number(CODE.RCV_ERROR_SAVE)||Number(CODE.RCV_ERROR_AUTH):
alert(resp.resultMessage);
break;
}
2024-01-03 08:59:14 +00:00
},
function (resp) {
console.log("err response : ", resp);
}
);
}
2023-12-29 02:56:04 +00:00
return (
2024-06-07 04:55:34 +00:00
<div className={"pe-3"} >
2023-12-29 02:56:04 +00:00
<Row className={"py-2 bg-light border-bottom"}>
2024-01-03 08:59:14 +00:00
<Col xs={3}>코드그룹</Col>
<Col xs={5}>코드그룹명</Col>
2023-12-29 02:56:04 +00:00
<Col xs={2}>삭제</Col>
<Col xs={2}>수정</Col>
</Row>
2024-01-02 09:02:31 +00:00
{codeGrpRow}
2023-12-29 02:56:04 +00:00
<Row className={"py-1"}>
2024-01-03 08:59:14 +00:00
<Col xs={3}>
<Form.Control type={"text"} id={"grpCd"} placeholder={"코드그룹"} size={"sm"}/>
2023-12-29 02:56:04 +00:00
</Col>
2024-01-03 08:59:14 +00:00
<Col xs={5}>
<Form.Control type={"text"} id={"grpCdNm"} placeholder={"코드그룹명"} size={"sm"}/>
2023-12-29 02:56:04 +00:00
</Col>
2024-01-03 08:59:14 +00:00
<Col xs={{span:2, offset:2}}><Button type={"button"} variant={"primary"} size={"sm"} onClick={addCodeGrp}>등록</Button></Col>
2023-12-29 02:56:04 +00:00
</Row>
2024-06-07 04:55:34 +00:00
</div>
2023-12-29 02:56:04 +00:00
);
}
export default ParentCodeDiv;