ITP_MPOMNG01010.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. require(['config'], function() {
  2. require([
  3. ], function($) {
  4. mobPageObj.init();
  5. });
  6. });
  7. /*API URL*/
  8. const API_MOBILE_INIT_INFO = '/api/pomng/init-pchReq';
  9. const API_MOBILE_SAVE = '/api/pomng/save-pchReq';
  10. const API_POP_SEARCH_LIST = '/api/whs/mng/pop-whs-search';
  11. const API_POP_ITEM_LIST = '/api/item/pop-grid-list';
  12. const API_MOBILE_BARCODE = '/api/item/info-barcode-item'; // 바코드
  13. const ID_ITP_POP_MPOMNG01010_REQ_AREA = "ITP_POP_MPOMNG01010_REQ_AREA";
  14. const ID_ITP_POP_MPOMNG01010_WHS_AREA = "ITP_POP_MPOMNG01010_WHS_AREA";
  15. const ID_ITP_POP_MPOMNG01010_ITEM_AREA = "ITP_POP_MPOMNG01010_ITEM_AREA";
  16. const PCH_REQ_ST_CD_TEMP_SAVE ="PR00";
  17. const PCH_REQ_ST_CD_REQUEST_SAVE ="PR20";
  18. let mobPageObj = {
  19. isPrevPage: false,
  20. pageParam: null,
  21. init: function () {
  22. this.ui.init();
  23. this.event.init();
  24. this.ready();
  25. },
  26. ui: {
  27. init: function () {
  28. this.info();
  29. },
  30. info: function() {
  31. $('input:hidden[id$="_BRAND_ID"]').val(fn_make_user_info.get('brandId'));
  32. $('input:hidden[id$="_STORE_ID"]').val(fn_make_user_info.get('storeId'));
  33. $('#ITP_MOBILE_MPOMNG01010 .itp_input.date').datepicker(ITP_DATE_LANGUAGE);
  34. $('#ITP_FORM_MPOMNG01010_DETAIL_DLV_REQ_DT').datepicker('setDate', itp_fn_date_add('D', 5));
  35. // if(fn_make_user_info.get('authTpCd') === '50') {
  36. // $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_NM').attr('readonly', true);
  37. // $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_BTN_MPOMNG01010_DETAIL_SEARCH_WHS_NM').attr('disabled', true);
  38. // $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_BTN_MPOMNG01010_DETAIL_DELETE_WHS_NM').attr('disabled', true);
  39. // }
  40. }
  41. },
  42. event: {
  43. init: function() {
  44. this.button();
  45. },
  46. button: function() {
  47. $('button[id^="ITP_BTN_MPOMNG01010_DETAIL"]').on('click', function() {
  48. if($(this).is('[data-call-popup]')) {
  49. mobPopObj.show($(this).data('call-popup'), $(this).attr('id'));
  50. } else {
  51. var id = $(this).attr('id');
  52. switch (id) {
  53. case 'ITP_BTN_MPOMNG01010_DETAIL_DELROW' : mobContObj.list.delRow(); break;
  54. case 'ITP_BTN_MPOMNG01010_DETAIL_SEARCH_WHS_NM' : mobPopObj.popWhsNm.init(); break;
  55. case 'ITP_BTN_MPOMNG01010_DETAIL_DELETE_WHS_NM' : mobPopObj.popWhsNm.delete(); break;
  56. case 'ITP_BTN_MPOMNG01010_DETAIL_SCAN' : mobContObj.barcode.callApp(); break;
  57. case 'ITP_BTN_MPOMNG01010_DETAIL_WISH' : mobContObj.wishList.init(); break;
  58. case 'ITP_BTN_MPOMNG01010_DETAIL_CANCEL' : mobContObj.cancel(); break;
  59. }
  60. }
  61. return false;
  62. });
  63. }
  64. },
  65. ready: function() {
  66. mobContObj.init();
  67. }
  68. };
  69. let mobContObj = {
  70. init: function() {
  71. this.list.empty();
  72. this.data.load();
  73. },
  74. data: {
  75. initPchReq: null,
  76. load: function() {
  77. var _this = this;
  78. var callbackFn = function(result) {
  79. console.log(result);
  80. _this.initPchReq = result;
  81. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_BRAND_ID').val(result.brandId);
  82. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_STORE_ID').val(result.storeId);
  83. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOAN_DVSN').val(result.loanDvsn);
  84. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOAN_MGNT_UNQ_NO').val(result.loanMgntUnqNo);
  85. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_PCH_REQ_DVSN').val(result.pchReqDvsn);
  86. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_PCH_REQ_UNQ_NO').val(result.pchReqUnqNo);
  87. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_MALL_ID').val(result.mallId);
  88. $('#ITP_FORM_MPOMNG01010_DETAIL .fnPchReqAmtTot').text(CommonObj.currency.add('0'));
  89. $('#ITP_FORM_MPOMNG01010_DETAIL .fnOrdUseAmt').text(CommonObj.currency.add(result.ordUseAmt));
  90. if(result.whsId !== '' && result.location !== '') {
  91. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_ID').val(result.whsId);
  92. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_NM').val(result.whsNm);
  93. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOCATION').val(result.location);
  94. }
  95. };
  96. const param = {brandId:fn_make_user_info.get('brandId'), storeId:fn_make_user_info.get('storeId')};
  97. fn_ajax_call(API_MOBILE_INIT_INFO, param, callbackFn, 'GET');
  98. }
  99. },
  100. list: {
  101. rows: [],
  102. addRow: function() {
  103. },
  104. delRow: function() {
  105. this.detachRow();
  106. },
  107. attachRow: function (items) {
  108. var _this = this;
  109. var fnIsExist = function(rows, item) {
  110. var isExist = false;
  111. $.each(rows, function(i, row) {
  112. if(row.brandUnitUnqNo === item.brandUnitUnqNo) {
  113. isExist = true;
  114. return false;
  115. }
  116. });
  117. return isExist;
  118. };
  119. $.each(items, function(i, item) {
  120. if(!fnIsExist(_this.rows, item)) {
  121. _this.rows.push(item);
  122. $('#ITP_LIST_MPOMNG01010_ITEM_AREA .panel-group').append($('#ITP_LIST_MPOMNG01010_DETAIL_ROWCOPY').html());
  123. var $li = $('#ITP_LIST_MPOMNG01010_ITEM_AREA .panel-group > .list-row:last');
  124. $li.find('.fnBrandUnitUnqNo').val(item.brandUnitUnqNo);
  125. $li.find('.fnItemNm').text(item.itemNm);
  126. $li.find('#ITP_MPOMNG01010_DETAIL_NUM').val(item.pchReqQty ? item.pchReqQty : '1');
  127. $li.find('.fnUnitAmt').text(CommonObj.currency.add(item.unitAmt));
  128. $li.find('.fnOrdAmt').text(CommonObj.currency.add(Number(item.unitAmt) * Number(item.pchReqQty ? item.pchReqQty : '1')));
  129. $('.list-row #ITP_BTN_MPOMNG01010_DETAIL_PLUS')[$li.index()].addEventListener('click', function() { _this.actPlus(this); });
  130. $('.list-row #ITP_BTN_MPOMNG01010_DETAIL_MINUS')[$li.index()].addEventListener('click', function() { _this.actMinus(this); });
  131. $('.item-row #ITP_MPOMNG01010_DETAIL_NUM')[$li.index()].addEventListener('input', function() { _this.actInput(this); });
  132. _this.pchReqAmtTot();
  133. }
  134. });
  135. this.empty();
  136. },
  137. detachRow: function () {
  138. if($('#ITP_LIST_MPOMNG01010_ITEM_AREA input:checkbox[name=brandUnitUnqNo]:checked').length > 0) {
  139. var _this = this;
  140. $('#ITP_LIST_MPOMNG01010_DETAIL_ROWS li').each(function(index, elem) {
  141. var __this = this;
  142. var isChecked = $(this).find('input[type="checkbox"]').is(':checked');
  143. if(isChecked) {
  144. $.each(_this.rows, function(i, row){
  145. if(row.brandUnitUnqNo === $(__this).find('input[type="checkbox"]').val()) {
  146. _this.rows.splice(i, 1);
  147. return false;
  148. }
  149. });
  150. $(this).remove();
  151. }
  152. });
  153. this.pchReqAmtTot();
  154. }
  155. this.empty();
  156. },
  157. actPlus: function(elem) {
  158. var elQty = $(elem).prev();
  159. var num = Number($(elQty).val());
  160. if(num < 100000) {
  161. var calcNum = num + 1;
  162. $(elQty).val(calcNum.toString());
  163. this.rows[elQty.parents('li').index()]['pchReqQty'] = calcNum;
  164. this.pchReqAmtUnit(elem, calcNum);
  165. this.pchReqAmtTot();
  166. }
  167. },
  168. actMinus: function(elem) {
  169. var elQty = $(elem).next();
  170. var num = Number($(elQty).val());
  171. if(num > 1) {
  172. var calcNum = num - 1;
  173. $(elQty).val(calcNum.toString());
  174. this.rows[elQty.parents('li').index()]['pchReqQty'] = calcNum;
  175. this.pchReqAmtUnit(elem, calcNum);
  176. this.pchReqAmtTot();
  177. }
  178. },
  179. actInput: function(elem) {
  180. var _this = this;
  181. var index = $(elem).parents('li').index();
  182. CommonObj.chkMaxLength(elem, function(qty) {
  183. mobContObj.list.rows[index]['pchReqQty'] = qty;
  184. mobContObj.list.pchReqAmtUnit(elem, qty);
  185. mobContObj.list.pchReqAmtTot();
  186. });
  187. },
  188. pchReqAmtUnit: function(elem, qty) {
  189. var $div = $(elem).parent().prev();
  190. var unitAmt = CommonObj.onlyNumber($div.find('.fnUnitAmt').text());
  191. $div.find('.fnOrdAmt').text(CommonObj.currency.add(Number(unitAmt ? unitAmt : 0) * Number(qty)));
  192. },
  193. pchReqAmtTot: function() {
  194. var reqAmt = 0;
  195. $.each(this.rows, function(index, item) {
  196. var qty = item.pchReqQty;
  197. var amt = item.unitAmt;
  198. reqAmt += Number(qty) * amt;
  199. });
  200. $('#ITP_AJAX_MPOMNG01010_VIEW_CONTAINER').find('.fnPchReqAmtTot').text(CommonObj.currency.add(reqAmt));
  201. },
  202. empty: function() {
  203. ($('#ITP_LIST_MPOMNG01010_DETAIL_ROWS li').length > 0) ? $('.itp_non_data').hide() : $('.itp_non_data').show();
  204. }
  205. },
  206. reset: function() {
  207. $('#ITP_LIST_MPOMNG01010_DETAIL_ROWS').children().remove();
  208. this.list.rows.length = 0;
  209. this.data.load();
  210. },
  211. cancel: function () {
  212. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/main.html');
  213. },
  214. barcode: {
  215. callApp: function() {
  216. location.replace('app:scan');
  217. // appCallFnBarcode('ITEM221217000006BRD221200038');
  218. }
  219. },
  220. wishList: {
  221. init: function () {
  222. console.log('wishList');
  223. }
  224. }
  225. };
  226. function appCallFnBarcode(barcode) {
  227. var infoFn = function(result) {
  228. // console.log(JSON.stringify(result));
  229. if(result) {
  230. mobContObj.list.attachRow([result]);
  231. }
  232. };
  233. const param = {
  234. 'sBrandId': fn_make_user_info.get('brandId'),
  235. 'sStoreId': fn_make_user_info.get('storeId'),
  236. 'sBarcode': barcode
  237. };
  238. fn_ajax_call(API_MOBILE_BARCODE, param, infoFn, 'GET');
  239. }
  240. let mobPopObj = {
  241. init: function(popId, parentId) {
  242. switch (popId) {
  243. case 'ITP_POP_MPOMNG01010_REQ_AREA' : this.popReqConfirm.init(parentId); break;
  244. case 'ITP_POP_MPOMNG01010_WHS_AREA' : this.popWhsNm.init(); break;
  245. case 'ITP_POP_MPOMNG01010_ITEM_AREA' : this.popItem.init(); break;
  246. case 'ITP_POP_MPOMNG01010_WISH_LIST_AREA' : this.popWishList.init(); break;
  247. }
  248. },
  249. popItem: {
  250. // rows: null,
  251. init: function() {
  252. $('#ITP_POP_MPOMNG01010_ITEM_AREA #ITP_FORM_MPOMNG01010_POP_ITEM_KEYWORD').val('');
  253. this.search();
  254. },
  255. search: function() {
  256. $('#ITP_LIST_MPOMNG01010_POP_ITEM_AREA .panel-group').empty();
  257. var callbackFn = function(result) {
  258. console.log(result);
  259. mobPopObj.popItem.rows = result.gridRows;
  260. $.each(mobPopObj.popItem.rows, function (i, item) {
  261. $('#ITP_LIST_MPOMNG01010_POP_ITEM_AREA .panel-group').append($('#ITP_LIST_MPOMNG01010_POP_ITEM_ROWCOPY').html());
  262. var $li = $('#ITP_LIST_MPOMNG01010_POP_ITEM_AREA .panel-group > .row_2:last');
  263. $li.find('#ITP_FORM_MPOMNG01010_POP_ITEM_CHECKBOX').val(item.itemId);
  264. $li.find('.fnItemNm').text(item.itemNm);
  265. $li.find('.fnUnitAmt').text(CommonObj.currency.add(item.unitAmt));
  266. $li.find('.fnOrdAmt').text(CommonObj.currency.add(item.unitAmt));
  267. });
  268. mobPopObj.popItem.addRow.init();
  269. };
  270. let param = $('#ITP_FORM_MPOMNG01010_POPUP_ITEM').serializeObject();
  271. fn_ajax_call(API_POP_ITEM_LIST, JSON.stringify(param), callbackFn, 'POST');
  272. },
  273. addRow: {
  274. init: function() {
  275. this.button.init();
  276. },
  277. button: {
  278. init: function() {
  279. var _this = this;
  280. $('button[id^="ITP_BTN_MPOMNG01010_POP_ITEM_"]').off('click').on('click', function() {
  281. var id = $(this).attr('id');
  282. switch (id) {
  283. case 'ITP_BTN_MPOMNG01010_POP_ITEM_PLUS' : _this.actPlus($(this)); break;
  284. case 'ITP_BTN_MPOMNG01010_POP_ITEM_MINUS' : _this.actMinus($(this)); break;
  285. case 'ITP_BTN_MPOMNG01010_POP_ITEM_ADD' : _this.addItems(); break;
  286. // case 'ITP_BTN_MPOMNG01010_POP_ITEM_ADD' : _this.actItemAdd($(this)); break;
  287. case 'ITP_BTN_MPOMNG01010_POP_ITEM_SEARCH' : mobPopObj.popItem.search(); break;
  288. case 'ITP_BTN_MPOMNG01010_POP_ITEM_CLOSE' : mobPopObj.hide(id); break;
  289. }
  290. return false;
  291. });
  292. $('input[id="ITP_MPOMNG01010_POP_NUM"]').off('input').on('input', function() {
  293. var _this = this;
  294. CommonObj.chkMaxLength(this, function(qty) { mobPopObj.popItem.addRow.button.reqAmtUnit(_this, qty) });
  295. });
  296. },
  297. actPlus: function(elem) {
  298. var elQty = $(elem).prev();
  299. var num = Number($(elQty).val());
  300. if(num < 100000) {
  301. var calcNum = num + 1;
  302. $(elQty).val(calcNum.toString());
  303. this.reqAmtUnit(elem, calcNum);
  304. }
  305. },
  306. actMinus: function(elem) {
  307. var elQty = $(elem).next();
  308. var num = Number($(elQty).val());
  309. if(num > 1) {
  310. var calcNum = num - 1;
  311. $(elQty).val(calcNum.toString());
  312. this.reqAmtUnit(elem, calcNum);
  313. }
  314. },
  315. reqAmtUnit: function(elem, qty) {
  316. var $li = $(elem).closest('li');
  317. var unitAmt = CommonObj.onlyNumber($li.find('.fnUnitAmt').text());
  318. $li.find('.fnOrdAmt').text(CommonObj.currency.add(Number(unitAmt ? unitAmt : 0) * Number(qty)));
  319. },
  320. actItemAdd: function(elem) {
  321. var $li = $(elem).closest('li');
  322. var item = mobPopObj.popItem.rows[$li.index()];
  323. item['pchReqQty'] = $li.find('.fnPchReqQty').html();
  324. // var index = $(elem).closest('li').index();
  325. // var item = mobPopObj.popItem.rows[index];
  326. // item['pchReqQty'] = $(elem).closest('li').find('.fnPchReqQty').html();
  327. mobContObj.list.attachRow(item);
  328. },
  329. addItems: function() {
  330. var items = [];
  331. var chkMsg = '';
  332. $('#ITP_LIST_MPOMNG01010_POP_ITEM_ROWS').find('input:checkbox').each(function() {
  333. if($(this).is(':checked')) {
  334. var val = $(this).closest('li').find('#ITP_MPOMNG01010_POP_NUM').val();
  335. if(val === '') {
  336. chkMsg = '수량을 입력하세요.';
  337. return false;
  338. }
  339. var index = $(this).closest('li').index();
  340. var item = mobPopObj.popItem.rows[index];
  341. item['pchReqQty'] = val;
  342. items.push(item);
  343. }
  344. });
  345. if(chkMsg !== '') {
  346. itp_fn_modal_alert(chkMsg);
  347. return;
  348. }
  349. if(items.length < 1) {
  350. itp_fn_modal_alert('품목을 선택하세요.');
  351. return;
  352. }
  353. mobContObj.list.attachRow(items);
  354. mobPopObj.popItem.close();
  355. }
  356. }
  357. },
  358. delRow: function() {
  359. },
  360. close: function() {
  361. this.rows.length = 0;
  362. $('#ITP_LIST_MPOMNG01010_POP_ITEM_ROWS').children().remove();
  363. mobPopObj.hide('ITP_POP_MPOMNG01010_ITEM_AREA');
  364. }
  365. },
  366. popWishList: {
  367. rows: [],
  368. init: function () {
  369. this.clear();
  370. this.load();
  371. },
  372. load: function() {
  373. },
  374. search: function() {
  375. },
  376. clear: function() {
  377. this.rows.length = 0;
  378. }
  379. },
  380. popWhsNm: {
  381. init: function () {
  382. $('#ITP_LIST_MPOMNG01010_POP_WHS_AREA .mb_0').children().remove();
  383. this.rows.length = 0;
  384. this.search();
  385. this.action();
  386. },
  387. rows: [],
  388. search: function () {
  389. var _this = this;
  390. $('#ITP_LIST_MPOMNG01010_POP_WHS_AREA .mb_0').empty();
  391. var callbackFn = function(result) {
  392. console.log(result);
  393. $.each(result.gridRows, function (i, item) {
  394. $('#ITP_LIST_MPOMNG01010_POP_WHS_AREA .mb_0').append($('#ITP_LIST_MPOMNG01010_POP_WHS_ROWCOPY').html());
  395. var $li = $('#ITP_LIST_MPOMNG01010_POP_WHS_AREA .mb_0 > .row_2:last');
  396. $li.find('.fnWhsNm').text(item.whsNm);
  397. $li.find('.fnLocationNm').text(item.locationNm);
  398. $li.find('.fnWhsId').data('whs-id', item.whsId);
  399. $li.find('.fnWhsId').data('location', item.location);
  400. $('#ITP_LIST_MPOMNG01010_POP_WHS_ROWS li button')[$li.index()].addEventListener('click', function() { _this.choice(this); });
  401. });
  402. };
  403. const param = $('#ITP_FORM_MPOMNG01010_POP_WHS').serializeObject();
  404. (fn_make_user_info.get('authTpCd') === '50') ? param.swhsDvsn = 'W02' : param.swhsDvsn = 'W01';
  405. fn_ajax_call(API_POP_SEARCH_LIST, JSON.stringify(param), callbackFn, 'POST');
  406. },
  407. action: function() {
  408. var _this = this;
  409. $('#ITP_FORM_MPOMNG01010_POP_WHS button[id="ITP_BTN_MPOMNG01010_POP_WHS_SEARCH"]').off('click').on('click', function() {
  410. _this.search();
  411. });
  412. },
  413. choice: function(elem) {
  414. var whsId = $(elem).data('whs-id');
  415. var whsNm = $(elem).parent().prev().find('.fnWhsNm').text();
  416. var location = $(elem).data('location');
  417. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_ID').val(whsId);
  418. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_NM').val(whsNm);
  419. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOCATION').val(location);
  420. mobPopObj.hide(ID_ITP_POP_MPOMNG01010_WHS_AREA);
  421. itp_fn_form_clear_validate(null, '#ITP_FORM_MPOMNG01010_DETAIL');
  422. },
  423. delete: function() {
  424. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_ID').val('');
  425. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_WHS_NM').val('');
  426. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOCATION').val('');
  427. }
  428. },
  429. popReqConfirm: {
  430. saveMode: 1, // 1 : 임시저장, 2 : 구매요청, 요청금액이 가능금액보다 클 경우 (3 : PG 정보 없음, 4 : 선불매장, 5 : 후불매장)
  431. init: function (parentId) {
  432. this.formId = '#ITP_FORM_MPOMNG01010_DETAIL';
  433. this.pchReqStCd = (parentId === 'ITP_BTN_MPOMNG01010_DETAIL_REQ_ORDER') ? PCH_REQ_ST_CD_REQUEST_SAVE : PCH_REQ_ST_CD_TEMP_SAVE;
  434. this.view();
  435. this.action();
  436. },
  437. view: function() {
  438. var popMsg = '';
  439. var loanDvsn = $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_LOAN_DVSN').val();
  440. var ordUseAmt = CommonObj.onlyNumber($('#ITP_FORM_MPOMNG01010_DETAIL .fnOrdUseAmt').text());
  441. var pchReqAmtTot = CommonObj.onlyNumber($('#ITP_FORM_MPOMNG01010_DETAIL .fnPchReqAmtTot').text());
  442. if(this.pchReqStCd === PCH_REQ_ST_CD_REQUEST_SAVE) { // 구매요청
  443. if(loanDvsn === 'LD03') { // 무정산
  444. this.saveMode = 2;
  445. popMsg = '구매요청 하시겠습니까?';
  446. $('#ITP_POP_MPOMNG01010_REQ_AREA .divOrdPssblAmt').hide();
  447. $('#ITP_POP_MPOMNG01010_REQ_AREA .divOrdAmt').hide();
  448. $('#ITP_POP_MPOMNG01010_REQ_AREA .divOrdReqAmt').addClass('border');
  449. $('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('확인');
  450. } else {
  451. $('#ITP_POP_MPOMNG01010_REQ_AREA .divOrdPssblAmt').show();
  452. $('#ITP_POP_MPOMNG01010_REQ_AREA .divOrdAmt').show();
  453. $('#ITP_POP_MPOMNG01010_REQ_AREA .divOrdReqAmt').removeClass('border');
  454. if (Number(ordUseAmt) < Number(pchReqAmtTot)) { // 요청금액이 가능금액보다 클 경우
  455. if(CommonObj.isPayPossible()) { // PG 정보 여부
  456. if(loanDvsn === 'LD01') { // 선불매장
  457. this.saveMode = 4;
  458. popMsg = '선불매장이므로 결재를 하셔야 구매요청이 진행이 됩니다.<br>' +
  459. '결재를 하시겠습니까?';
  460. $('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('결제');
  461. } else if(loanDvsn === 'LD02') { // 후불매장
  462. this.saveMode = 5;
  463. popMsg = '구매한도가 부족합니다.<br>' +
  464. '선결재를 하신 후에 구매요청을 하시기 바랍니다.<br>' +
  465. '결재를 하시겠습니까?';
  466. $('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('결제');
  467. }
  468. } else {
  469. this.saveMode = 3;
  470. if(loanDvsn === 'LD01') { // 선불매장
  471. popMsg = '선불매장이므로 입금을 하시고, 입금등록 후 브랜드에서 승인이 되어야 구매요청을 하실 수 있습니다.';
  472. } else if(loanDvsn === 'LD02') { // 후불매장
  473. popMsg = '구매한도가 부족합니다.<br>' +
  474. '선입금을 하시고, 입금등록 후 브랜드에서 승인이 되어야 구매요청을 하실 수 있습니다.\n';
  475. }
  476. $('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('확인');
  477. }
  478. } else {
  479. this.saveMode = 2;
  480. popMsg = '구매요청 하시겠습니까?';
  481. $('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('확인');
  482. }
  483. }
  484. } else { // 임시저장
  485. this.saveMode = 1;
  486. popMsg = '임시저장 하시겠습니까?';
  487. $('#ITP_POP_MPOMNG01010_REQ_AREA #ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM').text('확인');
  488. }
  489. $('#ITP_POP_MPOMNG01010_REQ_AREA .fnPopDlvReqDt').text($('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_DLV_REQ_DT').val());
  490. $('#ITP_POP_MPOMNG01010_REQ_AREA .fnItemQty').text(CommonObj.currency.add(mobContObj.list.rows.length, '개'));
  491. $('#ITP_POP_MPOMNG01010_REQ_AREA .fnOrdReqAmt').text($('#ITP_AJAX_MPOMNG01010_VIEW_CONTAINER .fnPchReqAmtTot').text());
  492. $('#ITP_POP_MPOMNG01010_REQ_AREA .fnOrdPssblAmt').text($('#ITP_AJAX_MPOMNG01010_VIEW_CONTAINER .fnOrdUseAmt').text());
  493. var ordAmt = Number(pchReqAmtTot) - Number(ordUseAmt);
  494. $('#ITP_POP_MPOMNG01010_REQ_AREA .fnOrdAmt').text(CommonObj.currency.add(ordAmt > 0 ? ordAmt : 0));
  495. $('#ITP_POP_MPOMNG01010_REQ_AREA .pop_msg').html(popMsg);
  496. },
  497. action: function() {
  498. var _this = this;
  499. $('#ITP_POP_MPOMNG01010_REQ_AREA button[id="ITP_BTN_MPOMNG01010_POP_REQ_CONFIRM"]').off('click').on('click', function() {
  500. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_PCH_REQ_ST_CD').val(_this.pchReqStCd);
  501. _this.save();
  502. });
  503. },
  504. save: function() {
  505. var procSave = function () {
  506. let param = $('#ITP_FORM_MPOMNG01010_DETAIL').serializeObject();
  507. $.each(mobContObj.list.rows, function(index, item) {
  508. item['viewCd'] = 'C';
  509. item['pchReqAmt'] = Number(item.unitAmt) * Number(item.pchReqQty);
  510. });
  511. param.gridInsertData = mobContObj.list.rows;
  512. var saveFn = function (result) {
  513. console.log(result);
  514. mobPopObj.hide('ITP_POP_MPOMNG01010_REQ_AREA');
  515. mobContObj.reset();
  516. };
  517. // console.log(JSON.stringify(param));
  518. fn_ajax_call(API_MOBILE_SAVE, JSON.stringify(param), saveFn, 'POST');
  519. };
  520. if (this.saveMode === 1 || this.saveMode === 2 || this.saveMode === 3) {
  521. if(this.saveMode === 3)
  522. $('#ITP_FORM_MPOMNG01010_DETAIL #ITP_FORM_MPOMNG01010_DETAIL_PCH_REQ_ST_CD').val(PCH_REQ_ST_CD_TEMP_SAVE);
  523. procSave();
  524. } else if (this.saveMode === 4 || this.saveMode === 5) {
  525. // 결제 팝업
  526. var ordUseAmt = CommonObj.onlyNumber($('#ITP_FORM_MPOMNG01010_DETAIL .fnOrdUseAmt').text());
  527. var pchReqAmtTot = CommonObj.onlyNumber($('#ITP_FORM_MPOMNG01010_DETAIL .fnPchReqAmtTot').text());
  528. var args = {
  529. 'payTpCd' : '40',
  530. 'brandId' : $('#ITP_FORM_MPOMNG01010_DETAIL_BRAND_ID').val(),
  531. 'storeId' : $('#ITP_FORM_MPOMNG01010_DETAIL_STORE_ID').val(),
  532. 'goodsAmt' : Number(pchReqAmtTot - ordUseAmt)
  533. };
  534. fn_call_popup('biz', 'BIZPOP_PO_PAYMENT', '#ITP_ASIDE', procSave, args, 'M');
  535. }
  536. }
  537. },
  538. show: function(popId, parentId) {
  539. var _this = this;
  540. $('button[id$="CLOSE"]').off('click').on('click', function() {
  541. var id = $(this).attr('id');
  542. if($(this).hasClass('btn-pop-close')) {
  543. _this.hide(id);
  544. }
  545. });
  546. if(parentId === 'ITP_BTN_MPOMNG01010_DETAIL_REQ_ORDER' || parentId === 'ITP_BTN_MPOMNG01010_DETAIL_TEMP_SAVE') {
  547. var formId = '#ITP_FORM_MPOMNG01010_DETAIL';
  548. itp_fn_form_clear_validate(null, formId);
  549. if (itp_fn_form_event.isValid(formId)) {
  550. if($('#ITP_LIST_MPOMNG01010_DETAIL_ROWS > li').size() < 1) {
  551. itp_fn_modal_alert('품목추가 버튼을 이용하여 품목을 추가해 주세요.');
  552. return false;
  553. } else {
  554. var chkMsg = '';
  555. $.each(mobContObj.list.rows, function(index, item) {
  556. if(item.pchReqQty === '') {
  557. chkMsg = '수량을 입력하세요.';
  558. return false;
  559. }
  560. });
  561. if(chkMsg !== '') {
  562. itp_fn_modal_alert(chkMsg);
  563. return;
  564. }
  565. $('#' + popId).show();
  566. mobPopObj.init(popId, parentId);
  567. }
  568. }
  569. } else {
  570. $('#' + popId).show();
  571. mobPopObj.init(popId, parentId);
  572. }
  573. },
  574. hide: function(id) {
  575. $('#' + id).closest('.mobile-pop-close').hide();
  576. }
  577. };