require(['config'], function() {
	require([
		'kakao.map.util',
		'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			*
 * let sfflyObj = {}		: 공급업체담당자 Object		*
 *******************************************************/

/*화면 변수*/
const STINFO03010_GRID_ID = '#ITP_STINFO03010_jqGrid';
const STINFO03010_GRID_LIST = '#ITP_STINFO03010_jqGrid_list';
const STINFO03010_GRID_PAGER = '#ITP_STINFO03010_jqGridPager';
const STINFO03010_GRID_EMPTY = '#ITP_STINFO03010_jqGridEmpty';

const STINFO03010_VIEW_GRID_ID = '#ITP_STINFO03010_VIEW_jqGrid';
const STINFO03010_VIEW_GRID_LIST = '#ITP_STINFO03010_VIEW_jqGrid_list';
const STINFO03010_VIEW_GRID_PAGER = '#ITP_STINFO03010_VIEW_jqGridPager';
const STINFO03010_VIEW_GRID_EMPTY = '#ITP_STINFO03010_VIEW_jqGridEmpty';

const STINFO03010_DETAIL_GRID_ID = '#ITP_STINFO03010_DETAIL_jqGrid';
const STINFO03010_DETAIL_GRID_LIST = '#ITP_STINFO03010_DETAIL_jqGrid_list';
const STINFO03010_DETAIL_GRID_PAGER = '#ITP_STINFO03010_DETAIL_jqGridPager';
const STINFO03010_DETAIL_GRID_EMPTY = '#ITP_STINFO03010_DETAIL_jqGridEmpty';

let ITP_FORM_STINFO03010_DETAIL_IS_DUPLICATE = false;
let ITP_FORM_STINFO03010_DETAIL_IS_WRITING = false;

let STINFO03010_GRID_LAST_ROW_ID;

let ITP_COMMON_ASSGN_TASK = fn_make_common_cd_list(CODE_LIST, 'ASSGN_TASK', true, '담당업무');

/*API URL*/
let API_DETAIL_GRID_LIST 	= '/api/spply/detail-grid-list';	// 목록
let API_DETAIL_INFO 		= '/api/spply/info-spply';			// 상세
let API_DETAIL_SAVE 		= '/api/spply/save-spply';			// 저장
let API_INTI_PW				= '/api/spply/inti-spplyPw';		// 패스워드 초기화
let API_POP_GRID_LIST 		= '/api/spply/pop-grid-list';		// 공급사 팝업 그리드 리스트

/*화면 Grid ColModel*/
const gridColModel = {
	list: [
		{
			index: 'SFFLY_ID', name: 'spplyId',
			label: ITP_MSG_LOCALE.label.spplyId
			, //공급업체번호
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'SFFLY_NM', name: 'spplyNm',
			label: ITP_MSG_LOCALE.label.spplyNm, //공급업체명
			width: '13', fixed: false, align: 'left',
			sortable: false, hidden: false, classes: 'ui-ellipsis'
		},
		{
			index: 'BRAND_ID', name: 'brandId',
			label: ITP_MSG_LOCALE.label.brandId, //브랜드ID
			width: '10', fixed: false, align: 'center',
			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: '13', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'OWNER_NM', name: 'ownerNm',
			label: ITP_MSG_LOCALE.label.ownerNm, //대표자명
			width: '15', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'ST_NM', name: 'stNm',
			label: ITP_MSG_LOCALE.label.stNm, //상태
			width: '6', 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',
			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: 'SPPLY_ID', name: 'spplyId',
			label: ITP_MSG_LOCALE.label.spplyId,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'SPPLY_MGR_ID', name: 'spplyMgrId',
			label: ITP_MSG_LOCALE.label.spplyMgrId,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'ASSGN_TASK_NM', name: 'spplyMgrNm',
			label: ITP_MSG_LOCALE.label.spplyMgrNm, //담당자명
			width: '16', fixed: false, align: 'center',
			sortable: false, editable: true, edittype: 'text',
			classes: 'input_color',
			editrules: {required: true}, editoptions: {maxlength: 20}
		},
		{
			index: 'POSITION', name: 'position',
			label: ITP_MSG_LOCALE.label.position, //직위
			width: '10', fixed: false, align: 'center',
			sortable: true, editable: true, edittype: 'text',
			classes: 'input_color',
			editrules: {required: true}, editoptions: {maxlength: 20}
		},
		{
			index: 'RPRST_EMAIL', name: 'rprstEmal',
			label: ITP_MSG_LOCALE.label.rprstEmal, //이메일
			width: '20', fixed: false, align: 'center',
			classes: 'input_color',
			sortable: false, editable: true, edittype: 'text',
			editoptions: {maxlength: 50}
		},
		{
			index: 'RPRST_TEL_NO', name: 'rprstTelNo',
			label: ITP_MSG_LOCALE.label.rprstMblNo, //핸드폰번호
			width: '20', fixed: false, align: 'center',
			classes: 'input_color',
			sortable: false, editable: true, edittype: 'text',
			editoptions: {'data-key-up': 'tel', maxlength: 13}
		},
		{
			index: 'ASSGN_TASK', name: 'assgnTask',
			label: ITP_MSG_LOCALE.label.assgnTaskNm, //담당업무
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: true, formatter: 'select', edittype: 'select',
			editoptions: {value: ITP_COMMON_ASSGN_TASK},
			classes: 'input_color',
			editrules: {required: false}
		}/*,
		{
			index: 'ASSGN_TASK_NM', name: 'assgnTaskNm',
			label: ITP_MSG_LOCALE.label.assgnTaskNm, //담당업무
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: true, edittype: 'text'
		}*/
	]
};

/*화면공통 Object*/
let pageObj = {
	init: function () {
		this.ui.init();
		this.event.init();
		this.fileUpload();
	},
	ui: {
		init: function () {
			this.view();
			this.form();
			this.grid();
			this.ready();
		},
		view: function() {
			// 버튼 권한설정
			fn_proc_btn_auth('STINFO03010');

			// 공통코드 표시
			$('select').each(function() {
				if($(this).data('select-code')) {
					fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
				}
			});
		},
		form: function() {
			itp_fn_form_event.onKeyup('#ITP_FORM_STINFO03010_DETAIL');
		},
		grid: function() {
			itp_fn_jqgrid_resize(STINFO03010_GRID_ID, STINFO03010_GRID_LIST, 'lg');
			
		},
		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_STINFO03010_SRH'					: listObj.button.search();		break;	// 조회 버튼 클릭
						case 'ITP_BTN_STINFO03010_NEWREG'				: listObj.button.create(); 		break;	// 신규등록 버튼
						case 'ITP_BTN_STINFO03010_MODIFY'				: modifyObj.button.modify();	break;	// 수정 버튼
						case 'ITP_BTN_STINFO03010_CANCELLIST'			: createObj.button.cancel(); 	break;	// 취소/목록 버튼
						case 'ITP_BTN_STINFO03010_DELETE'				: 								break;	// 삭제 버튼
						case 'ITP_BTN_STINFO03010_SAVE'					: createObj.button.save(); 		break;	// 저장 버튼
						case 'ITP_BTN_STINFO03010_DETAIL_ADDROW'		: createObj.button.addRow();	break;	// 행추가
						case 'ITP_BTN_STINFO03010_DETAIL_DELROW'		: createObj.button.delRow();	break;	// 행삭제
						case 'ITP_FORM_STINFO03010_DETAIL_ADRES_SCH'	: createObj.button.address();	break;	// 신규등록 주소 찾기
					}
				});
			});

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

		}
	},
	fileUpload: function() {
		//파일업로드(등록/수정화면)
		var id = 'STINFO03010';
		var acctScrId = 'STINFO03010_ACCT';
		$('#ITP_' + id + '_DETAIL_ACCT_FILE_UPLOAD').empty();
		const acctFileArgs = {
			'fileNo': $('#ITP_FORM_' + id + '_DETAIL_ACCT_FILE_NO').val(),
			'viewCd': $('#ITP_FORM_' + id + '_DETAIL_VIEW_CD').val(),
			'showYn': $('#ITP_' + id + '_DETAIL_ACCT_FILE_UPLOAD').attr('data-show-yn'),
			'fileId': '#ITP_FORM_' + id + '_DETAIL_ACCT_FILE_NO' //파일번호를 서버에서 받아서 넣을 파일번호 인풋박스 아이디
		};
		itp_fn_set_file_upload('ITP_' + id + '_DETAIL_ACCT_FILE_UPLOAD', 'notice', true, false, acctScrId, acctFileArgs);

		var corpScrId = 'STINFO03010_CORP';
		$('#ITP_' + id + '_DETAIL_CORP_FILE_UPLOAD').empty();
		const corpFileArgs = {
			'fileNo': $('#ITP_FORM_' + id + '_DETAIL_CORP_FILE_NO').val(),
			'viewCd': $('#ITP_FORM_' + id + '_DETAIL_VIEW_CD').val(),
			'showYn': $('#ITP_' + id + '_DETAIL_CORP_FILE_UPLOAD').attr('data-show-yn'),
			'fileId': '#ITP_FORM_' + id + '_DETAIL_CORP_FILE_NO' //파일번호를 서버에서 받아서 넣을 파일번호 인풋박스 아이디
		};
		itp_fn_set_file_upload('ITP_' + id + '_DETAIL_CORP_FILE_UPLOAD', 'notice', true, false, corpScrId, corpFileArgs);
	},
	switchScreen: function(mode) {
		$('.itp_det_head').find('button[id^="ITP_BTN_STINFO03010_"]').each(function(i) {
			$(this).hide();
		});
		$('#ITP_TAB_STINFO03010').find('div[id$="_CONTAINER"]').each(function(i) {
			$(this).hide();
		});
		if(mode == 'LIST') { // 목록
			itp_fn_fire_window_resize();
			fn_show_btn_auth_array(['#ITP_BTN_STINFO03010_SRH', '#ITP_BTN_STINFO03010_NEWREG']);
			$('#ITP_AJAX_STINFO03010_LIST_CONTAINER').show();
			$('#ITP_FORM_STINFO03010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId'));
		} else if(mode == 'ADD') { // 등록
			fn_show_btn_auth_array(['#ITP_BTN_STINFO03010_CANCELLIST', '#ITP_BTN_STINFO03010_SAVE']);
			$('#ITP_AJAX_STINFO03010_DETAIL_CONTAINER').show();

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

			// 브랜드그룹 정보 설정
			$('#ITP_FORM_STINFO03010_DETAIL_AFFL_SHOP_ID').val(fn_make_user_info.get('afflShopId'));
			$('#ITP_FORM_STINFO03010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
			$('#ITP_FORM_STINFO03010_DETAIL .fnBrandNm').text(fn_make_user_info.get('brandNm'));
			$('#ITP_FORM_STINFO03010_DETAIL .fnSpplyId').text('(자동부여) (비밀번호는 사업자번호로 초기화 됩니다.)');
			$('#ITP_FORM_STINFO03010_DETAIL .itp_form_info').hide();
			$('#ITP_FORM_STINFO03010_DETAIL .itp_form_change').show();

			$('#ITP_BTN_STINFO03010_RESET_PW').hide();
			$.bootstrapFileUpload('resetUpload', "ITP_STINFO03010_DETAIL_ACCT_FILE_UPLOAD");
			$.bootstrapFileUpload('resetUpload', "ITP_STINFO03010_DETAIL_CORP_FILE_UPLOAD");
		} else if(mode == 'MODIFY') { // 수정
			fn_show_btn_auth_array(['#ITP_BTN_STINFO03010_CANCELLIST', '#ITP_BTN_STINFO03010_SAVE', '#ITP_BTN_STINFO03010_RESET_PW']);
			$('#ITP_AJAX_STINFO03010_DETAIL_CONTAINER').show();
			$('#ITP_BTN_STINFO03010_RESET_PW').show();
			$('#ITP_FORM_STINFO03010_DETAIL .itp_form_info').show();
			$('#ITP_FORM_STINFO03010_DETAIL .itp_form_change').hide();

			$('#ITP_FORM_STINFO03010_DETAIL_AFFL_SHOP_ID').val(fn_make_user_info.get('afflShopId'));
			$('#ITP_FORM_STINFO03010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
			$('#ITP_FORM_STINFO03010_DETAIL .fnBrandNm').text(fn_make_user_info.get('brandNm'));
			$.bootstrapFileUpload('resetUpload', "ITP_STINFO03010_DETAIL_ACCT_FILE_UPLOAD");
			$.bootstrapFileUpload('resetUpload', "ITP_STINFO03010_DETAIL_CORP_FILE_UPLOAD");
		} else if(mode == 'VIEW') { // 보기
			fn_show_btn_auth_array(['#ITP_BTN_STINFO03010_MODIFY', '#ITP_BTN_STINFO03010_CANCELLIST']);
			$('#ITP_AJAX_STINFO03010_VIEW_CONTAINER').show();
		}
	},
	grid: {
		init: function(mode, gridRows) {
			this.gridId = (mode === 'VIEW') ? STINFO03010_VIEW_GRID_ID : STINFO03010_DETAIL_GRID_ID;
			this.gridList = (mode === 'VIEW') ? STINFO03010_VIEW_GRID_LIST : STINFO03010_DETAIL_GRID_LIST;
			this.gridEmpty = (mode === 'VIEW') ? STINFO03010_VIEW_GRID_EMPTY : STINFO03010_DETAIL_GRID_EMPTY;
			this.gridRows = gridRows;
			this.unload();
			this.load(mode, gridRows);
		},
		gridId: '',
		gridList: '',
		gridEmpty: '',
		gridRows: '',
		load: function(mode, gridRows) {
			var _this = this;
			var option = {
				gridId: _this.gridId,
				colModel: gridColModel.detail,
				data: gridRows,
				multiselect: (mode !== 'VIEW'),
				// cellEdit: (mode !== 'VIEW'),
				loadComplete: function(data) {
					$(_this.gridList).find('.ui-jqgrid .ui-jqgrid-bdiv').css('overflow-x', 'hidden');
					(Array.isArray(data.rows) && data.rows.length === 0) ? $(_this.gridEmpty).show() : $(_this.gridEmpty).hide();
				},
				onCellSelect: function(rowid, cellIdx, cellValue) {
					console.log('mode ===> ' + mode);
					if(mode !== 'VIEW') {
						STINFO03010_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowid, cellIdx, STINFO03010_GRID_LAST_ROW_ID, _this.gridId, ['actionId']);
						itp_fn_form_event.onKeyup(STINFO03010_DETAIL_GRID_ID);
					}
				}
			};
			itp_fn_grid_make_local(option);
		},
		unload : function() {
			$.jgrid.gridUnload(this.gridId);
		},
		changeRows: function(gridRows) {
			var modifyRows = [];
			var chkColumns = ['spplyMgrNm', 'position', 'rprstEmal', 'rprstTelNo', 'assgnTask'];
			$.each(this.gridRows, function(index, item) {
				var row = gridRows[index];
				if(row.viewCd === 'C') {
					modifyRows.push(item);
				} else {
					if(row.itemId === item.itemId) {
						$.each(chkColumns, function(index, column) {
							if(row[column].toString() !== item[column].toString()) {
								row.viewCd = 'U';
								modifyRows.push(row);
								return false;
							}
						});
					}
				}
			});
			return modifyRows;
		}
	}
};

/*목록화면 Object*/
let listObj = {
	init: function () {
		this.grid.init();
	},
	itp_STINFO03010_search: false,
	button: {
		search: function() {
			listObj.itp_STINFO03010_search = true;
			let param = $('#ITP_FORM_STINFO03010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.gridPage = $.jgrid.defaults.page;
			$(STINFO03010_GRID_ID).data('grid-param',param);
			$(STINFO03010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
		},
		create: function() {
			if(!fn_make_user_info.isEmpty()) {
				createObj.init();
			}
		}
	},
	empty: {
		init: function() {
		},
		itp_STINFO03010_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_STINFO03010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.sbrandId = fn_make_user_info.get('brandId');
			
			var option = {
				gridId: STINFO03010_GRID_ID,
				colModel: gridColModel.list,
				param: param,
				url: DOMAIN + API_DETAIL_GRID_LIST,
				pager: STINFO03010_GRID_PAGER,
				onCellSelect: function(rowId, cellIdx, cellValue) {
					var cm = $(this).jqGrid('getGridParam', 'colModel');
					var colNm = cm[cellIdx].name;
					if (colNm == 'spplyId') {
						const selectVal = $(this).jqGrid('getCell', rowId, 'spplyId');
						const key = {brandId:fn_make_user_info.get('brandId'), spplyId: selectVal, viewCd: 'R'};
						var param = $.param(key);
						viewObj.init(param);
					}
				},
				loadComplete: function(data) {
					console.log(data);
					itp_fn_grid_load_complete(data, STINFO03010_GRID_ID, true, 'number', 'STINFO03010', listObj.itp_STINFO03010_search, listObj.empty, true, data.gridRecords, true);
					var ids = $(STINFO03010_GRID_ID).getDataIDs();
					$.each(ids, function(idx, rowId) {
						$(STINFO03010_GRID_ID).jqGrid('setCell', rowId, 'spplyId', '', ITP_GRID_COL_STYLE.link);
					});
				},
				onPaging: function(action) {
					itp_fn_grid_paging(STINFO03010_GRID_ID, action, param);
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(STINFO03010_GRID_ID).jqGrid('clearGridData', true);
			$(STINFO03010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(STINFO03010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(STINFO03010_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(STINFO03010_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) {
		pageObj.switchScreen('VIEW');
		console.log(result);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_SPPLY_ID').val(result.spplyId);
		$('#ITP_FORM_STINFO03010_VIEW .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_STINFO03010_VIEW .fnStCd').text(result.stNm);
		$('#ITP_FORM_STINFO03010_VIEW .fnSpplyId').text(result.spplyId);
		$('#ITP_FORM_STINFO03010_VIEW .fnCorpType').text(result.corpTypeNm);
		$('#ITP_FORM_STINFO03010_VIEW .fnSpplyNm').text(result.spplyNm);
		$('#ITP_FORM_STINFO03010_VIEW .fnBsnsCndt').text(result.bsnsCndt);
		$('#ITP_FORM_STINFO03010_VIEW .fnBsnsRegNo').text(result.bsnsRegNo);
		$('#ITP_FORM_STINFO03010_VIEW .fnCtgrBsns').text(result.ctgrBsns);
		$('#ITP_FORM_STINFO03010_VIEW .fnCorpRegNo').text(result.corpRegNo);
		$('#ITP_FORM_STINFO03010_VIEW .fnTelNo').text(result.mgrTelNo);
		$('#ITP_FORM_STINFO03010_VIEW .fnOwnerNm').text(result.ownerNm);
		$('#ITP_FORM_STINFO03010_VIEW .fnFaxNo').text(result.faxNo);
		$('#ITP_FORM_STINFO03010_VIEW .fnMblNo').text(result.mgrMblNo);
		$('#ITP_FORM_STINFO03010_VIEW .fnEmalAddr').text(result.mgrEmal);
		$('#ITP_FORM_STINFO03010_VIEW .fnAreaCd').text(result.areaNm);
		$('#ITP_FORM_STINFO03010_VIEW .fnBnkCd').text(result.bnkNm);
		$('#ITP_FORM_STINFO03010_VIEW .fnAcctNo').text(result.acctNo);
		$('#ITP_FORM_STINFO03010_VIEW .fnOwacNm').text(result.owacNm);
		// 통장사본 fileBookCopyNoList
		$('#ITP_FORM_STINFO03010_VIEW .fnFilePath').text(result.fileBookCopyNoList);
		// 사업자등록파일 fileBsnsRegNoList
		$('#ITP_FORM_STINFO03010_VIEW .fnFilePath').text(result.fileBsnsRegNoList);
		$('#ITP_FORM_STINFO03010_VIEW .fnZipNo').text(result.zipNo);
		$('#ITP_FORM_STINFO03010_VIEW .fnLoadAddr').text(result.addr1);
		$('#ITP_FORM_STINFO03010_VIEW .fnDtlAddr').text(result.addr2);
		// $('#ITP_FORM_STINFO03010_VIEW .fnRegDt').text(result.openDt);
		// $('#ITP_FORM_STINFO03010_VIEW .fnCloseDt').text(result.openDt);

		itp_fn_attach_file.view('ITP_STINFO03010_VIEW_ACCT_FILE', result.fileBookCopyNoList
			, 'form-control itp_input', 'border:none; top:12px; left:12px; height:100px; width:125px; position:absolute;');

		itp_fn_attach_file.view('ITP_STINFO03010_VIEW_REG_NO_FILE', result.fileBsnsRegNoList
			, 'form-control itp_input', 'border:none; top:12px; left:12px; height:100px; width:125px; position:absolute;');
		 
		
		/*
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_VIEW_CD').val('R');
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_STORE_ID').val(result.storeId);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_BRAND_ID').val(fn_make_user_info.get('brandId'));
		$('#ITP_FORM_STINFO03010_VIEW .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_ST_CD').val(result.stCd);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_SPPLY_ID').val(result.spplyId);
		$('#ITP_FORM_STINFO03010_VIEW .fnSpplyId').text(result.spplyId);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_CORP_TYPE').val(result.corpType);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_SPPLY_NM').val(result.spplyNm);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_BSNS_CNDT').val(result.bsnsCndt);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_BSNS_REG_NO').val(result.bsnsRegNo); 
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_CTGR_BSNS').val(result.ctgrBsns);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_CORP_REG_NO').val(result.corpRegNo);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_TEL_NO').val(result.mgrTelNo);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_OWNER_NM').val(result.ownerNm);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_FAX_NO').val(result.faxNo);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_MBL_NO').val(result.mgrMblNo);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_EMAL_ADDR').val(result.mgrEmal);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_AREA_CD').val(result.areaCd);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_BNK_CD').val(result.bnkCd);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_ACCT_NO').val(result.acctNo);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_OWAC_NM').val(result.owacNm);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_FROM_DT').val(result.openDt);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_ZIPNO').val(result.zipNo);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_ADRES').val(result.addr1);
		$('#ITP_FORM_STINFO03010_VIEW #ITP_FORM_STINFO03010_VIEW_ADRES_DTL').val(result.addr2);
		*/
		
		$('#ITP_FORM_STINFO03010_VIEW .fnRegId').text(result.sysRegId);
		$('#ITP_FORM_STINFO03010_VIEW .fnRegDt').text(result.sysRegDttm);
		$('#ITP_FORM_STINFO03010_VIEW .fnChgId').text(result.sysChgId);
		$('#ITP_FORM_STINFO03010_VIEW .fnChgDt').text(result.sysChgDttm);
		formReadonly("#ITP_FORM_STINFO03010_VIEW .form-control");
		fileUploadInfo3010('ACCT_FILE',result.fileBookCopyNoList);
		fileUploadInfo3010('CORP_FILE',result.fileBsnsRegNoList);
		
		// 담당자정보  리스트 조회
		pageObj.grid.init('VIEW', result.spplyMgrList);
		// viewObj.grid.load(result.spplyMgrList);
	}
};

/*수정화면 Object*/
let modifyObj = {
	init: function () {
	},
	button: {
		modify: function (param) {
			itp_fn_form_clear_validate(null, '#ITP_FORM_STINFO03010_DETAIL');
			const selectVal = $('#ITP_FORM_STINFO03010_VIEW_SPPLY_ID').val();
			const key = {brandId:fn_make_user_info.get('brandId'), spplyId: 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_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_VIEW_CD').val('U');
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_STORE_ID').val(result.storeId);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
		$('#ITP_FORM_STINFO03010_DETAIL .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_ST_CD').val(result.stCd);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_SPPLY_ID').val(result.spplyId);
		$('#ITP_FORM_STINFO03010_DETAIL .fnSpplyId').text(result.spplyId);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_CORP_TYPE').val(result.corpType);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_SPPLY_NM').val(result.spplyNm);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_BSNS_CNDT').val(result.bsnsCndt);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_BSNS_REG_NO').val(result.bsnsRegNo);
		$('#ITP_FORM_STINFO03010_DETAIL .fnBsnsRegNo').text(result.bsnsRegNo);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_CTGR_BSNS').val(result.ctgrBsns);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_CORP_REG_NO').val(result.corpRegNo);
		$('#ITP_FORM_STINFO03010_DETAIL .fnCorpRegNo').text(result.corpRegNo);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_TEL_NO').val(result.mgrTelNo);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_OWNER_NM').val(result.ownerNm);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_FAX_NO').val(result.faxNo);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_MBL_NO').val(result.mgrMblNo);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_EMAL_ADDR').val(result.mgrEmal);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_AREA_CD').val(result.areaCd);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_BNK_CD').val(result.bnkCd);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_ACCT_NO').val(result.acctNo);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_OWAC_NM').val(result.owacNm);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_FROM_DT').val(result.openDt);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_ZIPNO').val(result.zipNo);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_ADRES').val(result.addr1);
		$('#ITP_FORM_STINFO03010_DETAIL #ITP_FORM_STINFO03010_DETAIL_ADRES_DTL').val(result.addr2);

		$('#ITP_FORM_STINFO03010_DETAIL .fnRegId').text(result.sysRegId);
		$('#ITP_FORM_STINFO03010_DETAIL .fnRegDt').text(result.sysRegDttm);
		$('#ITP_FORM_STINFO03010_DETAIL .fnChgId').text(result.sysChgId);
		$('#ITP_FORM_STINFO03010_DETAIL .fnChgDt').text(result.sysChgDttm);

		// 담당자정보  리스트 조회
		pageObj.grid.init('DETAIL', result.spplyMgrList);
		// modifyObj.grid.load(result.spplyMgrList);
	}
};

/*신규화면 Object*/
let createObj = {
	init: function () {
		pageObj.switchScreen('ADD');
		itp_fn_form_clear_validate(null, '#ITP_FORM_STINFO03010_DETAIL');
		$('#ITP_FORM_STINFO03010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
		pageObj.grid.init('DETAIL', []);
	},
	button: {
		cancel: function() {
			listObj.grid.search();
		},
		address: function() {
			kakaoMap.simpleAddress('ITP_FORM_STINFO03010_DETAIL');
		},
		addRow: function() {
			itp_fn_grid_add_row(STINFO03010_DETAIL_GRID_ID, undefined, ['spplyId'], 'STINFO03010_DETAIL');
			itp_fn_form_event.onKeyup(STINFO03010_DETAIL_GRID_ID);
		},
		delRow: function() {
			itp_fn_grid_del_row(STINFO03010_DETAIL_GRID_ID);
		},
		save: function() {
			const formId = '#ITP_FORM_STINFO03010_DETAIL';
			itp_fn_form_clear_validate(null, formId);

			if (itp_fn_form_event.isValid(formId)) {
				itp_fn_grid_save_rows(STINFO03010_DETAIL_GRID_ID);
				let gridInsertData = [];
				// let gridUpdateData = [];
				let gridDeleteData = [];
				for(var i=0; i<$(STINFO03010_DETAIL_GRID_ID).getGridParam('reccount'); i++) {
					$(STINFO03010_DETAIL_GRID_ID).jqGrid('saveCell', i+1, 2)
				}
				const rowData = $(STINFO03010_DETAIL_GRID_ID).getRowData();
				var gridUpdateData = pageObj.grid.changeRows(rowData);
				$.each(rowData, function(key, value) {
					if (value.viewCd !== 'R') {
						if (value.viewCd === 'C') {
							value.spplyId = $(formId + '_SPPLY_ID').val();
							gridInsertData.push(value);
						} else if (value.viewCd === 'U') {
							gridUpdateData.push(value);
						} else if (value.viewCd === 'D') {
							gridDeleteData.push(value);
						}
					}
				});
				itp_fn_form_event.removeChar(formId);
				let param = $(formId).serializeObject();
				param.gridInsertData = gridInsertData;
				param.gridUpdateData = gridUpdateData;
				param.gridDeleteData = gridDeleteData;
				console.log(JSON.stringify(param));
				var searhFn = function() {
					ITP_FORM_STINFO03010_DETAIL_IS_WRITING = false;
					listObj.grid.search();
				};
				fn_ajax_call(API_DETAIL_SAVE, JSON.stringify(param), searhFn, 'POST');
			}
		}
	}
};

function fileUploadInfo3010(name, arr, type ) {
	//파일업로드(등록/수정화면)
	if(!type) type= 'VIEW';
	if(!name) name='ACCT_FILE';
	var uid='#ITP_STINFO03010_'+type+'_'+name+'_UPLOAD';
	var fid='#ITP_FORM_STINFO03010_'+type+'_'+name+'_NO';
	var sid='ITP_STINFO03010_'+type+'_'+name;
	var viewCd=type=='VIEW' ? 'R': 'U';
	if(Array.isArray(arr) && arr.length ) {
		$(fid).val(arr[0].fileNo);
	}
	$(uid).empty();  
	$(uid).bootstrapFileUpload({
		url: DOMAIN + '/api/file/upload',
		inputName: 'uploadFile',
		folderName: 'notice',
		fileNumber:  $(fid).val(),
		fileInput: fid,
		fileTypes: ITP_UPLOAD_DEFAULTS.fileTypes,
		viewCode: viewCd,
		formMethod: 'post',
		multiFile: true,
		multiUpload: false,
		maxSize: 100,
		maxFiles: 5,
		showThumb: true,
		thumbWidth: 80,
  		thumbHeight: 80,
		debug: true, 
		screen_id: sid,
		showYn: false,
		onInit: function() {
			 
		}
	});
	setTimeout(function() {
		$('#'+sid+'_UPLOAD_FORM').hide();
		/*
		$(uid+' .fileupload-add').hide();
		$(uid+' .filedownload-remove').hide();
		*/
	},20);
}