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

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

/*화면 변수*/
const STINFO02010_GRID_ID = '#ITP_STINFO02010_jqGrid';
const STINFO02010_GRID_LIST = '#ITP_STINFO02010_jqGrid_list';
const STINFO02010_GRID_PAGER = '#ITP_STINFO02010_jqGridPager';
const STINFO02010_GRID_EMPTY = '#ITP_STINFO02010_jqGridEmpty';

const STINFO02010_VIEW_GRID_ID = '#ITP_STINFO02010_VIEW_jqGrid';
const STINFO02010_VIEW_GRID_LIST = '#ITP_STINFO02010_VIEW_jqGrid_list';
const STINFO02010_VIEW_GRID_PAGER = '#ITP_STINFO02010_VIEW_jqGridPager';
const STINFO02010_VIEW_GRID_EMPTY = '#ITP_STINFO02010_VIEW_jqGridEmpty';

const STINFO02010_DETAIL_GRID_ID = '#ITP_STINFO02010_DETAIL_jqGrid';
const STINFO02010_DETAIL_GRID_LIST = '#ITP_STINFO02010_DETAIL_jqGrid_list';
const STINFO02010_DETAIL_GRID_PAGER = '#ITP_STINFO02010_DETAIL_jqGridPager';
const STINFO02010_DETAIL_GRID_EMPTY = '#ITP_STINFO02010_DETAIL_jqGridEmpty';

let ITP_FORM_STINFO02010_DETAIL_IS_WRITING = false;

/*API URL*/
let API_DETAIL_GRID_LIST 	= '/api/store/detail-grid-list';	// 목록
let API_DETAIL_INFO 		= '/api/store/info-store';			// 상세
let API_DETAIL_SAVE 		= '/api/store/save-store';			// 저장
let API_INTI_PW				= '/api/store/inti-storePw';		// 패스워드 초기화
let API_GET_KEY			 	= '/api/session/get-key';

/*화면 Grid ColModel*/
const gridColModel = {
	list: [
		{
			index: 'STORE_ID', name: 'storeId',
			label: ITP_MSG_LOCALE.label.storeId, //매장번호
			width: '10', fixed: false, align: 'center',
			minwidth: 160,
			sortable: false, hidden: false
		},
		{
			index: 'STORE_NM', name: 'storeNm',
			label: ITP_MSG_LOCALE.label.storeNm, //매장명
			width: '13', fixed: false, align: 'left',
			minwidth: 120,
			sortable: false, hidden: false, classes: 'ui-ellipsis'
		},
		{
			index: 'BRAND_ID', name: 'brandId',
			label: ITP_MSG_LOCALE.label.brandId, //브랜드ID
			width: '10', fixed: false, align: 'left',
			sortable: false, hidden: true
		},
		{
			index: 'BRAND_NM', name: 'brandNm',
			label: ITP_MSG_LOCALE.label.brandNm, //브랜드명
			width: '10', fixed: false, align: 'left',
			sortable: false, hidden: false, classes: 'ui-ellipsis'
		},
		{
			index: 'BSNS_REG_NO', name: 'bsnsRegNo',
			label: ITP_MSG_LOCALE.label.bsnsRegNo, //사업자등록번호
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'STORE_DVSN', name: 'storeDvsn',
			label: ITP_MSG_LOCALE.label.storeDvsn, //매장구분
			width: '13', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STORE_DVSN_NM', name: 'storeDvsnNm',
			label: ITP_MSG_LOCALE.label.storeDvsn, //매장구분명
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'STORE_ST_NM', name: 'storeStNm',
			label: ITP_MSG_LOCALE.label.stNm, //상태
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'SYS_REG_DTTM', name: 'sysRegDttm',
			label: ITP_MSG_LOCALE.label.sysRegDttm, //최초등록일
			width: '10', fixed: false, align: 'center',
			minwidth: 160,
			sortable: false, hidden: false
		},
	],
	detail: [
		{
			index: 'VIEW_CD', name: 'viewCd',
			label: ITP_MSG_LOCALE.label.viewCd,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'AUTH_NO', name: 'authNo',
			label: ITP_MSG_LOCALE.label.permitCd,
			width: '20', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text',
			editrules: {required: true}
		},
		{
			index: 'AUTH_NM', name: 'authNm',
			label: ITP_MSG_LOCALE.label.permitName,
			width: '30', fixed: false, align: 'center',
			sortable: true, editable: false, edittype: 'text',
			editrules: {required: true}
		},
		{
			index: 'USE_YN_NM', name: 'useYnNm',
			label: ITP_MSG_LOCALE.label.status,
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'ADD_DT', name: 'addDt',
			label: ITP_MSG_LOCALE.label.regDt,
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		}
	]
};

/*화면공통 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('STINFO02010');

			// 공통코드 표시
			$('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_STINFO02010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);
			$('#ITP_FORM_STINFO02010_SEARCH_FROM_DT').datepicker('setDate', new Date(now.setMonth(now.getMonth() - 1)));
			$('#ITP_FORM_STINFO02010_SEARCH_TO_DT').datepicker('setDate', new Date());
			// $('#ITP_FORM_STINFO02010_DETAIL_FROM_DT').datepicker('setDate', new Date());

			// form alert message 주입
			$('input[data-alert-required="ONLYCHK"]').each(function() {
				if($(this).data('alert-msg') === 'addrses') {
					$(this).data('alert-msg', ITP_MSG_LOCALE.message.form.emptyAddr);
				}
			});
			
			// 조회날짜 조건
			$('#ITP_FORM_STINFO02010_SERVICE_ST_DT').val("10");
			
		},
		form: function() {
			itp_fn_form_event.onKeyup('#ITP_FORM_STINFO02010_DETAIL');
			itp_fn_form_event.onKeyup('#ITP_FORM_STINFO02010_SEARCH');
		},
		grid: function() {
			//itp_fn_jqgrid_resize(STINFO02010_GRID_ID, STINFO02010_GRID_LIST, 'lg');
			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_STINFO02010_SRH'					: listObj.button.search();		break;	// 조회 버튼 클릭
						case 'ITP_BTN_STINFO02010_NEWREG'				: listObj.button.create(); 		break;	// 신규등록 버튼
						case 'ITP_BTN_STINFO02010_MODIFY'				: modifyObj.button.modify();	break;	// 수정 버튼
						case 'ITP_BTN_STINFO02010_CANCELLIST'			: createObj.button.cancel(); 	break;	// 취소/목록 버튼
						case 'ITP_BTN_STINFO02010_DELETE'				: 								break;	// 삭제 버튼
						case 'ITP_BTN_STINFO02010_SAVE'					: createObj.button.save(); 		break;	// 저장 버튼
						case 'ITP_FORM_STINFO02010_DETAIL_ADRES_SCH'	: createObj.button.address();	break;	// 신규등록 주소 찾기
					}
				});
			});

		}
	},
	switchScreen: function(mode) {
		$('.itp_det_head').find('button[id^="ITP_BTN_STINFO02010_"]').each(function(i) {
			$(this).hide();
		});
		$('#ITP_TAB_STINFO02010').find('div[id$="_CONTAINER"]').each(function(i) {
			$(this).hide();
		});
		if(mode == 'LIST') { // 목록
			itp_fn_fire_window_resize();
			$('#ITP_AJAX_STINFO02010_LIST_CONTAINER').show();
			fn_show_btn_auth_array(['#ITP_BTN_STINFO02010_SRH', '#ITP_BTN_STINFO02010_NEWREG']);
			$('#ITP_FORM_STINFO02010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId'));
		} else if(mode == 'ADD') { // 등록
			$('#ITP_AJAX_STINFO02010_DETAIL_CONTAINER').show();
			fn_show_btn_auth_array(['#ITP_BTN_STINFO02010_CANCELLIST', '#ITP_BTN_STINFO02010_SAVE']);

			$('#ITP_FORM_STINFO02010_DETAIL').find('input, textarea, select, checkbox').each(function(i, elem) {
				$(this).attr('id') === 'ITP_FORM_STINFO02010_DETAIL_VIEW_CD' ? $(this).val('C') : $(this).val('');
				if(elem.type === 'select') {
					$(this).val('').prop('selected', true);
				}
			});


			// 브랜드그룹 정보 설정
			$('#ITP_FORM_STINFO02010_DETAIL_AFFL_SHOP_ID').val(fn_make_user_info.get('afflShopId'));
			$('#ITP_FORM_STINFO02010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
			$('#ITP_FORM_STINFO02010_DETAIL .fnBrandNm').text(fn_make_user_info.get('brandNm'));

			$('#ITP_FORM_STINFO02010_DETAIL .fnStoreNm').text('(자동부여)');
			$('#ITP_FORM_STINFO02010_DETAIL_STORE_ID').removeAttr('readonly');
			$('#ITP_FORM_STINFO02010_DETAIL .itp_form_info').hide();
			$('#ITP_FORM_STINFO02010_DETAIL .itp_form_info').find('input, select').each(function(i, elem) {
				if($(this).data('check-required')) $(this).data('check-required', '');
				$(this).attr('disabled', true);
			});
			$('#ITP_FORM_STINFO02010_DETAIL .itp_form_change').show();
			$('#ITP_FORM_STINFO02010_DETAIL .itp_form_change').find('input, select').each(function(i, elem) {
				if($(this).data('check-required')) $(this).data('check-required', 'empty');
				$(this).attr('disabled', false);
			});
			$('#ITP_FORM_STINFO02010_DETAIL_FROM_DT').datepicker('setDate', new Date());
			
			$('#ITP_FORM_STINFO02010_DETAIL_BSNS_REG_NO').prop('readonly',false);
			$('#ITP_FORM_STINFO02010_DETAIL_CORP_REG_NO').prop('readonly',false);
			// $('#ITP_FORM_STINFO02010_DETAIL_FROM_DT').val(itp_fn_date_format(new Date(), 4));
		} else if(mode == 'MODIFY') { // 수정
			$('#ITP_AJAX_STINFO02010_DETAIL_CONTAINER').show();
			fn_show_btn_auth_array(['#ITP_BTN_STINFO02010_CANCELLIST', '#ITP_BTN_STINFO02010_SAVE', '#ITP_BTN_STINFO02010_RESET_PW']);

			$('#ITP_FORM_STINFO02010_DETAIL_AFFL_SHOP_ID').val(fn_make_user_info.get('afflShopId'));
			$('#ITP_FORM_STINFO02010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
			$('#ITP_FORM_STINFO02010_DETAIL .fnBrandNm').text(fn_make_user_info.get('brandNm'));

			$('#ITP_FORM_STINFO02010_DETAIL_STORE_ID').attr('readonly', true);
			$('#ITP_FORM_STINFO02010_DETAIL_BSNS_REG_NO').attr('readonly', true);
			$('#ITP_FORM_STINFO02010_DETAIL_CORP_REG_NO').attr('readonly', true);
			// $('#ITP_BTN_STINFO02010_RESET_PW').show();
			$('#ITP_FORM_STINFO02010_DETAIL .itp_form_info').show();
			$('#ITP_FORM_STINFO02010_DETAIL .itp_form_info').find('input, select').each(function(i, elem) {
				if($(this).data('check-required')) $(this).data('check-required', 'empty');
				$(this).attr('disabled', false);
			});
			$('#ITP_FORM_STINFO02010_DETAIL .itp_form_change').hide();
			$('#ITP_FORM_STINFO02010_DETAIL .itp_form_change').find('input, select').each(function(i, elem) {
				if($(this).data('check-required')) $(this).data('check-required', '');
				$(this).attr('disabled', true);
			});

		} else if(mode == 'VIEW') { // 보기
			$('#ITP_AJAX_STINFO02010_VIEW_CONTAINER').show();
			fn_show_btn_auth_array(['#ITP_BTN_STINFO02010_MODIFY', '#ITP_BTN_STINFO02010_CANCELLIST']);
			
		}
	}
};

/*목록화면 Object*/
let listObj = {
	init: function () {
		this.grid.init();
	},
	itp_STINFO02010_search: false,
	button: {
		search: function() {
			listObj.itp_STINFO02010_search = true;
			let param = $('#ITP_FORM_STINFO02010_SEARCH').serializeObject();
			//console.log(param);
			param.gridSize = $.jgrid.defaults.rowNum;
			param.gridPage = $.jgrid.defaults.page;
			$(STINFO02010_GRID_ID).data('grid-param',param);
			$(STINFO02010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
		},
		create: function() {
			pageObj.switchScreen('ADD');
			itp_fn_form_clear_validate(null, '#ITP_FORM_STINFO02010_DETAIL');
			createObj.init();
		}
	},
	empty: {
		init: function() {
		},
		itp_STINFO02010_param: {},
		push: function() {
		},
		back: function() {
		}
	},
	grid: {
		init: function () {
			// 데이터 없을때
			this.search();
		},
		colModel: gridColModel.list,
		search: function() {
			pageObj.switchScreen('LIST');
			this.unload();
			this.load();
		},
		load: function() {
			let param = $('#ITP_FORM_STINFO02010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.sbrandId = fn_make_user_info.get('brandId');
			// param.sbrandId = sessionStorage.getItem('itp_brand_id') !== null ? sessionStorage.getItem('itp_brand_id') : 'BRD221000001';
			//console.log(param);
			var option = {
				gridId: STINFO02010_GRID_ID,
				colModel: gridColModel.list,
				param: param,
				url: DOMAIN + API_DETAIL_GRID_LIST,
				pager: STINFO02010_GRID_PAGER,
				onCellSelect: function(rowId, cellIdx, cellValue) {
					var cm = $(this).jqGrid('getGridParam', 'colModel');
					var colNm = cm[cellIdx].name;
					if (colNm == 'storeId') {
						const selectVal = $(this).jqGrid('getCell', rowId, 'storeId');
						const key = {brandId:fn_make_user_info.get('brandId'), storeId: selectVal, viewCd: 'R'};
						var param = $.param(key);
						viewObj.init(param);
					}
				},
				loadComplete: function(data) {
					//console.log(data);
					itp_fn_grid_load_complete(data, STINFO02010_GRID_ID, true, 'number', 'STINFO02010', listObj.itp_STINFO02010_search, listObj.empty, true, data.gridRecords, true);
					var ids = $(STINFO02010_GRID_ID).getDataIDs();
					$.each(ids, function(idx, rowId) {
						$(STINFO02010_GRID_ID).jqGrid('setCell', rowId, 'storeId', '', ITP_GRID_COL_STYLE.link);
					});
				},
				onPaging: function(action) {
					itp_fn_grid_paging(STINFO02010_GRID_ID, action, param);
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(STINFO02010_GRID_ID).jqGrid('clearGridData', true);
			$(STINFO02010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(STINFO02010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(STINFO02010_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(STINFO02010_GRID_ID);
		}
	}
};

/*상세화면 Object*/
let viewObj = {
	init: function (param) {
		this.load(param);
	},
	load: function(param) {
		fn_ajax_call(API_DETAIL_INFO, param, this.callback, 'GET');
	},
	callback: function (result) {
		console.log(result);
		pageObj.switchScreen('VIEW');
		$('#ITP_FORM_STINFO02010_VIEW #ITP_FORM_STINFO02010_VIEW_STORE_ID').val(result.storeId);
		$('#ITP_FORM_STINFO02010_VIEW .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_STINFO02010_VIEW .fnStCd').text(result.storeStNm);
		$('#ITP_FORM_STINFO02010_VIEW .fnStoreId').text(result.storeId);
		$('#ITP_FORM_STINFO02010_VIEW .fnStoreDvsn').text(result.storeDvsnNm);
		$('#ITP_FORM_STINFO02010_VIEW .fnStoreNm').text(result.storeNm);
		$('#ITP_FORM_STINFO02010_VIEW .fnBsnsCndt').text(result.bsnsCndt);
		$('#ITP_FORM_STINFO02010_VIEW .fnBsnsRegNo').text(result.bsnsRegNo);
		$('#ITP_FORM_STINFO02010_VIEW .fnCtgrBsns').text(result.ctgrBsns);
		$('#ITP_FORM_STINFO02010_VIEW .fnCorpRegNo').text(result.corpRegNo);
		$('#ITP_FORM_STINFO02010_VIEW .fnTelNo').text(result.telNo);
		$('#ITP_FORM_STINFO02010_VIEW .fnOwnerNm').text(result.ownerNm);
		$('#ITP_FORM_STINFO02010_VIEW .fnFaxNo').text(result.faxNo);
		$('#ITP_FORM_STINFO02010_VIEW .fnMblNo').text(result.mblNo);
		$('#ITP_FORM_STINFO02010_VIEW .fnEmalAddr').text(result.emalAddr);
		$('#ITP_FORM_STINFO02010_VIEW .fnAreaCd').text(result.areaNm);
		$('#ITP_FORM_STINFO02010_VIEW .fnFromDt').text(result.openDt);
		$('#ITP_FORM_STINFO02010_VIEW .fnZipNo').text(result.zipNo);
		$('#ITP_FORM_STINFO02010_VIEW .fnLoadAddr').text(result.addr1);
		$('#ITP_FORM_STINFO02010_VIEW .fnDtlAddr').text(result.addr2);

		var cmpyAdres = result.addr1/* + ' ' + result.addr*/;
		kakaoMap.init('ITP_FORM_STINFO02010_VIEW', cmpyAdres);
		
		$('#ITP_FORM_STINFO02010_VIEW #ITP_FORM_STINFO02010_VIEW_BNK_CD').val(result.storeBnkCd);
		let storeBnkNm;
		if (result.storeBnkCd == '') {
			storeBnkNm = '';
		} else {
			storeBnkNm = $('#ITP_FORM_STINFO02010_VIEW_BNK_CD option:selected').text();
		}
		$('#ITP_FORM_STINFO02010_VIEW .fnStoreAcctInfo').text('(' + storeBnkNm + ') ' + result.storeAcctNo + ' (예금주) ' + result.storeOwacNm);
		$('#ITP_FORM_STINFO02010_VIEW .fnLoanDvsn').text(result.loanDvsnNm + " - (" + itp_fn_number_comma(result.limitAmt) + "원)");
		$('#ITP_FORM_STINFO02010_VIEW .fnBrandAcctInfo').text('(' + result.brandBnkNm + ') ' + result.brandAcctNo + ' (예금주) ' + result.brandOwacNm);
		$('#ITP_FORM_STINFO02010_VIEW .fnAcctBal').text(itp_fn_number_comma(result.acctBal) + "원");
		$('#ITP_FORM_STINFO02010_VIEW .fnWhsUseYn').text(result.whsUseYn);
		$('#ITP_FORM_STINFO02010_VIEW .fnLimitAmt').text(result.limitAmt);
		$('#ITP_FORM_STINFO02010_VIEW .fnSysRegDttm').text(result.sysRegDttm);
		$('#ITP_FORM_STINFO02010_VIEW .fnCloseDt').text(result.closeDt);
		
		$('#ITP_FORM_STINFO02010_VIEW .fnOqStoreId').text(result.oqStoreId);
		
	}
};

/*수정화면 Object*/
let modifyObj = {
	init: function () {
	},
	button: {
		modify: function (param) {
			itp_fn_form_clear_validate(null, '#ITP_FORM_STINFO02010_DETAIL');
			const selectVal = $('#ITP_FORM_STINFO02010_VIEW_STORE_ID').val();
			const key = {brandId:fn_make_user_info.get('brandId'), storeId: selectVal, viewCd: 'R'};
			var param = $.param(key);
			modifyObj.load(param);
		}
	},
	load: function(param) {
		fn_ajax_call(API_DETAIL_INFO, param, this.callback, 'GET');
	},
	callback: function (result) {
		//console.log(result);
		pageObj.switchScreen('MODIFY');

		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_VIEW_CD').val('U');
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_STORE_ID').val(result.storeId);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_LOAN_MGNT_UNQ_NO').val(result.loanMgntUnqNo);
		$('#ITP_FORM_STINFO02010_DETAIL .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_STORE_ST_CD').val(result.storeStCd);
		$('#ITP_FORM_STINFO02010_DETAIL .fnStoreNm').text(result.storeId);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_STORE_DVSN').val(result.storeDvsn);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_STORE_NM').val(result.storeNm);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_BSNS_CNDT').val(result.bsnsCndt);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_BSNS_REG_NO').val(result.bsnsRegNo);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_CTGR_BSNS').val(result.ctgrBsns);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_CORP_REG_NO').val(result.corpRegNo);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_TEL_NO').val(result.telNo);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_OWNER_NM').val(result.ownerNm);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_FAX_NO').val(result.faxNo);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_MBL_NO').val(result.mblNo);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_EMAL_ADDR').val(result.emalAddr);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_AREA_CD').val(result.areaCd);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_FROM_DT').val(result.openDt);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_ZIPNO').val(result.zipNo);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_ADRES').val(result.addr1);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_ADRES_DTL').val(result.addr2);

		var cmpyAdres = result.addr1/* + ' ' + result.addr*/;
		kakaoMap.init('ITP_FORM_STINFO02010_DETAIL', cmpyAdres);

		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_BNK_CD').val(result.storeBnkCd);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_ACCT_NO').val(result.storeAcctNo);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_OWAC_NM').val(result.storeOwacNm);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_LOAN_DVSN').val(result.loanDvsn);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_LIMIT_AMT').val(itp_fn_number_comma(result.limitAmt));
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_WHS_USE_YN').val(result.whsUseYn);
		$('#ITP_FORM_STINFO02010_DETAIL .fnBrandAcctInfo').text(result.brandBnkNm + ' ' + result.brandAcctNo + ' ' + result.brandOwacNm);
		$('#ITP_FORM_STINFO02010_DETAIL .fnAcctBal').text(itp_fn_number_comma(result.acctBal) + "원");
		$('#ITP_FORM_STINFO02010_DETAIL .fnTmpRcvAcctTotal').text(result.tmpRcvAcctTotal);
		$('#ITP_FORM_STINFO02010_DETAIL .fnSysChgDttm').text(result.sysChgDttm);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_OQ_BRAND_ID').val(result.oqBrandId);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_OQ_STORE_ID').val(result.oqStoreId);
		
		if (fn_make_user_info.get('storeId') != null && fn_make_user_info.get('storeId') != '') {
			$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_LOAN_DVSN').attr('disabled', true);
			$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_LIMIT_AMT').attr('readonly', true);
		} else {
			$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_LOAN_DVSN').attr('disabled', false);
			$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_LIMIT_AMT').attr('readonly', false);
		}
	}
};

/*신규화면 Object*/
let createObj = {
	init: function () {
		this.load();
		kakaoMap.init('ITP_FORM_STINFO02010_DETAIL', '');
	},
	load: function() {
		$('#ITP_FORM_STINFO02010_DETAIL_OQ_BRAND_ID').val(fn_make_user_info.get('oqBrandId'));
		var param = {keyType:"St"};
        fn_ajax_call(API_GET_KEY, param, this.callback, 'GET');
    },
	callback: function (result) {
		$('#ITP_FORM_STINFO02010_DETAIL .fnStoreNm').text(result.keyData);
		$('#ITP_FORM_STINFO02010_DETAIL #ITP_FORM_STINFO02010_DETAIL_STORE_ID').val(result.keyData);
		$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LOAN_DVSN').on('change', function() {
			if ($('#ITP_FORM_STINFO02010_DETAIL_CREATE_LOAN_DVSN').val() == 'LD02') {
				$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT').attr('data-check-required', 'empty');
			} else {
				$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT').removeAttr('data-check-required');
			}
		});
		
		$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT').on('propertychange change keyup paste input', function() {
			if ($('#ITP_FORM_STINFO02010_DETAIL_CREATE_LOAN_DVSN').val() == 'LD02' && $('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT').val() == '0') {
				let temp = Number.POSITIVE_INFINITY;
				$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT').removeAttr('name');
				$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT_HIDE').val(temp);
				$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT_HIDE').attr('name', 'limitAmt');
			} else {
				$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT_HIDE').removeAttr('name');
				$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT').attr('name', 'limitAmt');
				let temp = $('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT').val();
			}
		});		
	},
	button: {
		address: function() {
			kakaoMap.address('ITP_FORM_STINFO02010_DETAIL');
		},
		cancel: function() {
			listObj.grid.search();
		},
		save: function() {
			const formId = '#ITP_FORM_STINFO02010_DETAIL';
			itp_fn_form_clear_validate(null, formId);
			
			// 여신이 후불이면 후불 한도 입력하돌고 함
			var loanDvsn = $('#ITP_FORM_STINFO02010_DETAIL_CREATE_LOAN_DVSN').val();
			var limAmt = 0;
			var jobtype = 'N';
			
			if (loanDvsn == null || loanDvsn == '') {
				jobtype = 'M';
				loanDvsn = $('#ITP_FORM_STINFO02010_DETAIL_LOAN_DVSN').val();
			}
			
			if (loanDvsn == 'LD02') {
				if (jobtype == 'N') {
					limAmt = $('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT').val();
				} else {
					limAmt = $('#ITP_FORM_STINFO02010_DETAIL_LIMIT_AMT').val();
				}
				
				if (limAmt == '' || limAmt == '0') {
					alert("후불은 한도금액을 입력해야 합니다.");
					return ;
				}
			} else {
				if (jobtype == 'N') {
					$('#ITP_FORM_STINFO02010_DETAIL_CREATE_LIMIT_AMT').val('0');
				} else {
					$('#ITP_FORM_STINFO02010_DETAIL_LIMIT_AMT').val('0');
				}
			}			
			
			if (itp_fn_form_event.isValid(formId)) {
				var modalFn = {
					callBack: (args) => {
						itp_fn_form_event.removeChar('#ITP_FORM_OPER03010_DETAIL');
						let param = $(formId).serializeObject();
						console.log(JSON.stringify(param));
						var searhFn = function () {
							ITP_FORM_STINFO02010_DETAIL_IS_WRITING = false;
							listObj.grid.search();
						}
						fn_ajax_call(API_DETAIL_SAVE, JSON.stringify(param), searhFn, 'POST');
					}
				};
				itp_fn_modal_confirm('저장 하시겠습니까?', modalFn);
			}
			
		}
	}
};
