forked from HANYANG/HANYANG_MES
350 lines
13 KiB
JavaScript
350 lines
13 KiB
JavaScript
|
|
//Grid용 클래스. 블록 처리용
|
|
class Tb_class_Wh {
|
|
constructor(){
|
|
let _this = this;
|
|
_this.tblWhList = "";
|
|
_this.ajax_url = "./warehouse.ajax.php";
|
|
}
|
|
|
|
//리스트 로드
|
|
getMainList () {
|
|
let _this = this;
|
|
|
|
let talert = window.setTimeout(function () { _this.tblWhList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력
|
|
ajax_json({
|
|
url: _this.ajax_url,
|
|
data: { mode: 'getWhList' },
|
|
success: function (data) {
|
|
if (data.code) {
|
|
_this.tblWhList.setData(data.data);
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function () {
|
|
window.clearTimeout(talert);
|
|
_this.tblWhList.clearAlert();
|
|
Tb_funcs_Wh.setFilter();
|
|
}
|
|
});
|
|
return true;
|
|
};
|
|
|
|
//Row 클릭 콜백
|
|
rowClick (e, tgt){
|
|
let _this = this;
|
|
|
|
Tb_funcs_Loc.getMainList(tgt.getData().WH_CD);
|
|
jQuery(tgt.getElement()).siblings().removeClass("user-checked");
|
|
tgt.getElement().classList.add("user-checked");
|
|
$("#btnAddLoc").attr("disabled", false);
|
|
$("#btnPutLoc").attr("disabled", false);
|
|
};
|
|
|
|
setFilter () {
|
|
let _this = this;
|
|
|
|
_this.tblWhList.setFilter(function(data){ //필터링
|
|
return (
|
|
true
|
|
&& ( !document.getElementById("S_USE_FLG") || ( !document.getElementById("S_USE_FLG").checked || data.USE_FLG === 'Y' ) )
|
|
&& ( !document.getElementById("S_WH_NM") || ( (data.WH_CD+"|"+data.WH_NM).search(document.getElementById("S_WH_NM").value) !== -1 ) )
|
|
&& ( !document.getElementById("S_WH_TYPE") || ( (data.WH_TYPE).search(document.getElementById("S_WH_TYPE").value) !== -1 ) )
|
|
)
|
|
}, '=', true);
|
|
};
|
|
|
|
//Row 추가
|
|
addRow(){
|
|
let _this = this;
|
|
_this.tblWhList.addRow({_STATUS_:'I', USE_FLG:'Y', IN_FLG:'Y', OT_FLG:'Y', WH_TYPE:'I'});
|
|
}
|
|
|
|
//Cell 클릭 콜백
|
|
cellClick (e, tgt){
|
|
let _this = this;
|
|
_this.tgt = tgt;
|
|
switch( tgt.getField() ){
|
|
case "USE_FLG":
|
|
case "IN_FLG":
|
|
case "OT_FLG":
|
|
tgt.setValue( tgt.getValue() == "Y"?"N":"Y" );
|
|
break;
|
|
case "BIZ_AREA_NM":
|
|
popBizareaList('BIZ_AREA_CD', 'BIZ_AREA_NM', tgt.getRow()._row);
|
|
break;
|
|
case "WH_BP_NM":
|
|
popPartnerList({tgt_id:'WH_BP_CD',tgt_name:'WH_BP_NM'}, tgt.getRow()._row);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
};
|
|
|
|
//Cell 변경 콜백
|
|
cellEdited (cell){
|
|
let _this = this;
|
|
cell.getData()._STATUS_ = cell.getData()._STATUS_||'U';
|
|
};
|
|
|
|
// 창고 등록
|
|
putWh (){
|
|
let _this = this;
|
|
let pdata = _this.tblWhList.getData();
|
|
let dupdata = pdata.map( data => data.WH_CD ).filter( data => data );
|
|
if( dupdata.filter( (data,idx) => dupdata.indexOf(data) !== idx ).length > 0 ){
|
|
kuls_alert("창고 코드가 중복됩니다.");
|
|
return false;
|
|
}
|
|
let postdata = {
|
|
'mode': 'putWh',
|
|
'reqdata': JSON.stringify(_this.tblWhList.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_Wh.tblWhList.getRows().forEach( row => { //일부 적용된 열 update 처리
|
|
if( data.data.includes(row.getData()['WH_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;
|
|
|
|
const fields = [
|
|
{ formatter: "rownum", title: "No", width: "4%", },
|
|
{ field: "WH_CD", title: "창고코드", width: "10%", editor:'input', editable:(cell)=>{ let val = cell.getData(); return val._STATUS_ === 'I' }},
|
|
{ field: "WH_NM", title: "창고명", width: "15%", editor:'input', },
|
|
{ field: "IN_FLG", title: "입하창고", width: "6%", cssClass:'user-editable', formatter: tb_common_funtions.formatterToggleboxIcon, formatterParams: {checkval:'Y'}},
|
|
{ field: "OT_FLG", title: "출하창고", width: "6%", cssClass:'user-editable', formatter: tb_common_funtions.formatterToggleboxIcon, formatterParams: {checkval:'Y'}},
|
|
{ field: "WH_TYPE", title: "창고유형", width: "10%", cssClass:'user-list', editor:'list', editorParams: {values: varsWH_TYPE,}, formatter: tb_common_funtions.formatterSelect, formatterParams: {values: varsWH_TYPE,}, },
|
|
{ field: "BIZ_AREA_NM", title: "사업장", width: "14%", editor:'input', cssClass:'user-editable', },
|
|
{ field: "WH_BP_NM", title: "거래처", width: "14%", editor:'input', cssClass:'user-editable', },
|
|
{ field: "REMK", title: "비고", width: "15%", editor:'input', },
|
|
{ field: "USE_FLG", title: "사용", width: "6%", cssClass:'user-editable', formatter: tb_common_funtions.formatterToggleboxGreenIcon, formatterParams: {checkval:'Y'}},
|
|
];
|
|
|
|
_this.tblWhList = new Tabulator("#tblWhList",{
|
|
layout: "fitColumns",
|
|
height: "calc(100% - 20px)",
|
|
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.tblWhList.on("tableBuilt", () => { //Tabulator 초기 데이터 불러오기 이벤트
|
|
_this.getMainList();
|
|
});
|
|
_this.tblWhList.on("rowClick", (e,tgt) => { //Tabulator Row Click
|
|
_this.rowClick && Tb_funcs_Wh.rowClick(e,tgt);
|
|
});
|
|
_this.tblWhList.on("cellClick", (e,tgt) => { //Tabulator cell Click
|
|
_this.cellClick && Tb_funcs_Wh.cellClick(e,tgt);
|
|
});
|
|
_this.tblWhList.on("cellEdited", (cell) => { //Tabulator cell Edited
|
|
_this.cellEdited && Tb_funcs_Wh.cellEdited(cell);
|
|
});
|
|
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnAddWh").addEventListener(evt,()=>{_this.addRow()}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnPutWh").addEventListener(evt,()=>{_this.putWh()}));
|
|
['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_WH_NM, #S_WH_TYPE, #S_USE_FLG").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_funcs_Wh.setFilter()})));
|
|
};
|
|
}
|
|
|
|
//Grid용 클래스. 블록 처리용
|
|
class Tb_class_Loc {
|
|
constructor(){
|
|
let _this = this;
|
|
_this.tblLocList = "";
|
|
_this.ajax_url = "./warehouse.ajax.php";
|
|
_this.wc = "";
|
|
}
|
|
|
|
//리스트 로드
|
|
getMainList (wc) {
|
|
let _this = this;
|
|
_this.wc = wc;
|
|
|
|
let talert = window.setTimeout(function () { _this.tblLocList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력
|
|
ajax_json({
|
|
url: _this.ajax_url,
|
|
data: { mode: 'getLocList', WH_CD: wc },
|
|
success: function (data) {
|
|
if (data.code) {
|
|
_this.tblLocList.setData(data.data);
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function () {
|
|
window.clearTimeout(talert);
|
|
_this.tblLocList.clearAlert();
|
|
Tb_funcs_Loc.setFilter();
|
|
}
|
|
});
|
|
return true;
|
|
};
|
|
|
|
setFilter () {
|
|
let _this = this;
|
|
|
|
_this.tblLocList.setFilter(function(data){ //필터링
|
|
return (
|
|
true
|
|
&& ( !document.getElementById("S_USE_FLG") || ( !document.getElementById("S_USE_FLG").checked || data.USE_FLG === 'Y' ) )
|
|
)
|
|
}, '=', true);
|
|
};
|
|
|
|
//Row 추가
|
|
addRow(){
|
|
let _this = this;
|
|
_this.tblLocList.addRow({_STATUS_:'I', USE_FLG:'Y', WH_CD:_this.wc, LOCATION_TYPE:'RA'});
|
|
}
|
|
|
|
//Cell 클릭 콜백
|
|
cellClick (e, tgt){
|
|
let _this = this;
|
|
_this.tgt = tgt;
|
|
switch( tgt.getField() ){
|
|
case "USE_FLG":
|
|
tgt.setValue( tgt.getValue() == "Y"?"N":"Y" );
|
|
break;
|
|
}
|
|
};
|
|
|
|
//Cell 변경 콜백
|
|
cellEdited (cell){
|
|
let _this = this;
|
|
cell.getData()._STATUS_ = cell.getData()._STATUS_||'U';
|
|
};
|
|
|
|
// 로케이션 등록
|
|
putLoc (){
|
|
let _this = this;
|
|
let pdata = _this.tblLocList.getData();
|
|
let dupdata = pdata.map( data => data.LOC_CD ).filter( data => data );
|
|
if( dupdata.filter( (data,idx) => dupdata.indexOf(data) !== idx ).length > 0 ){
|
|
kuls_alert("로케이션 코드가 중복됩니다.");
|
|
return false;
|
|
}
|
|
let postdata = {
|
|
'mode': 'putLoc',
|
|
'reqdata': JSON.stringify(_this.tblLocList.getData().filter(row=> row._STATUS_)),
|
|
};
|
|
console.log(postdata);
|
|
ajax_json({
|
|
url: _this.ajax_url,
|
|
data: postdata,
|
|
success: function (data) {
|
|
if (data.code) {
|
|
kuls_success("저장되었습니다.");
|
|
_this.getMainList(_this.wc);
|
|
}else{
|
|
Tb_funcs_Loc.tblLocList.getRows().forEach( row => { //일부 적용된 열 update 처리
|
|
if( data.data.includes(row.getData()['LOC_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;
|
|
|
|
const fields = [
|
|
{ formatter: "rownum", title: "No", width: "4%", },
|
|
{ field: "LOC_CD", title: "로케이션코드", width: "18%", editor:'input', editable:(cell)=>{ let val = cell.getData(); return val._STATUS_ === 'I' }, },
|
|
{ field: "LOCATION_NM", title: "로케이션명", width: "18%", editor:'input', },
|
|
{ field: "LOCATION_TYPE", title: "로케이션유형", width: "18%", cssClass:'user-list', editor:'list', editorParams: {values: varsLOCATION_TYPE,},
|
|
formatter: tb_common_funtions.formatterSelect, formatterParams: {values: varsLOCATION_TYPE,}, },
|
|
{ field: "LOAD_TYPE", title: "적재방법", width: "18%", cssClass:'user-list', editor:'list', editorParams: {values: varsLOAD_TYPE,},
|
|
formatter: tb_common_funtions.formatterSelect, formatterParams: {values: varsLOAD_TYPE,}, },
|
|
{ field: "REMK", title: "비고", width: "18%", editor:'input', },
|
|
{ field: "USE_FLG", title: "사용", width: "6%", cssClass:'user-editable', formatter: tb_common_funtions.formatterToggleboxGreenIcon, formatterParams: {checkval:'Y'}},
|
|
];
|
|
|
|
_this.tblLocList = new Tabulator("#tblLocList",{
|
|
layout: "fitColumns",
|
|
height: "calc(100% - 20px)",
|
|
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.tblLocList.on("cellClick", (e,tgt) => { //Tabulator cell Click
|
|
_this.cellClick && Tb_funcs_Loc.cellClick(e,tgt);
|
|
});
|
|
_this.tblLocList.on("cellEdited", (cell) => { //Tabulator cell Edited
|
|
_this.cellEdited && Tb_funcs_Loc.cellEdited(cell);
|
|
});
|
|
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnAddLoc").addEventListener(evt,()=>{_this.addRow()}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnPutLoc").addEventListener(evt,()=>{_this.putLoc()}));
|
|
['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_USE_FLG").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_funcs_Loc.setFilter()})));
|
|
};
|
|
}
|
|
|
|
const Tb_funcs_Wh = new Tb_class_Wh();
|
|
const Tb_funcs_Loc = new Tb_class_Loc();
|
|
Tb_funcs_Wh.init();
|
|
Tb_funcs_Loc.init();
|
|
|