HANYANG_REACT/www/ksvc/base/partner/partner.js

726 lines
23 KiB
JavaScript

/*
* @Overview 거래처 페이지
* @History 2024-03-20 / 이원기 / 최초작성
* @ETC 거래처 리스트의 경우 입력 정보가 많아 별도의 팝업을 통해 정보를 입력
*/
class Tb_Partner_class {
constructor(container) {
let _this = this;
_this.ajaxUrl = "./partner.ajax.php";
_this.tbList = "";
_this.removeData="";
_this.container = document.querySelector(container);
_this.table = this.container.querySelector(".hy-table");
// _this.upBtn = this.container.querySelector(".up-btn") || "";
// _this.downBtn = this.container.querySelector(".down-btn") || "";
_this.updateBtn = this.container.querySelector(".update-btn")
_this.addBtn = this.container.querySelector(".add-btn");
_this.removeBtn = this.container.querySelector(".remove-btn");
_this.putPartnerModal = "";
//조회 관련 변수 선언
_this.BP_CD_P = "";
_this.BP_NM_P = "";
_this.salesType = "";
_this.pur_FLG = "";
_this.sal_FLG = "";
_this.use_FLG = "";
_this.putPartner = "putBPInfo";
_this.setPartner = "setBPInfo";
}
/*
* @Overview 거래처 정보 조회 함수.
* @Parameter 파라미터 없음. 조회 관련 변수 참조
*/
getMainList = () => {
let _this = this;
_this.BP_CD_P = document.getElementById("BP_CD_P").value;
_this.BP_NM_P = document.getElementById("BP_NM_P").value;
// _this.salesType = document.getElementById("sales_type").value;
// console.log(_this.salesType)
_this.pur_FLG = document.getElementById("pur_flag").checked ? "Y" : "";
_this.sal_FLG = document.getElementById("sal_flag").checked ? "Y" : "";
_this.use_FLG = document.getElementById("use_flag").value;
let talert = window.setTimeout(()=> { this.tbList.alert("Loading ...") }, 1000);
ajax_json({
url: this.ajaxUrl,
data: {
mode : "getBPList" ,
USE_FLG :_this.use_FLG,
BP_CD :_this.BP_CD_P,
BP_NM :_this.BP_NM_P,
salesType :_this.salesType,
PUR_FLG :_this.pur_FLG,
SAL_FLG :_this.sal_FLG
},
success: (data) => {
if(data.code) {
this.tbList.setData(data.data);
}else{
kuls_alert(data.mesg);
}
},
error: (req, status, err) => {
kuls_alert(err.message);
},
complete: () => {
window.clearTimeout(talert);
this.tbList.clearAlert();
// this.setFilter();
},
});
return true;
}
/*
* @Overview 데이터 필터 함수
* @Parameter 없음
* @function 공장, 작업장, 사용 여부 필터링
*/
// setFilter() {
// this.tbList.setFilter((data)=>{
// return (
// true
// && ( !document.getElementById("partner_name") || ( (data.BP_CD+"|"+data.BP_NM).search(document.getElementById("partner_name").value) !== -1 ) )
// // && ( !document.getElementById("sales_type") || ( (data.SALES_GRP).search(document.getElementById("sales_type").value) !== -1 ) )
// && ( !document.getElementById("pur_flag") || ( !document.getElementById("pur_flag").checked || data.PUR_FLG === 'Y' ) )
// && ( !document.getElementById("sal_flag") || ( !document.getElementById("sal_flag").checked || data.SAL_FLG === 'Y' ) )
// && ( !document.getElementById("use_flag") || ( !document.getElementById("use_flag").checked || data.USE_FLG === 'Y' ) )
// )
// }, '=', true);
// }
/*
* @Overview 거래처 등록 팝업을 여는 함수.
* @Parameter
* @Function 기존 ROW 추가 함수명과 통일.
*/
addRow = () => {
let _this = this;
_this.modalPartner();
}
/*
* @Overview 팝업 오픈
* @Parameter 거래처 코드
* @function 공장, 작업장, 사용 여부 필터링
*/
modalPartner = ( rowData )=>{
let _this = this;
vnLoad( '', './partner_pop.inc.php', '', function(loadHtml){
_this.putPartnerModal = kuls_modal(loadHtml,{ dontclose: true });
// document.querySelector(".btn_close").addEventListener("click", ()=>_this.putpartnerModal.delete());
Partner_Pop.init( rowData );
console.log(rowData);
});
};
/*
* @Overview 저장 버튼 활성화 버튼
* @Parameter 없음
* @function 선택된 모든 행 STATUS D
*/
saveButtonActive(boolean){
if(boolean){
document.getElementById("put_btn").classList.add('disabled-btn');
document.getElementById("put_btn").disabled = true;
}else{
document.getElementById("put_btn").classList.remove('disabled-btn');
document.getElementById("put_btn").disabled = false;
}
}
removeRow() {
const selectedRows = this.tbList.getRows().filter(row=>{
return row.getData().check ==="Y"
});
if(selectedRows.length > 0 ){
// 선택된 각 행 삭제
selectedRows.forEach((row) => {
// STAUS D로 바꾸기
row.getData()._STATUS_ = row.getData()._STATUS_=="I"?null:"D";
const rowElement = row.getElement();
rowElement.classList.add("remove-row");
this.saveButtonActive(false);
},)
}else{
kuls_alert("삭제할 행을 선택해주세요.")
}
const postdata = this.tbList.getData().reduce( (nrow, mem, i) => { // 상태 변화 있는 ROW에 대하여 변수 대입
mem._STATUS_ && nrow.push({...mem});
return nrow;
}, [] );
this.removeData = postdata;
}
/*
* @Overview 테이블 행 선택 함수
* @Parameter 이벤트, 타겟 행
*/
rowClick = (e, tgt) => {
if (tgt.isSelected()) {
tgt.deselect();
this.updateBtn.classList.add("disabled-btn");
this.updateBtn.disabled = true;
this.clearRemove(tgt)
} else {
this.tbList.deselectRow();
tgt.select();
this.updateBtn.disabled = false;
this.updateBtn.classList.remove("disabled-btn")
}
}
/*
* @Overview 테이블 행 더블 클릭시에 팝업
* @Parameter 이벤트, 타겟 행
*/
rowDblClick = (e, tgt)=> {
let _this = this;
let row = tgt._row;
_this.modalPartner(row.data);
}
/*
* @Overview 삭제 취소 함수
* @Parameter 삭제 행
* @function 클릭시 삭제 취소 & STATUS를 공란으로 변경
*/
clearRemove(tgt){
let _this = this;
if(tgt._row.data._STATUS_ == "D"){
tgt._row.data._STATUS_ = "";
tgt._row.getElement().classList.remove("remove-row")
_this.saveButtonActive(true);
}
}
/*
* @Overview cell 클릭 함수
* @Parameter 클릭한 cell
* @Function 클릭한 cell의 filed 값에 따라 토글 상태 변경 또는 팝업
*/
cellClick = (e, tgt) => {
var editor = tgt.getColumn().getDefinition().editor;
switch (tgt.getField()) {
case "check":
tgt.setValue(tgt.getValue() == "Y" ? "" : "Y");
this.clearRemove(tgt.getRow())
break;
default:
if (!editor) {
this.rowClick && this.rowClick(e, tgt.getRow());
}
break;
}
}
/*
* @Overview 테이블 행 삭제 함수
* @Parameter 없음
*/
deleteRow = () => {
if(this.tbList.getData().filter(row=> row._STATUS_).length == 0){
this.getMainList();
return false;
}
let _this = this;
let BP_CD = this.tbList.getData().filter( row=> row._STATUS_ );
let postData = {mode:"delBPInfo", data: JSON.stringify(BP_CD) }
ajax_json({
url: _this.ajaxUrl,
data: postData,
success: function (data) {
if( data.code ){
kuls_success("적용 되었습니다.");
Tb_Partner.getMainList();
}else {
kuls_alert(data.msg);
}
},
error: function (request, status, error) {
kuls_alert(error.message);
},
complete: function(){
this.saveButtonActive(true);
this.updateBtn.disabled = false;
this.updateBtn.classList.remove("disabled-btn")
}
});
}
/*
* @Overview 테이블 셀 수정 함수
* @Parameter 셀
* @function 셀 편집이 이후 저장될수 있도록 _STATUS_:U로 데이터 업데이트
*/
cellEdited = (cell) => {
cell.getData()._STATUS_ = cell.getData()._STATUS_ || "U";
}
/*
* @Overview 추가, 수정 및 삭제 데이터 저장
* @Parameter 없음
*/
/*
* @Overview 최초 실행 함수
* @Parameter 없음
*/
init = () => {
// field 정의
const fields = [
{ field:"check", title: "선택", width: 40,
formatter: tb_common_funtions.formatterCheckboxIcon,
formatterParams: { checkval: "Y" },
},
{ formatter: "rownum", title: "No", width: 40, },
{ field: "BP_CD", title: "거래처", width: 60, },
{ field: "BP_FULL_NM", title: "거래처명", width: 100, hozAlign:"left" },
{ field: "BP_NM", title: "약명", width: 80, hozAlign:"left" },
{ field: "BP_TYPE", title: "자사", width: 50, formatter: tb_common_funtions.formatterSelCircleIcon, },
{ field: "BIZ_REG_NO", title: "사업자등록번호", width: 180, visible: false },
{ field: "REPRESN_NM", title: "대표자명", width: 150, visible: false },
{ field: "PUR_FLG", title: "매입처", width: 50, formatter: tb_common_funtions.formatterSelCircleIcon, },
{ field: "SAL_FLG", title: "매출처", width: 50, formatter: tb_common_funtions.formatterSelCircleIcon, },
{ field: "ZIP_CD", title: "우편번호", width: 100, visible: false },
{ field: "ADDR1", title: "주소", width: 300, hozAlign:"left" },
{ field: "BIZ_TYPE", title: "업종", width: 300, hozAlign:"left", visible: false},
{ field: "BIZ_ITEM", title: "업태", width: 50, hozAlign:"left", visible: false},
{ field: "TEL_NO", title: "전화번호", width: 90, },
{ field: "FAX_NO", title: "팩스번호", width: 90, },
{ field: "NAT_CD", title: "국가", width: 100, formatter: tb_common_funtions.formatterNations, visible: false},
{ field: "CURRENCY_CD", title: "거래화폐", width: 100, visible: false /*formatter: tb_common_funtions.formatterCurrency,*/ },
{ field: "BP_PRSN_NM", title: "업체담당자", width: 80, },
{ field: "BP_PRSN_EMAIL", title: "담당자이메일", width: 200, hozAlign:"left" },
{ field: "BP_PRSN_CELL_NO", title: "담당자연락처", width: 100, },
{ field: "REMK", title: "비고", width: 200, hozAlign:"left" },
];
const commonFieldData = {
headerSort: true,
vertAlign: "middle",
hozAlign: "center",
resizable: "header", //Resize 는 헤더에서만 가능
headerHozAlign: "center", //헤더 정렬
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
};
/*
* @Overview tabulator 객체 생성
* @Parameter 생성 위치(html class값)
*/
this.tbList = new Tabulator(this.table, {
layout: "fitColumns",
data: [], //기본 데이터
columns: fields, //컬럼 설정
columnDefaults: commonFieldData,
headerSortElement: "<i class='bi'></i>", //정렬 아이콘
});
/*
* @Overview 테이블 만들어지면 데이터 불러오기
* @Parameter 없음
*/
this.tbList.on("tableBuilt", () => {
this.getMainList();
});
/*
* @Overview cell 클릭시 체크 또는 팝업
* @Parameter 이벤트, 셀
*/
this.tbList.on("cellClick", (e,tgt) => {
this.cellClick && this.cellClick(e,tgt);
});
/*
* @Overview row 더블 클릭시 팝업
* @Parameter 이벤트, 행
*/
this.tbList.on("rowDblClick", (e, tgt)=>{
this.rowDblClick && this.rowDblClick(e,tgt);
});
/*
* @Overview cell 수정 함수
* @Parameter cell
* @Function status u로 변경
*/
this.tbList.on("cellEdited", (cell) => {
this.cellEdited && this.cellEdited(cell);
});
/*
* @Overview 거래처 등록을 위한 팝업
* @Parameter
* @function 팝업 등록 완료 시 Tabulator table에 ROW추가
*/
["click", "keypress"].forEach((evt) => {
this.addBtn.addEventListener(evt, () => {
this.addRow && this.addRow();
});
});
/*
* @Overview 삭제 버튼
* @Parameter
* @function 삭제버튼 클릭 시 해당 ROW의 CSS 속성 변경 & STATUS 상태 D 추가
*/
["click", "keypress"].forEach((evt) => {
this.updateBtn.addEventListener(evt, () => {
this.modalPartner(this.tbList.getSelectedRows()[0]._row.data)
});
});
/*
* @Overview 삭제 버튼
* @Parameter
* @function 삭제버튼 클릭 시 해당 ROW의 CSS 속성 변경 & STATUS 상태 D 추가
*/
["click", "keypress"].forEach((evt) => {
this.removeBtn.addEventListener(evt, () => {
// 삭제 함수
this.removeRow && this.removeRow();
});
});
/*
* @Overview 조회버튼
* @Parameter
*/
["click", "keypress"].forEach((evt) => {
const filterBtn = document.querySelector("#filter_btn");
filterBtn.addEventListener(evt, () => {
let _this = this;
_this.getMainList && _this.getMainList();
});
});
/*
* @Overview 저장버튼
* @Parameter
* @function 해당 거래처 화면은 팝업으로 저장되므로 저장버튼은 삭제한 ROW에 한하여 기능
*/
["click", "keypress"].forEach((evt) => {
const putBtn = document.querySelector("#put_btn");
putBtn.addEventListener(evt, () => {
let _this = this;
_this.deleteRow();
});
});
}
}
/*
* @Overview 팝업 클래스
* @Parameter 없음
*/
class Partner_Pop_class{
constructor() {
let _this = this;
_this.ajaxUrl = "./partner.ajax.php";
_this.putOrSet = "";
_this.tblList = "";
}
/*
* @Overview 팝업 input 데이터 바인딩
* @Parameter 테이블에서 선택한 데이터 정보
*/
getPartnerInfo = (rowData)=>{
let _this = this;
let BP_CD = rowData?.BP_CD;
let BP_NM = rowData?.BP_NM;
let PUR_FLG = rowData?.PUR_FLG;
let SAL_FLG = rowData?.SAL_FLG;
let USE_FLG = rowData?.USE_FLG;
if(BP_CD) { //거래처 코드 있는 경우 => 수정 시
document.getElementById("BP_CD").readOnly = true;
_this.putOrSet = "set";
}else if(!BP_CD){
document.getElementById("BP_CD").readOnly = false;
_this.putOrSet = "put";
return false;
}
let talert = window.setTimeout(function () { _this.tblList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력
ajax_json({
url: _this.ajaxUrl,
data: { mode: 'getBPInfo', BP_CD : BP_CD ,BP_MN :BP_NM, PUR_FLAG:PUR_FLG ,SAL_FLAG: SAL_FLG, USE_FLG: USE_FLG },
success: function (data) {
if (data.code) {
_this.tblList.setData(data.data.prsn); //팝업창 오픈 시 거래처 담당자
const {prsn, ...getData} = data.data; //거래처 담당자 제외
for(const dataName in getData){
if(dataName === "PUR_FLG"||dataName ==="BP_TYPE"||dataName ==="SAL_FLG" ||dataName ==="USE_FLG" ){
document.getElementById(`${dataName}`).checked = getData[dataName] === 'Y'? true : false;
}else if(dataName =="BIZ_REG_NO"){
const regex = /(\d{3})(\d{2})(\d{5})/;
document.getElementById(`${dataName}`).value = getData[dataName]?.replace(regex, "$1-$2-$3")
}else{
document.getElementById(`${dataName}`).value = getData[dataName]; //input 태그에 가져온 데이터 위치
}
}
}else{
kuls_alert(data.mesg);
}
},
error: function (request, status, error) {
kuls_alert(error.message);
},
complete: function () {
window.clearTimeout(talert);
_this.tblList.clearAlert();
}
});
return true;
}
/*
* @Overview 팝업 데이터 INSERT/UPDATE 함수
* @Parameter 없음/테이블 상 수정 또는 삭제되어 상태 변화된 ROW는 요청 후 PHP 상에서 가공 처리
*/
putPartnerInfo = (e)=>{
e.preventDefault();
let _this = this;
_this.formdata = form2Json(document.frmPartner);
let postdata = _this.tblList.getData().reduce( (nrow, mem, i) => {
mem._STATUS_ && nrow.push({...mem});
return nrow;
}, [] );
_this.formdata['USE_FLG'] = document.getElementById("USE_FLG").checked?"Y":"N";
_this.formdata['BP_TYPE'] = document.getElementById("BP_TYPE").checked?"Y":"N";
_this.formdata['SAL_FLG'] = document.getElementById("SAL_FLG").checked?"Y":"";
_this.formdata['PUR_FLG'] = document.getElementById("PUR_FLG").checked?"Y":"";
_this.formdata['PRSN'] = JSON.stringify(postdata);
_this.formdata['mode'] = "putBPInfo";
_this.formdata['putOrSet'] = _this.putOrSet;// 수정 : set, 등록 : put 백에서 처리
ajax_json({
url: _this.ajaxUrl,
data: _this.formdata,
success: function (data) {
if( data.code ){
kuls_success("적용 되었습니다.");
Tb_Partner.putPartnerModal.delete();
Tb_Partner.getMainList();
}else {
kuls_alert(data.msg);
}
},
error: function (request, status, error) {
kuls_alert(error.message);
},
complete: function(){
}
});
}
/*
* @Overview 삭제 버튼 클릭 후 상태 변화
* @Parameter 없음
*/
removeRow() {
const _this = this;
const selectedRows = this.tblList.getRows().filter(row=>{
return row.getData().check ==="Y"
});
if(selectedRows.length > 0 ){
kuls_confirm("삭제","하시겠습니까?", ()=>{
// 선택된 각 행 삭제
selectedRows.forEach((row) => {
// STAUS D로 바꾸기
row.getData()._STATUS_ = row.getData()._STATUS_=="I"?null:"D";
const rowElement = row.getElement();
rowElement.classList.add("remove-row");
});
})
}else{
kuls_alert("삭제할 행을 선택해주세요.")
}
const postdata = this.tblList.getData().reduce( (nrow, mem, i) => { // 상태 변화 있는 ROW에 대하여 변수 대입
mem._STATUS_ && nrow.push({...mem});
return nrow;
}, [] );
this.removeData = postdata;
}
/*
* @Overview 선택한 ROW의 정보 또는 상태 변화에 활용하는 함수
* @Parameter 클릭한 row 데이터
*/
rowClick = (e, tgt)=> {
let _this = this;
if (tgt.isSelected()) {
tgt.deselect();
_this.clearRemove(tgt);
} else {
tgt.select();
}
}
/*
* @Overview 삭제 취소 함수
* @Parameter 삭제 행
* @function 클릭시 삭제 취소 & STATUS를 공란으로 변경
*/
clearRemove(tgt){
if(tgt._row.data._STATUS_ == "D"){
// console.log();
tgt._row.data._STATUS_ = "";
tgt._row.getElement().classList.remove("remove-row")
// const selectedRows = this.tbList.getSelectedRows(); // 선택된 모든 행 가져오기
}
}
/*
* @Overview 선택한 CELL의 정보 또는 상태 변화에 활용하는 함수
* @Parameter 클릭한 CELL 데이터
*/
cellClick = (e, tgt)=> {
switch (tgt.getField()) {
case "check":
tgt.setValue(tgt.getValue() == "Y" ? "" : "Y");
this.clearRemove(tgt.getRow())
break;
}
}
/*
* @Overview Tabulator 초기화 및 선언
* @Parameter
*/
init = (rowData) => {
let _this = this;
const fields = [
{ field:"check", title: "삭제", width: 50,
formatter: tb_common_funtions.formatterCheckboxIcon,
formatterParams: { checkval: "Y" },
},
{ formatter:"rownum", title: "NO", width: 50, headerSort: false, hozAlign:'center', },
{ field: "BP_PRSN_NM", title: "담당자명", width: 100, editor:"input", editable: (cell) => {
const val = cell.getData();
return val._STATUS_ === "I";
},},
{ field: "BP_PRSN_EMAIL", title: "이메일", width: 200, editor:"input", },
{ field: "BP_PRSN_TEL_NO", title: "연락처", width: 150,editor:"input", },
{ field: "BP_PRSN_CELL_NO", title: "휴대폰", width: 150, editor:"input"},
{ field: "BP_PRSN_FAX_NO", title: "FAX NO", width: 150, editor:"input",},
{ field: "REMK", title: "비고", width: 300,editor:"input", hozAlign:'left', },
];
_this.tblList = new Tabulator("#tbl_partner_member",{
layout: "fitColumns",
data: [], //기본 데이터
height: "100%",
columns: fields, //컬럼 설정
columnDefaults: { //컬럼 공통 규칙
vertAlign: "middle",
resizable: "header",//Resize 는 헤더에서만 가능
headerHozAlign: "center", //헤더 정렬
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
},
headerSortElement: "<i class='bi'></i>", //정렬 아이콘
});
_this.tblList.on("cellEdited", function(cell) { //Tabulator 초기 데이터 불러오기 이벤트
cell.getData()._STATUS_ = cell.getData()._STATUS_||'U';
});
_this.tblList.on("tableBuilt", function(){ //Tabulator 초기 데이터 불러오기 이벤트
_this.getPartnerInfo(rowData);
});
_this.tblList.on("cellClick", (e,tgt) => {
this.cellClick && this.cellClick(e,tgt);
});
/*
* @Overview 행 추가 이벤트
* @Parameter 없음
*/
["click", "keypress"].forEach((evt) => {
let _this = this;
const addBtn = document.querySelector("#awn-popup-wrapper .add-btn") || "";
addBtn.addEventListener(evt, () => {
_this.tblList.addRow({ _STATUS_:'I', USE_FLG:'Y'});
});
});
/*
* @Overview 행 삭제 이벤트
* @Parameter 없음
*/
["click", "keypress"].forEach((evt) => {
const removeBtn = document.querySelector("#awn-popup-wrapper .remove-btn") || "";
removeBtn.addEventListener(evt, () => {
// 삭제 함수
this.removeRow && this.removeRow();
});
});
/*
* @Overview 거래처 정보 저장
* @Parameter 없음
* @function FORM 태그로 SERVER 요청
*/
document.querySelector("form[name=frmPartner]").addEventListener("submit", Partner_Pop.putPartnerInfo);
};
}
const Tb_Partner = new Tb_Partner_class("#main_table");
const Partner_Pop = new Partner_Pop_class();
Tb_Partner.init();
/*
* @Overview 전화번호 및 팩스번호 formatting
* @Parameter HTML 입력값
*/
localAutoHyphen = (target) => {
target.value = target.value
?.replace(/[^0-9]/g, '')
?.replace(/^(\d{2,3})(\d{3,4})(\d{4})$/, `$1-$2-$3`);
}
/*
* @Overview 사업자등록번호 formatting
* @Parameter HTML 입력값
*/
formatBusinessRegistrationNumber = (target) => {
const regex = /(\d{3})(\d{2})(\d{5})/;
target.value = target.value.replace(regex, "$1-$2-$3");
}