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

201 lines
7.8 KiB
JavaScript

//Grid용 클래스. 블록 처리용
class Tb_class {
constructor(){
let _this = this;
_this.tblList = "";
_this.ajax_url = "./bizarea.ajax.php";
}
//리스트 로드
getMainList () {
let _this = this;
let talert = window.setTimeout(function () { _this.tblList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력
ajax_json({
url: _this.ajax_url,
data: { mode: 'getBizareaList' },
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_NM") || ( (data.BIZ_AREA_CD+"|"+data.BIZ_AREA_NM).search(document.getElementById("S_BIZ_AREA_NM").value) !== -1 ) )
&& ( !document.getElementById("S_BP_NM") || ( (data.BP_CD+"|"+data.BP_NM).search(document.getElementById("S_BP_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', USE_FLG:'Y'});
}
//Row 클릭 콜백
rowClick (e, tgt){
let _this = this;
};
//Cell 클릭 콜백
cellClick (e, tgt){
let _this = this;
_this.tgt = tgt;
switch( tgt.getField() ){
case "HQ_FLG":
case "USE_FLG":
tgt.setValue( tgt.getValue() == "Y"?"N":"Y" );
break;
case "BIZ_AREA_BP_CD":
popPartnerList({tgt_id:'BIZ_AREA_BP_CD',tgt_name:'BIZ_AREA_BP_NM',tgt_addr:'BIZ_AREA_ADDR',tgt_currency:'STD_CURRENCY_CD'}, tgt.getRow()._row);
break;
}
};
//Cell 변경 콜백
cellEdited (cell){
let _this = this;
cell.getData()._STATUS_ = cell.getData()._STATUS_||'U';
};
//등록
putBizarea (){
let _this = this;
let pdata = _this.tblList.getData();
let dupdata = pdata.map( data => data.BIZ_AREA_CD ).filter( data => data );
if( dupdata.filter( (data,idx) => dupdata.indexOf(data) !== idx ).length > 0 ){
kuls_alert("사업장 코드를 입력하지 않았거나 중복됩니다.");
return false;
}
let postdata = {
'mode': 'putBizarea',
'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{
Tb_funcs.tblList.getRows().forEach( row => { //일부 적용된 열 update 처리
if( data.data.includes(row.getData()['BIZ_AREA_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: "BIZ_AREA_CD", title: "사업장코드", width: "10%", minWidth:100, editor:'input', editable:(cell)=>{ let val = cell.getData(); return val._STATUS_ === 'I' }, },
{ field: "BIZ_AREA_NM", title: "사업장명", width: "12%", minWidth:120, editor:'input', },
{ field: "HQ_FLG", title: "본사구분", width: "8%", minWidth:80, cssClass:'user-editable', formatter: tb_common_funtions.formatterToggleboxIcon, formatterParams: {checkval:'Y'} },
{ field: "BIZ_AREA_BP_CD", title: "거래처코드", width: "10%", minWidth:100, cssClass:'user-editable', editor:'input', },
{ field: "BIZ_AREA_BP_NM", title: "거래처명", width: "12%", minWidth:120, },
{ field: "BIZ_AREA_ADDR", title: "거래처주소", width: "18%", minWidth:180, },
{ field: "WORK_STD_TIME", title: "기준시간", width: "10%", minWidth:100, cssClass:'user-list', editor:'list', editorParams:{ values: timerow, }, },
{ field: "STD_CURRENCY_CD", title: "기준화폐", width: "8%", minWidth:80, cssClass:'user-list', editor:'list', editorParams:{ values: currow }, },
{ field: "USE_FLG", title: "사용", width: "8%", minWidth:80, cssClass:'user-editable', formatter: tb_common_funtions.formatterToggleboxGreenIcon, formatterParams: {checkval:'Y'}},
];
_this.tblList = new Tabulator("#tblBizareaList",{
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("#btnAddBizarea").addEventListener(evt,()=>{_this.addRow()}));
['click','keypress'].forEach(evt => document.querySelector("#btnPutBizarea").addEventListener(evt,()=>{_this.putBizarea()}));
['click','keypress'].forEach(evt => document.querySelector("#btnExcelDown").addEventListener(evt,()=>{_this.excelDataLoad(_this.tblList,'사업장리스트')}));
['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_BP_NM, #S_BIZ_AREA_NM, #S_USE_FLG").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_funcs.setFilter()})));
};
excelDataLoad(table_block, title) { //페이징 처리된 리스트에서 엑셀 전체 다운
let _this = this;
let filename = title + "_"+luxon.DateTime.now().toFormat('yyyyMMdd')+".xlsx";
tb_common_funtions.tabu2xls(table_block, filename, title, _this.tblList.getData('active') );
}
}
const Tb_funcs = new Tb_class();
Tb_funcs.init();