//Grid용 클래스. 블록 처리용 class Tb_class { constructor(){ let _this = this; _this.tblList = ""; _this.ajax_url = "./inadd.ajax.php"; } //리스트 로드 getMainList (sdata) { let _this = this; let talert = window.setTimeout(function () { _this.tblList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력 ajax_json({ url: _this.ajax_url, data: { mode: 'getInAddList', BP_CD: sdata?.BP_CD||'', IN_PLN_DT_ST: sdata?.IN_PLN_DT_ST||'', IN_PLN_DT_ED: sdata?.IN_PLN_DT_ED||'', MNG_NO: sdata?.MNG_NO||'', OFLD: sdata?.OFLD||'', OASC: sdata?.OASC||'', LINE_NUM: sdata?.LINE_NUM||'', NOW_PAGE: sdata?.NOW_PAGE||'', }, success: function (data) { if (data.code) { _this.tblList.setData(data.data); //page putPagiNation({ ...sdata, TARGET: ".tabulator-footer-contents", PREB_PAGE: data?.data[0]?.PREB_PAGE, NEXB_PAGE: data?.data[0]?.NEXB_PAGE, LAST_PAGE: data?.data[0]?.LAST_PAGE, PAGE_LISTS: data?.data[0]?.PAGE_LISTS?.split('|'), callback: (conf)=>{ _this.getMainList({ BP_CD: conf?.BP_CD||'', IN_PLN_DT_ST: conf?.IN_PLN_DT_ST||'', IN_PLN_DT_ED: conf?.IN_PLN_DT_ED||'', MNG_NO: conf?.MNG_NO||'', OFLD: conf?.OFLD||'', OASC: conf?.OASC||'', LINE_NUM: conf?.LINE_NUM||'', NOW_PAGE: conf?.NOW_PAGE||'', }); } }); }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; _this.setFilter(); }; setFilter () { let _this = this; let stdate = document.getElementById("S_IN_PLN_DT_ST").value; let endate = document.getElementById("S_IN_PLN_DT_ED").value; _this.tblList.setFilter(function(data){ //필터링 return ( true && ( !document.getElementById("S_BP_NM") || ( (data.DLVY_BP_CD+"|"+data.DLVY_BP_NM).search(document.getElementById("S_BP_NM").value) !== -1 ) ) && ( (!stdate || stdate <= data['PLN_IN_DT']) && (!endate || endate >= data['PLN_IN_DT']) ) && ( !document.getElementById("S_MNG_NO") || ( (data.MNG_SN_ID).search(document.getElementById("S_MNG_NO").value) !== -1 ) ) ) }, '=', true); }; //Cell 변경 콜백 cellEdited (cell){ let _this = this; cell.getData()._STATUS_ = cell.getData()._STATUS_||'U'; }; popBP () { let _this = this; popPartnerList({tgt_id:'#S_BP_CD',tgt_name:'#S_BP_NM'}); }; //sort columnSort(e,tgt) { let _this = this; let sorters = tgt.getTable().getSorters()[0]; _this.getMainList({..._this.searchData,OFLD:sorters?.field,OASC:sorters?.dir}); }; //등록 putInAdd (){ let _this = this; let postdata = { 'mode': 'putInAdd', 'reqdata': JSON.stringify(_this.tblList.getSelectedData()), }; 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; }; shGFormatter ( cell ) { let _this = this; return varsSHAPE_GRP[cell.getValue()]?.Code_Exp; }; //시작 실행 init () { let _this = this; const fields = [ { formatter:"rowSelection", titleFormatter: "rowSelection", width: "4%", }, // { field: "LIST_NUM", title: "No", width: "4%", }, { field: "IN_DT", title: "입고일", width: "8%", editor:'date', editorParams: {max:'9999-12-31'}, }, { field: "IN_TYPE", title: "입고유형", width: "7%", editor:'list', cssClass:"user-list", editorParams:{ values: varsIN_TYPE }, formatter: tb_common_funtions.formatterSelect, formatterParams:{ values: varsIN_TYPE }, }, { field: "WH_CD", title: "창고", width: "8%", formatter:(tgt)=>{ let s = varLOCGRP.filter(r=>r['WH_CD']===tgt.getValue())[0]; return s?.WH_NM },}, { field: "LOC_CD", title: "로케이션", width: "8%", editor: tb_common_funtions.editorGrpSelect, editorParams:{values:varLOCGRP.map( v => { return { name: v.WH_NM, code: v.WH_CD, options: v.OPTIONS.reduce( (retv,vo) => { retv[vo.LOC_CD+'|'+vo.WH_CD]=vo.LOCATION_NM; return retv; }, {} ) }; } ), cfunc:(cell,value)=>{let spval = value.split('|'); cell.getRow().update({WH_CD:spval[1]}); return value;} }, formatter: tb_common_funtions.formatterSelect, formatterParams: {values:varLOCGRP.reduce( (r,v) => { return Object.assign(r, v.OPTIONS.reduce( (rev,vo) => { rev[vo.LOC_CD+'|'+vo.WH_CD]=vo.LOCATION_NM; return rev; }, {} ) ); }, {} ),}, }, { field: "PLN_IN_DT", title: "입고계획일", width: "7%", }, { field: "MNG_SN_ID", title: "S/N", width: "11%", }, { field: "ITEM_CD", title: "품명", width: "8%", formatter:_this.shGFormatter, }, { field: "MATR_TYPE", title: "재질", width: "8%", }, { field: "", title: "규격", width: "25%", columns:[ { field:"OUT_DIA", title:"OD", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, { field:"IN_DIA", title:"ID", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, { field:"THICK", title:"T", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, { field:"WIDTH", title:"W", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, { field:"LENGTH", title:"L", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, ], }, { field: "DLVY_BP_NM", title: "거래처", width: "8%", }, { field: "REMK", title: "비고", width: "14%", editor:'input', }, ]; _this.tblList = new Tabulator("#tblInAddList",{ layout: "fitColumns", height: "100%", data: [], //기본 데이터 columns: fields, //컬럼 설정 columnDefaults: { //컬럼 공통 규칙 sorter:()=>{}, headerSort: false, vertAlign: "middle", hozAlign: "center", resizable: "header",//Resize 는 헤더에서만 가능 headerHozAlign: "center", //헤더 정렬 headerSortTristate: true, //데이터 정렬 => 정/역/초기화 }, footerElement:'', headerSortElement: "", //정렬 아이콘 }); _this.tblList.on("tableBuilt", () => { //Tabulator 초기 데이터 불러오기 이벤트 _this.getMainList(); }); _this.tblList.on("cellEdited", (cell) => { //Tabulator cell Edited _this.cellEdited && _this.cellEdited(cell); }); _this.tblList.on("headerClick", (e,tgt) => { //Tabulator cell Edited _this.columnSort && _this.columnSort(e,tgt); }); _this.tblList.on("rowSelected", function(row){ jQuery(row.getElement()).removeClass('text-secondary'); row.update({_STATUS_:'I'}); }); ['click','keypress'].forEach(evt => document.querySelector("#bntListSearch").addEventListener(evt,()=>{ _this.searchData = { BP_CD: document.querySelector('#S_BP_CD').value||'', IN_PLN_DT_ST: document.querySelector('#S_IN_PLN_DT_ST').value||'', IN_PLN_DT_ED: document.querySelector('#S_IN_PLN_DT_ED').value||'', MNG_NO: document.querySelector('#S_MNG_NO').value||'', LINE_NUM: document.querySelector('#S_LINE_NUM').value||'', NOW_PAGE: 1, }; // _this.searchData 는 전체적으로 이용되므로 간략화 금지 _this.getMainList(_this.searchData); })); ['click','keypress'].forEach(evt => document.querySelector("#S_BP_NM").addEventListener(evt,()=>{_this.popBP()})); ['click','keypress'].forEach(evt => document.querySelector("#btnPutInAdd").addEventListener(evt,()=>{_this.putInAdd()})); ['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_BP_CD, #S_BP_NM, #S_IN_PLN_DT_ST, #S_IN_PLN_DT_ED, #S_MNG_NO").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_funcs.setFilter()}))); }; } const Tb_funcs = new Tb_class(); Tb_funcs.init();