ITP_MSTOCKMNG01010.js 15 KB

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