//Grid용 클래스. 블록 처리용 class Tb_class { constructor(){ let _this = this; _this.tblList = ""; _this.ajax_url = "./employee.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: 'getEmployeeList', BIZ_AREA_CD:_this.BIZ_AREA_CD }, success: function (data) { if (data.code) { _this.tblList.setData(data.data); console.log(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_EMP_NM") || ( (data.EMP_NO+"|"+data.EMP_NM).search(document.getElementById("S_EMP_NM").value) !== -1 ) ) && ( !document.getElementById("S_RET_FLG") || ( !document.getElementById("S_RET_FLG").checked || data.RET_FLG !== 'Y' ) ) ) }, '=', true); }; //Row 추가 addRow(){ let _this = this; _this.tblList.addRow({_STATUS_:'I', BIZ_AREA_CD:_this.BIZ_AREA_CD}); } //Row 클릭 콜백 rowClick (e, tgt){ let _this = this; }; //Cell 클릭 콜백 cellClick (e, tgt){ let _this = this; _this.tgt = tgt; switch( tgt.getField() ){ case "RET_FLG": tgt.setValue( tgt.getValue() == "Y"?"N":"Y" ); break; case "DEPT_NM": popDeptList('DEPT_CD','DEPT_NM', 'INTNL_DEPT_CD', _this.BIZ_AREA_CD, tgt.getRow()); break; } }; //Cell 변경 콜백 cellEdited (cell){ let _this = this; cell.getData()._STATUS_ = cell.getData()._STATUS_||'U'; }; //등록 putEmployee (){ let _this = this; let pdata = _this.tblList.getData(); let dupdata = pdata.map( data => data.EMP_NO ).filter(data => data); if( dupdata.filter( (data,idx) => dupdata.indexOf(data) !== idx ).length > 0 ){ kuls_alert("사번 코드가 중복됩니다."); return false; } let postdata = { 'mode': 'putEmployee', '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{ 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: "EMP_NO", title: "사번", width: "7%", minWidth:60, editor:'input', editable:(cell)=>{ let val = cell.getData(); return val._STATUS_ === 'I' }, }, { field: "EMP_NM", title: "이름", width: "8%", minWidth:80, editor:'input', }, { field: "EMP_SHORT_NM", title: "표시명", width: "8%", minWidth:80, editor:'input', }, { field: "DEPT_NM", title: "부서", width: "8%", minWidth:60, cssClass:'user-editable', /*formatter: tb_common_funtions.formatterInvalidVal, formatterParams:{field:'EXP_DEPT',value:'Y',invalidClass:'bg-danger',sp:'='}*/}, { field: "EMPLM_TYPE", title: "고용형태", width: "8%", minWidth:80, cssClass:'user-list', editor:'list', editorParams:{ values: varsEmptype, }, formatter: tb_common_funtions.formatterSelect, formatterParams:{values:varsEmptype}}, { field: "JOB_POS", title: "직위", width: "8%", minWidth:80, cssClass:'user-list', editor:'list', editorParams:{ values: varsPosition, }, formatter: tb_common_funtions.formatterSelect, formatterParams:{values:varsPosition}}, { field: "JOB_ROLE", title: "직책", width: "8%", minWidth:80, cssClass:'user-list', editor:'list', editorParams:{ values: varsJobrole, }, formatter: tb_common_funtions.formatterSelect, formatterParams:{values:varsJobrole}}, { field: "JOB_FUNC", title: "직무", width: "8%", minWidth:80, cssClass:'user-list', editor:'list', editorParams:{ values: varsJobfunc, }, formatter: tb_common_funtions.formatterSelect, formatterParams:{values:varsJobfunc}}, { field: "MAIL_ID", title: "이메일", width: "12%", minWidth:120, editor:'input', }, { field: "ENT_DT", title: "입사일", width: "7%", minWidth:80, editor:'date', editorParams: {max:'9999-12-31'}, }, { field: "RET_DT", title: "퇴사일", width: "7%", minWidth:80, editor:'date', editorParams: {max:'9999-12-31'}, }, { field: "RET_FLG", title: "퇴사구분", width: "6%", minWidth:80, cssClass:'user-editable', formatter: tb_common_funtions.formatterToggleboxRedIcon, formatterParams: {checkval:'Y'}}, ]; _this.tblList = new Tabulator("#tblEmployeeList",{ 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().RET_FLG == "Y"){ row.getElement().classList.add('text-secondary'); } }, headerSortElement: "", //정렬 아이콘 }); _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("#btnAddEmployee").addEventListener(evt,()=>{_this.addRow()})); ['click','keypress'].forEach(evt => document.querySelector("#btnPutEmployee").addEventListener(evt,()=>{_this.putEmployee()})); ['click','keypress'].forEach(evt => document.querySelector("#btnExcelDown").addEventListener(evt,()=>{_this.excelDataLoad(_this.tblList,'작업자리스트')})); ['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_BIZ_AREA_CD, #S_DEPT_NM, #S_EMP_NM, #S_RET_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(); }); }; 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').map( row => { row.EMPLM_TYPE = varsEmptype[row.EMPLM_TYPE]; row.JOB_POS = varsPosition[row.JOB_POS]; row.JOB_ROLE = varsJobrole[row.JOB_ROLE]; row.JOB_FUNC = varsJobfunc[row.JOB_FUNC]; return row; } )); } } const Tb_funcs = new Tb_class(); Tb_funcs.init();