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

/*API URL*/
const API_MOBILE_GRID_LIST 			= '/api/pomng/po/detail-grid-list';	// 목록
const API_MOBILE_INFO 				= '/api/pomng/po/info-pchOdr';		// 상세
const API_POP_SEARCH_LIST			= '/api/whs/mng/pop-whs-search';
const API_POP_ITEM_LIST 			= '/api/item/pop-grid-list';

const VIEW_MODE_LIST				= "LIST";
const VIEW_MODE_VIEW				= "VIEW";

let mobPageObj = {
	viewMode: VIEW_MODE_LIST,
	init: function () {
		this.ui.init();
		this.event.init();
		this.ready();
	},
	ui: {
		init: function () {
			this.view();
			this.info();
			this.action();
		},
		view: function() {
			// 공통코드 표시
			$('select').each(function() {
				if($(this).data('select-code')) {
					fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
				}
			});

			// 조회일자 지정
			$('#ITP_FORM_MPOMNG03010_VIEW_SEARCH_FROM_DT').val(itp_fn_date_add('M', -1));
			$('#ITP_FORM_MPOMNG03010_VIEW_SEARCH_TO_DT').val(itp_fn_date_add('M', 0));
		},
		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'));
		}
	},
	event: {
		init: function() {
			this.button();
		},
		button: function() {
			$('button[id^="ITP_BTN_MPOMNG03010_VIEW"]').on('click', function() {
				var id = $(this).attr('id');
				switch (id) {
					case 'ITP_BTN_MPOMNG03010_VIEW_SEARCH_WHS_NM'	: mobPopObj.popWhsNm.init(VIEW_MODE_LIST); 		break;
					case 'ITP_BTN_MPOMNG03010_VIEW_DELETE_WHS_NM'	: mobPopObj.popWhsNm.delete(VIEW_MODE_LIST); 	break;
					case 'ITP_BTN_MPOMNG03010_VIEW_SEARCH'			: mobContObj.list.search();					break;
				}
				return false;
			});

			$('button[id^="ITP_BTN_MPOMNG03010_DETAIL"]').on('click', function() {
				var id = $(this).attr('id');
				switch (id) {
					case 'ITP_BTN_MPOMNG03010_DETAIL_CANCEL_LIST'		: mobContObj.detail.cancel();	break;
				}
				return false;
			});

			$('button[id^="ITP_BTN_MPOMNG03010_MODIFY"]').on('click', function() {
				var id = $(this).attr('id');
				switch (id) {
					case 'ITP_BTN_MPOMNG03010_MODIFY_SEARCH_WHS_NM'		: mobPopObj.popWhsNm.init(VIEW_MODE_MODIFY); 	break;
					case 'ITP_BTN_MPOMNG03010_MODIFY_DELETE_WHS_NM'		: mobPopObj.popWhsNm.delete(VIEW_MODE_MODIFY); 	break;
					case 'ITP_BTN_MPOMNG03010_MODIFY_ADD_ROW'			: mobPopObj.popItem.init();						break;
					case 'ITP_BTN_MPOMNG03010_MODIFY_DEL_ROW'			: mobContObj.modify.list.detachRow();		break;
					case 'ITP_BTN_MPOMNG03010_MODIFY_CANCEL'			: mobContObj.modify.cancel();				break;
					case 'ITP_BTN_MPOMNG03010_MODIFY_REQ_ORDER'			: mobPopObj.popReqConfirm.init(PCH_REQ_ST_CD_REQUEST_SAVE);	break;
					case 'ITP_BTN_MPOMNG03010_MODIFY_TEMP_SAVE'			: mobPopObj.popReqConfirm.init(PCH_REQ_ST_CD_TEMP_SAVE);	break;
				}
				return false;
			});

		}
	},
	switchScreen: function(mode) {
		$('#ITP_MOBILE_MPOMNG03010').find('div[id$="_CONTAINER"]').each(function(i) {
			$(this).hide();
		});
		if(mode === VIEW_MODE_LIST) {
			$('#ITP_AJAX_MPOMNG03010_LIST_CONTAINER').show();
		} else if(mode === VIEW_MODE_VIEW) {
			$('#ITP_AJAX_MPOMNG03010_VIEW_CONTAINER').show();
			CommonObj.moreView('#ITP_LIST_MPOMNG03010_LIST_ITEM_AREA', false);
		}
		this.viewMode = mode;
	},
	ready: function() {
		mobContObj.list.init();
	}
};

let mobContObj = {
	list: {
		listPage: 1,
		rows: [],
		init: function() {
			mobPageObj.switchScreen(VIEW_MODE_LIST);
			this.search();
		},
		search: function() {
			this.listPage = 1;
			this.rows.length = 0;
			$('#ITP_LIST_MPOMNG03010_LIST_ROWS').empty();
			setTimeout(function() {
				mobContObj.list.load();
			}, 100);
		},
		pager: function(totPage) {
			(this.listPage < totPage) ?
				CommonObj.moreView('#ITP_LIST_MPOMNG03010_LIST_AREA', true, mobContObj.list.load) :
				CommonObj.moreView('#ITP_LIST_MPOMNG03010_LIST_AREA', false);
			this.listPage += 1;
		},
		load: function() {
			var _this = this;
			var callbackFn = function(result) {
				console.log(result);
				mobContObj.list.pager(result.gridTotal);
				$.each(result.gridRows, function (i, item) {
					$('#ITP_LIST_MPOMNG03010_LIST_AREA .panel-group').append($('#ITP_LIST_MPOMNG03010_LIST_ROWCOPY').html());
					var $li = $('#ITP_LIST_MPOMNG03010_LIST_AREA .panel-group > .list-row:last');
					$li.find('.fnPchReqDt').text(item.pchReqDt);
					$li.find('.fnPchReqMgrNm').text(item.pchReqMgrNm);
					$li.find('.fnPchReqStNm').text(item.pchReqStNm);
					$li.find('.fnWhsLocationNm').text(item.whsLocationNm);
					$li.find('.fnPchReqItemQty').text(CommonObj.comma.set(item.pchReqItemQty));
					$li.find('.fnPchReqTotalAmt').text(CommonObj.comma.set(item.pchReqTotalAmt));
					$li.find('.fnPchReqRjctNm').text(item.pchReqRjctNm);
					mobContObj.list.rows.push(item);
				});
			};
			const param = $('#ITP_FORM_MPOMNG03010_VIEW_SEARCH').serializeObject();
			param.gridPage = mobContObj.list.listPage;
			param.gridSize = mobile_list_size;
			fn_ajax_call(API_MOBILE_GRID_LIST, JSON.stringify(param), callbackFn, 'POST');
		}
	},
	detail: {
		rows: [],
		init: function(item) {
			mobPageObj.switchScreen(VIEW_MODE_DETAIL);
			this.search(item);
		},
		search: function(item) {
			var _this = this;
			var callbackFn = function(result) {
				console.log(result);
				_this.rows = result.pchReqDtlList;
				_this.view(result);
			};
			const param = {'brandId':fn_make_user_info.get('brandId'), 'pchReqUnqNo': item.pchReqUnqNo};
			fn_ajax_call(API_MOBILE_INFO, param, callbackFn, 'GET');
		},
		view: function(result) {
			var _this = this;
			var id = '#ITP_AJAX_MPOMNG03010_DETAIL_CONTAINER';
			$(id).find('.fnDlvReqDt').text(result.dlvReqDt);
			$(id).find('.fnPchReqTotalAmt').text(CommonObj.currency.add(result.pchReqTotalAmt));
			$(id).find('.fnLocationNm').text(result.locationNm);
			$(id).find('.fnPchApprNm').text('(' + result.pchApprNm + ')' + CommonObj.currency.add(result.pchApprAmt));
			$.each(result.pchReqDtlList, function (i, item) {
				$('#ITP_LIST_MPOMNG03010_DETAIL_AREA .panel-group').append($('#ITP_LIST_MPOMNG03010_DETAIL_ROWCOPY').html());
				var $li = $('#ITP_LIST_MPOMNG03010_DETAIL_AREA .panel-group > .list-row:last');
				$li.find('.fnItemNm').text(item.itemNm);
				$li.find('.fnUnit').text(item.pchReqQty + item.unit);
				$li.find('.fnPchReqAmt').text(CommonObj.comma.set(item.pchReqAmt));
				$li.find('.fnPchReqQty').text(CommonObj.currency.add(item.pchReqQty, ''));
				_this.rows.push(item);
			});
		},
		cancel: function () {
			this.rows.length = 0;
			var id = '#ITP_AJAX_MPOMNG03010_DETAIL_CONTAINER';
			$(id).find('.fnDlvReqDt').text('');
			$(id).find('.fnPchReqTotalAmt').text('');
			$(id).find('.fnLocationNm').text('');
			$(id).find('.fnPchApprNm').text('');
			$('#ITP_LIST_MPOMNG03010_DETAIL_AREA .panel-group').empty();
			mobPageObj.switchScreen(VIEW_MODE_LIST);
		}
	},
	modify: {
		init: function(item) {
			mobPageObj.switchScreen(VIEW_MODE_MODIFY);
			this.clear();
			this.search(item);
		},
		search: function(item) {
			var _this = this;
			var callbackFn = function(result) {
				console.log(result);
				_this.view(result);
			};
			const param = {'brandId':fn_make_user_info.get('brandId'), 'pchReqUnqNo': item.pchReqUnqNo};
			fn_ajax_call(API_MOBILE_INFO, param, callbackFn, 'GET');
		},
		view: function(result) {
			var _this = this;
			var id = '#ITP_AJAX_MPOMNG03010_MODIFY_CONTAINER';
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_DLV_REQ_DT').val(result.dlvReqDt.replace(/\./g, "-"));
			$(id).find('.fnPchReqTotalAmt').text(CommonObj.currency.add(result.pchReqTotalAmt));
			$(id).find('.fnOrdUseAmt').text(CommonObj.currency.add(result.ordUseAmt));
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_LOAN_DVSN').val(result.loanDvsn);
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_LOAN_MGNT_UNQ_NO').val(result.loanMgntUnqNo);
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_PCH_REQ_UNQ_NO').val(result.pchReqUnqNo);
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_PCH_REQ_DVSN').val(result.pchReqDvsn);
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_WHS_NM').val(result.whsNm);
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_WHS_ID').val(result.whsId);
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_LOCATION').val(result.location);
			_this.list.init(result.pchReqDtlList);
		},
		list: {
			rows: [],
			init: function(pchReqDtlList) {
				var _this = this;
				$.each(pchReqDtlList, function (i, item) {
					item['viewCd'] = 'U';
					_this.attachRow(item);
				});
			},
			attachRow: function (item) {
				var _this = this;
				var append = function() {
					$('#ITP_LIST_MPOMNG03010_MODIFY_AREA .panel-group').append($('#ITP_LIST_MPOMNG03010_MODIFY_ROWCOPY').html());
					var $li = $('#ITP_LIST_MPOMNG03010_MODIFY_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));
					_this.pchReqAmtTot();
				};
				var fnChkExist = function() {
					var isExist = false;
					$.each(_this.rows, function(i, row) {
						if(row.brandUnitUnqNo === item.brandUnitUnqNo) {
							if(row.viewCd === 'D') {
								item.viewCd = _this.rows[i].viewCd;
								_this.rows[i] = item;
								append();
							} else {
								alert('이미 존재하는 품목입니다.');
							}
							isExist = true;
							return false;
						}
					});
					if(!isExist) {
						_this.rows.push(item);
						append();
					}
				};
				fnChkExist();
			},
			detachRow: function () {
				if($('#ITP_LIST_MPOMNG03010_MODIFY_AREA input:checkbox[name=brandUnitUnqNo]:checked').length > 0) {
					var _this = this;
					$('#ITP_LIST_MPOMNG03010_MODIFY_ROWS li').each(function(index, elem) {
						var isChecked = $(this).find('input[type="checkbox"]').is(':checked');
						if(isChecked) {
							$(this).remove();
							_this.rows[index].viewCd = 'D';
						}
					});
					this.pchReqAmtTot();
				}
			},
			actPlus: function(elem) {
				var $div = $(elem).siblings('div');
				var num = Number($div.text());
				$($div).text((num + 1).toString());
				this.rows[$div.parents('li').index()]['pchReqQty'] = $($div).text();
				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.pchReqAmtTot();
				}
			},
			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_MPOMNG03010_VIEW_CONTAINER').find('.fnPchReqAmtTot').text(CommonObj.currency.add(reqAmt));
			}
		},
		cancel: function () {
			mobPageObj.switchScreen(VIEW_MODE_LIST);
		},
		clear: function() {
			this.list.rows.length = 0;
			var id = '#ITP_AJAX_MPOMNG03010_MODIFY_CONTAINER';
			$(id).find('.fnDlvReqDt').val('');
			$(id).find('.fnPchReqTotalAmt').text('');
			$(id).find('.fnOrdUseAmt').text('');
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_LOAN_DVSN').val('');
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_LOAN_MGNT_UNQ_NO').val('');
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_PCH_REQ_UNQ_NO').val('');
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_PCH_REQ_DVSN').val('');
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_WHS_NM').val('');
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_WHS_ID').val('');
			$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_LOCATION').val('');
			$('#ITP_LIST_MPOMNG03010_MODIFY_AREA .panel-group').empty();
		}
	}
};

let mobPopObj = {
	popItem: {
		popId: 'ITP_POP_MPOMNG03010_ITEM_AREA',
		init: function() {
			mobPopObj.show(this.popId);
			this.search();
		},
		search: function() {
			$('#ITP_LIST_MPOMNG03010_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_MPOMNG03010_POP_ITEM_AREA .panel-group').append($('#ITP_LIST_MPOMNG03010_POP_ITEM_ROWCOPY').html());
					var $li = $('#ITP_LIST_MPOMNG03010_POP_ITEM_AREA .panel-group > .row_2:last');
					$li.find('#ITP_FORM_MPOMNG03010_POP_ITEM_CHECKBOX').val(item.itemId);
					$li.find('.fnItemNm').text(item.itemNm);
					$li.find('.fnUnitAmt').text(CommonObj.currency.add(item.unitAmt));
				});
				mobPopObj.popItem.addRow.init();
			};
			let param = $('#ITP_FORM_MPOMNG03010_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_MPOMNG03010_POP_ITEM_"]').off('click').on('click', function() {
						var id = $(this).attr('id');
						switch (id) {
							case 'ITP_BTN_MPOMNG03010_POP_ITEM_PLUS'	: _this.actPlus($(this)); 		break;
							case 'ITP_BTN_MPOMNG03010_POP_ITEM_MINUS'	: _this.actMinus($(this)); 		break;
							case 'ITP_BTN_MPOMNG03010_POP_ITEM_ADD'		: _this.actItemAdd($(this)); 	break;
							case 'ITP_BTN_MPOMNG03010_POP_ITEM_SEARCH'	: mobPopObj.popItem.search(); 	break;
							case 'ITP_BTN_MPOMNG03010_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());
				},
				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());
					}
				},
				actItemAdd: function(elem) {
					var index = $(elem).closest('li').index();
					var item = mobPopObj.popItem.rows[index];
					item['pchReqQty'] = $(elem).closest('li').find('.fnPchReqQty').html();
					mobContObj.modify.list.attachRow(item);
				}
			}
		},
		delRow: function() {

		}
	},
	popWhsNm: {
		popId: 'ITP_POP_MPOMNG03010_WHS_AREA',
		mode: '',
		rows: [],
		init: function (mode) {
			this.mode = mode;
			this.rows.length = 0;
			mobPopObj.show(this.popId);
			this.search();
			this.action();
		},
		search: function () {
			var _this = this;
			$('#ITP_LIST_MPOMNG03010_POP_WHS_AREA .panel-group').empty();
			var callbackFn = function(result) {
				console.log(result);
				_this.view(result.gridRows);
			};
			const param = $('#ITP_FORM_MPOMNG03010_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');
		},
		view: function(gridRows) {
			this.rows = gridRows;
			$.each(gridRows, function (i, item) {
				$('#ITP_LIST_MPOMNG03010_POP_WHS_AREA .panel-group').append($('#ITP_LIST_MPOMNG03010_POP_WHS_ROWCOPY').html());
				var $li = $('#ITP_LIST_MPOMNG03010_POP_WHS_AREA .panel-group > .row_2:last');
				$li.find('.fnWhsNm').text(item.whsNm);
				$li.find('.fnLocationNm').text(item.locationNm);
				$li.find('.fnWhsId').data('whs-id', item.whsId);
			});
		},
		choice: function(elem) {
			var _this = this;
			var whsId = $(elem).data('whs-id');
			$.each(this.rows, function (i, item) {
				if(whsId === item.whsId) {
					if(_this.mode === VIEW_MODE_LIST) {
						$('#ITP_FORM_MPOMNG03010_VIEW_SEARCH #ITP_FORM_MPOMNG03010_VIEW_SEARCH_WHS_ID').val(item.whsId);
						$('#ITP_FORM_MPOMNG03010_VIEW_SEARCH #ITP_FORM_MPOMNG03010_VIEW_SEARCH_WHS_NM').val(item.whsNm);
					} else if(_this.mode === VIEW_MODE_MODIFY) {
						$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_WHS_ID').val(item.whsId);
						$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_WHS_NM').val(item.whsNm);
						$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_LOCATION').val(item.location);
					}
					mobPopObj.hide(_this.popId);
					return false;
				}
			});
		},
		action: function() {
			var _this = this;
			$('button[id^="ITP_BTN_MPOMNG03010_POP"]').off('click').on('click', function() {
				var id = $(this).attr('id');
				switch (id) {
					case 'ITP_BTN_MPOMNG03010_POP_WHS_SEARCH'	: _this.search();				break;
					case 'ITP_BTN_MPOMNG03010_POP_WHS_CHOICE'	: _this.choice($(this)); 		break;
					case 'ITP_BTN_MPOMNG03010_POP_WHS_CLOSE'	: mobPopObj.hide(_this.popId);	break;
				}
				return false;
			});
		},
		delete: function(mode) {
			if(mode === VIEW_MODE_LIST) {
				$('#ITP_FORM_MPOMNG03010_VIEW_SEARCH #ITP_FORM_MPOMNG03010_VIEW_SEARCH_WHS_ID').val('');
				$('#ITP_FORM_MPOMNG03010_VIEW_SEARCH #ITP_FORM_MPOMNG03010_VIEW_SEARCH_WHS_NM').val('');
			} else if(mode === VIEW_MODE_MODIFY) {
				$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_WHS_ID').val('');
				$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_WHS_NM').val('');
				$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_LOCATION').val('');
				mobPopObj.hide(ID_ITP_POP_MPOMNG03010_WHS_AREA);
			}
		}
	},
	popReqConfirm: {
		popId: 'ITP_POP_MPOMNG03010_REQ_AREA',
		pchReqStCd: '',
		init: function (pchReqStCd) {
			this.pchReqStCd = pchReqStCd;
			mobPopObj.show(this.popId);
			this.view();
			this.action();
		},
		view: function() {
			if(this.pchReqStCd === PCH_REQ_ST_CD_REQUEST_SAVE) {
				$('#ITP_POP_MPOMNG03010_REQ_AREA .msg_save').text('구매요청 하시겠습니까?');
			} else {
				$('#ITP_POP_MPOMNG03010_REQ_AREA .msg_save').text('임시저장 하시겠습니까?');
			}
			$('#ITP_POP_MPOMNG03010_REQ_AREA .fnPopDlvReqDt').text($('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_DLV_REQ_DT').val());
			$('#ITP_POP_MPOMNG03010_REQ_AREA .fnItemQty').text(CommonObj.currency.add(mobContObj.modify.list.rows.length, '개'));
			$('#ITP_POP_MPOMNG03010_REQ_AREA .fnOrdAmt').text(CommonObj.currency.add($('#ITP_FORM_MPOMNG03010_MODIFY .fnPchReqTotalAmt').text()));
		},
		action: function() {
			var _this = this;
			$('#ITP_POP_MPOMNG03010_REQ_AREA button[id="ITP_BTN_MPOMNG03010_POP_REQ_CONFIRM"]').off('click').on('click', function() {
				$('#ITP_FORM_MPOMNG03010_MODIFY #ITP_FORM_MPOMNG03010_MODIFY_PCH_REQ_ST_CD').val(_this.pchReqStCd);
				_this.save('#ITP_FORM_MPOMNG03010_MODIFY');
			});
		},
		save: function(formId) {
			var _this = this;
			let param = $(formId).serializeObject();

			if (param.loanDvsn !== 'LD03' && this.pchReqStCd === PCH_REQ_ST_CD_REQUEST_SAVE ) {
				var ordUseAmt = $('#ITP_FORM_MPOMNG03010_MODIFY .fnOrdUseAmt').text();
				var pchReqTotalAmt = $('#ITP_FORM_MPOMNG03010_DETAIL .fnPchReqTotalAmt').text();

				if (parseInt(CommonObj.onlyNumber(ordUseAmt)) < parseInt(CommonObj.onlyNumber(pchReqTotalAmt))) {
					alert(ITP_MSG_LOCALE.message.ajax.lackReqAmt);
					return;
				}
			}

			var gridInsertData = [];
			var gridUpdateData = [];
			var gridDeleteData = [];
			$.each(mobContObj.modify.list.rows, function(index, item) {
				item['pchReqUnqNo'] = param.pchReqUnqNo;
				if(item.viewCd === 'R' || item.viewCd === 'C' ) {
					item['viewCd'] = 'C';
					gridInsertData.push(item);
				} else if(item.viewCd === 'U') {
					gridUpdateData.push(item);
				} else if(item.viewCd === 'D') {
					gridDeleteData.push(item);
				}
			});
			param['dlvReqDt'] = param.dlvReqDt.replace(/[^0-9]/g, "");
			param.gridInsertData = gridInsertData;
			param.gridUpdateData = gridUpdateData;
			param.gridDeleteData = gridDeleteData;
			console.log(JSON.stringify(param));
			var saveFn = function (result) {
				console.log(result);
				mobPopObj.hide(_this.popId);
				mobContObj.list.init();
			};
			fn_ajax_call(API_MOBILE_SAVE, JSON.stringify(param), saveFn, 'POST');
		}
	},
	show: function(popId) {
		$('button[id$="_CLOSE"]').off('click').on('click', function() {
			if($(this).hasClass('btn-pop-close')) {
				mobPopObj.hide(popId);
			}
		});
		$('#' + popId).show();
	},
	hide: function(popId) {
		$('#' + popId).closest('.mobile-pop-close').hide();
	}
};
