123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- 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('M', 0));
- 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.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 .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 (item) {
- console.log(item);
- var _this = this;
- 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_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));
- this.pchReqAmtTot();
- $('.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); });
- }
- },
- 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 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());
- console.log('actPlus ===> ' + num);
- $($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());
- console.log('actMinus ===> ' + num);
- 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_MPOMNG01010_VIEW_CONTAINER').find('.fnPchReqAmtTot').text(CommonObj.currency.add(reqAmt));
- }
- },
- 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));
- });
- 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.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());
- },
- 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_MPOMNG01010_POP_WHS_AREA .panel-group').empty();
- var callbackFn = function(result) {
- console.log(result);
- _this.view(result.gridRows);
- };
- const param = $('#ITP_FORM_MPOMNG01010_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_MPOMNG01010_POP_WHS_AREA .panel-group').append($('#ITP_LIST_MPOMNG01010_POP_WHS_ROWCOPY').html());
- var $li = $('#ITP_LIST_MPOMNG01010_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_MPOMNG01010_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_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;
- }
- });
- });
- $('#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 (ordUseAmt < pchReqAmtTot) { // 요청금액이 가능금액보다 클 경우
- if($('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_MALL_ID').val() === '') { // PG 정보 없음
- this.saveMode = 3;
- popMsg = '무통장 입금 후 구매요청해 주세요.<br>' +
- '임시저장 하시겠습니까?';
- $('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('확인');
- } else {
- 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 = 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 .fnOrdAmt').text(CommonObj.currency.add(pchReqAmtTot));
- $('#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 (rtnFn) {
- let param = $('#ITP_FORM_MPOMNG01010_DETAIL').serializeObject();
- $.each(mobContObj.list.rows, function(index, item) {
- item['viewCd'] = 'C';
- });
- param.gridInsertData = mobContObj.list.rows;
- var saveFn = function (result) {
- console.log(result);
- mobPopObj.hide('ITP_POP_MPOMNG01010_REQ_AREA');
- if(typeof rtnFn === 'function') rtnFn();
- };
- 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 popFn = function(rowDataPop) {
- console.log(JSON.stringify(rowDataPop));
- procSave(function(result) { mobContObj.data.load(); });
- };
- // 결제 팝업
- 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', popFn, 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();
- }
- };
|