1
0
Fork 0
HANYANG_MES/home_dir/www/ksvc_old/base/dept/dept.js

210 lines
7.6 KiB
JavaScript

//Grid용 클래스. 블록 처리용
class Tb_class {
constructor(){
let _this = this;
_this.tblList = "";
_this.ajax_url = "./dept.ajax.php";
_this.BIZ_AREA_CD = document.querySelector("#S_BIZ_AREA_CD").value;
}
//리스트 로드
getMainList () {
let _this = this;
let talert = window.setTimeout(function () { _this.tblList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력
ajax_json({
url: _this.ajax_url,
data: { mode: 'getDeptList', BIZ_AREA_CD:_this.BIZ_AREA_CD },
success: function (data) {
if (data.code) {
_this.tblList.setData(data.data);
}else{
kuls_alert(data.mesg);
}
},
error: function (request, status, error) {
kuls_alert(error.message);
},
complete: function () {
window.clearTimeout(talert);
_this.tblList.clearAlert();
_this.setFilter();
}
});
return true;
};
//검색 조건 Clear
clearInput (){
let _this = this;
//let today = new Date();
// document.querySelector("#T_CONTR_NO").value = "";
// document.querySelector("#T_BP_CD").value = "";
// document.querySelector("#T_BP_NM").value = "";
// document.querySelector("#stdate").value = luxon.DateTime.now().toFormat("yyyy-MM-dd");
// document.querySelector("#endate").value = luxon.DateTime.now().toFormat("yyyy-MM-dd");
_this.setFilter();
};
setFilter () {
let _this = this;
_this.tblList.setFilter(function(data){ //필터링
return (
true
&& ( !document.getElementById("S_BIZ_AREA_CD") || ( data.BIZ_AREA_CD === document.getElementById("S_BIZ_AREA_CD").value ) )
&& ( !document.getElementById("S_DEPT_NM") || ( (data.DEPT_CD+"|"+data.DEPT_NM).search(document.getElementById("S_DEPT_NM").value) !== -1 ) )
&& ( !document.getElementById("S_USE_FLG") || ( !document.getElementById("S_USE_FLG").checked || data.USE_FLG === 'Y' ) )
)
}, '=', true);
};
//Row 추가
addRow(){
let _this = this;
_this.tblList.addRow({_STATUS_:'I', BIZ_AREA_CD:_this.BIZ_AREA_CD, USE_FLG:'Y'});
}
//Row 클릭 콜백
rowClick (e, tgt){
let _this = this;
};
//Cell 클릭 콜백
cellClick (e, tgt){
let _this = this;
_this.tgt = tgt;
switch( tgt.getField() ){
case "USE_FLG":
tgt.setValue( tgt.getValue() == "Y"?"N":"Y" );
break;
case "PAR_DEPT_CD":
case "PAR_DEPT_NM":
//popDeptListLive('PAR_DEPT_CD','PAR_DEPT_NM', tgt.getRow());
popDeptList('PAR_DEPT_CD','PAR_DEPT_NM', 'INTNL_PAR_DEPT_CD', _this.BIZ_AREA_CD, tgt.getRow());
break;
case "BIZ_AREA_CD":
popBizareaList('BIZ_AREA_CD','BIZ_AREA_NM', tgt.getRow()._row);
break;
case "MANAGER_EMP_NO":
popEmployeeList('MANAGER_EMP_NO','MANAGER_EMP_NM', _this.BIZ_AREA_CD, tgt.getRow()._row);
break;
}
};
//Cell 변경 콜백
cellEdited (cell){
let _this = this;
cell.getData()._STATUS_ = cell.getData()._STATUS_||'U';
};
//등록
putDept (){
let _this = this;
let pdata = _this.tblList.getData();
let dupdata = pdata.map( data => data.DEPT_CD ).filter( data => data );
if( dupdata.filter( (data,idx) => dupdata.indexOf(data) !== idx ).length > 0 ){
kuls_alert("부서 코드를 입력하지 않았거나 중복됩니다.");
return false;
}
let postdata = {
'mode': 'putDept',
'reqdata': JSON.stringify(_this.tblList.getData().filter(row=> row._STATUS_)),
};
ajax_json({
url: _this.ajax_url,
data: postdata,
success: function (data) {
if (data.code) {
kuls_success("적용 되었습니다.");
_this.getMainList();
}else{
console.log(data.data);
Tb_funcs.tblList.getRows().forEach( row => { //일부 적용된 열 update 처리
if( data.data.includes(row.getData()['DEPT_CD']) ){
row.update({_STATUS_:'U'});
}
} );
kuls_alert(data.mesg);
}
},
error: function (request, status, error) {
kuls_alert(error.message);
},
complete: function () {
}
});
return true;
};
//시작 실행
init () {
let _this = this;
let timerow = Array.from(Array(24)).map( (a,i) => i.toString().padStart(2,'0') ).reduce( (timerow, time) => { return timerow.concat(Array.from(Array(60/30)).map( (a,i) => time+':'+(30*i).toString().padStart(2,'0') ) ); }, [] );
let currow = Object.keys(varsCurrency).reduce( (param,key) => {param[key] = `${key} (${varsCurrency[key]})`; return param;}, {});
const fields = [
{ formatter: "rownum", title: "No", width: "4%", minWidth:60, },
{ field: "DEPT_CD", title: "부서코드", width: "10%", minWidth:100, editor:'input', editable:(cell)=>{ let val = cell.getData(); return val._STATUS_ === 'I' }, },
{ field: "DEPT_NM", title: "부서명", width: "16%", minWidth:160, editor:'input', },
{ field: "PAR_DEPT_CD", title: "상위부서코드", width: "10%", minWidth:100, cssClass:'user-editable', },
{ field: "PAR_DEPT_NM", title: "상위부서명", width: "16%", minWidth:160, },
{ field: "BIZ_AREA_CD", title: "사업장코드", width: "10%", minWidth:100, cssClass:'user-editable', },
{ field: "BIZ_AREA_NM", title: "사업장명", width: "16%", minWidth:160, },
{ field: "MANAGER_EMP_NO", title: "관리자", width: "10%", minWidth:100, cssClass:'user-editable', formatter: function(tgt){ return (tgt.getData()['MANAGER_EMP_NM']||''); }},
{ field: "USE_FLG", title: "사용", width: "8%", minWidth:80, cssClass:'user-editable', formatter: tb_common_funtions.formatterToggleboxGreenIcon, formatterParams: {checkval:'Y'}},
];
_this.tblList = new Tabulator("#tblDeptList",{
layout: "fitColumns",
height: "100%",
data: [], //기본 데이터
columns: fields, //컬럼 설정
columnDefaults: { //컬럼 공통 규칙
vertAlign: "middle",
hozAlign: "center",
resizable: "header",//Resize 는 헤더에서만 가능
headerHozAlign: "center", //헤더 정렬
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
},
rowFormatter:function(row){
if(row.getData().USE_FLG != "Y"){
row.getElement().classList.add('text-secondary');
}
},
headerSortElement: "<i class='bi'></i>", //정렬 아이콘
});
_this.tblList.on("tableBuilt", () => { //Tabulator 초기 데이터 불러오기 이벤트
_this.getMainList();
});
_this.tblList.on("rowClick", (e,tgt) => { //Tabulator Row Click
_this.rowClick && Tb_funcs.rowClick(e,tgt);
});
_this.tblList.on("cellClick", (e,tgt) => { //Tabulator cell Click
_this.cellClick && Tb_funcs.cellClick(e,tgt);
});
_this.tblList.on("cellEdited", (cell) => { //Tabulator cell Edited
_this.cellEdited && Tb_funcs.cellEdited(cell);
});
['click','keypress'].forEach(evt => document.querySelector("#btnAddDept").addEventListener(evt,()=>{_this.addRow()}));
['click','keypress'].forEach(evt => document.querySelector("#btnPutDept").addEventListener(evt,()=>{_this.putDept()}));
['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_BIZ_AREA_CD, #S_DEPT_NM, #S_USE_FLG").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_funcs.setFilter()})));
document.querySelector("#S_BIZ_AREA_CD").addEventListener("change",function(){
_this.BIZ_AREA_CD = this.value;
_this.getMainList();
});
};
}
const Tb_funcs = new Tb_class();
Tb_funcs.init();