require(['config'], function() {
	require([
	], function($) {
		mobPageObj.init();
	});
});

/*API URL*/
const API_MOBILE_INIT_INFO	= '/api/pomng/init-pchReq';
const API_MOBILE_SAVE		= '/api/pomng/save-pchReq';
const API_POP_SEARCH_LIST	= '/api/whs/mng/pop-whs-search';
const API_POP_ITEM_LIST 	= '/api/item/pop-grid-list';

const ID_ITP_POP_MPOMNG01010_REQ_AREA 	= "ITP_POP_MPOMNG01010_REQ_AREA";
const ID_ITP_POP_MPOMNG01010_WHS_AREA 	= "ITP_POP_MPOMNG01010_WHS_AREA";
const ID_ITP_POP_MPOMNG01010_ITEM_AREA 	= "ITP_POP_MPOMNG01010_ITEM_AREA";

const PCH_REQ_ST_CD_TEMP_SAVE		="PR00";
const PCH_REQ_ST_CD_REQUEST_SAVE	="PR20";

let mobPageObj = {
	isPrevPage: false,
	pageParam: null,
	init: function () {
		this.ui.init();
		this.event.init();
		this.ready();
	},
	ui: {
		init: function () {
			this.info();
		},
		info: function() {
			$('input:hidden[id$="_BRAND_ID"]').val(fn_make_user_info.get('brandId'));
			$('input:hidden[id$="_STORE_ID"]').val(fn_make_user_info.get('storeId'));

			$('#ITP_MOBILE_MPOMNG01010 .itp_input.date').datepicker(ITP_DATE_LANGUAGE);
			$('#ITP_FORM_MPOMNG01010_DETAIL_DLV_REQ_DT').datepicker('setDate', itp_fn_date_add('D', 5));

			if(fn_make_user_info.get('authTpCd') === '50') {
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_NM').attr('readonly', true);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_BTN_MPOMNG01010_DETAIL_SEARCH_WHS_NM').attr('disabled', true);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_BTN_MPOMNG01010_DETAIL_DELETE_WHS_NM').attr('disabled', true);
			}
		}
	},
	event: {
		init: function() {
			this.button();
		},
		button: function() {
			$('button[id^="ITP_BTN_MPOMNG01010_DETAIL"]').on('click', function() {
				if($(this).is('[data-call-popup]')) {
					mobPopObj.show($(this).data('call-popup'), $(this).attr('id'));
				} else {
					var id = $(this).attr('id');
					switch (id) {
						case 'ITP_BTN_MPOMNG01010_DETAIL_DELROW'		: mobContObj.list.delRow(); 		break;
						case 'ITP_BTN_MPOMNG01010_DETAIL_SEARCH_WHS_NM'	: mobPopObj.popWhsNm.init(); 		break;
						case 'ITP_BTN_MPOMNG01010_DETAIL_DELETE_WHS_NM'	: mobPopObj.popWhsNm.delete();		break;
						case 'ITP_BTN_MPOMNG01010_DETAIL_CANCEL'		: mobContObj.cancel();				break;
					}
				}
				return false;
			});
		}
	},
	ready: function() {
		mobContObj.init();
	}
};

let mobContObj = {
	init: function() {
		this.list.empty();
		this.data.load();
	},
	data: {
		initPchReq: null,
		load: function() {
			var _this = this;
			var callbackFn = function(result) {
				console.log(result);
				_this.initPchReq = result;
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_BRAND_ID').val(result.brandId);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_STORE_ID').val(result.storeId);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOAN_DVSN').val(result.loanDvsn);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOAN_MGNT_UNQ_NO').val(result.loanMgntUnqNo);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_PCH_REQ_DVSN').val(result.pchReqDvsn);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_PCH_REQ_UNQ_NO').val(result.pchReqUnqNo);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_MALL_ID').val(result.mallId);

				$('#ITP_FORM_MPOMNG01010_DETAIL .fnPchReqAmtTot').text(CommonObj.currency.add('0'));
				$('#ITP_FORM_MPOMNG01010_DETAIL .fnOrdUseAmt').text(CommonObj.currency.add(result.ordUseAmt));
				if(result.whsId !== '' && result.location !== '') {
					$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_ID').val(result.whsId);
					$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_NM').val(result.whsNm);
					$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOCATION').val(result.location);
				}
			};
			const param = {brandId:fn_make_user_info.get('brandId'), storeId:fn_make_user_info.get('storeId')};
			fn_ajax_call(API_MOBILE_INIT_INFO, param, callbackFn, 'GET');
		}
	},
	list: {
		rows: [],
		addRow: function() {
		},
		delRow: function() {
			this.detachRow();
		},
		attachRow: function (items) {
			var _this = this;
			var fnIsExist = function(rows, item) {
				var isExist = false;
				$.each(rows, function(i, row) {
					if(row.brandUnitUnqNo === item.brandUnitUnqNo) {
						isExist = true;
						return false;
					}
				});
				return isExist;
			};
			$.each(items, function(i, item) {
				if(!fnIsExist(_this.rows, item)) {
					_this.rows.push(item);
					$('#ITP_LIST_MPOMNG01010_ITEM_AREA .panel-group').append($('#ITP_LIST_MPOMNG01010_DETAIL_ROWCOPY').html());
					var $li = $('#ITP_LIST_MPOMNG01010_ITEM_AREA .panel-group > .list-row:last');
					$li.find('.fnBrandUnitUnqNo').val(item.brandUnitUnqNo);
					$li.find('.fnItemNm').text(item.itemNm);
					$li.find('.fnPchReqQty').text(item.pchReqQty);
					$li.find('.fnUnitAmt').text(CommonObj.currency.add(item.unitAmt));
					$li.find('.fnOrdAmt').text(CommonObj.currency.add(Number(item.unitAmt) * Number(item.pchReqQty)));
					$('.list-row #ITP_BTN_MPOMNG01010_DETAIL_PLUS')[$li.index()].addEventListener('click', function() { _this.actPlus(this); });
					$('.list-row #ITP_BTN_MPOMNG01010_DETAIL_MINUS')[$li.index()].addEventListener('click', function() { _this.actMinus(this); });
					_this.pchReqAmtTot();
				}
			});
			this.empty();
		},
		detachRow: function () {
			if($('#ITP_LIST_MPOMNG01010_ITEM_AREA input:checkbox[name=brandUnitUnqNo]:checked').length > 0) {
				var _this = this;
				$('#ITP_LIST_MPOMNG01010_DETAIL_ROWS li').each(function(index, elem) {
					var __this = this;
					var isChecked = $(this).find('input[type="checkbox"]').is(':checked');
					if(isChecked) {
						$.each(_this.rows, function(i, row){
							if(row.brandUnitUnqNo === $(__this).find('input[type="checkbox"]').val()) {
								_this.rows.splice(i, 1);
								return false;
							}
						});
						$(this).remove();
					}
				});
				this.pchReqAmtTot();
			}
			this.empty();
		},
		actPlus: function(elem) {
			var $li = $(elem).closest('li');
			var num = Number($li.find('.fnPchReqQty').text());
			var calcNum = num + 1;
			$($li).find('.fnPchReqQty').text(calcNum.toString());
			this.rows[$li.index()]['pchReqQty'] = calcNum;
			this.pchReqAmtUnit(elem, calcNum);
			this.pchReqAmtTot();
		},
		actMinus: function(elem) {
			var $div = $(elem).siblings('div');
			var num = Number($div.text());
			if(num <= 1) {
				itp_fn_modal_alert('수량을 확인하세요.');
			} else {
				$($div).text((num - 1).toString());
				this.rows[$div.parents('li').index()]['pchReqQty'] = $($div).text();
				this.pchReqAmtUnit(elem,  $($div).text());
				this.pchReqAmtTot();
			}
		},
		pchReqAmtUnit: function(elem, qty) {
			var $div = $(elem).parent().prev();
			var unitAmt = CommonObj.onlyNumber($div.find('.fnUnitAmt').text());
			$div.find('.fnOrdAmt').text(CommonObj.currency.add(Number(unitAmt ? unitAmt : 0) * Number(qty)));
		},
		pchReqAmtTot: function() {
			var reqAmt = 0;
			$.each(this.rows, function(index, item) {
				var qty = item.pchReqQty;
				var amt = item.unitAmt;
				reqAmt += Number(qty) * amt;
			});
			$('#ITP_AJAX_MPOMNG01010_VIEW_CONTAINER').find('.fnPchReqAmtTot').text(CommonObj.currency.add(reqAmt));
		},
		empty: function() {
			($('#ITP_LIST_MPOMNG01010_DETAIL_ROWS li').length > 0) ? $('.itp_non_data').hide() :  $('.itp_non_data').show();
		}
	},
	reset: function() {
		$('#ITP_LIST_MPOMNG01010_DETAIL_ROWS').children().remove();
		this.list.rows.length = 0;
		this.data.load();
	},
	cancel: function () {
		$(location).attr('href', MOBILE_CONTEXTPATH + '/app/main.html');
	}
};

let mobPopObj = {
	init: function(popId, parentId) {
		switch (popId) {
			case 'ITP_POP_MPOMNG01010_REQ_AREA'		: this.popReqConfirm.init(parentId); 	break;
			case 'ITP_POP_MPOMNG01010_WHS_AREA'		: this.popWhsNm.init(); 				break;
			case 'ITP_POP_MPOMNG01010_ITEM_AREA'	: this.popItem.init();					break;
		}
	},
	popItem: {
		// rows: null,
		init: function() {
			this.search();
		},
		search: function() {
			$('#ITP_LIST_MPOMNG01010_POP_ITEM_AREA .panel-group').empty();
			var callbackFn = function(result) {
				console.log(result);
				mobPopObj.popItem.rows = result.gridRows;
				$.each(mobPopObj.popItem.rows, function (i, item) {
					$('#ITP_LIST_MPOMNG01010_POP_ITEM_AREA .panel-group').append($('#ITP_LIST_MPOMNG01010_POP_ITEM_ROWCOPY').html());
					var $li = $('#ITP_LIST_MPOMNG01010_POP_ITEM_AREA .panel-group > .row_2:last');
					$li.find('#ITP_FORM_MPOMNG01010_POP_ITEM_CHECKBOX').val(item.itemId);
					$li.find('.fnItemNm').text(item.itemNm);
					$li.find('.fnUnitAmt').text(CommonObj.currency.add(item.unitAmt));
					$li.find('.fnOrdAmt').text(CommonObj.currency.add(item.unitAmt));
				});
				mobPopObj.popItem.addRow.init();
			};
			let param = $('#ITP_FORM_MPOMNG01010_POPUP_ITEM').serializeObject();
			fn_ajax_call(API_POP_ITEM_LIST, JSON.stringify(param), callbackFn, 'POST');
		},
		addRow: {
			init: function() {
				this.button.init();
			},
			button: {
				init: function() {
					var _this = this;
					$('button[id^="ITP_BTN_MPOMNG01010_POP_ITEM_"]').off('click').on('click', function() {
						var id = $(this).attr('id');
						switch (id) {
							case 'ITP_BTN_MPOMNG01010_POP_ITEM_PLUS'	: _this.actPlus($(this)); 		break;
							case 'ITP_BTN_MPOMNG01010_POP_ITEM_MINUS'	: _this.actMinus($(this)); 		break;
							case 'ITP_BTN_MPOMNG01010_POP_ITEM_ADD'		: _this.addItems(); 			break;
							// case 'ITP_BTN_MPOMNG01010_POP_ITEM_ADD'		: _this.actItemAdd($(this)); 	break;
							case 'ITP_BTN_MPOMNG01010_POP_ITEM_SEARCH'	: mobPopObj.popItem.search(); 	break;
							case 'ITP_BTN_MPOMNG01010_POP_ITEM_CLOSE'	: mobPopObj.hide(id); 			break;
						}
						return false;
					});
				},
				actPlus: function(elem) {
					var $div = $(elem).siblings('div');
					var num = Number($div.text());
					$($div).text((num + 1).toString());
					this.reqAmtUnit(elem, $($div).text());
				},
				actMinus: function(elem) {
					var $div = $(elem).siblings('div');
					var num = Number($div.text());
					if(num <= 1) {
						itp_fn_modal_alert('수량을 확인하세요.');
					} else {
						$($div).text((num - 1).toString());
						this.reqAmtUnit(elem, $($div).text());
					}
				},
				reqAmtUnit: function(elem, qty) {
					var $li = $(elem).closest('li');
					var unitAmt = CommonObj.onlyNumber($li.find('.fnUnitAmt').text());
					$li.find('.fnOrdAmt').text(CommonObj.currency.add(Number(unitAmt ? unitAmt : 0) * Number(qty)));
				},
				actItemAdd: function(elem) {
					var $li = $(elem).closest('li');
					var item = mobPopObj.popItem.rows[$li.index()];
					item['pchReqQty'] = $li.find('.fnPchReqQty').html();
					// var index = $(elem).closest('li').index();
					// var item = mobPopObj.popItem.rows[index];
					// item['pchReqQty'] = $(elem).closest('li').find('.fnPchReqQty').html();
					mobContObj.list.attachRow(item);
				},
				addItems: function() {
					var items = [];
					$('#ITP_LIST_MPOMNG01010_POP_ITEM_ROWS').find('input:checkbox').each(function() {
						if($(this).is(':checked')) {
							var index = $(this).closest('li').index();
							var item = mobPopObj.popItem.rows[index];
							item['pchReqQty'] = $(this).closest('li').find('.fnPchReqQty').html();
							items.push(item);
						}
					});
					if(items.length > 0) {
						mobContObj.list.attachRow(items);
						mobPopObj.popItem.close();
					} else {
						itp_fn_modal_alert('품목을 선택하세요.');
					}
				}
			}
		},
		delRow: function() {

		},
		close: function() {
			this.rows.length = 0;
			$('#ITP_LIST_MPOMNG01010_POP_ITEM_ROWS').children().remove();
			mobPopObj.hide('ITP_POP_MPOMNG01010_ITEM_AREA');
		}
	},
	popWhsNm: {
		init: function () {
			$('#ITP_LIST_MPOMNG01010_POP_WHS_AREA .mb_0').children().remove();
			this.rows.length = 0;
			this.search();
			this.action();
		},
		rows: [],
		search: function () {
			var _this = this;
			$('#ITP_LIST_MPOMNG01010_POP_WHS_AREA .panel-group').empty();
			var callbackFn = function(result) {
				console.log(result);
				$.each(result.gridRows, function (i, item) {
					$('#ITP_LIST_MPOMNG01010_POP_WHS_AREA .mb_0').append($('#ITP_LIST_MPOMNG01010_POP_WHS_ROWCOPY').html());
					var $li = $('#ITP_LIST_MPOMNG01010_POP_WHS_AREA .mb_0 > .row_2:last');
					$li.find('.fnWhsNm').text(item.whsNm);
					$li.find('.fnLocationNm').text(item.locationNm);
					$li.find('.fnWhsId').data('whs-id', item.whsId);
					$li.find('.fnWhsId').data('location', item.location);
				});
			};
			const param = $('#ITP_FORM_MPOMNG01010_POP_WHS').serializeObject();
			(fn_make_user_info.get('authTpCd') === '50') ? param.swhsDvsn = 'W02' : param.swhsDvsn = 'W01';
			fn_ajax_call(API_POP_SEARCH_LIST, JSON.stringify(param), callbackFn, 'POST');
		},
		action: function() {
			var _this = this;
			$('#ITP_LIST_MPOMNG01010_POP_WHS_AREA button[id$="POP_WHS_CHOICE"]').off('click').on('click', function() {
				var whsId = $(this).data('whs-id');
				var whsNm = $(this).parent().prev().find('.fnWhsNm').text();
				var location = $(this).data('location');
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_ID').val(whsId);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_NM').val(whsNm);
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOCATION').val(location);
				mobPopObj.hide(ID_ITP_POP_MPOMNG01010_WHS_AREA);
				itp_fn_form_clear_validate(null, '#ITP_FORM_MPOMNG01010_DETAIL');
				// console.log($(this).parent().prev().find('.fnWhsNm').text());
				// $.each(_this.rows, function (i, item) {
				// 	if(whsId === item.whsId) {
				// 		$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_ID').val(item.whsId);
				// 		$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_NM').val(item.whsNm);
				// 		$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOCATION').val(item.location);
				// 		mobPopObj.hide(ID_ITP_POP_MPOMNG01010_WHS_AREA);
				// 		itp_fn_form_clear_validate(null, '#ITP_FORM_MPOMNG01010_DETAIL');
				// 		return false;
				// 	}attachRow
				// });
			});
			$('#ITP_FORM_MPOMNG01010_POP_WHS button[id="ITP_BTN_MPOMNG01010_POP_WHS_SEARCH"]').off('click').on('click', function() {
				_this.search();
			});
		},
		delete: function() {
			$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_ID').val('');
			$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_NM').val('');
			$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOCATION').val('');
		}
	},
	popReqConfirm: {
		saveMode: 1, // 1 : 임시저장, 2 : 구매요청, 요청금액이 가능금액보다 클 경우 (3 : PG 정보 없음, 4 : 선불매장, 5 : 후불매장)
		init: function (parentId) {
			this.formId = '#ITP_FORM_MPOMNG01010_DETAIL';
			this.pchReqStCd = (parentId === 'ITP_BTN_MPOMNG01010_DETAIL_REQ_ORDER') ? PCH_REQ_ST_CD_REQUEST_SAVE : PCH_REQ_ST_CD_TEMP_SAVE;
			this.view();
			this.action();
		},
		view: function() {
			var popMsg = '';
			var loanDvsn = $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOAN_DVSN').val();
			var ordUseAmt = CommonObj.onlyNumber($('#ITP_FORM_MPOMNG01010_DETAIL .fnOrdUseAmt').text());
			var pchReqAmtTot = CommonObj.onlyNumber($('#ITP_FORM_MPOMNG01010_DETAIL .fnPchReqAmtTot').text());
			if(this.pchReqStCd === PCH_REQ_ST_CD_REQUEST_SAVE) { // 구매요청
				if(loanDvsn === 'LD03') {		// 무정산
					this.saveMode = 2;
					popMsg = '구매요청 하시겠습니까?';
					$('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('확인');
				} else {
					if (Number(ordUseAmt) < Number(pchReqAmtTot)) { // 요청금액이 가능금액보다 클 경우
						if(CommonObj.isPayPossible()) {	// PG 정보 여부
							if(loanDvsn === 'LD01') {	// 선불매장
								this.saveMode = 4;
								popMsg = 	'선불매장이므로 결재를 하셔야 구매요청이 진행이 됩니다.<br>' +
									'결재를 하시겠습니까?';
								$('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('결제');
							} else if(loanDvsn === 'LD02') { // 후불매장
								this.saveMode = 5;
								popMsg = 	'구매한도가 부족합니다.<br>' +
									'선결재를 하신 후에 구매요청을 하시기 바랍니다.<br>' +
									'결재를 하시겠습니까?';
								$('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('결제');
							}
						} else {
							this.saveMode = 3;
							if(loanDvsn === 'LD01') {	// 선불매장
								popMsg = 	'선불매장이므로 입금을 하시고, 입금등록 후 브랜드에서 승인이 되어야  구매요청을 하실 수 있습니다.';
							} else if(loanDvsn === 'LD02') { // 후불매장
								popMsg = 	'구매한도가 부족합니다.<br>' +
									'선입금을 하시고, 입금등록 후 브랜드에서 승인이 되어야 구매요청을  하실 수 있습니다.\n';
							}
							$('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('확인');
						}
					} else {
						this.saveMode = 2;
						popMsg = '구매요청 하시겠습니까?';
						$('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('확인');
					}
				}
			} else { // 임시저장
				this.saveMode = 1;
				popMsg = '임시저장 하시겠습니까?';
				$('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('확인');
			}
			$('#ITP_POP_MPOMNG01010_REQ_AREA .fnPopDlvReqDt').text($('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_DLV_REQ_DT').val());
			$('#ITP_POP_MPOMNG01010_REQ_AREA .fnItemQty').text(CommonObj.currency.add(mobContObj.list.rows.length, '개'));
			$('#ITP_POP_MPOMNG01010_REQ_AREA .fnOrdReqAmt').text($('#ITP_AJAX_MPOMNG01010_VIEW_CONTAINER .fnPchReqAmtTot').text());
			$('#ITP_POP_MPOMNG01010_REQ_AREA .fnOrdPssblAmt').text($('#ITP_AJAX_MPOMNG01010_VIEW_CONTAINER .fnOrdUseAmt').text());
			var ordAmt = Number(pchReqAmtTot) - Number(ordUseAmt);
			$('#ITP_POP_MPOMNG01010_REQ_AREA .fnOrdAmt').text(CommonObj.currency.add(ordAmt > 0 ? ordAmt : 0));
			$('#ITP_POP_MPOMNG01010_REQ_AREA .pop_msg').html(popMsg);
		},
		action: function() {
			var _this = this;
			$('#ITP_POP_MPOMNG01010_REQ_AREA button[id="ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM"]').off('click').on('click', function() {
				$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_PCH_REQ_ST_CD').val(_this.pchReqStCd);
				_this.save();
			});
		},
		save: function() {
			var procSave = function () {
				let param = $('#ITP_FORM_MPOMNG01010_DETAIL').serializeObject();
				$.each(mobContObj.list.rows, function(index, item) {
					item['viewCd'] = 'C';
					item['pchReqAmt'] = Number(item.unitAmt) * Number(item.pchReqQty);
				});
				param.gridInsertData = mobContObj.list.rows;
				var saveFn = function (result) {
					console.log(result);
					mobPopObj.hide('ITP_POP_MPOMNG01010_REQ_AREA');
					mobContObj.reset();
				};
				console.log(JSON.stringify(param));
				fn_ajax_call(API_MOBILE_SAVE, JSON.stringify(param), saveFn, 'POST');
			};
			if (this.saveMode === 1 || this.saveMode === 2 || this.saveMode === 3) {
				if(this.saveMode === 3)
					$('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_PCH_REQ_ST_CD').val(PCH_REQ_ST_CD_TEMP_SAVE);
				procSave();
			} else if (this.saveMode === 4 || this.saveMode === 5) {
				// 결제 팝업
				var ordUseAmt = CommonObj.onlyNumber($('#ITP_FORM_MPOMNG01010_DETAIL .fnOrdUseAmt').text());
				var pchReqAmtTot = CommonObj.onlyNumber($('#ITP_FORM_MPOMNG01010_DETAIL .fnPchReqAmtTot').text());
				var args = {
					'payTpCd'	: '40',
					'brandId'	: $('#ITP_FORM_MPOMNG01010_DETAIL_BRAND_ID').val(),
					'storeId'	: $('#ITP_FORM_MPOMNG01010_DETAIL_STORE_ID').val(),
					'goodsAmt'	: Number(pchReqAmtTot - ordUseAmt)
				};
				fn_call_popup('biz', 'BIZPOP_PO_PAYMENT', '#ITP_ASIDE', procSave, args, 'M');
			}
		}
	},
	show: function(popId, parentId) {
		var _this = this;
		$('button[id$="CLOSE"]').off('click').on('click', function() {
			var id = $(this).attr('id');
			if($(this).hasClass('btn-pop-close')) {
				_this.hide(id);
			}
		});
		if(parentId === 'ITP_BTN_MPOMNG01010_DETAIL_REQ_ORDER' || parentId === 'ITP_BTN_MPOMNG01010_DETAIL_TEMP_SAVE') {
			var formId = '#ITP_FORM_MPOMNG01010_DETAIL';
			itp_fn_form_clear_validate(null, formId);
			if (itp_fn_form_event.isValid(formId)) {
				if($('#ITP_LIST_MPOMNG01010_DETAIL_ROWS > li').size() < 1) {
					alert('품목추가 버튼을 이용하여 품목을 추가해 주세요.');
					return false;
				} else {
					$('#' + popId).show();
					mobPopObj.init(popId, parentId);
				}
			}
		} else {
			$('#' + popId).show();
			mobPopObj.init(popId, parentId);
		}
	},
	hide: function(id) {
		$('#' + id).closest('.mobile-pop-close').hide();
	}
};
