ITP_MRTNMNG05010.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. require(['config'], function() {
  2. require([
  3. ], function($) {
  4. mobPageObj.init();
  5. });
  6. });
  7. /*API URL*/
  8. const API_MOBILE_GRID_LIST = '/api/rtnmng/inoutmng/retstock-target-grid-list'; // 목록
  9. const API_MOBILE_SAVE = '/api/rtnmng/inoutmng/save-retstock'; // 반품처리
  10. const API_POP_SEARCH_LIST = '/api/whs/mng/pop-whs-search';
  11. const API_POP_SPPLY_LIST = '/api/spply/pop-grid-list';
  12. const PAGE_MODE_LIST = "LIST";
  13. const PAGE_MODE_VIEW = "VIEW";
  14. let mobPageObj = {
  15. viewMode: PAGE_MODE_LIST,
  16. init: function () {
  17. this.ui.init();
  18. this.event.init();
  19. this.ready();
  20. },
  21. ui: {
  22. init: function () {
  23. this.view();
  24. this.info();
  25. },
  26. view: function() {
  27. // 공통코드 표시
  28. $('select').each(function() {
  29. if($(this).data('select-code')) {
  30. fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
  31. }
  32. });
  33. // 조회일자 지정
  34. $('#ITP_MOBILE_MRTNMNG05010 .itp_input.date').datepicker(ITP_DATE_LANGUAGE);
  35. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH_FROM_DT').datepicker('setDate', itp_fn_date_add('M', 0));
  36. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH_TO_DT').datepicker('setDate', itp_fn_date_add('M', 1));
  37. },
  38. info: function() {
  39. $('input:hidden[id$="_BRAND_ID"]').val(fn_make_user_info.get('brandId'));
  40. $('input:hidden[id$="_STORE_ID"]').val(fn_make_user_info.get('storeId'));
  41. }
  42. },
  43. event: {
  44. init: function() {
  45. this.button();
  46. },
  47. button: function() {
  48. $('button[id^="ITP_BTN_MRTNMNG05010_LIST"]').on('click', function() {
  49. var id = $(this).attr('id');
  50. switch (id) {
  51. case 'ITP_BTN_MRTNMNG05010_LIST_SEARCH_WHS_NM' : mobPopObj.popWhsNm.init(); break;
  52. case 'ITP_BTN_MRTNMNG05010_LIST_DELETE_WHS_NM' : mobPopObj.popWhsNm.delete(); break;
  53. case 'ITP_BTN_MRTNMNG05010_LIST_SEARCH_SPPLY_NM' : mobPopObj.popSpply.init(); break;
  54. case 'ITP_BTN_MRTNMNG05010_LIST_DELETE_SPPLY_NM' : mobPopObj.popSpply.delete(); break;
  55. case 'ITP_BTN_MRTNMNG05010_LIST_SEARCH' : mobContObj.list.search(); break;
  56. case 'ITP_BTN_MRTNMNG05010_LIST_MODIFY' : mobContObj.list.save(); break;
  57. }
  58. return false;
  59. });
  60. $(document).on('click', '#ITP_POP_MRTNMNG05010_LIST_SPPLY_ROWS li button', function() {
  61. mobPopObj.popSpply.choice($(this));
  62. });
  63. $(document).on('click', '#ITP_LIST_MRTNMNG05010_POP_WHS_ROWS li button', function() {
  64. mobPopObj.popWhsNm.choice($(this));
  65. });
  66. }
  67. },
  68. switchScreen: function(mode) {
  69. $('#ITP_MOBILE_MRTNMNG05010').find('div[id$="_CONTAINER"]').each(function(i) {
  70. $(this).hide();
  71. });
  72. if(mode === PAGE_MODE_LIST) {
  73. $('#ITP_AJAX_MRTNMNG05010_LIST_CONTAINER').show();
  74. }
  75. this.viewMode = mode;
  76. },
  77. ready: function() {
  78. mobContObj.list.init();
  79. }
  80. };
  81. let mobContObj = {
  82. list: {
  83. listPage: 1,
  84. rows: [],
  85. init: function() {
  86. mobPageObj.switchScreen(PAGE_MODE_LIST);
  87. // this.search();
  88. },
  89. search: function() {
  90. var formId = '#ITP_FORM_MRTNMNG05010_LIST_SEARCH';
  91. itp_fn_form_clear_validate(null, formId);
  92. if (itp_fn_form_event.isValid(formId)) {
  93. this.listPage = 0;
  94. this.totPage = 0;
  95. this.rows.length = 0;
  96. $('#ITP_LIST_MRTNMNG05010_LIST_ITEM_ROWS').empty();
  97. setTimeout(function() {
  98. mobContObj.list.load();
  99. }, 100);
  100. }
  101. },
  102. pager: function(totPage) {
  103. (this.listPage < totPage) ?
  104. CommonObj.moreView('#ITP_LIST_MRTNMNG05010_LIST_ITEM_AREA', true, mobContObj.list.load) :
  105. CommonObj.moreView('#ITP_LIST_MRTNMNG05010_LIST_ITEM_AREA', false);
  106. this.listPage += 1;
  107. },
  108. load: function() {
  109. var _this = this;
  110. var callbackFn = function(result) {
  111. console.log(result);
  112. mobContObj.list.pager(result.gridTotal);
  113. $.each(result.gridRows, function (i, item) {
  114. $('#ITP_LIST_MRTNMNG05010_LIST_ITEM_AREA .panel-group').append($('#ITP_LIST_MRTNMNG05010_LIST_ITEM_ROWCOPY').html());
  115. var $li = $('#ITP_LIST_MRTNMNG05010_LIST_ITEM_AREA .panel-group > .item-row:last');
  116. $li.find('.fnRtnPodrUnqNo').text(item.rtnPodrUnqNo);
  117. $li.find('.fnColSchDt').text(item.colSchDt);
  118. $li.find('.fnSpplyNm').text(item.spplyNm);
  119. $li.find('.fnRtnWhsNm').text(item.rtnWhsNm);
  120. $li.find('.fnItemNm').text(item.itemNm);
  121. $li.find('.fnColReqQty').text(CommonObj.comma.set(item.colReqQty));
  122. $li.find('#ITP_FORM_MRTNMNG05010_LIST_COL_QTY').val(item.colQty);
  123. mobContObj.list.rows.push(item);
  124. });
  125. };
  126. const param = $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH').serializeObject();
  127. param.gridPage = mobContObj.list.listPage;
  128. param.gridSize = mobile_list_size;
  129. // console.log(JSON.stringify(param));
  130. fn_ajax_call(API_MOBILE_GRID_LIST, JSON.stringify(param), callbackFn, 'POST');
  131. },
  132. save: function() {
  133. var _this = this;
  134. var chkQtyYn1 = true;
  135. var chkQtyYn2 = true;
  136. var chkQtyYn3 = true;
  137. var gridInsertData = [];
  138. var swhsId = "";
  139. var srtnWhsId = "";
  140. var storeId = "";
  141. $('#ITP_LIST_MRTNMNG05010_LIST_ITEM_ROWS li').each(function(index) {
  142. var row = mobContObj.list.rows[index];
  143. var colQty = $(this).find('input[name="colQty"]').val();
  144. if(colQty !== '') {
  145. if(Number(colQty) > row.colReqQty) {
  146. chkQtyYn1 = false;
  147. return false;
  148. }
  149. if (swhsId !== "" && swhsId !== row.whsId) {
  150. chkQtyYn2 = false;
  151. return false;
  152. }
  153. if (srtnWhsId !== "" && srtnWhsId !== row.rtnWhsId) {
  154. chkQtyYn3 = false;
  155. return false;
  156. }
  157. var item = {
  158. 'colPickDtlNo' : row.colPickDtlNo,
  159. 'colPickUnqNo' : row.colPickUnqNo,
  160. 'itemId' : row.itemId,
  161. 'colQty' : colQty
  162. };
  163. swhsId = row.whsId;
  164. srtnWhsId = row.rtnWhsId;
  165. storeId = row.storeId;
  166. gridInsertData.push(item);
  167. }
  168. });
  169. if (chkQtyYn1 === false) {
  170. itp_fn_modal_alert("수거요청수량보다 수거수량이 더 많습니다.");
  171. return;
  172. }
  173. if (chkQtyYn2 === false) {
  174. itp_fn_modal_alert("서로 다른 반품입고창고 품목은 처리할 수 없습니다.");
  175. return;
  176. }
  177. if (chkQtyYn3 === false) {
  178. itp_fn_modal_alert("서로 다른 수거창고 품목은 처리할 수 없습니다.");
  179. return;
  180. }
  181. if (gridInsertData.length === 0) {
  182. itp_fn_modal_alert("반품처리할 품목이 없습니다.");
  183. return ;
  184. }
  185. var modalFn = {
  186. callBack: (args) => {
  187. let param = {};
  188. param['viewCd'] = 'C';
  189. param['whsId'] = swhsId;
  190. param['rtnWhsId'] = srtnWhsId;
  191. param['brandId'] = $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_BRAND_ID').val();
  192. param['storeId'] = storeId;
  193. param['gridInsertData'] = gridInsertData;
  194. var saveFn = function () {
  195. mobContObj.list.search();
  196. };
  197. fn_ajax_call(API_MOBILE_SAVE, JSON.stringify(param), saveFn, 'POST');
  198. }
  199. };
  200. itp_fn_modal_confirm('반품처리 하시겠습니까?', modalFn);
  201. }
  202. }
  203. };
  204. let mobPopObj = {
  205. popSpply: {
  206. popId: 'ITP_POP_MRTNMNG05010_SPPLY_AREA',
  207. rows: [],
  208. init: function() {
  209. this.rows.length = 0;
  210. mobPopObj.show(this.popId);
  211. this.search();
  212. this.action();
  213. },
  214. search: function() {
  215. var _this = this;
  216. $('#ITP_POP_MRTNMNG05010_LIST_SPPLY_AREA .panel-group').empty();
  217. var callbackFn = function(result) {
  218. console.log(result);
  219. _this.view(result.gridRows);
  220. };
  221. let param = $('#ITP_FORM_MRTNMNG05010_POP_SPPLY_SEARCH').serializeObject();
  222. fn_ajax_call(API_POP_SPPLY_LIST, JSON.stringify(param), callbackFn, 'POST');
  223. },
  224. view: function(gridRows) {
  225. this.rows = gridRows;
  226. $.each(gridRows, function (i, item) {
  227. $('#ITP_POP_MRTNMNG05010_LIST_SPPLY_AREA .panel-group').append($('#ITP_POP_MRTNMNG05010_LIST_SPPLY_ROWCOPY').html());
  228. var $li = $('#ITP_POP_MRTNMNG05010_LIST_SPPLY_AREA .panel-group > .row_2:last');
  229. $li.find('.fnSpplyNm').text(item.spplyNm);
  230. $li.find('.fnStNm').text($li.find('.fnStNm').text().replace('$', item.stNm));
  231. $li.find('.fnSpplyId').data('item-key', item.spplyId);
  232. });
  233. },
  234. choice: function(elem) {
  235. var _this = this;
  236. var spplyId = $(elem).data('item-key');
  237. $.each(this.rows, function (i, item) {
  238. if(spplyId === item.spplyId) {
  239. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_SPPLY_ID').val(item.spplyId);
  240. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_SPPLY_NM').val(item.spplyNm);
  241. _this.close();
  242. return false;
  243. }
  244. });
  245. },
  246. action: function() {
  247. var _this = this;
  248. $('button[id^="ITP_BTN_MRTNMNG05010_POP_SPPLY"]').off('click').on('click', function() {
  249. var id = $(this).attr('id');
  250. switch (id) {
  251. case 'ITP_BTN_MRTNMNG05010_POP_SPPLY_SEARCH' : _this.search(); break;
  252. case 'ITP_BTN_MRTNMNG05010_POP_SPPLY_CHOICE' : _this.choice($(this)); break;
  253. case 'ITP_BTN_MRTNMNG05010_POP_SPPLY_CLOSE' : _this.close(); break;
  254. }
  255. return false;
  256. });
  257. },
  258. delete: function() {
  259. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_SPPLY_ID').val('');
  260. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_SPPLY_NM').val('');
  261. },
  262. close: function() {
  263. this.rows.length = 0;
  264. $('#ITP_POP_MRTNMNG05010_LIST_SPPLY_AREA .panel-group').empty();
  265. $('#ITP_FORM_MRTNMNG05010_POP_SPPLY_SEARCH #ITP_FORM_MRTNMNG05010_POP_SPPLY_KEYWORD').val('');
  266. mobPopObj.hide(this.popId);
  267. }
  268. },
  269. popWhsNm: {
  270. popId: 'ITP_POP_MRTNMNG05010_WHS_AREA',
  271. rows: [],
  272. init: function () {
  273. this.rows.length = 0;
  274. mobPopObj.show(this.popId);
  275. this.search();
  276. this.action();
  277. },
  278. search: function () {
  279. var _this = this;
  280. $('#ITP_LIST_MRTNMNG05010_POP_WHS_AREA .panel-group').empty();
  281. var callbackFn = function(result) {
  282. console.log(result);
  283. _this.view(result.gridRows);
  284. };
  285. const param = $('#ITP_FORM_MRTNMNG05010_POP_WHS').serializeObject();
  286. param.swhsDvsn = CommonObj.schWhsDvsn();
  287. fn_ajax_call(API_POP_SEARCH_LIST, JSON.stringify(param), callbackFn, 'POST');
  288. },
  289. view: function(gridRows) {
  290. this.rows = gridRows;
  291. $.each(gridRows, function (i, item) {
  292. $('#ITP_LIST_MRTNMNG05010_POP_WHS_AREA .panel-group').append($('#ITP_LIST_MRTNMNG05010_POP_WHS_ROWCOPY').html());
  293. var $li = $('#ITP_LIST_MRTNMNG05010_POP_WHS_AREA .panel-group > .list-row:last');
  294. $li.find('.fnWhsNm').text(item.whsNm);
  295. $li.find('.fnLocationNm').text(item.locationNm);
  296. $li.find('.fnWhsId').data('whs-id', item.whsId);
  297. });
  298. },
  299. choice: function(elem) {
  300. var _this = this;
  301. var whsId = $(elem).data('whs-id');
  302. $.each(this.rows, function (i, item) {
  303. if(whsId === item.whsId) {
  304. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_WHS_ID').val(item.whsId);
  305. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_WHS_NM').val(item.whsNm);
  306. _this.close();
  307. return false;
  308. }
  309. });
  310. },
  311. action: function() {
  312. var _this = this;
  313. $('button[id^="ITP_BTN_MRTNMNG05010_POP_WHS"]').off('click').on('click', function() {
  314. var id = $(this).attr('id');
  315. switch (id) {
  316. case 'ITP_BTN_MRTNMNG05010_POP_WHS_SEARCH' : _this.search(); break;
  317. case 'ITP_BTN_MRTNMNG05010_POP_WHS_CHOICE' : _this.choice($(this)); break;
  318. case 'ITP_BTN_MRTNMNG05010_POP_WHS_CLOSE' : _this.close(); break;
  319. }
  320. return false;
  321. });
  322. },
  323. delete: function() {
  324. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_WHS_ID').val('');
  325. $('#ITP_FORM_MRTNMNG05010_LIST_SEARCH #ITP_FORM_MRTNMNG05010_LIST_SEARCH_WHS_NM').val('');
  326. },
  327. close: function() {
  328. this.rows.length = 0;
  329. $('#ITP_POP_MRTNMNG05010_LIST_WHS_AREA .panel-group').empty();
  330. $('#ITP_FORM_MRTNMNG05010_POP_WHS #ITP_FORM_MRTNMNG05010_POP_WHS_KEYWORD').val('');
  331. mobPopObj.hide(this.popId);
  332. }
  333. },
  334. show: function(popId) {
  335. $('button[id$="_CLOSE"]').off('click').on('click', function() {
  336. console.log($(this).attr('id'));
  337. if($(this).hasClass('btn-pop-close')) {
  338. mobPopObj.hide(popId);
  339. }
  340. });
  341. $('#' + popId).show();
  342. },
  343. hide: function(popId) {
  344. $('#' + popId).closest('.mobile-pop-close').hide();
  345. }
  346. };