forked from HANYANG/HANYANG_MES
318 lines
13 KiB
JavaScript
318 lines
13 KiB
JavaScript
|
|
//Grid와 함께 사용될 사용자정의 함수
|
|
class Tb_class {
|
|
constructor(){
|
|
let _this = this;
|
|
_this.partner_ajax_url = "./partner.ajax.php";
|
|
_this.tblList = "";
|
|
_this.putPartnerModal = "";
|
|
_this.saveExcel = tb_common_funtions.tabu2xls; //엑셀 다운로드
|
|
}
|
|
|
|
//파트너 리스트 로드
|
|
getPartnerList () {
|
|
let _this = this;
|
|
|
|
let talert = window.setTimeout(function () { _this.tblList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력
|
|
ajax_json({
|
|
url: _this.partner_ajax_url,
|
|
data: { mode: 'getPartnerList' },
|
|
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 false;
|
|
};
|
|
|
|
//검색 조건 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_BP_NM") || ( (data.BP_CD+"|"+data.BP_NM).search(document.getElementById("S_BP_NM").value) !== -1 ) )
|
|
&& ( !document.getElementById("S_SALES_GRP") || ( (data.SALES_GRP).search(document.getElementById("S_SALES_GRP").value) !== -1 ) )
|
|
&& ( !document.getElementById("S_PUR_FLG") || ( !document.getElementById("S_PUR_FLG").checked || data.PUR_FLG === 'Y' ) )
|
|
&& ( !document.getElementById("S_SAL_FLG") || ( !document.getElementById("S_SAL_FLG").checked || data.SAL_FLG === 'Y' ) )
|
|
&& ( !document.getElementById("S_USE_FLG") || ( !document.getElementById("S_USE_FLG").checked || data.USE_FLG === 'Y' ) )
|
|
)
|
|
}, '=', true);
|
|
};
|
|
|
|
//거래처 등록 팝업
|
|
modalPartner ( BP_CD ){
|
|
let _this = this;
|
|
|
|
vnLoad( '', './partner.pop.inc.php', '', function(loadHtml){
|
|
_this.putPartnerModal = kuls_modal(loadHtml);
|
|
document.querySelector(".btn_close").addEventListener("click", ()=>_this.putPartnerModal.delete());
|
|
|
|
Tb_funcs_pinfo.init( BP_CD );
|
|
});
|
|
};
|
|
|
|
//Row 클릭 콜백
|
|
rowClick (e, tgt){
|
|
let _this = this;
|
|
let row = tgt._row;
|
|
|
|
_this.modalPartner(row.data.BP_CD);
|
|
};
|
|
|
|
//시작 실행
|
|
init () {
|
|
let _this = this;
|
|
|
|
const fields = [
|
|
{ formatter: "rownum", title: "No", width: "2%", minWidth:45 },
|
|
{ field: "SALES_GRP", title: "영업분류", width: "6%", minWidth:60, formatter: (cell)=> varsSALES_GRP[cell.getValue()] },
|
|
{ field: "BP_CD", title: "거래처", width: "6%", minWidth:60, },
|
|
{ field: "BP_NM", title: "거래처명", width: "7%", minWidth:80, },
|
|
{ field: "BP_TYPE", title: "자사", width: "4%", minWidth:40, formatter: tb_common_funtions.formatterSelCircleIcon, },
|
|
{ field: "BIZ_TYPE", title: "업종", width: "11%", minWidth:100, },
|
|
{ field: "BIZ_ITEM", title: "업태", width: "5%", minWidth:50, },
|
|
{ field: "BIZ_REG_NO", title: "사업자등록번호", width: "8%", minWidth:80, },
|
|
{ field: "REPRESN_NM", title: "대표자명", width: "6%", minWidth:60, },
|
|
{ field: "ZIP_CD", title: "우편번호", width: "6%", minWidth:50, },
|
|
{ field: "ADDR1", title: "주소", width: "15%", minWidth:150, },
|
|
{ field: "TEL_NO", title: "전화번호", width: "7%", minWidth:70, },
|
|
{ field: "FAX_NO", title: "팩스번호", width: "7%", minWidth:70, },
|
|
{ field: "PUR_FLG", title: "매입처", width: "5%", minWidth:50, formatter: tb_common_funtions.formatterSelCircleIcon, },
|
|
{ field: "SAL_FLG", title: "매출처", width: "5%", minWidth:50, formatter: tb_common_funtions.formatterSelCircleIcon, },
|
|
{ field: "NAT_CD", title: "국가", width: "5%", minWidth:50, formatter: tb_common_funtions.formatterNations, },
|
|
{ field: "CURRENCY_CD", title: "거래화폐", width: "5%", minWidth:50, /*formatter: tb_common_funtions.formatterCurrency,*/ },
|
|
{ field: "BP_PRSN_NM", title: "업체담당자", width: "6%", minWidth:60, },
|
|
{ field: "BP_PRSN_EMAIL", title: "담당자이메일", width: "8%", minWidth:80, },
|
|
{ field: "BP_PRSN_CELL_NO", title: "담당자연락처", width: "7%", minWidth:70, },
|
|
{ field: "REMK", title: "비고", width: "10%", minWidth:100, },
|
|
];
|
|
|
|
_this.tblList = new Tabulator("#tblPartnerList",{
|
|
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.getPartnerList();
|
|
});
|
|
_this.tblList.on("rowClick", function(e,tgt){ //Tabulator Row Click
|
|
Tb_funcs.rowClick(e,tgt);
|
|
});
|
|
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnAddPartner").addEventListener(evt,()=>{Tb_funcs.modalPartner()}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnExcelDown").addEventListener(evt,()=>{_this.excelDataLoad(_this.tblList,'거래처리스트')}));
|
|
['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_BP_NM, #S_SALES_GRP, #S_PUR_FLG, #S_SAL_FLG, #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').map( row => { row.NAT_CD = varsNations[row.NAT_CD]; return row; } ));
|
|
}
|
|
}
|
|
|
|
class Tb_class_pinfo {
|
|
constructor(){
|
|
let _this = this;
|
|
_this.partner_ajax_url = "./partner.ajax.php";
|
|
_this.tblList = "";
|
|
_this.saveExcel = tb_common_funtions.tabu2xls; //엑셀 다운로드
|
|
_this.BP_CD = "";
|
|
}
|
|
|
|
//파트너 리스트 로드
|
|
getPartnerInfo (BP_CD) {
|
|
let _this = this;
|
|
|
|
ajax_json({
|
|
url: _this.partner_ajax_url,
|
|
type: "POST",
|
|
data: {
|
|
mode: 'getPartnerInfo',
|
|
BP_CD,
|
|
},
|
|
success: function (data) {
|
|
if( data.code ){
|
|
Object.keys(data.data).forEach( key => {
|
|
if( key === 'PRSN' ){
|
|
_this.tblList.setData(data.data[key]);
|
|
}else{
|
|
if( data.data[key] != null ){
|
|
document.forms['frmPartner'].querySelector('[name='+key+']').setAttribute(['data-defval'], data.data[key]);
|
|
//jQuery("form[name=frmPartner] [name="+key+"]").data(key, data.data[key]);
|
|
|
|
if( key === 'BP_CD' ){
|
|
document.forms['frmPartner'].querySelector('[name=BP_CD]').setAttribute('readonly',true);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
formSetVal(document.forms['frmPartner']);
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function(){
|
|
}
|
|
});
|
|
return false;
|
|
};
|
|
|
|
putPartner = (e) => {
|
|
e.preventDefault();
|
|
|
|
let _this = this;
|
|
let formdata = form2Json(document.frmPartner);
|
|
if( formdata['BP_CD_OLD'] ){
|
|
formdata['mode'] = "setPartner";
|
|
}else{
|
|
formdata['mode'] = "putPartner";
|
|
}
|
|
|
|
let postdata = _this.tblList.getData().reduce( (nrow, mem, i) => {
|
|
mem._STATUS_ && nrow.push({...mem});
|
|
return nrow;
|
|
}, [] );
|
|
formdata['PRSN'] = JSON.stringify(postdata);
|
|
|
|
ajax_json({
|
|
url: _this.partner_ajax_url,
|
|
type: "POST",
|
|
data: formdata,
|
|
success: function (data) {
|
|
if( data.code ){
|
|
kuls_success("적용 되었습니다.");
|
|
Tb_funcs.getPartnerList();
|
|
Tb_funcs.putPartnerModal.delete();
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function(){
|
|
}
|
|
});
|
|
};
|
|
|
|
revokeData(row){
|
|
let _this = this;
|
|
row.update({USE_FLG:"Y"});
|
|
row.getElement().classList.remove("del-row");
|
|
};
|
|
|
|
init(BP_CD) {
|
|
let _this = this;
|
|
|
|
const fields_member = [
|
|
{ formatter:"rowSelection", titleFormatter: "rowSelection", width: "2%", minWidth:36, headerSort: false, },
|
|
{ field: "BP_PRSN_ID", title: "담당자ID", width: "0%", minWidth:0, visible: false, },
|
|
{ field: "BP_PRSN_NM", title: "담당자명", width: "10%", minWidth:75, editor:'input', },
|
|
{ field: "BP_PRSN_EMAIL", title: "이메일", width: "18%", minWidth:100, editor:'input', },
|
|
{ field: "BP_PRSN_TEL_NO", title: "연락처", width: "15%", minWidth:75, editor:'input', },
|
|
{ field: "BP_PRSN_CELL_NO", title: "휴대폰", width: "15%", minWidth:75, editor:'input', },
|
|
{ field: "BP_PRSN_FAX_NO", title: "FAX NO", width: "15%", minWidth:75, editor:'input', },
|
|
{ field: "REMK", title: "비고", width: "15%", minWidth:75, editor:'input', },
|
|
{ field: "MPC_FLG", title: "메인", width: "7%", minWidth:40, cssClass:'user-editable', formatter: tb_common_funtions.formatterCheckIcon2, formatterParams: {checkval:'Y'} },
|
|
{ field: "USE_FLG", title: "사용여부", width: "0%", minWidth:0, visible: false, },
|
|
];
|
|
|
|
_this.tblList = new Tabulator("#tblPartnerMember",{
|
|
layout: "fitColumns",
|
|
data: [], //기본 데이터
|
|
height: "100%",
|
|
columns: fields_member, //컬럼 설정
|
|
columnDefaults: { //컬럼 공통 규칙
|
|
vertAlign: "middle",
|
|
hozAlign: "center",
|
|
resizable: "header",//Resize 는 헤더에서만 가능
|
|
headerHozAlign: "center", //헤더 정렬
|
|
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
|
|
},
|
|
headerSortElement: "<i class='bi'></i>", //정렬 아이콘
|
|
});
|
|
|
|
_this.tblList.on("cellEdited", function(cell) { //Tabulator 초기 데이터 불러오기 이벤트
|
|
cell.getData()._STATUS_ = cell.getData()._STATUS_||'U';
|
|
});
|
|
_this.tblList.on("cellClick", function(e, tgt) { //Tabulator 초기 데이터 불러오기 이벤트
|
|
switch( tgt.getField() ){
|
|
case "MPC_FLG" :
|
|
tgt.getTable().getRows().forEach(row => row.update({MPC_FLG:'N'}));
|
|
tgt.setValue('Y');
|
|
break;
|
|
}
|
|
});
|
|
_this.tblList.on("rowDeselected", (row) => { //Tabulator cell Deslected
|
|
_this.revokeData && _this.revokeData(row);
|
|
});
|
|
_this.tblList.on("tableBuilt", function(){ //Tabulator 초기 데이터 불러오기 이벤트
|
|
if( BP_CD ){
|
|
_this.getPartnerInfo(BP_CD);
|
|
}
|
|
});
|
|
|
|
document.querySelector("form[name=frmPartner]").addEventListener("submit", _this.putPartner);
|
|
['click','keypress'].forEach( evt => document.querySelector("#btnAddPmem").addEventListener(evt, ()=>{
|
|
_this.tblList.addRow({'_STATUS_':'I', 'USE_FLG':'Y'});
|
|
//_this.tblList.setData([..._this.tblList.getData(),[]]);
|
|
} ) );
|
|
['click','keypress'].forEach( evt => document.querySelector("#btnDelPmem").addEventListener(evt, ()=>{
|
|
_this.tblList.getSelectedRows().forEach( row => {
|
|
row.update({_STATUS_:row.getData()._STATUS_||'U',USE_FLG:'N'});
|
|
row.getElement().classList.add('del-row');
|
|
} );
|
|
// _this.tblList.setFilter(function(data){ //필터링
|
|
// return ( data.USE_FLG === 'Y' )
|
|
// }, '=', true);
|
|
} ) );
|
|
};
|
|
}
|
|
|
|
const Tb_funcs = new Tb_class();
|
|
const Tb_funcs_pinfo = new Tb_class_pinfo();
|
|
Tb_funcs.init(); |