123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- require(['config'], function() {
- require([
- ], function($) {
- mobPageObj.init();
- });
- });
- /*API URL*/
- const API_MOBILE_INIT_INFO = '/api/rtnmng/init-rtnReq';
- const API_MOBILE_SAVE = '/api/rtnmng/save-rtnReq';
- 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_MRTNMNG01010_REQ_AREA = "ITP_POP_MRTNMNG01010_REQ_AREA";
- const ID_ITP_POP_MRTNMNG01010_WHS_AREA = "ITP_POP_MRTNMNG01010_WHS_AREA";
- const ID_ITP_POP_MRTNMNG01010_ITEM_AREA = "ITP_POP_MRTNMNG01010_ITEM_AREA";
- const RTN_REQ_ST_CD_TEMP_SAVE ="RR00";
- const RTN_REQ_ST_CD_REQUEST_SAVE ="RR20";
- let mobPageObj = {
- isPrevPage: false,
- pageParam: null,
- init: function () {
- this.ui.init();
- this.event.init();
- this.ready();
- },
- ui: {
- init: function () {
- this.info();
- this.view();
- },
- 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'));
- },
- view: function() {
- // 조회일자 지정
- $('#ITP_FORM_MRTNMNG01010_DETAIL_DLV_REQ_DT').val(itp_fn_date_add('M', 1));
- }
- },
- event: {
- init: function() {
- this.button();
- },
- button: function() {
- $('button[id^="ITP_BTN_MRTNMNG01010_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_MRTNMNG01010_DETAIL_DELROW' : mobContObj.list.delRow(); break;
- case 'ITP_BTN_MRTNMNG01010_DETAIL_SEARCH_WHS_NM' : mobPopObj.popWhsNm.init(); break;
- case 'ITP_BTN_MRTNMNG01010_DETAIL_DELETE_WHS_NM' : mobPopObj.popWhsNm.delete(); break;
- case 'ITP_BTN_MRTNMNG01010_DETAIL_CANCEL' : mobContObj.cancel(); break;
- }
- }
- return false;
- });
- }
- },
- ready: function() {
- mobContObj.init();
- }
- };
- let mobContObj = {
- init: function() {
- this.button();
- this.data.load();
- },
- button: function() {
- var _this = this;
- $(document).on('click', '.DETAIL_ITEM_PLUS', function() {
- _this.list.actPlus($(this));
- });
- $(document).on('click', '.DETAIL_ITEM_MINUS', function() {
- _this.list.actMinus($(this));
- });
- },
- data: {
- initPchReq: null,
- load: function() {
- var _this = this;
- var callbackFn = function(result) {
- console.log(result);
- _this.initPchReq = result;
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_BRAND_ID').val(result.brandId);
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_STORE_ID').val(result.storeId);
- // $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_RTN_WHS_ID').val(result.rtnWhsId);
- // $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_RTN_LOCATION').val(result.rtnLocation);
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_DVSN').val(result.whsDvsn);
- };
- 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 (item) {
- console.log(item);
- var fnIsExist = function(rows) {
- var isExist = false;
- $.each(rows, function(i, row) {
- if(row.brandUnitUnqNo === item.brandUnitUnqNo) {
- isExist = true;
- return false;
- }
- });
- return isExist;
- };
- if(!fnIsExist(this.rows)) {
- this.rows.push(item);
- $('#ITP_LIST_MRTNMNG01010_ITEM_AREA .panel-group').append($('#ITP_LIST_MRTNMNG01010_DETAIL_ROWCOPY').html());
- var $li = $('#ITP_LIST_MRTNMNG01010_ITEM_AREA .panel-group > .row_2: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();
- }
- },
- detachRow: function () {
- if($('#ITP_LIST_MRTNMNG01010_ITEM_AREA input:checkbox[name=brandUnitUnqNo]:checked').length > 0) {
- var _this = this;
- $('#ITP_LIST_MRTNMNG01010_DETAIL_ROWS li').each(function(index, elem) {
- var isChecked = $(this).find('input[type="checkbox"]').is(':checked');
- if(isChecked) {
- $(this).remove();_this.rows.splice(index, 1);
- }
- });
- 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) {
- 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_MRTNMNG01010_DETAIL_CONTAINER').find('.fnRtnReqAmt').text(CommonObj.currency.add(reqAmt));
- }
- },
- cancel: function () {
- $(location).attr('href', MOBILE_CONTEXTPATH + '/app/main.html');
- }
- };
- let mobPopObj = {
- init: function(popId, parentId) {
- console.log(popId);
- switch (popId) {
- case 'ITP_POP_MRTNMNG01010_RTN_AREA' : this.popReqConfirm.init(parentId); break;
- case 'ITP_POP_MRTNMNG01010_WHS_AREA' : this.popWhsNm.init(); break;
- case 'ITP_POP_MRTNMNG01010_ITEM_AREA' : this.popItem.init(); break;
- }
- $('#' + popId).show();
- },
- popItem: {
- // rows: null,
- init: function() {
- this.search();
- },
- search: function() {
- $('#ITP_LIST_MRTNMNG01010_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_MRTNMNG01010_POP_ITEM_AREA .panel-group').append($('#ITP_LIST_MRTNMNG01010_POP_ITEM_ROWCOPY').html());
- var $li = $('#ITP_LIST_MRTNMNG01010_POP_ITEM_AREA .panel-group > .row_2:last');
- $li.find('#ITP_FORM_MRTNMNG01010_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_MRTNMNG01010_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_MRTNMNG01010_POP_ITEM_"]').off('click').on('click', function() {
- var id = $(this).attr('id');
- switch (id) {
- case 'ITP_BTN_MRTNMNG01010_POP_ITEM_PLUS' : _this.actPlus($(this)); break;
- case 'ITP_BTN_MRTNMNG01010_POP_ITEM_MINUS' : _this.actMinus($(this)); break;
- case 'ITP_BTN_MRTNMNG01010_POP_ITEM_ADD' : _this.actItemAdd($(this)); break;
- case 'ITP_BTN_MRTNMNG01010_POP_ITEM_SEARCH' : mobPopObj.popItem.search(); break;
- case 'ITP_BTN_MRTNMNG01010_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) {
- 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.list.attachRow(item);
- }
- }
- },
- delRow: function() {
- }
- },
- popWhsNm: {
- init: function () {
- this.rows.length = 0;
- this.search();
- this.action();
- },
- rows: [],
- search: function () {
- var _this = this;
- $('#ITP_LIST_MRTNMNG01010_POP_WHS_AREA .panel-group').empty();
- var callbackFn = function(result) {
- console.log(result);
- _this.view(result.gridRows);
- };
- const param = $('#ITP_FORM_MRTNMNG01010_POP_WHS').serializeObject();
- 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_MRTNMNG01010_POP_WHS_AREA .panel-group').append($('#ITP_LIST_MRTNMNG01010_POP_WHS_ROWCOPY').html());
- var $li = $('#ITP_LIST_MRTNMNG01010_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);
- });
- },
- action: function() {
- var _this = this;
- $('#ITP_LIST_MRTNMNG01010_POP_WHS_AREA button[id$="POP_WHS_CHOICE"]').off('click').on('click', function() {
- var whsId = $(this).data('whs-id');
- $.each(_this.rows, function (i, item) {
- if(whsId === item.whsId) {
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_ID').val(item.whsId);
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_NM').val(item.whsNm);
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_LOCATION').val(item.location);
- mobPopObj.hide(ID_ITP_POP_MRTNMNG01010_WHS_AREA);
- itp_fn_form_clear_validate(null, '#ITP_FORM_MRTNMNG01010_DETAIL');
- return false;
- }
- });
- });
- $('#ITP_FORM_MRTNMNG01010_POP_WHS button[id="ITP_BTN_MRTNMNG01010_POP_WHS_SEARCH"]').off('click').on('click', function() {
- _this.search();
- });
- },
- delete: function() {
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_ID').val('');
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_NM').val('');
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_LOCATION').val('');
- }
- },
- popReqConfirm: {
- init: function (parentId) {
- this.rtnReqStCd = (parentId === 'ITP_BTN_MRTNMNG01010_DETAIL_RTN_ORDER') ? RTN_REQ_ST_CD_REQUEST_SAVE : RTN_REQ_ST_CD_TEMP_SAVE;
- this.view();
- this.action();
- },
- view: function() {
- console.log(this.rtnReqStCd);
- if(this.rtnReqStCd === RTN_REQ_ST_CD_REQUEST_SAVE) {
- $('#ITP_POP_MRTNMNG01010_RTN_AREA .msg_save').text('빈품요청 하시겠습니까?');
- } else {
- $('#ITP_POP_MRTNMNG01010_RTN_AREA .msg_save').text('임시저장 하시겠습니까?');
- }
- $('#ITP_POP_MRTNMNG01010_RTN_AREA .fnRtnReqDt').text($('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_DLV_REQ_DT').val());
- $('#ITP_POP_MRTNMNG01010_RTN_AREA .fnItemQty').text(CommonObj.currency.add(mobContObj.list.rows.length, '개'));
- $('#ITP_POP_MRTNMNG01010_RTN_AREA .fnRtnAmt').text($('#ITP_FORM_MRTNMNG01010_DETAIL .fnRtnReqAmt').text());
- $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_RTN_REQ_ST_CD').val(this.rtnReqStCd);
- },
- action: function() {
- var _this = this;
- $('#ITP_POP_MRTNMNG01010_RTN_AREA button[id="ITP_BTN_MRTNMNG01010_POP_RTN_CONFIRM"]').off('click').on('click', function() {
- _this.save('#ITP_FORM_MRTNMNG01010_DETAIL');
- });
- },
- save: function(formId) {
- let param = $(formId).serializeObject();
- var gridInsertData = [];
- $.each(mobContObj.list.rows, function(index, row) {
- var item = {};
- item['viewCd'] = 'C';
- item['brandUnitUnqNo'] = row.brandUnitUnqNo;
- item['itemId'] = row.itemId;
- item['itemNm'] = row.itemNm;
- item['rtnAmt'] = parseInt(row.unitAmt) * parseInt(row.pchReqQty);
- item['rtnDvsn'] = row.rtnDvsn;
- item['rtnQty'] = row.pchReqQty;
- item['rtnReqDtlNo'] = row.rtnReqDtlNo;
- item['rtnReqUnqNo'] = row.rtnReqUnqNo;
- item['rtnRsn'] = row.rtnRsn;
- item['rtnRsnDvsn'] = row.rtnRsnDvsn;
- item['spplyId'] = row.spplyId;
- item['storeUnitUnqNo'] = row.storeUnitUnqNo;
- item['unit'] = row.unit;
- item['unitAmt'] = row.unitAmt;
- item['unitGubun'] = row.unitGubun;
- gridInsertData.push(item);
- });
- param.gridInsertData = gridInsertData;
- param['colReqDt'] = param.colReqDt.replace(/[^0-9]/g, "");
- console.log(JSON.stringify(param));
- var saveFn = function (result) {
- console.log(result);
- mobPopObj.hide('ITP_POP_MRTNMNG01010_RTN_AREA');
- $('#ITP_LIST_MRTNMNG01010_DETAIL_ROWS').empty();
- };
- fn_ajax_call(API_MOBILE_SAVE, JSON.stringify(param), saveFn, 'POST');
- }
- },
- 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_MRTNMNG01010_DETAIL_RTN_ORDER' || parentId === 'ITP_BTN_MRTNMNG01010_DETAIL_TEMP_SAVE') {
- var formId = '#ITP_FORM_MRTNMNG01010_DETAIL';
- itp_fn_form_clear_validate(null, formId);
- if (itp_fn_form_event.isValid(formId)) {
- mobPopObj.init(popId, parentId);
- }
- } else {
- mobPopObj.init(popId, parentId);
- }
- },
- hide: function(id) {
- $('#' + id).closest('.mobile-pop-close').hide();
- }
- };
|