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

/*화면 변수*/
const STOCKMNG04011_VIEW_GRID_ID = '#ITP_STOCKMNG04011_VIEW_jqGrid';
const STOCKMNG04011_VIEW_GRID_LIST = '#ITP_STOCKMNG04011_VIEW_jqGrid_list';
const STOCKMNG04011_VIEW_GRID_PAGER = '#ITP_STOCKMNG04011_VIEW_jqGridPager';
const STOCKMNG04011_VIEW_GRID_EMPTY = '#ITP_STOCKMNG04011_VIEW_jqGridEmpty';

const STOCKMNG04011_DETAIL_GRID_ID = '#ITP_STOCKMNG04011_DETAIL_jqGrid';
const STOCKMNG04011_DETAIL_GRID_LIST = '#ITP_STOCKMNG04011_DETAIL_jqGrid_list';
const STOCKMNG04011_DETAIL_GRID_PAGER = '#ITP_STOCKMNG04011_DETAIL_jqGridPager';
const STOCKMNG04011_DETAIL_GRID_EMPTY = '#ITP_STOCKMNG04011_DETAIL_jqGridEmpty';

let ITP_FORM_STOCKMNG04011_DETAIL_IS_DUPLICATE = false;
let ITP_FORM_STOCKMNG04011_DETAIL_IS_WRITING = false;
let STOCKMNG04011_DETAIL_GRID_LAST_ROW_ID;

/* 공통코드 리스트 */
let ITP_COMMON_CD_STCK_DVSN = fn_make_common_cd_list(CODE_LIST, 'STCK_DVSN', true);
let ITP_COMMON_CD_LOC_ST_CD = fn_make_common_cd_list(CODE_LIST, 'LOC_ST_CD', true);

/*API URL*/
let WHS_MNG_LOCATION_GRID_LIST = '/api/whs/mng/location-grid-list';
let WHS_MNG_INFO_WHS = '/api/whs/mng/info-whs';
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'; 

/*화면 Grid ColModel*/
const gridColModel = {
	view: [
		{
			index: 'VIEW_CD', name: 'viewCd',
			label: ITP_MSG_LOCALE.label.viewCd,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},		
		{
			index: 'LOCATION', name: 'location',
			label: "로케이션",
			width: '7', fixed: false, align: 'left',
			sortable: false, editable: false, edittype: 'text',
			editrules: {required: true}
		},
		{
			index: 'LOCATION_NM', name: 'locationNm',
			label: "로케이션명",
			width: '25', fixed: false, align: 'left',
			sortable: true, editable: false, edittype: 'text',
			editrules: {required: true}, classes: 'ui-ellipsis'
		},
		{
			index: 'STCK_DVSN_NM', name: 'stckDvsnNm',
			label: "관리등록",
			width: '6', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'LOC_ST_NM', name: 'locStNm',
			label: "상태",
			width: '6', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		}
	],
	detail: [
		{
			index: 'VIEW_CD', name: 'viewCd',
			label: ITP_MSG_LOCALE.label.viewCd,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'LOCATION', name: 'location',
			label: "로케이션",
			width: '7', fixed: false, align: 'left',
			sortable: false, editable: true, edittype: 'text',
			editrules: {required: false}
		},
		{
			index: 'LOCATION_NM', name: 'locationNm',
			label: "로케이션명",
			width: '25', fixed: false, align: 'left',
			classes: 'input_color',
			sortable: false, editable: true, edittype: 'text',
			editrules: {required: true}, classes: 'ui-ellipsis',
			editoptions: {maxlength: 50}
		},
		{
			index: 'STCK_DVSN', name: 'stckDvsn',
			label: "관리등록",
			width: '6', fixed: false, align: 'center',
			sortable: false, editable: true, formatter: 'select', edittype: 'select',
			editoptions: {value: ITP_COMMON_CD_STCK_DVSN},
			classes: 'input_color',
			editrules: {required: true}
		},
		{
			index: 'LOC_ST_CD', name: 'locStCd',
			label: "상태",
			width: '6', fixed: false, align: 'center',
			sortable: false, editable: true, formatter: 'select', edittype: 'select',
			editoptions: {value: ITP_COMMON_CD_LOC_ST_CD},
			classes: 'input_color',
			editrules: {required: true}
		}
	]
};

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

/*화면공통 Object*/
let pageObj = {
	init: function () {
		this.ui.init();
		this.event.init();
		locInfoObj.init();
	},
	ui: {
		init: function () {
			this.view();
			this.form();
			this.ready();
		},
		view: function() {
			// 버튼 권한설정
			fn_proc_btn_auth('STOCKMNG04011');
			
			// 브랜드ID 지정
			$('#ITP_FORM_STOCKMNG04011_VIEW_BRAND_ID').val(fn_make_user_info.get('brandId'));
			$('#ITP_FORM_STOCKMNG04011_VIEW_STORE_ID').val(fn_make_user_info.get('storeId'));
			
			// 공통코드 표시
			fn_make_select(CODE_LIST, 'WHS_ST_CD', 'ITP_FORM_STOCKMNG04011_DETAIL_WHS_ST_CD', true, '선택');
		},
		form: function() {
			itp_fn_form_event.onKeyup('#ITP_FORM_STOCKMNG04011_DETAIL');
		},
		ready: function() {
			pageObj.changeView();	
		}
	},
	changeView: function() {
		const brandIdVal = $('#ITP_FORM_STOCKMNG04011_VIEW_BRAND_ID').val();
		const storeIdVal = $('#ITP_FORM_STOCKMNG04011_VIEW_STORE_ID').val();
					
		const key = {brandId: brandIdVal, storeId: storeIdVal, whsId: '', viewCd: 'R'};
		var param = $.param(key);
		viewObj.init(param);
	}, 
	event: {
		init: function () {
			this.button();
		},
		button: function () {
			// 버튼 클릭 이벤트
			$('button').each(function() {
				var id = $(this).attr('id');
				$(this).on('click', function() {
					switch (id) {
						case 'ITP_BTN_STOCKMNG04011_MODIFY'				: modifyObj.button.modify();	break;	// 수정 버튼
						case 'ITP_BTN_STOCKMNG04011_CANCELLIST'			: modifyObj.button.cancel(); 	break;	// 취소/목록 버튼
						case 'ITP_BTN_STOCKMNG04011_SAVE'				: modifyObj.button.save(); 		break;	// 저장 버튼
						case 'ITP_BTN_STOCKMNG04011_DETAIL_ADDROW'		: locInfoObj.button.addRow();	break;	// 상세:추가버튼
						case 'ITP_BTN_STOCKMNG04011_DETAIL_DELROW'		: locInfoObj.button.delRow();	break;	// 상세:삭제버튼
						case 'ITP_BTN_STOCKMNG04011_DETAIL_ADDRESS_SEARCH'		: modifyObj.button.address();	break;	// 신규등록 주소 찾기
					}
				});
			});

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

		}
	},
	switchScreen: function(mode) {
		if(mode == 'MODIFY') { // 수정
			$('#ITP_BTN_STOCKMNG04011_SRH').hide();
			$('#ITP_BTN_STOCKMNG04011_MODIFY').hide();
			$('#ITP_BTN_STOCKMNG04011_NEWREG').hide();
			$('#ITP_BTN_STOCKMNG04011_DELETE').hide();
			fn_show_btn_auth('#ITP_BTN_STOCKMNG04011_CANCELLIST');
			fn_show_btn_auth('#ITP_BTN_STOCKMNG04011_SAVE');
			fn_show_btn_auth('#ITP_BTN_STOCKMNG04011_RESET_PW');

			$('#ITP_AJAX_STOCKMNG04011_LIST_CONTAINER').hide();
			$('#ITP_AJAX_STOCKMNG04011_DETAIL_CONTAINER').show();
			$('#ITP_AJAX_STOCKMNG04011_VIEW_CONTAINER').hide();
			// $('#ITP_FORM_STOCKMNG04011_DETAIL_USER_ID').attr('readonly', true);
			// $('#ITP_FORM_STOCKMNG04011_DETAIL_DUP').attr('disabled', true);
			$('#ITP_FORM_STOCKMNG04011_DETAIL_SEARCH_AFFL_SHOP_NM').attr('readonly', true);

			$('#ITP_FORM_STOCKMNG04011_DETAIL_SEARCH_AFFL_SHOP').hide();
			$('#ITP_FORM_STOCKMNG04011_DETAIL_DELETE_AFFL_SHOP').hide();
		} else if(mode == 'VIEW') { // 보기
			$('#ITP_BTN_STOCKMNG04011_SRH').hide();
			$('#ITP_BTN_STOCKMNG04011_NEWREG').hide();
			$('#ITP_BTN_STOCKMNG04011_DELETE').hide();
			$('#ITP_BTN_STOCKMNG04011_SAVE').hide();
			$('#ITP_BTN_STOCKMNG04011_CANCELLIST').hide();
			
			fn_show_btn_auth('#ITP_BTN_STOCKMNG04011_MODIFY');

			$('#ITP_AJAX_STOCKMNG04011_LIST_CONTAINER').hide();
			$('#ITP_AJAX_STOCKMNG04011_DETAIL_CONTAINER').hide();
			$('#ITP_AJAX_STOCKMNG04011_VIEW_CONTAINER').show();
		}
	}
};

/*상세화면 Object*/
let viewObj = {
	init: function (param) {
		this.load(param);
	},
	load: function(param) {
		fn_ajax_call(WHS_MNG_INFO_WHS, param, this.callback, 'GET');
	},
	callback: function (result) {
		// console.log(result);
		pageObj.switchScreen('VIEW');
		$('#ITP_FORM_STOCKMNG04011_VIEW #ITP_FORM_STOCKMNG04011_VIEW_BRAND_ID').val(result.brandId);
		$('#ITP_FORM_STOCKMNG04011_VIEW #ITP_FORM_STOCKMNG04011_VIEW_STORE_ID').val(result.storeId);
		$('#ITP_FORM_STOCKMNG04011_VIEW #ITP_FORM_STOCKMNG04011_VIEW_WHS_ID').val(result.whsId);
		
		$('#ITP_FORM_STOCKMNG04011_VIEW .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_STOCKMNG04011_VIEW .fnStCd').text(result.whsStNm);
		$('#ITP_FORM_STOCKMNG04011_VIEW .fnWhsId').text(result.whsId);
		$('#ITP_FORM_STOCKMNG04011_VIEW .fnWhsNm').text(result.whsNm);
		$('#ITP_FORM_STOCKMNG04011_VIEW .fnTelNo').text(result.mgrTelNo);
		$('#ITP_FORM_STOCKMNG04011_VIEW .fnMgrNm').text(result.mgrNm);		
		$('#ITP_FORM_STOCKMNG04011_VIEW .fnSpplyNm').text(result.storeNm ? result.storeNm : '');		
		$('#ITP_FORM_STOCKMNG04011_VIEW .fnRegDtm').text(result.sysRegDttm);
		if(result.zipNo) {
			$('#ITP_FORM_STOCKMNG04011_VIEW .fnAddress').text('('+result.zipNo+') ' + result.addr1 + ' ' + result.addr2);	
		}		

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

			var option = {
				gridId: STOCKMNG04011_VIEW_GRID_ID,
				colModel: gridColModel.view,
				param: param,
				url: DOMAIN + WHS_MNG_LOCATION_GRID_LIST,
				pager: STOCKMNG04011_VIEW_GRID_PAGER,
				loadComplete: function(data) {
					itp_fn_grid_load_complete(data, STOCKMNG04011_VIEW_GRID_ID, true, undefined, 'STOCKMNG04011_VIEW');
				},
				onPaging: function(action) {
					var pagingFn = {
						callBack: function(args) {
							$(args).trigger('reloadGrid');
						}
					};
					if (itp_fn_check_grid_is_writing(STOCKMNG04011_VIEW_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, pagingFn, STOCKMNG04011_VIEW_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_paging(STOCKMNG04011_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(STOCKMNG04011_VIEW_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, sortingFn, STOCKMNG04011_VIEW_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_sorting(STOCKMNG04011_VIEW_GRID_ID, index, sortOrder);
					}
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(STOCKMNG04011_VIEW_GRID_ID).jqGrid('clearGridData', true);
			$(STOCKMNG04011_VIEW_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(STOCKMNG04011_VIEW_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(STOCKMNG04011_VIEW_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(STOCKMNG04011_VIEW_GRID_ID);
		}
	}
};

/*수정화면 Object*/
let modifyObj = {
	init: function () {
	},
	button: {
		modify: function (param) {
			itp_fn_form_clear_validate(null, '#ITP_FORM_STOCKMNG04011_DETAIL');
			const brandIdVal = $('#ITP_FORM_STOCKMNG04011_VIEW_BRAND_ID').val();
			const storeIdVal = $('#ITP_FORM_STOCKMNG04011_VIEW_STORE_ID').val();
			const whsIdVal = $('#ITP_FORM_STOCKMNG04011_VIEW_WHS_ID').val();
			const key = {brandId: brandIdVal, storeId: storeIdVal, whsId: whsIdVal, viewCd: 'R'};
			var param = $.param(key);
			modifyObj.load(param);
		}, 
		cancel: function() {
			pageObj.changeView();
		}, 
		save: function() {
			var detailViewCd = $('#ITP_FORM_STOCKMNG04011_DETAIL_VIEW_CD').val();
			const formId = '#ITP_FORM_STOCKMNG04011_DETAIL';
			itp_fn_form_clear_validate(null, formId);
			
			var vali_whsStatCd = itp_fn_form_validate(formId, formId + '_WHS_ST_CD', ['empty'], undefined); // 상태
			var vali_whsNm = itp_fn_form_validate(formId, formId + '_WHS_NM', ['empty'], undefined);
			
			if (vali_whsStatCd && vali_whsNm) {
				let gridInsertData = [];
				let gridUpdateData = [];
				let gridDeleteData = [];
				const rowData = $(STOCKMNG04011_DETAIL_GRID_ID).getRowData();
				// const keyValue = $(formId + '_WHS_ID').val();
				$.each(rowData, function(key, value) {
					if (value.viewCd != 'R') {
						// value.whsId = keyValue;
						if (value.viewCd == 'C') {
							gridInsertData.push(value);
						} else if (value.viewCd == 'U') {
							gridUpdateData.push(value);
						} else if (value.viewCd == 'D') {
							gridDeleteData.push(value);
						}
					}
				});
				let param = $(formId).serializeObject();
				param.gridInsertData = gridInsertData;
				param.gridUpdateData = gridUpdateData;
				param.gridDeleteData = gridDeleteData;
				//console.log(JSON.stringify(param));
				var searhFn = function() {
					ITP_FORM_STOCKMNG04011_DETAIL_IS_WRITING = false;
					pageObj.changeView();					
				};
				fn_ajax_call(detailViewCd == 'C' ? WHS_MNG_ADD_WHS : WHS_MNG_MIDIFY_WHS, JSON.stringify(param), searhFn, 'POST');
			}
		}, 
		address: function() {
			kakaoMap.address('ITP_FORM_STOCKMNG04011_DETAIL');
		}
	},
	load: function(param) {
		fn_ajax_call(WHS_MNG_INFO_WHS, param, this.callback, 'GET');
	},
	callback: function (result) {
		// console.log(result);
		pageObj.switchScreen('MODIFY');
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_VIEW_CD').val('U');
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_BRAND_ID').val(result.brandId);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_STORE_ID').val(result.storeId);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_WHS_ID').val(result.whsId);
				
		$('#ITP_FORM_STOCKMNG04011_DETAIL .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_STOCKMNG04011_DETAIL .fnWhsId').text(result.whsId);
		$('#ITP_FORM_STOCKMNG04011_DETAIL .fnRegDtm').text(result.sysRegDttm);
		
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_WHS_ST_CD').val(result.whsStCd);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_WHS_NM').val(result.whsNm);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_WHS_NM').val(result.whsNm);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_MGR_TEL_NO').val(result.mgrTelNo);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_MGR_NM').val(result.mgrNm);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_STORE_NM').val(result.storeNm);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_ZIPNO').val(result.zipNo);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_ADRES').val(result.addr1);
		$('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_ADRES_DTL').val(result.addr2);
		
		kakaoMap.init('ITP_FORM_STOCKMNG04011_DETAIL', $('#ITP_FORM_STOCKMNG04011_DETAIL #ITP_FORM_STOCKMNG04011_DETAIL_ADRES').val());
		
		// 권한정보 리스트 조회
		modifyObj.grid.init();
	},
	grid: {
		init: function() {
			this.unload();
			this.load();
		},
		load : function() {
			let param = $('#ITP_FORM_STOCKMNG04011_DETAIL').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.pagingYn = false; // 페이지안함

			var option = {
				gridId: STOCKMNG04011_DETAIL_GRID_ID,
				colModel: gridColModel.detail,
				param: param,
				url: DOMAIN + WHS_MNG_LOCATION_GRID_LIST,
				pager: STOCKMNG04011_DETAIL_GRID_PAGER,
				multiselect: true,
				onCellSelect: function(rowId, cellIdx, cellValue) {
					STOCKMNG04011_DETAIL_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowId, cellIdx, STOCKMNG04011_DETAIL_GRID_LAST_ROW_ID, STOCKMNG04011_DETAIL_GRID_ID, ['location']);
		   		},
				loadComplete: function(data) {
					itp_fn_grid_load_complete(data, STOCKMNG04011_DETAIL_GRID_ID, true, undefined, 'STOCKMNG04011_DETAIL');
				},
				onPaging: function(action) {
					var pagingFn = {
						callBack: function(args) {
							$(args).trigger('reloadGrid');
						}
					};
					if (itp_fn_check_grid_is_writing(STOCKMNG04011_DETAIL_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, pagingFn, STOCKMNG04011_DETAIL_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_paging(STOCKMNG04011_DETAIL_GRID_ID, action, param);
					}
				},
				onSortCol: function(index, columnIndex, sortOrder) {
					var sortingFn = {
						callBack: function(args) {
							$(args).trigger('reloadGrid');
						}
					};
					if (itp_fn_check_grid_is_writing(STOCKMNG04011_DETAIL_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, sortingFn, STOCKMNG04011_DETAIL_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_sorting(STOCKMNG04011_DETAIL_GRID_ID, index, sortOrder);
					}
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(STOCKMNG04011_DETAIL_GRID_ID).jqGrid('clearGridData', true);
			$(STOCKMNG04011_DETAIL_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(STOCKMNG04011_DETAIL_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(STOCKMNG04011_DETAIL_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(STOCKMNG04011_DETAIL_GRID_ID);
		}
	}
};

/*로케이션정보 Object*/
let locInfoObj = {
	init: function () {
		// if(AUTH_TYPE_CD === '10' || AUTH_TYPE_CD === '20') {
		this.action();
		// } else {
		// this.make();
		// }
	},
	button: {
		addRow: function() {
			// $(STOCKMNG04011_DETAIL_GRID_ID).jqGrid('addRow', {position: 'last'});
			// $(STOCKMNG04011_DETAIL_GRID_EMPTY).hide();
			STOCKMNG04011_DETAIL_GRID_LAST_ROW_ID = itp_fn_add_grid_row(STOCKMNG04011_DETAIL_GRID_ID, undefined, ['location'],'STOCKMNG04011_DETAIL');
		},
		delRow: function() {
			itp_fn_grid_del_row(STOCKMNG04011_DETAIL_GRID_ID);
		}
	},
	make: function() {
		$('#ITP_FORM_STOCKMNG04011_SEARCH_AFFL_SHOP').hide();
		$('#ITP_FORM_STOCKMNG04011_DELETE_AFFL_SHOP').hide();
		if(AFFL_SHOP_LIST) {
			$('#ITP_FORM_STOCKMNG04011_SEARCH_AFFL_SHOP_ID').val(AFFL_SHOP_LIST[0].afflShopId);
			$('#ITP_FORM_STOCKMNG04011_SEARCH_AFFL_SHOP_NM').val(AFFL_SHOP_LIST[0].afflShopNm);
		}
		if(AFFL_BRAND_LIST) {
			fn_make_select_brand(AFFL_BRAND_LIST, 'ITP_FORM_STOCKMNG04011_SEARCH_BRAND_ID');
		}
	},
	action: function () {
		var _this = this;
		// 로케이션정보 조회 버튼 클릭
		$('#ITP_FORM_STOCKMNG04011_SEARCH_AFFL_SHOP').on('click', function() {
			_this.popup('L');
		});
		// 로케이션정보 텍스트 삭제 버튼 클릭
		$('#ITP_FORM_STOCKMNG04011_DELETE_AFFL_SHOP').on('click', function() {
			$('#ITP_FORM_STOCKMNG04011_SEARCH_AFFL_SHOP_NM').val('');
			$('select#ITP_FORM_STOCKMNG04011_SEARCH_BRAND_ID option').remove();
		});
		// 신규등록 로케이션정보 조회 버튼 클릭
		$('#ITP_FORM_STOCKMNG04011_DETAIL_SEARCH_AFFL_SHOP').on('click', function() {
			_this.popup('C');
		});
		// 신규등록 로케이션정보 텍스트 삭제 버튼 클릭
		$('#ITP_FORM_STOCKMNG04011_DETAIL_DELETE_AFFL_SHOP').on('click', function() {
			$('#ITP_FORM_STOCKMNG04011_DETAIL_SEARCH_AFFL_SHOP_NM').val('');
			$('select#ITP_FORM_STOCKMNG04011_DETAIL_SEARCH_BRAND_ID option').remove();
		});
	},
	popup: function (view) {
		// 팝업
		var popFn = (view === 'C') ? this.callback.create : this.callback.list;
		fn_call_popup('biz', 'BIZPOP_AFFL_SHOP', '#ITP_ASIDE', popFn, null, 'S');
	},
	callback: {
		list: function(rowDataPop) {
			// console.log(rowDataPop);
			if(rowDataPop.AFFL_SHOP) {
				$('#ITP_FORM_STOCKMNG04011_SEARCH_AFFL_SHOP_ID').val(rowDataPop.AFFL_SHOP.afflShopId);
				$('#ITP_FORM_STOCKMNG04011_SEARCH_AFFL_SHOP_NM').val(rowDataPop.AFFL_SHOP.afflShopNm);
			}
			if(rowDataPop.AFFL_BRAND) {
				fn_make_select_brand(rowDataPop.AFFL_BRAND, 'ITP_FORM_STOCKMNG04011_SEARCH_BRAND_ID', true, '선택');
			}
		},
		create: function(rowDataPop) {
			// console.log(rowDataPop);
			if(rowDataPop.AFFL_SHOP) {
				// $('#ITP_FORM_STOCKMNG04011_DETAIL_SEARCH_AFFL_SHOP_ID').val(rowDataPop.AFFL_SHOP.afflShopId);
				// $('#ITP_FORM_STOCKMNG04011_DETAIL_SEARCH_AFFL_SHOP_NM').val(rowDataPop.AFFL_SHOP.afflShopNm);
			}
			if(rowDataPop.AFFL_BRAND) {
				fn_make_select_brand(rowDataPop.AFFL_BRAND, 'ITP_FORM_STOCKMNG04011_DETAIL_SEARCH_BRAND_ID', true, '선택');
			}
		}
	}
};