require(['config'], function() { require([ ], function($) { mobPageObj.init(); }); }); /*API URL*/ const API_MOBILE_GRID_LIST = '/api/rtnmng/inoutmng/retstock-target-grid-list'; // 목록 const API_MOBILE_SAVE = '/api/rtnmng/inoutmng/save-retstock'; // 반품처리 const API_POP_SEARCH_LIST = '/api/whs/mng/pop-whs-search'; const API_POP_SPPLY_LIST = '/api/spply/pop-grid-list'; const PAGE_MODE_LIST = "LIST"; const PAGE_MODE_VIEW = "VIEW"; let mobPageObj = { viewMode: PAGE_MODE_LIST, init: function () { this.ui.init(); this.event.init(); this.ready(); }, ui: { init: function () { this.view(); this.info(); }, view: function() { // 공통코드 표시 $('select').each(function() { if($(this).data('select-code')) { fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id')); } }); // 조회일자 지정 $('#ITP_MOBILE_MRTNMNG05010 .itp_input.date').datepicker(ITP_DATE_LANGUAGE); $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH_FROM_DT').datepicker('setDate', itp_fn_date_add('M', 0)); $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH_TO_DT').datepicker('setDate', itp_fn_date_add('M', 1)); }, 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_MRTNMNG05010_LIST"]').on('click', function() { var id = $(this).attr('id'); switch (id) { case 'ITP_BTN_MRTNMNG05010_LIST_SEARCH_WHS_NM' : mobPopObj.popWhsNm.init(); break; case 'ITP_BTN_MRTNMNG05010_LIST_DELETE_WHS_NM' : mobPopObj.popWhsNm.delete(); break; case 'ITP_BTN_MRTNMNG05010_LIST_SEARCH_SPPLY_NM' : mobPopObj.popSpply.init(); break; case 'ITP_BTN_MRTNMNG05010_LIST_DELETE_SPPLY_NM' : mobPopObj.popSpply.delete(); break; case 'ITP_BTN_MRTNMNG05010_LIST_SEARCH' : mobContObj.list.search(); break; case 'ITP_BTN_MRTNMNG05010_LIST_MODIFY' : mobContObj.list.save(); break; } return false; }); $(document).on('click', '#ITP_POP_MRTNMNG05010_LIST_SPPLY_ROWS li button', function() { mobPopObj.popSpply.choice($(this)); }); $(document).on('click', '#ITP_LIST_MRTNMNG05010_POP_WHS_ROWS li button', function() { mobPopObj.popWhsNm.choice($(this)); }); } }, switchScreen: function(mode) { $('#ITP_MOBILE_MRTNMNG05010').find('div[id$="_CONTAINER"]').each(function(i) { $(this).hide(); }); if(mode === PAGE_MODE_LIST) { $('#ITP_AJAX_MRTNMNG05010_LIST_CONTAINER').show(); } this.viewMode = mode; }, ready: function() { mobContObj.list.init(); } }; let mobContObj = { list: { listPage: 1, rows: [], init: function() { mobPageObj.switchScreen(PAGE_MODE_LIST); // this.search(); }, search: function() { var formId = '#ITP_FORM_MRTNMNG05010_LIST_SEARCH'; itp_fn_form_clear_validate(null, formId); if (itp_fn_form_event.isValid(formId)) { this.listPage = 0; this.totPage = 0; this.rows.length = 0; $('#ITP_LIST_MRTNMNG05010_LIST_ITEM_ROWS').empty(); setTimeout(function() { mobContObj.list.load(); }, 100); } }, pager: function(totPage) { (this.listPage < totPage) ? CommonObj.moreView('#ITP_LIST_MRTNMNG05010_LIST_ITEM_AREA', true, mobContObj.list.load) : CommonObj.moreView('#ITP_LIST_MRTNMNG05010_LIST_ITEM_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_MRTNMNG05010_LIST_ITEM_AREA .panel-group').append($('#ITP_LIST_MRTNMNG05010_LIST_ITEM_ROWCOPY').html()); var $li = $('#ITP_LIST_MRTNMNG05010_LIST_ITEM_AREA .panel-group > .item-row:last'); $li.find('.fnRtnPodrUnqNo').text(item.rtnPodrUnqNo); $li.find('.fnColSchDt').text(item.colSchDt); $li.find('.fnSpplyNm').text(item.spplyNm); $li.find('.fnRtnWhsNm').text(item.rtnWhsNm); $li.find('.fnItemNm').text(item.itemNm); $li.find('.fnColReqQty').text(CommonObj.comma.set(item.colReqQty)); $li.find('#ITP_FORM_MRTNMNG05010_LIST_COL_QTY').val(item.colQty); mobContObj.list.rows.push(item); }); }; const param = $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH').serializeObject(); param.gridPage = mobContObj.list.listPage; param.gridSize = mobile_list_size; // console.log(JSON.stringify(param)); fn_ajax_call(API_MOBILE_GRID_LIST, JSON.stringify(param), callbackFn, 'POST'); }, save: function() { var _this = this; var chkQtyYn1 = true; var chkQtyYn2 = true; var chkQtyYn3 = true; var gridInsertData = []; var swhsId = ""; var srtnWhsId = ""; var storeId = ""; $('#ITP_LIST_MRTNMNG05010_LIST_ITEM_ROWS li').each(function(index) { var row = mobContObj.list.rows[index]; var colQty = $(this).find('input[name="colQty"]').val(); if(colQty !== '') { if(Number(colQty) > row.colReqQty) { chkQtyYn1 = false; return false; } if (swhsId !== "" && swhsId !== row.whsId) { chkQtyYn2 = false; return false; } if (srtnWhsId !== "" && srtnWhsId !== row.rtnWhsId) { chkQtyYn3 = false; return false; } var item = { 'colPickDtlNo' : row.colPickDtlNo, 'colPickUnqNo' : row.colPickUnqNo, 'itemId' : row.itemId, 'colQty' : colQty }; swhsId = row.whsId; srtnWhsId = row.rtnWhsId; storeId = row.storeId; gridInsertData.push(item); } }); if (chkQtyYn1 === false) { itp_fn_modal_alert("수거요청수량보다 수거수량이 더 많습니다."); return; } if (chkQtyYn2 === false) { itp_fn_modal_alert("서로 다른 반품입고창고 품목은 처리할 수 없습니다."); return; } if (chkQtyYn3 === false) { itp_fn_modal_alert("서로 다른 수거창고 품목은 처리할 수 없습니다."); return; } if (gridInsertData.length === 0) { itp_fn_modal_alert("반품처리할 품목이 없습니다."); return ; } var modalFn = { callBack: (args) => { let param = {}; param['viewCd'] = 'C'; param['whsId'] = swhsId; param['rtnWhsId'] = srtnWhsId; param['brandId'] = $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_BRAND_ID').val(); param['storeId'] = storeId; param['gridInsertData'] = gridInsertData; var saveFn = function () { mobContObj.list.search(); }; fn_ajax_call(API_MOBILE_SAVE, JSON.stringify(param), saveFn, 'POST'); } }; itp_fn_modal_confirm('반품처리 하시겠습니까?', modalFn); } } }; let mobPopObj = { popSpply: { popId: 'ITP_POP_MRTNMNG05010_SPPLY_AREA', rows: [], init: function() { this.rows.length = 0; mobPopObj.show(this.popId); this.search(); this.action(); }, search: function() { var _this = this; $('#ITP_POP_MRTNMNG05010_LIST_SPPLY_AREA .panel-group').empty(); var callbackFn = function(result) { console.log(result); _this.view(result.gridRows); }; let param = $('#ITP_FORM_MRTNMNG05010_POP_SPPLY_SEARCH').serializeObject(); fn_ajax_call(API_POP_SPPLY_LIST, JSON.stringify(param), callbackFn, 'POST'); }, view: function(gridRows) { this.rows = gridRows; $.each(gridRows, function (i, item) { $('#ITP_POP_MRTNMNG05010_LIST_SPPLY_AREA .panel-group').append($('#ITP_POP_MRTNMNG05010_LIST_SPPLY_ROWCOPY').html()); var $li = $('#ITP_POP_MRTNMNG05010_LIST_SPPLY_AREA .panel-group > .row_2:last'); $li.find('.fnSpplyNm').text(item.spplyNm); $li.find('.fnStNm').text($li.find('.fnStNm').text().replace('$', item.stNm)); $li.find('.fnSpplyId').data('item-key', item.spplyId); }); }, choice: function(elem) { var _this = this; var spplyId = $(elem).data('item-key'); $.each(this.rows, function (i, item) { if(spplyId === item.spplyId) { $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_SPPLY_ID').val(item.spplyId); $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_SPPLY_NM').val(item.spplyNm); _this.close(); return false; } }); }, action: function() { var _this = this; $('button[id^="ITP_BTN_MRTNMNG05010_POP_SPPLY"]').off('click').on('click', function() { var id = $(this).attr('id'); switch (id) { case 'ITP_BTN_MRTNMNG05010_POP_SPPLY_SEARCH' : _this.search(); break; case 'ITP_BTN_MRTNMNG05010_POP_SPPLY_CHOICE' : _this.choice($(this)); break; case 'ITP_BTN_MRTNMNG05010_POP_SPPLY_CLOSE' : _this.close(); break; } return false; }); }, delete: function() { $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_SPPLY_ID').val(''); $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_SPPLY_NM').val(''); }, close: function() { this.rows.length = 0; $('#ITP_POP_MRTNMNG05010_LIST_SPPLY_AREA .panel-group').empty(); $('#ITP_FORM_MRTNMNG05010_POP_SPPLY_SEARCH #ITP_FORM_MRTNMNG05010_POP_SPPLY_KEYWORD').val(''); mobPopObj.hide(this.popId); } }, popWhsNm: { popId: 'ITP_POP_MRTNMNG05010_WHS_AREA', rows: [], init: function () { this.rows.length = 0; mobPopObj.show(this.popId); this.search(); this.action(); }, search: function () { var _this = this; $('#ITP_LIST_MRTNMNG05010_POP_WHS_AREA .panel-group').empty(); var callbackFn = function(result) { console.log(result); _this.view(result.gridRows); }; const param = $('#ITP_FORM_MRTNMNG05010_POP_WHS').serializeObject(); param.swhsDvsn = CommonObj.schWhsDvsn(); 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_MRTNMNG05010_POP_WHS_AREA .panel-group').append($('#ITP_LIST_MRTNMNG05010_POP_WHS_ROWCOPY').html()); var $li = $('#ITP_LIST_MRTNMNG05010_POP_WHS_AREA .panel-group > .list-row: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) { $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_WHS_ID').val(item.whsId); $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_WHS_NM').val(item.whsNm); _this.close(); return false; } }); }, action: function() { var _this = this; $('button[id^="ITP_BTN_MRTNMNG05010_POP_WHS"]').off('click').on('click', function() { var id = $(this).attr('id'); switch (id) { case 'ITP_BTN_MRTNMNG05010_POP_WHS_SEARCH' : _this.search(); break; case 'ITP_BTN_MRTNMNG05010_POP_WHS_CHOICE' : _this.choice($(this)); break; case 'ITP_BTN_MRTNMNG05010_POP_WHS_CLOSE' : _this.close(); break; } return false; }); }, delete: function() { $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_WHS_ID').val(''); $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_WHS_NM').val(''); }, close: function() { this.rows.length = 0; $('#ITP_POP_MRTNMNG05010_LIST_WHS_AREA .panel-group').empty(); $('#ITP_FORM_MRTNMNG05010_POP_WHS #ITP_FORM_MRTNMNG05010_POP_WHS_KEYWORD').val(''); mobPopObj.hide(this.popId); } }, show: function(popId) { $('button[id$="_CLOSE"]').off('click').on('click', function() { console.log($(this).attr('id')); if($(this).hasClass('btn-pop-close')) { mobPopObj.hide(popId); } }); $('#' + popId).show(); }, hide: function(popId) { $('#' + popId).closest('.mobile-pop-close').hide(); } };