require(['config'], function() {
	require([
		'jquery'
	], function($) {

	});
});

let API_POP_GRID_LIST = '/api/rtnmng/reject-rtnreq-target'; 

function itp_fn_BIZPOP_RTN_PO_REJECT(parentPopFn, args, returnType) {
	
	let itp_BIZPOP_RTN_PO_REJECT_param = args;
	let itp_BIZPOP_RTN_PO_REJECT_search = false;

	const THIS_FORM_ID = '#ITP_FORM_BIZPOP_RTN_PO_REJECT';
	const THIS_GIRD_ID = '#ITP_BIZPOP_RTN_PO_REJECT_jqGrid';
	const THIS_GIRD_PAGER = '#ITP_BIZPOP_RTN_PO_REJECT_jqGridPager';
	console.log(args);
	$('#ITP_FORM_ITP_BIZPOP_RTN_PO_REJECT_RTN_REQ_UNQ_NO').val(args.rtnReqUnqNo);
	$('#ITP_FORM_ITP_BIZPOP_RTN_PO_REJECT_STORE_ID').val(args.storeId);
	

	$('#ITP_BIZPOP_RTN_PO_REJECT').one('shown.bs.modal', function(e) {
		itp_fn_jqgrid_resize(THIS_GIRD_ID, '#ITP_BIZPOP_RTN_PO_REJECT_jqGrid_list', '');
		itp_fn_fire_window_resize();
	}).one('hidden.bs.modal', function(e) {
		$('#ITP_BIZPOP_RTN_PO_REJECT').remove();
	}).modal('show');

	$('#ITP_BIZPOP_RTN_PO_REJECT_BTN_SELECT').on('click', function() {
		let transParm = {rtnReqUnqNo: $('#ITP_FORM_ITP_BIZPOP_RTN_PO_REJECT_RTN_REQ_UNQ_NO').val(),rtnRjctRsn: $('#ITP_FORM_ITP_BIZPOP_RTN_PO_REJECT_REJECT_DSN').val(), retVal:'Y', storeId:$('#ITP_FORM_ITP_BIZPOP_RTN_PO_REJECT_STORE_ID').val()}
		parentPopFn(transParm);
		$('#ITP_BIZPOP_RTN_PO_REJECT').modal('hide'); // 팝업닫
	});
	
	$('#ITP_BIZPOP_RTN_PO_REJECT_BTN_CANCEL').on('click', function() {
		let transParm = {rtnReqUnqNo: $('#ITP_FORM_ITP_BIZPOP_RTN_PO_REJECT_RTN_REQ_UNQ_NO').val(),rtnRjctRsn: '', retVal:'N', storeId:$('#ITP_FORM_ITP_BIZPOP_RTN_PO_REJECT_STORE_ID').val()}
		parentPopFn(transParm);
		$('#ITP_BIZPOP_RTN_PO_REJECT').modal('hide'); // 팝업닫기
	});

	$('#ITP_BIZPOP_RTN_PO_REJECT_jqGridEmpty').on('click', function() {
		itp_fn_BIZPOP_RTN_PO_REJECT_empty.back();
		//itp_BIZPOP_RTN_PO_REJECT_param.gridSize = 10;
		$(THIS_GIRD_ID).setGridParam({'postData': JSON.stringify(itp_BIZPOP_RTN_PO_REJECT_param)}).trigger('reloadGrid');
	});

	var itp_fn_BIZPOP_RTN_PO_REJECT_empty = {
		push: function() {
			let param = {rtnReqUnqNo: $('#ITP_FORM_ITP_BIZPOP_RTN_PO_REJECT_RTN_REQ_UNQ_NO').val() };
			itp_BIZPOP_RTN_PO_REJECT_param = param;
		},
		back: function() {
		}
	};

	itp_fn_BIZPOP_RTN_PO_REJECT_empty.push();
	let param = {rtnReqUnqNo: $('#ITP_FORM_ITP_BIZPOP_RTN_PO_REJECT_RTN_REQ_UNQ_NO').val() };
	console.log(JSON.stringify(param));

	$(THIS_GIRD_ID).jqGrid({
		colModel: [
			{
				index: 'AFFL_SHOP_NM', name: 'itemId',
				label: '품목번호', //
				width: '13', fixed: false, align: 'center',
				sortable: false, hidden: false
			},
			{
				index: 'ITEM_NM', name: 'itemNm',
				label: '품목명', //
				width: '14', fixed: false, align: 'left',
				sortable: false, hidden: false
			},
			{
				index: 'RTN_QTY', name: 'rtnQty',
				label: '반품요청수량', //
				width: '10', fixed: false, align: 'right',
				sortable: false, hidden: false, 
				formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
			},
			{
				index: 'RTN_AMT', name: 'rtnAmt',
				label: '반품요청금액', //
				width: '10', fixed: false, align: 'right',
				sortable: false, hidden: false, 
				formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
			},
			{
				index: 'RTN_REQ_UNQ_NO', name: 'rtnReqUnqNo',
				label: '반품요청번호', //
				width: '5', fixed: false, align: 'center',
				sortable: false, hidden: true
			},
			{
				index: 'RTN_REQ_DTL_NO', name: 'rtnReqDtlNo',
				label: '반품요청순번', //
				width: '5', fixed: false, align: 'center',
				sortable: false, hidden: true
			}
		],
		loadBeforeSend: function(jqXHR) {
		    jqXHR.setRequestHeader('X-AUTH-TOKEN', CONN_KEY);
		},
		postData: JSON.stringify(param),
		url: DOMAIN + API_POP_GRID_LIST,
		pager: THIS_GIRD_PAGER,
		multiselect: false,
		rownumbers: false,
		loadComplete: function(data) {
			console.log(data);
			itp_fn_grid_load_complete(data, THIS_GIRD_ID, true, undefined, 'BIZPOP_RTN_PO_REJECT', itp_BIZPOP_RTN_PO_REJECT_search, itp_fn_BIZPOP_RTN_PO_REJECT_empty, true, data.gridRecords, false);
	    },
	    loadError: function(jqXHR, textStatus, errorThrown) {
	    	itp_fn_grid_load_error(jqXHR, textStatus, errorThrown);
	    },
	    onPaging: function(action) {
	    	itp_fn_grid_paging(THIS_GIRD_ID, action, param);
	    }
	}).navGrid(THIS_GIRD_PAGER, ITP_GRID_NAV_DEFAULTS.navGrid);
};
