1
0
Fork 0
HANYANG_MES/home_dir/www/ksvc_old/inout/otadd/otadd.js

224 lines
7.6 KiB
JavaScript

//Grid용 클래스. 블록 처리용
class Tb_class {
constructor(){
let _this = this;
_this.tblList = "";
_this.ajax_url = "./otadd.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: 'getOtAddList',
BP_CD: sdata?.BP_CD||'',
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||'',
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 () {
return false;
let _this = this;
_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 ) )
&& ( !document.getElementById("S_MNG_NO") || ( (data.MNG_SN_ID).search(document.getElementById("S_MNG_NO").value) !== -1 ) )
)
}, '=', true);
};
//Cell 클릭 콜백
cellClick (e, tgt){
let _this = this;
_this.tgt = tgt;
// switch( tgt.getField() ){
// case "BP_NM":
// popPartnerList({tgt_id:'',tgt_name:'BP_NM',tgt_addr:'',tgt_currency:''}, tgt.getRow()._row);
// break;
// }
};
//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});
};
//등록
putOtAdd (){
let _this = this;
let postdata = {
'mode': 'putOtAdd',
'reqdata': JSON.stringify(_this.tblList.getSelectedData()),
};
// console.log(_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: "OT_DT", title: "출하일", width: "7%", editor:'date', editorParams: {max:'9999-12-31'}, },
{ field: "MNG_SN_ID", title: "S/N", width: "14%", },
{ field: "ITEM_CD", title: "품명", width: "13%", formatter:_this.shGFormatter, },
{ field: "MATR_TYPE", title: "재질", width: "13%", },
{ 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: "7%", },
{ field: "IN_DT", title: "입고일", width: "7%", },
{ field: "REMK", title: "비고", width: "10%", editor:'input', },
];
_this.tblList = new Tabulator("#tblOtAddList",{
layout: "fitColumns",
height: "100%",
data: [], //기본 데이터
columns: fields, //컬럼 설정
columnDefaults: { //컬럼 공통 규칙
sorter:()=>{},
headerSort: false,
vertAlign: "middle",
hozAlign: "center",
resizable: "header",//Resize 는 헤더에서만 가능
headerHozAlign: "center", //헤더 정렬
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
},
footerElement:'<ul class="pagination justify-content-center align-items-center mb-1"><li><a class="pn_link npage btn btn-light"><span class="f_page">1</span></a></li></ul>',
headerSortElement: "<i class='bi'></i>", //정렬 아이콘
});
_this.tblList.on("tableBuilt", () => { //Tabulator 초기 데이터 불러오기 이벤트
_this.getMainList();
});
_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);
});
_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||'',
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("#btnPutOtAdd").addEventListener(evt,()=>{_this.putOtAdd()}));
['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_BP_CD, #S_BP_NM, #S_MNG_NO").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_funcs.setFilter()})));
};
}
const Tb_funcs = new Tb_class();
Tb_funcs.init();