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

/*화면 변수*/
const LOANMNG03010_GRID_ID = '#ITP_LOANMNG03010_jqGrid';
const LOANMNG03010_GRID_LIST = '#ITP_LOANMNG03010_jqGrid_list';
const LOANMNG03010_GRID_PAGER = '#ITP_LOANMNG03010_jqGridPager';
const LOANMNG03010_GRID_EMPTY = '#ITP_LOANMNG03010_jqGridEmpty';

const LOANMNG03010_VIEW_GRID_ID = '#ITP_LOANMNG03010_VIEW_jqGrid';
const LOANMNG03010_VIEW_GRID_LIST = '#ITP_LOANMNG03010_VIEW_jqGrid_list';
const LOANMNG03010_VIEW_GRID_PAGER = '#ITP_LOANMNG03010_VIEW_jqGridPager';
const LOANMNG03010_VIEW_GRID_EMPTY = '#ITP_LOANMNG03010_VIEW_jqGridEmpty';

const LOANMNG03010_DETAIL_GRID_ID = '#ITP_LOANMNG03010_DETAIL_jqGrid';
const LOANMNG03010_DETAIL_GRID_LIST = '#ITP_LOANMNG03010_DETAIL_jqGrid_list';
const LOANMNG03010_DETAIL_GRID_PAGER = '#ITP_LOANMNG03010_DETAIL_jqGridPager';
const LOANMNG03010_DETAIL_GRID_EMPTY = '#ITP_LOANMNG03010_DETAIL_jqGridEmpty';

let ITP_FORM_LOANMNG03010_DETAIL_IS_DUPLICATE = false;
let ITP_FORM_LOANMNG03010_DETAIL_IS_WRITING = false;
let LOANMNG03010_DETAIL_GRID_LAST_ROW_ID;

/*API URL*/
let UNPAID_MNG_DETAIL_GRID_LIST = '/api/unpaid/mng/detail-grid-list';
let UNPAID_MNG_STL_GRID_LIST = '/api/unpaid/mng/stl-grid-list';
let UNPAID_MNG_INFO_UNPAID = '/api/unpaid/mng/info-unpaid';

let WHS_MNG_ADD_WHS = '/api/whs/mng/add-whs';
let WHS_MNG_MIDIFY_WHS = '/api/whs/mng/modify-whs';
let WHS_MNG_REMOVE_WHS = '/api/whs/mng/remove-whs'; 

let LOGIN_AUTH_TYPE_CD;

/*화면 Grid ColModel*/
const gridColModel = {
	list: [
		{
			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: '13', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STORE_NM', name: 'storeNm',
			label: "매장명", 
			width: '13', fixed: false, align: 'left',
			sortable: false, hidden: false, classes: 'ui-ellipsis'
		},
		{
			index: 'LOAN_DVSN_NM', name: 'loanDvsnNm',
			label: "정산타입", 
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false
		},		
		{
			index: 'STTL_MGNT_UNQ_NO', name: 'sttlMgntUnqNo',
			label: "정산번호", 
			width: '14', fixed: false, align: 'center',
			sortable: false, hidden: false
		},		
		{
			index: 'STTL_ST_NM', name: 'sttlStNm',
			label: "상태", 
			width: '6', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'STTL_REQ_DT', name: 'sttlReqDt',
			label: "정산요청일", 
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'STTL_REQ_AMT', name: 'sttlReqAmt',
			label: '정산요청금액', 
			width: '10', fixed: false, align: 'right',
			sortable: false, hidden: false, 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'STTL_DT', name: 'sttlDt',
			label: "정산확정일", 
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: false
		},	
		{
			index: 'UNPAId_AMT', name: 'right',
			label: '미납금액', 
			width: '10', fixed: false, align: 'right',
			sortable: false, hidden: false, 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},		
		{
			index: 'USE_AMT_TOTAL', name: 'useAmtTotal',
			label: '사용가능한도', 
			width: '10', fixed: false, align: 'right',
			sortable: false, hidden: false, 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		}		
	],
	view: [
		{
			index: 'VIEW_CD', name: 'viewCd',
			label: ITP_MSG_LOCALE.label.viewCd,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STTL_MGNT_DTL_NO', name: 'sttlMgntDtlNo',
			label: '정산관리상세번호',
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},		
		{
			index: 'BRAND_NM', name: 'brandNm',
			label: "브랜드",
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STORE_NM', name: 'storeNm',
			label: "매장명",
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'ITEM_ID', name: 'itemId',
			label: "품목코드",
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'ITEM_NM', name: 'itemNm',
			label: "품목명",
			width: '10', fixed: false, align: 'left',
			sortable: false, editable: false, edittype: 'text', classes: 'ui-ellipsis'
		},
		{
			index: 'UNIT', name: 'unit',
			label: "단위",
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'UNIT_AMT', name: 'unitAmt',
			label: "단가",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'PODR_QTY', name: 'podrQty',
			label: "발주수량",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'DLV_QTY', name: 'dlvQty',
			label: "납품수량",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'WHS_COL_QTY', name: 'whsColQty',
			label: "입고/수거수량",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		}, 
		{
			index: 'WHS_COL_DT', name: 'whsColDt',
			label: "입고/수거일자",
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'WHS_COL_AMT', name: 'whsColAmt',
			label: "입고/수거금액",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'STTL_DVSN_NM', name: 'sttlDvsnNm',
			label: "정산구분",
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'PODR_UNQ_NO', name: 'podrUnqNo',
			label: "발주번호",
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'PODR_DTL_NO', name: 'podrDtlNo',
			label: "발주항번",
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		}
	]
};

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

/*화면공통 Object*/
let pageObj = {
	init: function () {
		this.ui.init();
		this.event.init();
	},
	ui: {
		init: function () {
			this.view();
			this.grid();
			this.ready();
		},
		view: function() {
			// 버튼 권한설정
			fn_proc_btn_auth('LOANMNG03010');
			
			// 공통코드 표시
			$('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_LOANMNG03010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);			
			$('#ITP_FORM_LOANMNG03010_SEARCH_FROM_DT').datepicker('setDate', new Date(now.setMonth(now.getMonth() - 1)));
			$('#ITP_FORM_LOANMNG03010_SEARCH_TO_DT').datepicker('setDate', new Date());
			
			// 권한에 따라 매장값 설정
			$('#ITP_FORM_LOANMNG03010_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_LOANMNG03010_SEARCH_STORE_ID').val(fn_make_user_info.get('storeId'));
				$('#ITP_FORM_LOANMNG03010_SEARCH_STORE_NM').val(fn_make_user_info.get('storeNm'));	
			}
			
		},
		grid: function() {
			itp_fn_jqgrid_resize(LOANMNG03010_GRID_ID, LOANMNG03010_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_LOANMNG03010_SRH'				: listObj.button.search();		break;	// 조회 버튼 클릭
						case 'ITP_BTN_LOANMNG03010_CANCELLIST'		: viewObj.button.cancel(); 	break;	// 취소/목록 버튼
						case 'ITP_BTN_LOANMNG03010_PAYMENT'			: viewObj.button.payment();	break;	// 결제 버튼
						case 'ITP_BTN_LOANMNG03010_DEPOSIT'			: viewObj.button.deposit();	break;	// 입금 버튼
						case 'ITP_BTN_LOANMNG03010_STORE_SEARCH'	: listObj.button.storePop();	break;	// 매장검색 팝업
						case 'ITP_BTN_LOANMNG03010_STORE_ERASE'		: listObj.button.storeErase();	break;	// 매장 지움
						case 'ITP_BTN_LOANMNG03010_EXCEL'			: listObj.excelDown();	break;	// 엑셀다운로드
					}
				});
			});

			$('body').on('click', function(e) {
				var gridId = LOANMNG03010_DETAIL_GRID_ID.replace('#', '');
				var rids = $(LOANMNG03010_DETAIL_GRID_ID).jqGrid('getDataIDs');
				var last_row_id = rids[rids.length - 1];
				itp_fn_grid_reset_selection(e, last_row_id, gridId, 'LOANMNG03010_DETAIL');
			});

		}
	},
	switchScreen: function(mode) {
		if(mode == 'LIST') { // 목록
			$('#ITP_BTN_LOANMNG03010_MODIFY').hide();
			$('#ITP_BTN_LOANMNG03010_CANCELLIST').hide();
			$('#ITP_BTN_LOANMNG03010_DELETE').hide();
			$('#ITP_BTN_LOANMNG03010_PAYMENT').hide();
			$('#ITP_BTN_LOANMNG03010_DEPOSIT').hide();
			
			if(LOGIN_AUTH_TYPE_CD == '50') { // 매장관리자
				$('#ITP_BTN_LOANMNG03010_STORE_SEARCH').hide();
				$('#ITP_BTN_LOANMNG03010_STORE_ERASE').hide();
			} else {
				$('#ITP_BTN_LOANMNG03010_STORE_SEARCH').show();
				$('#ITP_BTN_LOANMNG03010_STORE_ERASE').show();
			}
			
			fn_show_btn_auth('#ITP_BTN_LOANMNG03010_SRH');
			fn_show_btn_auth('#ITP_BTN_LOANMNG03010_NEWREG');
			
			$('#ITP_AJAX_LOANMNG03010_LIST_CONTAINER').show();
			$('#ITP_AJAX_LOANMNG03010_DETAIL_CONTAINER').hide();
			$('#ITP_AJAX_LOANMNG03010_VIEW_CONTAINER').hide();
			
			$('#ITP_BTN_LOANMNG03010_EXCEL').show();
			
		} else if(mode == 'VIEW') { // 보기
			$('#ITP_BTN_LOANMNG03010_SRH').hide();
			$('#ITP_BTN_LOANMNG03010_NEWREG').hide();
			$('#ITP_BTN_LOANMNG03010_DELETE').hide();
			
			fn_show_btn_auth('#ITP_BTN_LOANMNG03010_PAYMENT');			
			fn_show_btn_auth('#ITP_BTN_LOANMNG03010_DEPOSIT');
			fn_show_btn_auth('#ITP_BTN_LOANMNG03010_CANCELLIST');

			$('#ITP_AJAX_LOANMNG03010_LIST_CONTAINER').hide();
			$('#ITP_AJAX_LOANMNG03010_DETAIL_CONTAINER').hide();
			$('#ITP_AJAX_LOANMNG03010_VIEW_CONTAINER').show();
		}
	}
};

/*목록화면 Object*/
let listObj = {
	init: function () {
		this.grid.init();
	},
	itp_LOANMNG03010_search: false,
	button: {
		search: function() {
			listObj.itp_LOANMNG03010_search = true;
			let param = $('#ITP_FORM_LOANMNG03010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.gridPage = $.jgrid.defaults.page;
			$(LOANMNG03010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
		},
		create: function() {
			pageObj.switchScreen('ADD');			
			itp_fn_form_clear_validate(null, '#ITP_FORM_LOANMNG03010_DETAIL');						
			// 로케이션 리스트 조회
			createObj.init();
		}, 
		storePop: function() {
			fn_call_popup('biz', 'BIZPOP_BRAND_STORE', '#ITP_ASIDE', function(result) {
				// alert(JSON.stringify(result));
				$('#ITP_FORM_LOANMNG03010_SEARCH_STORE_ID').val(result[0].storeId);
				$('#ITP_FORM_LOANMNG03010_SEARCH_STORE_NM').val(result[0].storeNm);				
				listObj.button.search();
			}, null, 'S');
		}, 
		storeErase: function() {
			$('#ITP_FORM_LOANMNG03010_SEARCH_STORE_ID').val('');
			$('#ITP_FORM_LOANMNG03010_SEARCH_STORE_NM').val('');
			listObj.button.search();
		}
	},
	empty: {
		init: function() {
			var _this = this;
			this.push();
			$(LOANMNG03010_GRID_EMPTY).on('click', function() {
				_this.back();
				_this.itp_LOANMNG03010_param.gridSize = $.jgrid.defaults.rowNum;
				$(LOANMNG03010_GRID_ID).setGridParam({'postData': JSON.stringify(_this.itp_LOANMNG03010_param)}).trigger('reloadGrid');
			});
		},
		itp_LOANMNG03010_param: {},
		push: function() {
			let param = $('#ITP_FORM_LOANMNG03010_SEARCH').serializeObject();
			listObj.itp_LOANMNG03010_param = param;
		},
		back: function() {
			$('#ITP_FORM_LOANMNG03010_SEARCH_STORE_ID').val(listObj.itp_LOANMNG03010_param.sstoreId);
			$('#ITP_FORM_LOANMNG03010_SEARCH_STORE_NM').val(listObj.itp_LOANMNG03010_param.sstoreNm);
			$('#ITP_FORM_LOANMNG03010_SEARCH_FROM_DT').val(listObj.itp_LOANMNG03010_param.fromDt);
			$('#ITP_FORM_LOANMNG03010_SEARCH_TO_DT').val(listObj.itp_LOANMNG03010_param.toDt);
		}
	},
	grid: {
		init: function () {
			// 데이터 없을때
			listObj.empty.push();
			this.search();
		},
		colModel: gridColModel.list,
		search: function() {
			pageObj.switchScreen('LIST');
			this.unload();
			this.load();
		},
		load: function() {			
			let param = $('#ITP_FORM_LOANMNG03010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;

			var option = {
				gridId: LOANMNG03010_GRID_ID,
				colModel: gridColModel.list,
				param: param,
				url: DOMAIN + UNPAID_MNG_DETAIL_GRID_LIST,
				pager: LOANMNG03010_GRID_PAGER,
				onCellSelect: function(rowId, cellIdx, cellValue) {
					var cm = $(this).jqGrid('getGridParam', 'colModel');
					var colNm = cm[cellIdx].name;
					if (colNm == 'sttlMgntUnqNo') {
						const sttlMgntUnqNoVal = $(this).jqGrid('getCell', rowId, 'sttlMgntUnqNo');
						
						const key = {sttlMgntUnqNo: sttlMgntUnqNoVal, viewCd: 'R'};
						var param = $.param(key);
						viewObj.init(param);
					}
				},
				loadComplete: function(data) {
					console.log(data);
					itp_fn_grid_load_complete(data, LOANMNG03010_GRID_ID, true, 'number', 'LOANMNG03010', listObj.itp_LOANMNG03010_search, listObj.empty, true, data.gridRecords, true);
					var ids = $(LOANMNG03010_GRID_ID).getDataIDs();
					$.each(ids, function(idx, rowId) {
						$(LOANMNG03010_GRID_ID).jqGrid('setCell', rowId, 'sttlMgntUnqNo', '', ITP_GRID_COL_STYLE.link);
					});
				},
				onPaging: function(action) {
					itp_fn_grid_paging(LOANMNG03010_GRID_ID, action, param);
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(LOANMNG03010_GRID_ID).jqGrid('clearGridData', true);
			$(LOANMNG03010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(LOANMNG03010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(LOANMNG03010_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(LOANMNG03010_GRID_ID);
		}
	},
	excelDown: function() {
		var param = {
			'url': UNPAID_MNG_DETAIL_GRID_LIST,
			'param': $('#ITP_FORM_LOANMNG03010_SEARCH').serializeObject(),
			'gridColumns': $(LOANMNG03010_GRID_ID).jqGrid('getGridParam', 'colModel'),
			'fileName': '미납금현황.xlsx',
			'sheetName': '미납금리스트'
		};
		itp_fn_remote_to_excel(param);
	}
};

/*상세화면 Object*/
let viewObj = {
	init: function (param) {
		this.load(param);
	},
	button: {
		cancel: function() {
			listObj.grid.search();
		},
		payment: function() {
			// 결제 팝업 결과
			var popFn = function(rowDataPop) {
				// console.log(JSON.stringify(rowDataPop));
				listObj.grid.search();
			};			
			// 결제 팝업
			// 결제타입코드 : 10(선불(충전)), 20(후불(결제)), 30(후불(선결제))			
			var args = {'payTpCd': '20', 
				'brandId': $('#ITP_FORM_LOANMNG03010_VIEW_BRAND_ID').val(), 
				'storeId': $('#ITP_FORM_LOANMNG03010_VIEW_STORE_ID').val(), 
				'sttlMgntUnqNoList': $('#ITP_FORM_LOANMNG03010_VIEW_STTL_MGNT_UNQ_NO').val(), 
				'goodsAmt': $('#ITP_FORM_LOANMNG03010_VIEW_UNPAID_AMT').val() }; 
			fn_call_popup('biz', 'BIZPOP_PO_PAYMENT', '#ITP_ASIDE', popFn, args, 'S');
		}, 
		deposit: function() {
			// 입금관리 화면 활성화
			// $('#LOANMNG02010_PAGE_NO').trigger('click');
			
			if($('#ITP_FORM_LOANMNG03010_VIEW_DSPT_MGNT_NO').val() != '' && $('#ITP_FORM_LOANMNG03010_VIEW_DPST_ST_CD').val() == 'DP01') {
				itp_fn_modal_alert_ajax('입금 요청중인 데이터 입니다.<br>입금관리에서 데이터를 확인하세요.');
				return;
			}
			
			var args = {'payTpCd': '20', 
				'brandId': $('#ITP_FORM_LOANMNG03010_VIEW_BRAND_ID').val(), 
				'brandNm': $('#ITP_FORM_LOANMNG03010_VIEW .fnBrandNm').text(), 
				'storeId': $('#ITP_FORM_LOANMNG03010_VIEW_STORE_ID').val(), 
				'storeNm': $('#ITP_FORM_LOANMNG03010_VIEW .fnStoreNm').text(), 
				'sttlMgntUnqNo': $('#ITP_FORM_LOANMNG03010_VIEW_STTL_MGNT_UNQ_NO').val(), 
				'goodsAmt': $('#ITP_FORM_LOANMNG03010_VIEW_UNPAID_AMT').val() };
				
			fn_call_popup('biz', 'BIZPOP_DSPT_INFO_REG', '#ITP_ASIDE', function(result) {				
				// console.log('>>>>> 팝업결과 : ' + JSON.stringify(result));
				listObj.grid.search();				
			}, args, 'S');			
		}
	}, 
	load: function(param) {
		fn_ajax_call(UNPAID_MNG_INFO_UNPAID, param, this.callback, 'GET');
	},
	callback: function (result) {
		// console.log(result);
		pageObj.switchScreen('VIEW');
		$('#ITP_FORM_LOANMNG03010_VIEW #ITP_FORM_LOANMNG03010_VIEW_BRAND_ID').val(result.brandId);
		$('#ITP_FORM_LOANMNG03010_VIEW #ITP_FORM_LOANMNG03010_VIEW_STORE_ID').val(result.storeId);
		$('#ITP_FORM_LOANMNG03010_VIEW #ITP_FORM_LOANMNG03010_VIEW_STTL_MGNT_UNQ_NO').val(result.sttlMgntUnqNo);
		$('#ITP_FORM_LOANMNG03010_VIEW #ITP_FORM_LOANMNG03010_VIEW_RCPT_YN').val(result.rcptYn);
		$('#ITP_FORM_LOANMNG03010_VIEW #ITP_FORM_LOANMNG03010_VIEW_UNPAID_AMT').val(result.unpaidAmt);
		$('#ITP_FORM_LOANMNG03010_VIEW #ITP_FORM_LOANMNG03010_VIEW_DSPT_MGNT_NO').val(result.dsptMgntNo);
		$('#ITP_FORM_LOANMNG03010_VIEW #ITP_FORM_LOANMNG03010_VIEW_DPST_ST_CD').val(result.dpstStCd);
		
		$('#ITP_FORM_LOANMNG03010_VIEW .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_LOANMNG03010_VIEW .fnStoreNm').text(result.storeNm);
		$('#ITP_FORM_LOANMNG03010_VIEW .fnSttlReqDt').text(result.sttlReqDt);
		$('#ITP_FORM_LOANMNG03010_VIEW .fnSttlDt').text(result.sttlDt == null ? '' : result.sttlDt);
		$('#ITP_FORM_LOANMNG03010_VIEW .fnSttlStNm').text(result.sttlStNm);
		// $('#ITP_FORM_LOANMNG03010_VIEW .fnSysRegDttm').text(result.sysRegDttm);
		$('#ITP_FORM_LOANMNG03010_VIEW .fnSysRegNm').text(result.sysRegNm + ' (' + result.sysRegDttm + ')');
		$('#ITP_FORM_LOANMNG03010_VIEW .fnSttlReqAmt').text(itp_fn_number_comma(result.sttlReqAmt));
		$('#ITP_FORM_LOANMNG03010_VIEW .fnUseAmtTotal').text(itp_fn_number_comma(result.useAmtTotal));
		$('#ITP_FORM_LOANMNG03010_VIEW .fnAcctBal').text(itp_fn_number_comma(result.acctBal));
		$('#ITP_FORM_LOANMNG03010_VIEW .fnUnpaidAmt').text(itp_fn_number_comma(result.unpaidAmt));
		
		if(result.rcptYn == 'Y') { // 수납여부
			$('#ITP_BTN_LOANMNG03010_PAYMENT').hide();
			$('#ITP_BTN_LOANMNG03010_DEPOSIT').hide();
		} else {			
			// 카드결제가능여부에 따라 처리
			if( result.mallId == null || result.mallId == '' ) {
				$('#ITP_BTN_LOANMNG03010_PAYMENT').hide();					
			} else {
				$('#ITP_BTN_LOANMNG03010_PAYMENT').show();				
			}
		}

		// 리스트 조회
		viewObj.grid.init();
	},
	grid: {
		init: function() {
			this.unload();
			this.load();
		},
		load : function() {
			let param = $('#ITP_FORM_LOANMNG03010_VIEW').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.pagingYn = false; // 페이징안함

			var option = {
				gridId: LOANMNG03010_VIEW_GRID_ID,
				colModel: gridColModel.view,
				param: param,
				url: DOMAIN + UNPAID_MNG_STL_GRID_LIST,
				pager: LOANMNG03010_VIEW_GRID_PAGER,
				loadComplete: function(data) {
					itp_fn_grid_load_complete(data, LOANMNG03010_VIEW_GRID_ID, true, undefined, 'LOANMNG03010_VIEW');
				},
				onPaging: function(action) {
					var pagingFn = {
						callBack: function(args) {
							$(args).trigger('reloadGrid');
						}
					};
					if (itp_fn_check_grid_is_writing(LOANMNG03010_VIEW_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, pagingFn, LOANMNG03010_VIEW_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_paging(LOANMNG03010_VIEW_GRID_ID, action, param);
					}
				},
				onSortCol: function(index, columnIndex, sortOrder) {
					var sortingFn = {
						callBack: function(args) {
							$(args).trigger('reloadGrid');
						}
					};
					if (itp_fn_check_grid_is_writing(LOANMNG03010_VIEW_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, sortingFn, LOANMNG03010_VIEW_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_sorting(LOANMNG03010_VIEW_GRID_ID, index, sortOrder);
					}
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(LOANMNG03010_VIEW_GRID_ID).jqGrid('clearGridData', true);
			$(LOANMNG03010_VIEW_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(LOANMNG03010_VIEW_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(LOANMNG03010_VIEW_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(LOANMNG03010_VIEW_GRID_ID);
		}
	}
};
