/********************************************************
 --------------------------------------------------------
 - Object 목록								            -
 --------------------------------------------------------
 * const gridColModel = {}	: 화면 Grid Object			*
 * let pageObj = {}			: 화면공통 Object			*
 * let listObj = {}			: 목록화면 Object			*
 * let viewObj = {}			: 상세화면 Object			*
 * let createObj = {}		: 신규화면 Object			*
 *******************************************************/

/*화면 변수*/
const LOANMNG02010_GRID_ID = '#ITP_LOANMNG02010_jqGrid';
const LOANMNG02010_GRID_LIST = '#ITP_LOANMNG02010_jqGrid_list';
const LOANMNG02010_GRID_PAGER = '#ITP_LOANMNG02010_jqGridPager';
const LOANMNG02010_GRID_EMPTY = '#ITP_LOANMNG02010_jqGridEmpty';

let ITP_FORM_LOANMNG02010_DETAIL_IS_DUPLICATE = false;
let ITP_FORM_LOANMNG02010_DETAIL_IS_WRITING = false;
let LOANMNG02010_DETAIL_GRID_LAST_ROW_ID;

/*API URL*/
let DSPT_MNG_DETAIL_GRID_LIST = '/api/dspt/mng/detail-grid-list';
let DSPT_MNG_INFO_DSPT = '/api/dspt/mng/info-dspt';
let DSPT_MNG_REQUEST_DSPT = '/api/dspt/mng/request-dspt';
let DSPT_MNG_REMOVE_DSPT = '/api/dspt/mng/remove-dspt';
let DSPT_MNG_APPROVE_DSPT = '/api/dspt/mng/approve-dspt';
let DSPT_MNG_REJECT_DSPT = '/api/dspt/mng/reject-dspt';

let SCREEN_MODE = 'LIST';
let LOGIN_AUTH_TYPE_CD;

/*화면 Grid ColModel*/
const gridColModel = {
	list: [
		{
			index: 'VIEW_CD', name: 'viewCd',
			label: ITP_MSG_LOCALE.label.viewCd,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'DSPT_MGNT_NO', name: 'dsptMgntNo',
			label: "입금관리번호", 
			width: '0', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'BRAND_ID', name: 'brandId',
			label: "브랜드ID", 
			width: '0', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STORE_ID', name: 'storeId',
			label: "매장ID", 
			width: '0', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'BRAND_NM', name: 'brandNm',
			label: ITP_MSG_LOCALE.label.brandNm, //브랜드
			width: '12', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STORE_NM', name: 'storeNm',
			label: "매장명", 
			width: '12', fixed: false, align: 'left',
			sortable: false, hidden: false, classes: 'ui-ellipsis'
		},
		{
			index: 'LOAN_DVSN_NM', name: 'loanDvsnNm',
			label: "정산타입", 
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'DPST_DT', name: 'dpstDt',
			label: "입금일자", 
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'DPST_AMT', name: 'dpstAmt',
			label: "입금금액", 
			width: '10', fixed: false, align: 'right',
			sortable: false, hidden: false, 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'DPST_NM', name: 'dpstNm',
			label: "입금자", 
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false, classes: 'ui-ellipsis'
		},
		{
			index: 'DPST_ST_CD', name: 'dpstStCd',
			label: "입금상태", 
			width: '0', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'DPST_ST_NM', name: 'dpstStNm',
			label: "입금상태", 
			width: '6', fixed: false, align: 'center',
			minwidth: 100,
			sortable: false, hidden: false
		},
		{
			index: 'DPST_BNK_NM', name: 'dpstBnkNm',
			label: "입금은행", 
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'RCV_ACCT_NO', name: 'rcvAcctNo',
			label: "입금계좌번호", 
			minwidth: 140,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'REQ_DT', name: 'reqDt',
			label: "요청일", 
			minwidth: 120,
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'DPST_AUTH_DT', name: 'dpstAuthDt',
			label: "승인일", 
			minwidth: 120,
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'DSPT_RJCT_DT', name: 'dsptRjctDt',
			label: "반려일", 
			minwidth: 120,
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'DSPT_RJCT_RSN', name: 'dsptRjctRsn',
			label: "반려사유", 
			width: '12', fixed: false, align: 'center',
			sortable: false, hidden: false, classes: 'ui-ellipsis'
		}
	]
};

require(['config'], function() {
	require([
	], function($) {
		pageObj.init();
	});
});

/*화면공통 Object*/
let pageObj = {
	init: function () {
		this.ui.init();
		this.event.init();
	},
	ui: {
		init: function () {
			this.view();
			this.form();
			this.grid();
			this.ready();
		},
		view: function() {
			// 버튼 권한설정
			fn_proc_btn_auth('LOANMNG02010');
			
			// 공통코드 표시
			$('select').each(function() {
		        if($(this).data('select-code')) {
		            fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
		        }
		    });

			// 조회일자 지정
			var now = new Date();
			$('#ITP_TAB_LOANMNG02010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);			
			$('#ITP_FORM_LOANMNG02010_SEARCH_FROM_DT').datepicker('setDate', new Date(now.setMonth(now.getMonth() - 1)));
			$('#ITP_FORM_LOANMNG02010_SEARCH_TO_DT').datepicker('setDate', new Date());
			
			// 권한에 따라 매장값 설정
			$('#ITP_FORM_LOANMNG02010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId'));
			LOGIN_AUTH_TYPE_CD = fn_make_user_info.get('authTpCd'); // 권한타입
			if(LOGIN_AUTH_TYPE_CD == '50') {
				$('#ITP_FORM_LOANMNG02010_SEARCH_STORE_ID').val(fn_make_user_info.get('storeId'));
				$('#ITP_FORM_LOANMNG02010_SEARCH_STORE_NM').val(fn_make_user_info.get('storeNm'));
			} 
			
		},
		form: function() {
			itp_fn_form_event.onKeyup('#ITP_FORM_LOANMNG02010_DETAIL');
		},
		grid: function() {
			itp_fn_jqgrid_resize(LOANMNG02010_GRID_ID, LOANMNG02010_GRID_LIST, 'lg');
			listObj.empty.init();
			itp_fn_fire_window_resize();
		},
		ready: function() {
			listObj.init();
		}
	},
	event: {
		init: function () {
			this.button();
		},
		button: function () {
			// 버튼 클릭 이벤트
			$('button').each(function() {
				var id = $(this).attr('id');
				$(this).on('click', function() {
					switch (id) {
						case 'ITP_BTN_LOANMNG02010_CHARGE'			: listObj.button.charge();		break;	// 선결제/충전 버튼 클릭
						case 'ITP_BTN_LOANMNG02010_SRH'				: listObj.button.search();		break;	// 조회 버튼 클릭
						case 'ITP_BTN_LOANMNG02010_NEWREG'			: listObj.button.create(); 		break;	// 신규등록 버튼
						case 'ITP_BTN_LOANMNG02010_CANCELLIST'		: createObj.button.cancel(); 	break;	// 취소/목록 버튼
						case 'ITP_BTN_LOANMNG02010_DELETE'			: viewObj.button.remove(); 		break;	// 삭제 버튼
						case 'ITP_BTN_LOANMNG02010_REQUEST'			: createObj.button.request(); 		break;	// 요청 버튼
						case 'ITP_BTN_LOANMNG02010_STORE_SEARCH'	: createObj.button.popupStore();	break;	// 매장선택 팝업
						case 'ITP_BTN_LOANMNG02010_STORE_ERASE'		: createObj.button.eraseStore();	break;	// 매장선택 삭제
						case 'ITP_BTN_LOANMNG02010_AGREE'			: listObj.button.agree();		break;	// 승인
						case 'ITP_BTN_LOANMNG02010_REJECT'			: listObj.button.reject();		break;	// 반려
						case 'ITP_BTN_LOANMNG02010_EXCEL'			: listObj.excelDown();		break;	// 엑셀 다운로드
					}
				});
			});

			$('body').on('click', function(e) {

			});
		}
	},
	switchScreen: function(mode) {		
		SCREEN_MODE = mode;		
		if(mode == 'LIST') { // 목록
			$('#ITP_BTN_LOANMNG02010_MODIFY').hide();
			$('#ITP_BTN_LOANMNG02010_CANCELLIST').hide();
			$('#ITP_BTN_LOANMNG02010_DELETE').hide();
			$('#ITP_BTN_LOANMNG02010_SAVE').hide();
			$('#ITP_BTN_LOANMNG02010_REQUEST').hide();
			
			$('#ITP_BTN_LOANMNG02010_EXCEL').show();
			
			if(LOGIN_AUTH_TYPE_CD == '50') { // 매장관리자
				$('#ITP_BTN_LOANMNG02010_STORE_SEARCH').hide();
				$('#ITP_BTN_LOANMNG02010_STORE_ERASE').hide();
				$('#ITP_BTN_LOANMNG02010_AGREE').hide();
				$('#ITP_BTN_LOANMNG02010_REJECT').hide();
				
				var apprYn = fn_make_user_info.get('apprYn'); // 카드결제가능여부
				if(apprYn == 'Y') {
					fn_show_btn_auth('#ITP_BTN_LOANMNG02010_CHARGE');	
				} else {
					$('#ITP_BTN_LOANMNG02010_CHARGE').hide();	
				}				
			} else {
				$('#ITP_BTN_LOANMNG02010_STORE_SEARCH').show();
				$('#ITP_BTN_LOANMNG02010_STORE_ERASE').show();
				$('#ITP_BTN_LOANMNG02010_CHARGE').hide();
				fn_show_btn_auth('#ITP_BTN_LOANMNG02010_AGREE');			
				fn_show_btn_auth('#ITP_BTN_LOANMNG02010_REJECT');
			}
			fn_show_btn_auth('#ITP_BTN_LOANMNG02010_SRH');
			fn_show_btn_auth('#ITP_BTN_LOANMNG02010_NEWREG');			

			$('#ITP_AJAX_LOANMNG02010_LIST_CONTAINER').show();
			$('#ITP_AJAX_LOANMNG02010_DETAIL_CONTAINER').hide();
			$('#ITP_AJAX_LOANMNG02010_VIEW_CONTAINER').hide();
		} else if(mode == 'ADD') { // 등록
			ITP_FORM_LOANMNG02010_DETAIL_IS_DUPLICATE = true;

			$('#ITP_BTN_LOANMNG02010_CHARGE').hide();
			$('#ITP_BTN_LOANMNG02010_SRH').hide();
			$('#ITP_BTN_LOANMNG02010_MODIFY').hide();
			$('#ITP_BTN_LOANMNG02010_NEWREG').hide();
			$('#ITP_BTN_LOANMNG02010_DELETE').hide();
			$('#ITP_BTN_LOANMNG02010_AGREE').hide();
			$('#ITP_BTN_LOANMNG02010_REJECT').hide();
			
			fn_show_btn_auth('#ITP_BTN_LOANMNG02010_CANCELLIST');
			fn_show_btn_auth('#ITP_BTN_LOANMNG02010_REQUEST');

			$('#ITP_AJAX_LOANMNG02010_LIST_CONTAINER').hide();
			$('#ITP_AJAX_LOANMNG02010_DETAIL_CONTAINER').show();
			$('#ITP_AJAX_LOANMNG02010_VIEW_CONTAINER').hide();

			$('#ITP_FORM_LOANMNG02010_DETAIL_VIEW_CD').val('C');			
			$('#ITP_FORM_LOANMNG02010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
			$('#ITP_FORM_LOANMNG02010_DETAIL .fnBrandNm').text(fn_make_user_info.get('brandNm'));
			$('#ITP_FORM_LOANMNG02010_DETAIL_STORE_ID').val($('#ITP_FORM_LOANMNG02010_SEARCH_STORE_ID').val());
			$('#ITP_FORM_LOANMNG02010_DETAIL .fnStoreNm').text($('#ITP_FORM_LOANMNG02010_SEARCH_STORE_NM').val());
			
			$('#ITP_FORM_LOANMNG02010_DETAIL_DPST_AMT').val('');			
			$('#ITP_FORM_LOANMNG02010_DETAIL_DPST_DT').val('');			
			$('#ITP_FORM_LOANMNG02010_DETAIL_DPST_NM').val('');			
			$('#ITP_FORM_LOANMNG02010_DETAIL_DPST_BNK_CD').val('');			
			$('#ITP_FORM_LOANMNG02010_DETAIL_RCV_ACCT_NO').val('');			

		} else if(mode == 'VIEW') { // 보기
			$('#ITP_BTN_LOANMNG02010_CHARGE').hide();
			$('#ITP_BTN_LOANMNG02010_SRH').hide();
			$('#ITP_BTN_LOANMNG02010_NEWREG').hide();
			$('#ITP_BTN_LOANMNG02010_SAVE').hide();
			
			fn_show_btn_auth('#ITP_BTN_LOANMNG02010_MODIFY');
			fn_show_btn_auth('#ITP_BTN_LOANMNG02010_CANCELLIST');
			fn_show_btn_auth('#ITP_BTN_LOANMNG02010_DELETE');

			$('#ITP_AJAX_LOANMNG02010_LIST_CONTAINER').hide();
			$('#ITP_AJAX_LOANMNG02010_DETAIL_CONTAINER').hide();
			$('#ITP_AJAX_LOANMNG02010_VIEW_CONTAINER').show();
		}
	}
};

/*목록화면 Object*/
let listObj = {
	init: function () {
		this.grid.init();
	},
	itp_LOANMNG02010_search: false,
	button: {
		search: function() {			
			listObj.itp_LOANMNG02010_search = true;
			let param = $('#ITP_FORM_LOANMNG02010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.gridPage = $.jgrid.defaults.page;
			$(LOANMNG02010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
		},
		create: function() {
			// 매장선택 체크
			if($('#ITP_FORM_LOANMNG02010_SEARCH_STORE_ID').val() == '') {
				itp_fn_modal_alert_ajax('신규입금 처리를 위한 매장을 선택하세요.');
				return;
			}			
			pageObj.switchScreen('ADD');			
			itp_fn_form_clear_validate(null, '#ITP_FORM_LOANMNG02010_DETAIL');						
			createObj.init();
		}, 
		charge: function() {
			// 매장선택 체크
			if($('#ITP_FORM_LOANMNG02010_SEARCH_STORE_ID').val() == '') {
				itp_fn_modal_alert_ajax('신규입금 처리를 위한 매장을 선택하세요.');
				return;
			}
			// 결제 팝업 결과
			var popFn = function(rowDataPop) {
				console.log(JSON.stringify(rowDataPop));
				listObj.grid.search();
			};			
			// 결제 팝업 : LD01(선불(충전)), LD02(후불(신용))
			// 결제타입코드 : 10(선불(충전)), 20(후불(결제)), 30(후불(선결제))		
			var loanDvsn = $('#ITP_FORM_LOANMNG02010_SEARCH_STORE_LOAN_DVSN').val();
				
			var args = {'payTpCd': loanDvsn === 'LD01' ? '10' : '30',
				'brandId': $('#ITP_FORM_LOANMNG02010_SEARCH_BRAND_ID').val(), 
				'storeId': $('#ITP_FORM_LOANMNG02010_SEARCH_STORE_ID').val() }; 
			fn_call_popup('biz', 'BIZPOP_PO_PAYMENT', '#ITP_ASIDE', popFn, args, 'S');
		}, 
		agree: function() {
			if(SCREEN_MODE == 'LIST') {
				// 그리드에서 최소1개는 선택해야 함
				const rowKey = $(LOANMNG02010_GRID_ID).getGridParam('selrow');
			    if (!rowKey) {
					itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.noData);
			    	return;
			    }
				var selectedIds = $(LOANMNG02010_GRID_ID).getGridParam('selarrrow');
				let dsptMgntNoList = [];
				var check = true;
				$.each(selectedIds, function(key, value) {				
					var dsptMgntNo = $(LOANMNG02010_GRID_ID).jqGrid('getRowData', value).dsptMgntNo;				
					var dpstStCd = $(LOANMNG02010_GRID_ID).jqGrid('getRowData', value).dpstStCd;
									
					if('DP01' != dpstStCd) { // 요청 체크
						check = false;	
					}							
					dsptMgntNoList.push(dsptMgntNo);
				});
				if(!check) {
					itp_fn_modal_alert_ajax('입금요청 건만 승인처리를 할 수 있습니다.');
					return;
				}			
				
				var confirmFn= {
					callBack: function() {
						let param = {};
						param.dsptMgntNoList = dsptMgntNoList;
						fn_ajax_call(DSPT_MNG_APPROVE_DSPT, JSON.stringify(param), function() {
							listObj.button.search();
						}, 'POST');
					}
				};
				itp_fn_modal_confirm(ITP_MSG_LOCALE.message.form.procData, confirmFn, null);
					
			} else if(SCREEN_MODE == 'VIEW') {				
				var confirmFn= {
					callBack: function() {
						let dsptMgntNoList = [];
						dsptMgntNoList.push($('#ITP_FORM_LOANMNG02010_VIEW_DSPT_MGNT_NO').val());
						let param = {};
						param.dsptMgntNoList = dsptMgntNoList;
						fn_ajax_call(DSPT_MNG_APPROVE_DSPT, JSON.stringify(param), function() {					
							pageObj.switchScreen('LIST');
							listObj.button.search();					
						}, 'POST');		
					}
				};				
				itp_fn_modal_confirm(ITP_MSG_LOCALE.message.form.procData, confirmFn, null);
			}
		}, 
		reject: function() {
			if(SCREEN_MODE == 'LIST') {
				// 그리드에서 최소1개는 선택해야 함
				const rowKey = $(LOANMNG02010_GRID_ID).getGridParam('selrow');
			    if (!rowKey) {
					itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.noData);
			    	return;
			    }
				var selectedIds = $(LOANMNG02010_GRID_ID).getGridParam('selarrrow');
				let dsptMgntNoList = [];
				var check = true;
				$.each(selectedIds, function(key, value) {				
					var dsptMgntNo = $(LOANMNG02010_GRID_ID).jqGrid('getRowData', value).dsptMgntNo;				
					var dpstStCd = $(LOANMNG02010_GRID_ID).jqGrid('getRowData', value).dpstStCd;
									
					if('DP01' != dpstStCd) { // 요청 체크
						check = false;	
					}							
					dsptMgntNoList.push(dsptMgntNo);
				});
				if(!check) {
					itp_fn_modal_alert_ajax('입금요청 건만 반려처리를 할 수 있습니다.');
					return;
				}		
				
				fn_call_popup('biz', 'BIZPOP_PO_REJECT_REASON', '#ITP_ASIDE', function(result) {
					// API 호출
					let param = {};
					param.dsptMgntNoList = dsptMgntNoList;
					param.dsptRjctRsn = result;
					fn_ajax_call(DSPT_MNG_REJECT_DSPT, JSON.stringify(param), function() {
						listObj.button.search();						
					}, 'POST');				
				}, null, 'S');					
			} else if(SCREEN_MODE == 'VIEW') {
				
				let dsptMgntNoList = [];
				dsptMgntNoList.push($('#ITP_FORM_LOANMNG02010_VIEW_DSPT_MGNT_NO').val());
				
				fn_call_popup('biz', 'BIZPOP_PO_REJECT_REASON', '#ITP_ASIDE', function(result) {
					// API 호출
					let param = {};
					param.dsptMgntNoList = dsptMgntNoList;
					param.dsptRjctRsn = result;
					fn_ajax_call(DSPT_MNG_REJECT_DSPT, JSON.stringify(param), function() {						 
						listObj.grid.search();					
					}, 'POST');				
				}, null, 'S');				
			}
		}
	},
	empty: {
		init: function() {
			var _this = this;
			this.push();
			$(LOANMNG02010_GRID_EMPTY).on('click', function() {
				_this.back();
				_this.itp_LOANMNG02010_param.gridSize = $.jgrid.defaults.rowNum;
				$(LOANMNG02010_GRID_ID).setGridParam({'postData': JSON.stringify(_this.itp_LOANMNG02010_param)}).trigger('reloadGrid');
			});
		},
		itp_LOANMNG02010_param: {},
		push: function() {
			let param = $('#ITP_FORM_LOANMNG02010_SEARCH').serializeObject();
			listObj.itp_LOANMNG02010_param = param;
		},
		back: function() {
			$('#ITP_FORM_LOANMNG02010_SEARCH_STORE_ID').val(listObj.itp_LOANMNG02010_param.sstoreId);
			$('#ITP_FORM_LOANMNG02010_SEARCH_FROM_DT').val(listObj.itp_LOANMNG02010_param.fromDt);
			$('#ITP_FORM_LOANMNG02010_SEARCH_TO_DT').val(listObj.itp_LOANMNG02010_param.toDt);
			$('#ITP_FORM_LOANMNG02010_SEARCH_DPST_ST_CD').val(listObj.itp_LOANMNG02010_param.sdpstStCd);
		}
	},
	grid: {
		init: function () {
			// 데이터 없을때
			listObj.empty.push();
			this.search();
		},
		colModel: gridColModel.list,
		search: function() {
			pageObj.switchScreen('LIST');
			this.unload();
			this.load();
		},
		load: function() {
			$('#ITP_FORM_LOANMNG02010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId'));
			
			let param = $('#ITP_FORM_LOANMNG02010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			
			var option = {
				gridId: LOANMNG02010_GRID_ID,
				colModel: gridColModel.list,
				param: param,
				url: DOMAIN + DSPT_MNG_DETAIL_GRID_LIST,
				pager: LOANMNG02010_GRID_PAGER,
				multiselect: true,
				rownumbers: false,                                     
				onCellSelect: function(rowId, cellIdx, cellValue) {
					var cm = $(this).jqGrid('getGridParam', 'colModel');
					var colNm = cm[cellIdx].name;
					if (colNm == 'dpstDt') {
						const dsptMgntNoVal = $(this).jqGrid('getCell', rowId, 'dsptMgntNo');
						
						const key = {dsptMgntNo : dsptMgntNoVal, viewCd: 'R'};
						var param = $.param(key);
						viewObj.init(param);
					}
				},
				loadComplete: function(data) {
					// console.log(data);
					itp_fn_grid_load_complete(data, LOANMNG02010_GRID_ID, true, 'number', 'LOANMNG02010', listObj.itp_LOANMNG02010_search, listObj.empty, true, data.gridRecords, true);
					var ids = $(LOANMNG02010_GRID_ID).getDataIDs();
					$.each(ids, function(idx, rowId) {
						$(LOANMNG02010_GRID_ID).jqGrid('setCell', rowId, 'dpstDt', '', ITP_GRID_COL_STYLE.link);
					});
				},
				onPaging: function(action) {
					itp_fn_grid_paging(LOANMNG02010_GRID_ID, action, param);
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(LOANMNG02010_GRID_ID).jqGrid('clearGridData', true);
			$(LOANMNG02010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(LOANMNG02010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(LOANMNG02010_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(LOANMNG02010_GRID_ID);
		}
	},
	excelDown: function() {
		var param = {
			'url': DSPT_MNG_DETAIL_GRID_LIST,
			'param': $('#ITP_FORM_LOANMNG02010_SEARCH').serializeObject(),
			'gridColumns': $(LOANMNG02010_GRID_ID).jqGrid('getGridParam', 'colModel'),
			'fileName': '입금현황.xlsx',
			'sheetName': '입금리스트'
		};
		itp_fn_remote_to_excel(param);
	}
};

/*상세화면 Object*/
let viewObj = {
	init: function (param) {
		this.load(param);
	},
	button: {
		remove: function() {
			const formId = '#ITP_FORM_LOANMNG02010_VIEW';
			itp_fn_form_clear_validate(null, formId);
			
			var confirmFn = {
				callBack: function() {
					let param = $(formId).serializeObject();
					//console.log(JSON.stringify(param));
					var searhFn = function() {
						ITP_FORM_LOANMNG02010_DETAIL_IS_WRITING = false;
						listObj.grid.search();
					};				
					fn_ajax_call(DSPT_MNG_REMOVE_DSPT, JSON.stringify(param), searhFn, 'POST');
				}
			};			
			itp_fn_modal_confirm(ITP_MSG_LOCALE.message.form.deleteData, confirmFn, null);
		}
	}, 
	load: function(param) {
		fn_ajax_call(DSPT_MNG_INFO_DSPT, param, this.callback, 'GET');
	},
	callback: function (result) {
		// console.log(result);
		pageObj.switchScreen('VIEW');
		$('#ITP_FORM_LOANMNG02010_VIEW_BRAND_ID').val(result.brandId);
		$('#ITP_FORM_LOANMNG02010_VIEW_STORE_ID').val(result.storeId);
		$('#ITP_FORM_LOANMNG02010_VIEW_DSPT_MGNT_NO').val(result.dsptMgntNo);
		$('#ITP_FORM_LOANMNG02010_VIEW_DPST_ST_CD').val(result.dpstStCd);
		
		$('#ITP_FORM_LOANMNG02010_VIEW .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_LOANMNG02010_VIEW .fnStoreNm').text(result.storeNm);
		$('#ITP_FORM_LOANMNG02010_VIEW .fnDpstDt').text(result.dpstDt);
		$('#ITP_FORM_LOANMNG02010_VIEW .fnDpstNm').text(result.dpstNm);
		$('#ITP_FORM_LOANMNG02010_VIEW .fnDpstBnkNm').text(result.dpstBnkNm);
		$('#ITP_FORM_LOANMNG02010_VIEW .fnRcvAcctNo').text(result.rcvAcctNo);
		$('#ITP_FORM_LOANMNG02010_VIEW .fnDpstAmt').text(itp_fn_number_comma(result.dpstAmt));		
		
		// 입금정보 상태에 따라 버튼 처리
		if(LOGIN_AUTH_TYPE_CD == '50') { // 매장관리자
			$('#ITP_BTN_LOANMNG02010_AGREE').hide();
			$('#ITP_BTN_LOANMNG02010_REJECT').hide();			
			if(result.dpstStCd == 'DP01') {
				$('#ITP_BTN_LOANMNG02010_DELETE').show();
			} else {
				$('#ITP_BTN_LOANMNG02010_DELETE').hide();
			}
		} else {
			if(result.dpstStCd == 'DP01') {
				$('#ITP_BTN_LOANMNG02010_AGREE').show();
				$('#ITP_BTN_LOANMNG02010_REJECT').show();
				$('#ITP_BTN_LOANMNG02010_DELETE').show();
			} else {
				$('#ITP_BTN_LOANMNG02010_AGREE').hide();
				$('#ITP_BTN_LOANMNG02010_REJECT').hide();
				$('#ITP_BTN_LOANMNG02010_DELETE').hide();
			}	
		}
	}
};

/*신규화면 Object*/
let createObj = {
	init: function () {
	},
	button: {
		cancel: function() {
			listObj.grid.search();
		},
		request: function() {
			const formId = '#ITP_FORM_LOANMNG02010_DETAIL';
			itp_fn_form_clear_validate(null, formId);
			
			var vali_dpstAmt = itp_fn_form_validate(formId, formId + '_DPST_AMT', ['empty','number'], undefined); // 입금금액
			var vali_dpstDt = itp_fn_form_validate(formId, formId + '_DPST_DT', ['empty'], undefined); // 입금일자
			var vali_dpstNm = itp_fn_form_validate(formId, formId + '_DPST_NM', ['empty'], undefined); // 입금자명
			var vali_dpstBnkCd = itp_fn_form_validate(formId, formId + '_DPST_BNK_CD', ['empty'], undefined); // 입금은행
			var vali_rcvAcctNo = itp_fn_form_validate(formId, formId + '_RCV_ACCT_NO', ['empty'], undefined); // 입금계좌번호
			
			if (vali_dpstAmt && vali_dpstDt && vali_dpstNm && vali_dpstBnkCd && vali_rcvAcctNo) {				
				let param = $(formId).serializeObject();
				//console.log(JSON.stringify(param));
				var searhFn = function() {
					ITP_FORM_LOANMNG02010_DETAIL_IS_WRITING = false;
					listObj.grid.search();
				};
				fn_ajax_call(DSPT_MNG_REQUEST_DSPT, JSON.stringify(param), searhFn, 'POST');
			}
		}, 
		popupStore: function() { // 매장선택 팝업
			fn_call_popup('biz', 'BIZPOP_BRAND_STORE', '#ITP_ASIDE', function(result) {
				// alert(JSON.stringify(result));
				$('#ITP_FORM_LOANMNG02010_SEARCH_STORE_ID').val(result[0].storeId);
				$('#ITP_FORM_LOANMNG02010_SEARCH_STORE_NM').val(result[0].storeNm);				
				$('#ITP_FORM_LOANMNG02010_SEARCH_STORE_LOAN_DVSN').val(result[0].loanDvsn);				
				listObj.button.search();
			}, null, 'S');
		}, 
		eraseStore: function() { // 매장선택 삭제
			$('#ITP_FORM_LOANMNG02010_SEARCH_STORE_ID').val('');
			$('#ITP_FORM_LOANMNG02010_SEARCH_STORE_NM').val('');
			listObj.button.search();
		}
	}
};
