require(['config'], function() {
	require([
			'jquery.bootstrap.fileUpload' //파일 업로드가 있는 페이지에서 로딩
	], function($) {
			pageObj.init();
	});
});

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

/*화면 변수*/
const POMNG05010_GRID_ID = '#ITP_POMNG05010_jqGrid';
const POMNG05010_GRID_LIST = '#ITP_POMNG05010_jqGrid_list';
const POMNG05010_GRID_PAGER = '#ITP_POMNG05010_jqGridPager';
const POMNG05010_GRID_EMPTY = '#ITP_POMNG05010_jqGridEmpty';

let ITP_FORM_POMNG05010_DETAIL_IS_DUPLICATE = false;
let ITP_FORM_POMNG05010_DETAIL_IS_WRITING = false;

/*API URL*/
let API_DETAIL_GRID_LIST 	= '/api/pomng/inoutmng/deli-grid-list';// 목록
let API_DETAIL_INFO 		= '/api/pomng/inoutmng/info-inv';	// 상세
let API_DETAIL_SAVE 		= '/api/pomng/inoutmng/deli-grid-list';			// 저장
let API_ITEM_CLASS_LEVEL	= '/api/item/class-level-list';		//품목분류 level 검색

/*화면 Grid ColModel*/
const gridColModel = {
	list: [
	
			{
					index: 'Brand_Nm', name: 'brandNm',
					label: ITP_MSG_LOCALE.label.brandNm, //브랜드
					width: '8', fixed: false, align: 'center',
					sortable: false, hidden: false
			},
			{
					index: 'DLV_STTMT_NO', name: 'dlvSttmtUnqNo',
					label: ITP_MSG_LOCALE.label.dlvSttmtUnqNo, //납품서번호
					width: '10', fixed: false, align: 'center',
					sortable: false, hidden: false
			},
			{
					index: 'poBsnsRegno', name: 'poBsnsRegno',
					label: ITP_MSG_LOCALE.label.poBsnsRegno, //발주번호
					width: '10', fixed: false, align: 'center',
					sortable: false, hidden: false
			},
			{
					index: 'ITEM_CLASS_NM', name: 'SPPLY_NM',
					label: ITP_MSG_LOCALE.label.itemClassNm, //공급업체
					width: '10', fixed: false, align: 'center',
					sortable: false, hidden: false
			},
			{
					index: 'ITEM_ST_CD', name: 'stCd',
					label: ITP_MSG_LOCALE.label.stNm, //납품서상태
					width: '6', fixed: false, align: 'center',
					sortable: false, hidden: true
			},
			{
					index: 'PODR_PSSBLDVSN_NM', name: 'podrPssblDvsnNm',
					label: ITP_MSG_LOCALE.label.podrPssblDvsnNm, //발입고처
					width: '6', fixed: false, align: 'center',
					sortable: false, hidden: false
			},
			{
					index: 'UNIT', name: 'unit',
					label: ITP_MSG_LOCALE.label.unit, //발주생성일
					width: '6', fixed: false, align: 'center',
					sortable: false, hidden: true
			},
			{
					index: 'PCH_ITEM_YN', name: 'pchItemYn',
					label: ITP_MSG_LOCALE.label.pchItemYn, //납품요청일
					width: '6', fixed: false, align: 'center',
					sortable: false, hidden: false
			},
			{
					index: 'SALE_ITEM_YN', name: 'saleItemYn',
					label: ITP_MSG_LOCALE.label.saleItemYn, //납품생성일
					width: '10', fixed: false, align: 'center',
					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();
			this.fileUpload();
	},
	ui: {
			init: function () {
					this.view();
					this.grid();
					this.ready();
			},
			view: function() {
					// 버튼 권한설정
					fn_proc_btn_auth('POMNG05010');

					// 공통코드 표시
					$('select').each(function() {
							if($(this).data('select-code')) {
									fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
							}
					});

					itemClassLevel.make(1, 'LIST');
			},
			grid: function() {
					itp_fn_jqgrid_resize(POMNG05010_GRID_ID, POMNG05010_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_POMNG05010_SRH'				: listObj.button.search();		break;	// 조회 버튼 클릭
											case 'ITP_BTN_POMNG05010_NEWREG'			: listObj.button.create(); 		break;	// 신규등록 버튼
											case 'ITP_BTN_POMNG05010_MODIFY'			: modifyObj.button.modify();	break;	// 수정 버튼
											case 'ITP_BTN_POMNG05010_CANCELLIST'		: createObj.button.cancel(); 	break;	// 취소/목록 버튼
											case 'ITP_BTN_POMNG05010_DELETE'			: 								break;	// 삭제 버튼
											case 'ITP_BTN_POMNG05010_SAVE'				: createObj.button.save(); 		break;	// 저장 버튼
											case 'ITP_FORM_POMNG05010_DETAIL_DUP'		: createObj.button.duplicate();	break;	// 중복체크
											case 'ITP_BTN_POMNG05010_RESET_PW'			: createObj.button.resetPass();	break;	// 상세:비밀번호 초기화
									}
							});
					});

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

			}
	},
	fileUpload: function() {
			//파일업로드(등록/수정화면)
			var id = 'POMNG05010';
			$('#ITP_' + id + '_DETAIL_UPLOAD').empty();
			const fileArgs = {
					'fileNo': $('#ITP_FORM_' + id + '_DETAIL_FILE_NO').val(),
					'viewCd': $('#ITP_FORM_' + id + '_DETAIL_VIEW_CD').val(),
					'showYn': $('#ITP_' + id + '_DETAIL_UPLOAD').attr('data-show-yn'),
					'fileId': '#ITP_FORM_' + id + '_DETAIL_FILE_NO' //파일번호를 서버에서 받아서 넣을 파일번호 인풋박스 아이디
			};
			itp_fn_set_file_upload('ITP_' + id + '_DETAIL_UPLOAD', 'notice', true, false, id, fileArgs);
	},
	switchScreen: function(mode) {
			$('.itp_det_head').find('button[id^="ITP_BTN_POMNG05010_"]').each(function(i) {
					$(this).hide();
			});
			$('#ITP_TAB_POMNG05010').find('div[id$="_CONTAINER"]').each(function(i) {
					$(this).hide();
			});
			if(mode == 'LIST') { // 목록
					$('#ITP_AJAX_POMNG05010_LIST_CONTAINER').show();
					fn_show_btn_auth_array(['#ITP_BTN_POMNG05010_SRH', '#ITP_BTN_POMNG05010_MODIFY']);
			} else if(mode == 'ADD') { // 등록
					$('#ITP_AJAX_POMNG05010_DETAIL_CONTAINER').show();
					fn_show_btn_auth_array(['#ITP_BTN_POMNG05010_CANCELLIST', '#ITP_BTN_POMNG05010_SAVE']);

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

					$('#ITP_FORM_POMNG05010_DETAIL_STORE_ID').removeAttr('readonly');
					$('#ITP_FORM_POMNG05010_DETAIL_DUP').removeAttr('disabled');

					// 가맹점 정보 설정
					$('#ITP_FORM_POMNG05010_DETAIL_AFFL_SHOP_ID').val(fn_make_user_info.get('afflShopId'));
					$('#ITP_FORM_POMNG05010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
					$('#ITP_FORM_POMNG05010_DETAIL .fnBrandNm').text(fn_make_user_info.get('brandNm'));
					$('#ITP_FORM_POMNG05010_DETAIL .fnItemClassMgntNo').text('(자동부여)');
			} else if(mode == 'MODIFY') { // 수정
					$('#ITP_AJAX_POMNG05010_DETAIL_CONTAINER').show();
					fn_show_btn_auth_array(['#ITP_BTN_POMNG05010_CANCELLIST', '#ITP_BTN_POMNG05010_SAVE', '#ITP_BTN_POMNG05010_RESET_PW']);

					$('#ITP_FORM_POMNG05010_DETAIL_AFFL_SHOP_ID').val(fn_make_user_info.get('afflShopId'));
					$('#ITP_FORM_POMNG05010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
					$('#ITP_FORM_POMNG05010_DETAIL .fnBrandNm').text(fn_make_user_info.get('brandNm'));
					$('#ITP_FORM_POMNG05010_DETAIL_STORE_ID').attr('readonly', true);
					$('#ITP_FORM_POMNG05010_DETAIL_DUP').attr('disabled', true);
					$('#ITP_FORM_POMNG05010_DETAIL_SEARCH_AFFL_SHOP_NM').attr('readonly', true);

					$('#ITP_FORM_POMNG05010_DETAIL_SEARCH_AFFL_SHOP').hide();
					$('#ITP_FORM_POMNG05010_DETAIL_DELETE_AFFL_SHOP').hide();
			} else if(mode == 'VIEW') { // 보기
					$('#ITP_AJAX_POMNG05010_VIEW_CONTAINER').show();
					$('#ITP_FORM_POMNG05010_VIEW .fnBrandNm').text(fn_make_user_info.get('brandNm'));
					fn_show_btn_auth_array(['#ITP_BTN_POMNG05010_MODIFY', '#ITP_BTN_POMNG05010_CANCELLIST']);
			}
	}
};

/*목록화면 Object*/
let listObj = {
	init: function () {
			this.form();
			this.grid.init();
	},
	itp_POMNG05010_search: false,
	button: {
			search: function() {
					listObj.itp_POMNG05010_search = true;
					let param = $('#ITP_FORM_POMNG05010_SEARCH').serializeObject();
					param.gridSize = $.jgrid.defaults.rowNum;
					param.gridPage = $.jgrid.defaults.page;
					$(POMNG05010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
			},
			create: function() {
					if(!fn_make_user_info.isEmpty()) {
							createObj.init();
					}
			}
	},
	form: function() {
			$('#ITP_FORM_POMNG05010_SEARCH_ITEM_CLASS1').on('change', function() {
					($(this).val() === '') ? itemClassLevel.clear(2): itemClassLevel.change(2);
			});
			$('#ITP_FORM_POMNG05010_SEARCH_ITEM_CLASS2').on('change', function() {
					($(this).val() === '') ? itemClassLevel.clear(3): itemClassLevel.change(3);
			});
			$('#ITP_FORM_POMNG05010_SEARCH_ITEM_CLASS3').on('change', function() {
					($(this).val() === '') ? itemClassLevel.clear(4): itemClassLevel.change(4);
			});
	},
	empty: {
			init: function() {
					var _this = this;
					this.push();
					$(POMNG05010_GRID_EMPTY).on('click', function() {
							_this.back();
							_this.itp_POMNG05010_param.gridSize = $.jgrid.defaults.rowNum;
							$(POMNG05010_GRID_ID).setGridParam({'postData': JSON.stringify(_this.itp_POMNG05010_param)}).trigger('reloadGrid');
					});
			},
			itp_POMNG05010_param: {},
			push: function() {
					let param = $('#ITP_FORM_POMNG05010_SEARCH').serializeObject();
					listObj.itp_POMNG05010_param = param;
			},
			back: function() {
					$('#ITP_FORM_POMNG05010_SERVICE_ST_CD').val(this.itp_POMNG05010_param.sitemStCd);
					$('#ITP_FORM_POMNG05010_SEARCH_PODR_PSSBL_DVSN').val(this.itp_POMNG05010_param.spodrPssblDvsn);
					$('#ITP_FORM_POMNG05010_SEARCH_ITEM_KIND').val(this.itp_POMNG05010_param.sitemKind);
					$('#ITP_FORM_POMNG05010_SEARCH_ITEM_TYPE').val(this.itp_POMNG05010_param.sitemType);
					$('#ITP_FORM_POMNG05010_SEARCH_ITEM_CLASS1').val(this.itp_POMNG05010_param.sitemClass1);
					$('#ITP_FORM_POMNG05010_SEARCH_ITEM_CLASS2').val(this.itp_POMNG05010_param.sitemClass2);
					$('#ITP_FORM_POMNG05010_SEARCH_ITEM_CLASS3').val(this.itp_POMNG05010_param.sitemClass3);
					$('#ITP_FORM_POMNG05010_SEARCH_ITEM_CLASS4').val(this.itp_POMNG05010_param.sitemClass4);
					$('#ITP_FORM_POMNG05010_SEARCH_ITEM_NM').val(this.itp_POMNG05010_param.sitemNm);
			}
	},
	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_POMNG05010_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';

					var option = {
							gridId: POMNG05010_GRID_ID,
							colModel: gridColModel.list,
							param: JSON.stringify(param),
							url: DOMAIN + API_DETAIL_GRID_LIST,
							pager: POMNG05010_GRID_PAGER,
							onCellSelect: function(rowId, cellIdx, cellValue) {
									var cm = $(this).jqGrid('getGridParam', 'colModel');
									var colNm = cm[cellIdx].name;
									if (colNm == 'itemId') {
											const selectVal = $(this).jqGrid('getCell', rowId, 'itemId');
											const key = {brandId:fn_make_user_info.get('brandId'), itemId: selectVal, viewCd: 'R'};
											var param = $.param(key);
											viewObj.init(param);
									}
							},
							loadComplete: function(data) {
									console.log(data);
									itp_fn_grid_load_complete(data, POMNG05010_GRID_ID, true, 'number', 'POMNG05010', listObj.itp_POMNG05010_search, listObj.empty, true, data.gridRecords, true);
									var ids = $(POMNG05010_GRID_ID).getDataIDs();
									$.each(ids, function(idx, rowId) {
											$(POMNG05010_GRID_ID).jqGrid('setCell', rowId, 'itemId', '', ITP_GRID_COL_STYLE.link);
									});
							},
							onPaging: function(action) {
									itp_fn_grid_paging(POMNG05010_GRID_ID, action, param);
							}
					};
					itp_fn_grid_make_remote(option);
			},
			clearData : function() {
					$(POMNG05010_GRID_ID).jqGrid('clearGridData', true);
					$(POMNG05010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
					$(POMNG05010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
					$(POMNG05010_GRID_EMPTY).show();
			},
			unload : function() {
					$.jgrid.gridUnload(POMNG05010_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_POMNG05010_VIEW #ITP_FORM_POMNG05010_VIEW_ITEM_ID').val(result.itemId);
			$('#ITP_FORM_POMNG05010_VIEW .fnStCd').text(result.itemStCd);
			$('#ITP_FORM_POMNG05010_VIEW .fnItemClass1').text(result.itemClass1);
			$('#ITP_FORM_POMNG05010_VIEW .fnItemClass2').text(result.itemClass2);
			$('#ITP_FORM_POMNG05010_VIEW .fnItemClass3').text(result.itemClass3);
			$('#ITP_FORM_POMNG05010_VIEW .fnItemClass4').text(result.itemClass4);
			$('#ITP_FORM_POMNG05010_VIEW .fnItemClassMgntNo').text(result.itemClassMgntNo);
			$('#ITP_FORM_POMNG05010_VIEW .fnItemId').text(result.itemId);
			$('#ITP_FORM_POMNG05010_VIEW .fnItemTypeNm').text(result.itemTypeNm);
			$('#ITP_FORM_POMNG05010_VIEW .fnItemNm').text(result.itemClassNm);
			$('#ITP_FORM_POMNG05010_VIEW .fnImpDvsnNm').text(result.impDvsnNm);
			$('#ITP_FORM_POMNG05010_VIEW .fnPodrPssblDvsn').text(result.podrPssblDvsnNm);
			$('#ITP_FORM_POMNG05010_VIEW .fnUnit').text(result.unit);
			$('#ITP_FORM_POMNG05010_VIEW .fnWeightUnit').text(result.weightUnit);
			$('#ITP_FORM_POMNG05010_VIEW .fnVolumeUnit').text(result.volumeUnit);
			$('#ITP_FORM_POMNG05010_VIEW .fnWidthUnit').text(result.widthUnit);
			$('#ITP_FORM_POMNG05010_VIEW .fnHeightUnit').text(result.heightUnit);
			$('#ITP_FORM_POMNG05010_VIEW .fnHighUnit').text(result.highUnit);
			
			$('#ITP_FORM_POMNG05010_VIEW .fnPchItemYn').text(result.pchItemYn);
			$('#ITP_FORM_POMNG05010_VIEW .fnViewPchUnit').text(result.pchUnit);
			$('#ITP_FORM_POMNG05010_VIEW .fnSaleItemYn').text(result.saleItemYn);
			$('#ITP_FORM_POMNG05010_VIEW .fnSaleUnit').text(result.saleUnit);
			$('#ITP_FORM_POMNG05010_VIEW .fnAssetInfo').text(result.assetInfo);
			$('#ITP_FORM_POMNG05010_VIEW .fnStckUnit').text(result.stckUnit);
			$('#ITP_FORM_POMNG05010_VIEW .fnWeight').text(result.weight);
			$('#ITP_FORM_POMNG05010_VIEW .fnVolume').text(result.volume);
			$('#ITP_FORM_POMNG05010_VIEW .fnWidth').text(result.width);
			$('#ITP_FORM_POMNG05010_VIEW .fnHeight').text(result.height);
			$('#ITP_FORM_POMNG05010_VIEW .fnHigh').text(result.high);
			
			$('#ITP_FORM_POMNG05010_VIEW .fnOneBoxQty').text(result.oneBoxQty);
			$('#ITP_FORM_POMNG05010_VIEW .fnExpryYn').text(result.expryYn);
			$('#ITP_FORM_POMNG05010_VIEW .fnExpryPeriod').text(result.expryPeriod);
			$('#ITP_FORM_POMNG05010_VIEW .fnRtnPssblYn').text(result.rtnPssblYn);
			$('#ITP_FORM_POMNG05010_VIEW .fnRtnDvsn').text(result.rtnDvsnNm);
			// $('#ITP_FORM_POMNG05010_VIEW .fnItemImage').text(result.imageFileNoList);
			$.each(result.imageFileNoList, function(index, item) {
					$('#ITP_FORM_POMNG05010_VIEW .fnItemImage').append('<img src=" + item.filePath +" />');
			});
	}
};

/*수정화면 Object*/
let modifyObj = {
	init: function () {
	},
	button: {
			modify: function (param) {
					itp_fn_form_clear_validate(null, '#ITP_FORM_POMNG05010_DETAIL');
					const selectVal = $('#ITP_FORM_POMNG05010_VIEW_ITEM_ID').val();
					const key = {brandId:fn_make_user_info.get('brandId'), itemId: 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_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_VIEW_CD').val('U');
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_ITEM_ID').val(result.itemId);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_STORE_ST_CD').val(result.itemStCd);
			$('#ITP_FORM_POMNG05010_DETAIL .fnItemClassMgntNo').text(result.itemId);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_ITEM_TYPE').val(result.itemType);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_ITEM_NM').val(result.itemClassNm);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_IMP_DVSN').val(result.impDvsn);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_PODR_PSSBL_DVSN').val(result.podrPssblDvsn);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_UNIT').val(result.unit);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_PCH_ITEM_YN').val(result.pchItemYn);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_PCH_UNIT').val(result.pchUnit);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_SALE_ITEM_YN').val(result.saleItemYn);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_SALE_UNIT').val(result.saleUnit);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_ASSET_INFO').val(result.assetInfo);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_STCK_UNIT').val(result.stckUnit);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_WEIGHT').val(result.weight);
			$('#ITP_FORM_POMNG05010_DETAIL .item_unit').text(result.unit);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_VOLUME').val(result.volume);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_WIDTH').val(result.width);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_HEIGHT').val(result.height);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_HIGH').val(result.high);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_ONE_BOX_QTY').val(result.oneBoxQty);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_EXPRY_YN').val(result.expryYn);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_EXPRY_PERIOD').val(result.expryPeriod);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_RTN_PSSBL_YN').val(result.rtnPssblYn);
			$('#ITP_FORM_POMNG05010_DETAIL #ITP_FORM_POMNG05010_DETAIL_RTN_DVSN').val(result.rtnDvsn);
			$.each(result.imageFileNoList, function(index, item) {
					$('#ITP_FORM_POMNG05010_VIEW .ITEM_IMAGE').append('<img src=" + item.filePath +" />');
			});

			itemClassLevel.data.push(result.itemClass1);
			itemClassLevel.data.push(result.itemClass2);
			itemClassLevel.data.push(result.itemClass3);
			itemClassLevel.data.push(result.itemClass4);
			itemClassLevel.make(1, 'MODIFY');
	}
};

/*신규화면 Object*/
let createObj = {
	init: function () {
			pageObj.switchScreen('ADD');
			itp_fn_form_clear_validate(null, '#ITP_FORM_POMNG05010_DETAIL');
			this.button.init();
			itemClassLevel.make(1, 'ADD');
	},
	button: {
			init: function() {
					$('#ITP_FORM_POMNG05010_DETAIL_ITEM_CLASS1').off('change').on('change', function() {
							($(this).val() === '') ? itemClassLevel.clear(2): itemClassLevel.change(2);
					});
					$('#ITP_FORM_POMNG05010_DETAIL_ITEM_CLASS2').off('change').on('change', function() {
							($(this).val() === '') ? itemClassLevel.clear(3): itemClassLevel.change(3);
					});
					$('#ITP_FORM_POMNG05010_DETAIL_ITEM_CLASS3').off('change').on('change', function() {
							($(this).val() === '') ? itemClassLevel.clear(4): itemClassLevel.change(4);
					});
			},
			cancel: function() {
					listObj.grid.search();
			},
			save: function() {
					const formId = '#ITP_FORM_POMNG05010_DETAIL';
					itp_fn_form_clear_validate(null, formId);
					if (createObj.isValid(formId)) {
							let param = $(formId).serializeObject();
							console.log(JSON.stringify(param));
							var searhFn = function() {
									ITP_FORM_POMNG05010_DETAIL_IS_WRITING = false;
									listObj.grid.search();
							};
							fn_ajax_call(API_DETAIL_SAVE, JSON.stringify(param), searhFn, 'POST');
					}
			}
	},
	isValid: function(formId) {
			var isValid = false;
			$(formId).find('input, select, checkbox, textarea').each(function(k) {
					if($(this).data('check-required')) {
							var arry = $(this).data('check-required').split(',');
							isValid = itp_fn_form_validate(formId, '#' + $(this).attr('id'), arry, undefined);
							if(!isValid) return false;
					}
			});
			return isValid;
	}
};

var itemClassLevel = {
	level: 1,
	levelID: '',
	data: [],
	keys: function() {
			var keys = {sBrandId:fn_make_user_info.get('brandId'), sItemLevel: this.level};
			for(var i=1; i<=this.level; i++) {
					var key = 'sItemClass' + i;
					var id = '#' + this.levelID + i;
					keys[key] = $(id + ' option:selected').val();
			}
			return keys;
	},
	make: function(level, mode) {
			this.level = level;
			this.levelID = (mode === 'LIST' ? 'ITP_FORM_POMNG05010_SEARCH_ITEM_CLASS' : 'ITP_FORM_POMNG05010_DETAIL_ITEM_CLASS');
			if(mode !== 'MODIFY') {
					this.data.length = 0;
					this.clear(1);
			}
			this.call($.param(this.keys()), mode === 'MODIFY');
	},
	change: function(level) {
			this.level = level;
			this.clear(level);
			this.call($.param(this.keys()), false);
	},
	call: function(param, isModify) {
			var _this = this;
			var callbackFn = function(result) {
					var id = _this.levelID + _this.level;
					fn_make_select_item_class(result.searchList, id, true, _this.emptyText());
					if(isModify) {
							$('#' + id).val(_this.data[ _this.level - 1]);
							if(_this.level < _this.data.length) {
									if(_this.data[_this.level] !== '') {
											_this.level++;
											_this.call( $.param(_this.keys()), isModify);
									}
							}
					}
			};
			fn_ajax_call(API_ITEM_CLASS_LEVEL, param, callbackFn, 'GET');
	},
	emptyText: function() {
			return '품목분류Level' + this.level;
	},
	clear: function(level) {
			for(var i=level; i<5; i++) {
					$('#' + (this.levelID + i)).find('option:not(:first)').remove();
			}
	}
};
