ITP_MSTOCKMNG01010.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. require(['config'], function() {
  2. require([
  3. ], function($) {
  4. mobPageObj.init();
  5. });
  6. });
  7. /*API URL*/
  8. const API_MOBILE_GRID_LIST = '/api/stock/mng/detail-grid-list'; // 목록
  9. const API_MOBILE_INFO = '/api/stock/mng/info-stock'; // 상세
  10. const API_MOBILE_SAVE = '/api/stock/mng/proc-stock'; // 저장
  11. const API_MOBILE_HISTORY = '/api/stock/mng/hist-grid-list'; // 이력
  12. const API_MOBILE_WHS_GRID_LIST = '/api/whs/mng/detail-grid-list';
  13. const API_MOBILE_LOCATION_LIST = '/api/whs/mng/location-grid-list';
  14. const API_POP_SEARCH_LIST = '/api/store/pop-grid-list';
  15. const PAGE_MODE_LIST = "LIST";
  16. const PAGE_MODE_VIEW = "VIEW";
  17. let mobPageObj = {
  18. viewMode: PAGE_MODE_LIST,
  19. init: function () {
  20. this.ui.init();
  21. this.event.init();
  22. this.ready();
  23. },
  24. ui: {
  25. init: function () {
  26. this.view();
  27. this.info();
  28. },
  29. view: function() {
  30. },
  31. info: function() {
  32. $('input:hidden[id$="_BRAND_ID"]').val(fn_make_user_info.get('brandId'));
  33. $('input:hidden[id$="_STORE_ID"]').val(fn_make_user_info.get('storeId'));
  34. }
  35. },
  36. event: {
  37. init: function() {
  38. this.action();
  39. },
  40. action: function() {
  41. $('button[id^="ITP_BTN_MSTOCKMNG01010_LIST"]').on('click', function() {
  42. var id = $(this).attr('id');
  43. switch (id) {
  44. case 'ITP_BTN_MSTOCKMNG01010_LIST_SEARCH_WHS_NM' : mobPopObj.popWhsNm.init(); break;
  45. case 'ITP_BTN_MSTOCKMNG01010_LIST_DELETE_WHS_NM' : mobPopObj.popWhsNm.delete(); break;
  46. case 'ITP_BTN_MSTOCKMNG01010_LIST_SEARCH' : mobContentObj.list.search(); break;
  47. case 'ITP_BTN_MSTOCKMNG01010_LIST_ADD_STCK' : mobContentObj.list.procStck(); break;
  48. }
  49. return false;
  50. });
  51. $('button[id^="ITP_BTN_MSTOCKMNG01010_VIEW"]').on('click', function() {
  52. var id = $(this).attr('id');
  53. switch (id) {
  54. case 'ITP_BTN_MSTOCKMNG01010_VIEW_SEARCH' : mobContentObj.view.history.search(); break;
  55. case 'ITP_BTN_MSTOCKMNG01010_VIEW_CANCEL_LIST' : mobContentObj.view.cancel(); break;
  56. }
  57. return false;
  58. });
  59. $('select[id="ITP_FORM_MSTOCKMNG01010_LIST_SEARCH_WHS_NM"]').on('change', function() {
  60. mobContentObj.list.locationList();
  61. });
  62. $(document).on('click', '#ITP_LIST_MSTOCKMNG01010_LIST_ITEM_ROWS li', function() {
  63. var item = mobContentObj.list.rows[$(this).index()];
  64. mobContentObj.list.choice(item);
  65. $('#ITP_LIST_MSTOCKMNG01010_LIST_ITEM_ROWS li').removeClass('check');
  66. $(this).addClass('check');
  67. });
  68. $(document).on('click', '#ITP_LIST_MSTOCKMNG01010_POP_WHS_ROWS li button', function() {
  69. mobPopObj.popWhsNm.choice($(this));
  70. });
  71. }
  72. },
  73. switchScreen: function(mode) {
  74. $('#ITP_MOBILE_MSTOCKMNG01010').find('div[id$="_CONTAINER"]').each(function(i) {
  75. $(this).hide();
  76. });
  77. if(mode === PAGE_MODE_LIST) {
  78. $('#ITP_AJAX_MSTOCKMNG01010_LIST_CONTAINER').show();
  79. this.moreView(true);
  80. } else if(mode === PAGE_MODE_VIEW) {
  81. $('#ITP_AJAX_MSTOCKMNG01010_VIEW_CONTAINER').show();
  82. this.moreView(false);
  83. }
  84. this.viewMode = mode;
  85. },
  86. moreView: function(isScroll) {
  87. var _this = this;
  88. if(isScroll) {
  89. $('#ITP_LIST_MSTOCKMNG01010_LIST_ITEM_AREA').on('scroll', function () {
  90. if($(this).scrollTop() + $(this).innerHeight() + 1 >= $(this)[0].scrollHeight) {
  91. if(mobContentObj.list.totPage > mobContentObj.list.listPage) {
  92. if(!mobContentObj.list.isSearch) {
  93. mobContentObj.list.load();
  94. }
  95. }
  96. }
  97. });
  98. } else {
  99. $('#ITP_LIST_MSTOCKMNG01010_LIST_AREA').off('scroll');
  100. }
  101. },
  102. ready: function() {
  103. mobContentObj.list.init();
  104. }
  105. };
  106. let mobContentObj = {
  107. list: {
  108. listSize: 10,
  109. listPage: 0,
  110. totPage: 0,
  111. isSearch: false,
  112. rows: [],
  113. item: null,
  114. init: function() {
  115. mobPageObj.switchScreen(PAGE_MODE_LIST);
  116. // this.search();
  117. },
  118. search: function() {
  119. this.listPage = 0;
  120. this.totPage = 0;
  121. this.rows.length = 0;
  122. $('#ITP_LIST_MSTOCKMNG01010_LIST_ITEM_ROWS').empty();
  123. this.load();
  124. },
  125. load: function() {
  126. var _this = this;
  127. this.isSearch = true;
  128. var callbackFn = function(result) {
  129. console.log(result);
  130. _this.isSearch = false;
  131. _this.totPage = result.gridTotal;
  132. $.each(result.gridRows, function (i, item) {
  133. $('#ITP_LIST_MSTOCKMNG01010_LIST_ITEM_AREA .panel-group').append($('#ITP_LIST_MSTOCKMNG01010_LIST_ITEM_ROWCOPY').html());
  134. var $li = $('#ITP_LIST_MSTOCKMNG01010_LIST_ITEM_AREA .panel-group > .list-row:last');
  135. $li.find('.fnWhsId').text(item.whsId);
  136. $li.find('.fnWhsNm').text(item.whsNm);
  137. $li.find('.fnItemId').text(item.itemId);
  138. $li.find('.fnItemNm').text(item.itemNm);
  139. $li.find('.fnUnit').text(item.unit);
  140. $li.find('.fnUnitQty').text(item.unitQty);
  141. $li.find('.fnStckQty').text(item.stckQty);
  142. $li.find('.fnPrpStckQty').text(item.prpStckQty);
  143. $li.find('.fnSftStckRt').text(item.sftStckRt);
  144. $li.find('.fnLocationNm').text(item.locationNm);
  145. _this.rows.push(item);
  146. });
  147. };
  148. var errFn = function() { _this.isSearch = false;};
  149. const param = $('#ITP_FORM_MSTOCKMNG01010_LIST_SEARCH').serializeObject();
  150. param.gridPage = ++this.listPage;
  151. param.gridSize = this.listSize;
  152. param.pagingYn = true;
  153. console.log(JSON.stringify(param));
  154. fn_ajax_call(API_MOBILE_GRID_LIST, JSON.stringify(param), callbackFn, 'POST', errFn);
  155. },
  156. choice: function(item) {
  157. this.item = item;
  158. },
  159. procStck: function() {
  160. if(!this.item) {
  161. itp_fn_modal_alert(ITP_MSG_LOCALE.message.ajax.noData);
  162. return;
  163. }
  164. mobPopObj.popProcStck.init(this.item);
  165. }
  166. },
  167. view: {
  168. init: function(item) {
  169. mobPageObj.switchScreen(PAGE_MODE_VIEW);
  170. this.search(item);
  171. },
  172. search: function(item) {
  173. var _this = this;
  174. var callbackFn = function(result) {
  175. console.log(result);
  176. _this.view(result);
  177. };
  178. const param = {
  179. 'brandId': fn_make_user_info.get('brandId'),
  180. 'spplyId': fn_make_user_info.get('spplyId'),
  181. 'loanMgntUnqNo': item.loanMgntUnqNo
  182. };
  183. fn_ajax_call(API_MOBILE_INFO, param, callbackFn, 'GET');
  184. },
  185. view: function(result) {
  186. var _this = this;
  187. var id = '#ITP_AJAX_MSTOCKMNG01010_VIEW_CONTAINER';
  188. $(id).find('.fnStoreNm').text(result.storeNm);
  189. $(id).find('.fnLoanDvsnNm').text(result.loanDvsnNm);
  190. var limitAmt;
  191. if(result.loanDvsn == 'LD01') { // 선불(충전)
  192. limitAmt = result.chrgeLimitAmt;
  193. } else if(result.loanDvsn == 'LD02') { // 후불(신용)
  194. limitAmt = result.credtLimitAmt;
  195. }
  196. $(id).find('.fnLimitAmt').text(CommonObj.currency.add(limitAmt));
  197. $(id).find('.fnUseYnNm').text(result.useYnNm);
  198. $(id).find('.fnPosbLimitAmt').text(CommonObj.currency.add(limitAmt - result.useAmtTotal));
  199. $(id).find('.fnTmpRcvAcctTotal').text(CommonObj.currency.add(result.tmpRcvAcctTotal));
  200. $(id).find('.fnUseAmtTotal').text(CommonObj.currency.add(result.useAmtTotal));
  201. _this.history.init(result.loanMgntUnqNo);
  202. },
  203. cancel: function () {
  204. var id = '#ITP_AJAX_MSTOCKMNG01010_VIEW_CONTAINER';
  205. $(id).find('.fnItemid').text('');
  206. $(id).find('.fnItemNm').text('');
  207. $(id).find('.fnUPodrQty').text('');
  208. $(id).find('.fnUnitAmt').text('');
  209. $(id).find('.fnUnit').text('');
  210. $(id).find('.fnPodrQty').text('');
  211. $(id).find('.fnPodrAmt').text('');
  212. $(id).find('.fnDlvReqDt').text('');
  213. $('#ITP_LIST_MSTOCKMNG01010_VIEW_ITEM_AREA .panel-group').empty();
  214. mobPageObj.switchScreen(PAGE_MODE_LIST);
  215. }
  216. }
  217. };
  218. let mobPopObj = {
  219. popWhsNm: {
  220. popId: 'ITP_POP_MSTOCKMNG01010_WHS_AREA',
  221. rows: [],
  222. init: function () {
  223. this.rows.length = 0;
  224. mobPopObj.show(this.popId);
  225. this.search();
  226. this.action();
  227. },
  228. search: function () {
  229. var _this = this;
  230. $('#ITP_LIST_MSTOCKMNG01010_POP_WHS_AREA .panel-group').empty();
  231. var callbackFn = function(result) {
  232. console.log(result);
  233. _this.view(result.gridRows);
  234. };
  235. const param = $('#ITP_FORM_MSTOCKMNG01010_POP_WHS').serializeObject();
  236. (fn_make_user_info.get('authTpCd') === '50') ? param.swhsDvsn = 'W02' : param.swhsDvsn = 'W01';
  237. fn_ajax_call(API_MOBILE_WHS_GRID_LIST, JSON.stringify(param), callbackFn, 'POST');
  238. },
  239. view: function(gridRows) {
  240. this.rows = gridRows;
  241. $.each(gridRows, function (i, item) {
  242. $('#ITP_LIST_MSTOCKMNG01010_POP_WHS_AREA .panel-group').append($('#ITP_LIST_MSTOCKMNG01010_POP_WHS_ROWCOPY').html());
  243. var $li = $('#ITP_LIST_MSTOCKMNG01010_POP_WHS_AREA .panel-group > .row_2:last');
  244. $li.find('.fnWhsNm').text(item.whsNm);
  245. $li.find('.fnLocationNm').text(item.locationNm);
  246. $li.find('.fnWhsId').data('whs-id', item.whsId);
  247. });
  248. },
  249. choice: function(elem) {
  250. var _this = this;
  251. var whsId = $(elem).data('whs-id');
  252. $.each(this.rows, function (i, item) {
  253. if(whsId === item.whsId) {
  254. $('#ITP_FORM_MSTOCKMNG01010_LIST_SEARCH #ITP_FORM_MSTOCKMNG01010_LIST_SEARCH_WHS_ID').val(item.whsId);
  255. $('#ITP_FORM_MSTOCKMNG01010_LIST_SEARCH #ITP_FORM_MSTOCKMNG01010_LIST_SEARCH_WHS_NM').val(item.whsNm);
  256. _this.close();
  257. _this.location(item.whsId);
  258. return false;
  259. }
  260. });
  261. },
  262. location: function(whsId) {
  263. var callbackFn = function(result) {
  264. fn_make_select_location(result.gridRows, 'ITP_FORM_MSTOCKMNG01010_LIST_SEARCH_LOCATION');
  265. };
  266. var param = {
  267. 'brandId': fn_make_user_info.get('brandId'),
  268. 'storeId': fn_make_user_info.get('storeId'),
  269. 'whsId': whsId
  270. };
  271. fn_ajax_call(API_MOBILE_LOCATION_LIST, JSON.stringify(param), callbackFn, 'POST');
  272. },
  273. action: function() {
  274. var _this = this;
  275. $('button[id^="ITP_BTN_MSTOCKMNG01010_POP_WHS"]').off('click').on('click', function() {
  276. var id = $(this).attr('id');
  277. switch (id) {
  278. case 'ITP_BTN_MSTOCKMNG01010_POP_WHS_SEARCH' : _this.search(); break;
  279. case 'ITP_BTN_MSTOCKMNG01010_POP_WHS_CHOICE' : _this.choice($(this)); break;
  280. case 'ITP_BTN_MSTOCKMNG01010_POP_WHS_CLOSE' : _this.close(); break;
  281. }
  282. return false;
  283. });
  284. },
  285. delete: function() {
  286. $('#ITP_FORM_MSTOCKMNG01010_LIST_SEARCH #ITP_FORM_MSTOCKMNG01010_LIST_SEARCH_WHS_ID').val('');
  287. $('#ITP_FORM_MSTOCKMNG01010_LIST_SEARCH #ITP_FORM_MSTOCKMNG01010_LIST_SEARCH_WHS_NM').val('');
  288. $('#ITP_FORM_MSTOCKMNG01010_LIST_SEARCH #ITP_FORM_MSTOCKMNG01010_LIST_SEARCH_LOCATION option').remove();
  289. },
  290. close: function() {
  291. this.rows.length = 0;
  292. $('#ITP_POP_MSTOCKMNG01010_LIST_WHS_AREA .panel-group').empty();
  293. $('#ITP_FORM_MSTOCKMNG01010_POP_WHS #ITP_FORM_MSTOCKMNG01010_POP_WHS_KEYWORD').val('');
  294. mobPopObj.hide(this.popId);
  295. }
  296. },
  297. popProcStck: {
  298. item: null,
  299. popId: 'ITP_POP_MSTOCKMNG01010_ITEM_AREA',
  300. init: function(item) {
  301. this.item = item;
  302. this.reset();
  303. this.action();
  304. this.view();
  305. mobPopObj.show(this.popId);
  306. },
  307. view: function() {
  308. console.log(this.item);
  309. var id = '#' + this.popId;
  310. $(id).find('.fnWhsNm').text(this.item.whsNm);
  311. $(id).find('.fnLocation').text(this.item.locationNm);
  312. $(id).find('.fnItemId').text(this.item.itemId);
  313. $(id).find('.fnItemNm').text(this.item.itemNm);
  314. $(id).find('.fnStckQty').text(CommonObj.currency.add(this.item.stckQty, '개'));
  315. $(id).find('.fnWhsNm').text(this.item.whsNm);
  316. $(id).find('.fnMgntLevel').text(this.item.mgntLevel);
  317. $(id).find('#ITP_FORM_MSTOCKMNG01010_POP_BRAND_ID').val(this.item.brandId);
  318. $(id).find('#ITP_FORM_MSTOCKMNG01010_POP_ITEM_ID').val(this.item.itemId);
  319. $(id).find('#ITP_FORM_MSTOCKMNG01010_POP_SOURCE_LOCATION').val(this.item.location);
  320. $(id).find('#ITP_FORM_MSTOCKMNG01010_POP_SOURCE_WHS_ID').val(this.item.whsId);
  321. this.whsList();
  322. },
  323. action: function() {
  324. var _this = this;
  325. $('button[id^="ITP_BTN_MSTOCKMNG01010_POP_PROC_STCK"]').off('click').on('click', function() {
  326. var id = $(this).attr('id');
  327. switch (id) {
  328. case 'ITP_BTN_MSTOCKMNG01010_POP_PROC_STCK_REQ' : _this.procStck(); break;
  329. case 'ITP_BTN_MSTOCKMNG01010_POP_PROC_STCK_CANCEL' : _this.cancel(); break;
  330. }
  331. return false;
  332. });
  333. $('select[id^="ITP_FORM_MSTOCKMNG01010_POP_WHS_NM"]').off('change').on('change', function() {
  334. _this.locationList();
  335. });
  336. itp_fn_form_event.onKeyup('#ITP_FORM_MSTOCKMNG01010_POP');
  337. },
  338. whsList: function() {
  339. var _this = this;
  340. const brandIdVal = $('#ITP_FORM_MSTOCKMNG01010_POP_BRAND_ID').val();
  341. const storeIdVal = $('#ITP_FORM_MSTOCKMNG01010_POP_STORE_ID').val();
  342. const param = {sbrandId: brandIdVal, sstoreId: storeIdVal, pagingYn: false};
  343. fn_ajax_call(API_MOBILE_WHS_GRID_LIST, JSON.stringify(param), function(result) {
  344. fn_make_select_whs(result.gridRows, 'ITP_FORM_MSTOCKMNG01010_POP_WHS_NM');
  345. _this.locationList();
  346. }, 'POST');
  347. },
  348. locationList: function() {
  349. const brandIdVal = $('#ITP_FORM_MSTOCKMNG01010_POP_BRAND_ID').val();
  350. const storeIdVal = $('#ITP_FORM_MSTOCKMNG01010_POP_STORE_ID').val();
  351. const whsIdVal = $('#ITP_FORM_MSTOCKMNG01010_POP_WHS_NM').val();
  352. const param = {brandId: brandIdVal, storeId: storeIdVal, whsId: whsIdVal, pagingYn: false};
  353. fn_ajax_call(API_MOBILE_LOCATION_LIST, JSON.stringify(param), function(result) {
  354. fn_make_select_location(result.gridRows, 'ITP_FORM_MSTOCKMNG01010_POP_LOCATION');
  355. }, 'POST');
  356. },
  357. procStck: function() {
  358. var _this = this;
  359. var qty = $('#ITP_POP_MSTOCKMNG01010_ITEM_AREA #ITP_FORM_MSTOCKMNG01010_POP_QTY').val();
  360. if(qty.length < 1 || qty === '0') {
  361. itp_fn_modal_alert('이동 수량을 입력하세요.');
  362. return;
  363. }
  364. if(qty > this.item.stckQty) {
  365. itp_fn_modal_alert('재고 수량을 초과하여 입력할 수 없습니다.');
  366. return;
  367. }
  368. var param = $('#ITP_FORM_MSTOCKMNG01010_POP').serializeObject();
  369. console.log(JSON.stringify(param));
  370. fn_ajax_call(API_MOBILE_SAVE, JSON.stringify(param), function() {
  371. _this.cancel();
  372. mobContentObj.list.search();
  373. }, 'POST');
  374. },
  375. reset: function() {
  376. var id = '#' + this.popId;
  377. $(id).find('.fnWhsNm').text('');
  378. $(id).find('.fnLocation').text('');
  379. $(id).find('.fnItemNm').text('');
  380. $(id).find('.fnStckQty').text('');
  381. $(id).find('.fnWhsNm').text('');
  382. $(id).find('.fnMgntLevel').text('');
  383. $(id).find('#ITP_FORM_MSTOCKMNG01010_POP_BRAND_ID').val('');
  384. $(id).find('#ITP_FORM_MSTOCKMNG01010_POP_ITEM_ID').val('');
  385. $(id).find('#ITP_FORM_MSTOCKMNG01010_POP_SOURCE_LOCATION').val('');
  386. $(id).find('#ITP_FORM_MSTOCKMNG01010_POP_SOURCE_WHS_ID').val('');
  387. },
  388. cancel: function() {
  389. mobPopObj.hide(this.popId);
  390. }
  391. },
  392. show: function(popId) {
  393. $('button[id$="_CLOSE"]').off('click').on('click', function() {
  394. if($(this).hasClass('btn-pop-close')) {
  395. mobPopObj.hide(popId);
  396. }
  397. });
  398. $('#' + popId).show();
  399. },
  400. hide: function(popId) {
  401. $('#' + popId).closest('.mobile-pop-close').hide();
  402. }
  403. };