ITP_MSTOCKMNG02010.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. require(['config'], function() {
  2. require([
  3. ], function($) {
  4. mobPageObj.init();
  5. });
  6. });
  7. /*API URL*/
  8. const API_MOBILE_GRID_LIST = '/api/stock/cdd/detail-grid-list'; // 목록
  9. const API_MOBILE_SAVE = '/api/stock/cdd/save-stock-cdd'; // 저장
  10. const API_MOBILE_BARCODE = '/api/stock/mng/info-barcode-stock'; // 바코드
  11. const API_MOBILE_WHS_GRID_LIST = '/api/whs/mng/detail-grid-list';
  12. const API_MOBILE_LOCATION_LIST = '/api/whs/mng/location-grid-list';
  13. const API_POP_STOCK_MNG_LIST = '/api/stock/mng/detail-grid-list';
  14. const PAGE_MODE_LIST = "LIST";
  15. const PAGE_MODE_VIEW = "VIEW";
  16. let mobPageObj = {
  17. viewMode: PAGE_MODE_LIST,
  18. init: function () {
  19. this.ui.init();
  20. this.event.init();
  21. this.ready();
  22. },
  23. ui: {
  24. init: function () {
  25. this.view();
  26. this.info();
  27. },
  28. view: function() {
  29. // 공통코드 표시
  30. $('select').each(function() {
  31. if($(this).data('select-code')) {
  32. fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
  33. }
  34. });
  35. // 조회일자 지정
  36. $('#ITP_MOBILE_MSTOCKMNG02010 .itp_input.date').datepicker(ITP_DATE_LANGUAGE);
  37. $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_STCK_DT').datepicker('setDate', itp_fn_date_add('D', 1));
  38. },
  39. info: function() {
  40. $('input:hidden[id$="_BRAND_ID"]').val(fn_make_user_info.get('brandId'));
  41. $('input:hidden[id$="_STORE_ID"]').val(fn_make_user_info.get('storeId'));
  42. }
  43. },
  44. event: {
  45. init: function() {
  46. this.button();
  47. },
  48. button: function() {
  49. $('button[id^="ITP_BTN_MSTOCKMNG02010_LIST"]').on('click', function() {
  50. var id = $(this).attr('id');
  51. switch (id) {
  52. case 'ITP_BTN_MSTOCKMNG02010_LIST_SEARCH_WHS_NM' : mobPopObj.popWhsNm.init(); break;
  53. case 'ITP_BTN_MSTOCKMNG02010_LIST_DELETE_WHS_NM' : mobPopObj.popWhsNm.delete(); break;
  54. case 'ITP_BTN_MSTOCKMNG02010_LIST_SEARCH' : mobContObj.list.search(); break;
  55. case 'ITP_BTN_MSTOCKMNG02010_LIST_BARCODE' : mobContObj.barcode.callApp(); break;
  56. case 'ITP_BTN_MSTOCKMNG02010_LIST_SAVE' : mobContObj.list.save(); break;
  57. case 'ITP_BTN_MSTOCKMNG02010_LIST_CANCEL' : mobContObj.list.cancel(); break;
  58. }
  59. return false;
  60. });
  61. $(document).off('click', '#ITP_LIST_MSTOCKMNG02010_LIST_ITEM_ROWS li button');
  62. $(document).on('click', '#ITP_LIST_MSTOCKMNG02010_LIST_ITEM_ROWS li button', function() {
  63. if($(this).hasClass('DETAIL_ITEM_PLUS')) {
  64. mobContObj.list.actPlus($(this));
  65. } else if($(this).hasClass('DETAIL_ITEM_MINUS')) {
  66. mobContObj.list.actMinus($(this));
  67. }
  68. });
  69. }
  70. },
  71. switchScreen: function(mode) {
  72. $('#ITP_MOBILE_MSTOCKMNG02010').find('div[id$="_CONTAINER"]').each(function(i) {
  73. $(this).hide();
  74. });
  75. if(mode === PAGE_MODE_LIST) {
  76. $('#ITP_AJAX_MSTOCKMNG02010_LIST_CONTAINER').show();
  77. } else if(mode === PAGE_MODE_VIEW) {
  78. $('#ITP_AJAX_MSTOCKMNG02010_VIEW_CONTAINER').show();
  79. }
  80. this.viewMode = mode;
  81. },
  82. ready: function() {
  83. mobContObj.list.init();
  84. }
  85. };
  86. let mobContObj = {
  87. list: {
  88. rows: [],
  89. init: function() {
  90. mobPageObj.switchScreen(PAGE_MODE_LIST);
  91. },
  92. search: function() {
  93. var formId = '#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH';
  94. itp_fn_form_clear_validate(null, formId);
  95. if (itp_fn_form_event.isValid(formId)) {
  96. mobPopObj.popItemNm.init();
  97. }
  98. },
  99. itemAdd: function(rows) {
  100. var _this = this;
  101. $.each(rows, function(index, item) {
  102. $('#ITP_LIST_MSTOCKMNG02010_LIST_ITEM_ROWS').append($('#ITP_LIST_MSTOCKMNG02010_LIST_ITEM_ROWCOPY').html());
  103. var $li = $('#ITP_LIST_MSTOCKMNG02010_LIST_ITEM_ROWS > .item-row:last');
  104. $li.find('.fnItemId').text(item.itemId);
  105. $li.find('.fnItemNm').text(item.itemNm);
  106. $li.find('.fnUnit').text(item.unit);
  107. $li.find('.fnStckQty').text(CommonObj.currency.add(item.stckQty, '개'));
  108. $li.find('#ITP_MSTOCKMNG02010_DETAIL_NUM').val('1');
  109. item['cddQty'] = 1;
  110. item['normalYn'] = (item.itemId && item.itemId !== '') ? 'Y' : 'N';
  111. $('.item-row #ITP_MSTOCKMNG02010_DETAIL_NUM')[$li.index()].addEventListener('input', function() { _this.actInput(this); });
  112. mobContObj.list.rows.push(item);
  113. });
  114. },
  115. actPlus: function(elem) {
  116. var elQty = $(elem).prev();
  117. var num = Number($(elQty).val());
  118. if(num < 100000) {
  119. var calcNum = num + 1;
  120. $(elQty).val(calcNum.toString());
  121. this.rows[$(elQty).parents('li').index()]['cddQty'] = calcNum;
  122. }
  123. },
  124. actMinus: function(elem) {
  125. var elQty = $(elem).next();
  126. var num = Number($(elQty).val());
  127. if(num > 1) {
  128. var calcNum = num - 1;
  129. $(elQty).val(calcNum.toString());
  130. this.rows[$(elQty).parents('li').index()]['cddQty'] = calcNum;
  131. }
  132. },
  133. actInput: function(elem) {
  134. var index = $(elem).parents('li').index();
  135. CommonObj.chkMaxLength(elem, function(qty) {
  136. mobContObj.list.rows[index]['cddQty'] = qty;
  137. });
  138. },
  139. validClear: function() {
  140. var formId = '#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH';
  141. itp_fn_form_clear_validate(null, formId);
  142. },
  143. save: function() {
  144. if($('#ITP_LIST_MSTOCKMNG02010_LIST_ITEM_ROWS').children().length === 0) {
  145. itp_fn_modal_alert(ITP_MSG_LOCALE.message.grid.noData);
  146. return;
  147. }
  148. var formId = '#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH';
  149. itp_fn_form_clear_validate(null, formId);
  150. if (itp_fn_form_event.isValid(formId)) {
  151. var normalYnCheck = true;
  152. let gridInsertData = [];
  153. $.each(this.rows, function(key, value) {
  154. if (value.normalYn === 'N') {
  155. normalYnCheck = false;
  156. }
  157. gridInsertData.push({
  158. 'cddQty': value.cddQty,
  159. 'itemId': value.itemId
  160. });
  161. });
  162. if(!normalYnCheck) {
  163. itp_fn_modal_alert_ajax('정상여부 값이 N인 데이터가 있습니다.\n품목번호를 확인하세요.');
  164. return;
  165. }
  166. let param = $(formId).serializeObject();
  167. param['viewCd'] = 'C';
  168. param.whsId = $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_WHS_ID').val();
  169. param.location = $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_LOCATION').val();
  170. param.gridInsertData = gridInsertData;
  171. console.log(JSON.stringify(param));
  172. var searhFn = function() {
  173. $('#ITP_LIST_MSTOCKMNG02010_LIST_ITEM_ROWS').empty();
  174. };
  175. fn_ajax_call(API_MOBILE_SAVE, JSON.stringify(param), searhFn, 'POST');
  176. }
  177. },
  178. cancel: function() {
  179. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/main.html');
  180. }
  181. },
  182. barcode: {
  183. callApp: function() {
  184. var formId = '#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH';
  185. itp_fn_form_clear_validate(null, formId);
  186. if (itp_fn_form_event.isValid(formId)) {
  187. location.replace('app:scan');
  188. // appCallFnBarcode('ITEM221217000006BRD221200038');
  189. }
  190. }
  191. }
  192. };
  193. function appCallFnBarcode(barcode) {
  194. var infoFn = function(result) {
  195. console.log(JSON.stringify(result));
  196. if(result) {
  197. mobContObj.list.itemAdd([result]);
  198. }
  199. };
  200. const param = {
  201. 'sBrandId': $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH #ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_BRAND_ID').val(),
  202. 'sWhsId': $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH #ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_WHS_ID').val(),
  203. 'sLocation': $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH #ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_LOCATION').val(),
  204. 'sBarcode': barcode
  205. };
  206. // console.log(JSON.stringify(param));
  207. fn_ajax_call(API_MOBILE_BARCODE, param, infoFn, 'GET');
  208. }
  209. let mobPopObj = {
  210. popWhsNm: {
  211. popId: 'ITP_POP_MSTOCKMNG02010_WHS_AREA',
  212. rows: [],
  213. init: function () {
  214. this.rows.length = 0;
  215. mobPopObj.show(this.popId);
  216. this.search();
  217. this.action();
  218. },
  219. search: function () {
  220. var _this = this;
  221. $('#ITP_LIST_MSTOCKMNG02010_POP_WHS_AREA .panel-group').empty();
  222. var callbackFn = function(result) {
  223. console.log(result);
  224. _this.view(result.gridRows);
  225. };
  226. const param = $('#ITP_FORM_MSTOCKMNG02010_POP_WHS').serializeObject();
  227. (fn_make_user_info.get('authTpCd') === '50') ? param.swhsDvsn = 'W02' : param.swhsDvsn = 'W01';
  228. console.log(JSON.stringify(param));
  229. fn_ajax_call(API_MOBILE_WHS_GRID_LIST, JSON.stringify(param), callbackFn, 'POST');
  230. },
  231. view: function(gridRows) {
  232. this.rows = gridRows;
  233. $.each(gridRows, function (i, item) {
  234. $('#ITP_LIST_MSTOCKMNG02010_POP_WHS_AREA .panel-group').append($('#ITP_LIST_MSTOCKMNG02010_POP_WHS_ROWCOPY').html());
  235. var $li = $('#ITP_LIST_MSTOCKMNG02010_POP_WHS_AREA .panel-group > .row_2:last');
  236. $li.find('.fnWhsNm').text(item.whsNm);
  237. $li.find('.fnLocationNm').text(item.locationNm);
  238. $li.find('.fnWhsId').data('whs-id', item.whsId);
  239. });
  240. },
  241. choice: function(elem) {
  242. var _this = this;
  243. var whsId = $(elem).data('whs-id');
  244. $.each(this.rows, function (i, item) {
  245. if(whsId === item.whsId) {
  246. $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH #ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_WHS_ID').val(item.whsId);
  247. $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH #ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_WHS_NM').val(item.whsNm);
  248. _this.close();
  249. _this.location(item.whsId);
  250. return false;
  251. }
  252. });
  253. },
  254. location: function(whsId) {
  255. var callbackFn = function(result) {
  256. fn_make_select_location(result.gridRows, 'ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_LOCATION');
  257. };
  258. var param = {
  259. 'brandId': fn_make_user_info.get('brandId'),
  260. 'storeId': fn_make_user_info.get('storeId'),
  261. 'whsId': whsId
  262. };
  263. fn_ajax_call(API_MOBILE_LOCATION_LIST, JSON.stringify(param), callbackFn, 'POST');
  264. },
  265. action: function() {
  266. var _this = this;
  267. $('button[id^="ITP_BTN_MSTOCKMNG02010_POP_WHS"]').off('click').on('click', function() {
  268. var id = $(this).attr('id');
  269. switch (id) {
  270. case 'ITP_BTN_MSTOCKMNG02010_POP_WHS_SEARCH' : _this.search(); break;
  271. case 'ITP_BTN_MSTOCKMNG02010_POP_WHS_CHOICE' : _this.choice($(this)); break;
  272. case 'ITP_BTN_MSTOCKMNG02010_POP_WHS_CLOSE' : _this.close(); break;
  273. }
  274. return false;
  275. });
  276. },
  277. delete: function() {
  278. $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH #ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_WHS_ID').val('');
  279. $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH #ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_WHS_NM').val('');
  280. $('#ITP_FORM_MSTOCKMNG02010_LIST_SEARCH #ITP_FORM_MSTOCKMNG02010_LIST_SEARCH_LOCATION option').remove();
  281. },
  282. close: function() {
  283. this.rows.length = 0;
  284. $('#ITP_POP_MSTOCKMNG02010_LIST_WHS_AREA .panel-group').empty();
  285. $('#ITP_FORM_MSTOCKMNG02010_POP_WHS #ITP_FORM_MSTOCKMNG02010_POP_WHS_KEYWORD').val('');
  286. mobPopObj.hide(this.popId);
  287. }
  288. },
  289. popItemNm: {
  290. popId: 'ITP_POP_MSTOCKMNG02010_ITEM_AREA',
  291. rows: [],
  292. init: function () {
  293. this.rows.length = 0;
  294. mobPopObj.show(this.popId);
  295. this.reset();
  296. this.search();
  297. this.action();
  298. },
  299. search: function () {
  300. var _this = this;
  301. $('#ITP_POP_MSTOCKMNG02010_TABLE_AREA .table_body').remove();
  302. var callbackFn = function(result) {
  303. console.log(result);
  304. _this.rows = result.gridRows;
  305. $.each(result.gridRows, function (i, item) {
  306. $('#ITP_POP_MSTOCKMNG02010_TABLE_AREA .m_table_body').append($('#ITP_POP_MSTOCKMNG02010_TABLE_TR').html());
  307. var $li = $('#ITP_POP_MSTOCKMNG02010_TABLE_AREA .m_table_body > .table_body:last');
  308. $li.find('.fnItemId').text(item.itemId);
  309. $li.find('.fnItemNm').text(item.itemNm);
  310. $li.find('.fnUnit').text(item.unit);
  311. $li.find('.fnStckQty').text(CommonObj.currency.add(item.stckQty, '개'));
  312. });
  313. };
  314. var param = $('#ITP_FORM_MSTOCKMNG02010_POPUP_ITEM').serializeObject();
  315. console.log(JSON.stringify(param));
  316. fn_ajax_call(API_POP_STOCK_MNG_LIST, JSON.stringify(param), callbackFn, 'POST');
  317. },
  318. action: function() {
  319. var _this = this;
  320. $('button[id="ITP_BTN_MSTOCKMNG02010_POP_ITEM_SEARCH"]').off('click').on('click', function() {
  321. _this.search();
  322. });
  323. $('button[id="ITP_BTN_MSTOCKMNG02010_POP_ITEM_CHOICE"]').off('click').on('click', function() {
  324. _this.choice();
  325. });
  326. $('#ITP_POP_MSTOCKMNG02010_TABLE_AREA input:checkbox').off('click').on('click', function() {
  327. _this.checked($(this));
  328. });
  329. },
  330. checked: function(elem) {
  331. var clsNm = '.table_body';
  332. if($(elem).hasClass('chkAll')) {
  333. $(clsNm).find('input:checkbox').prop('checked', $(elem).is(':checked'));
  334. } else {
  335. var isChkAll = true;
  336. $(clsNm).find('input:checkbox').each(function() {
  337. if(!$(this).hasClass('chkAll') && !$(this).is(':checked')) {
  338. isChkAll = false;
  339. return false;
  340. }
  341. });
  342. $(clsNm).find('.chkAll').prop('checked', isChkAll);
  343. }
  344. },
  345. choice: function() {
  346. var _this = this;
  347. var items = [];
  348. $('#ITP_POP_MSTOCKMNG02010_TABLE_AREA input:checkbox').each(function(i) {
  349. if(!$(this).hasClass('chkAll') && $(this).is(':checked')) {
  350. items.push(_this.rows[i-1]);
  351. }
  352. });
  353. mobContObj.list.itemAdd(items);
  354. mobPopObj.hide(this.popId);
  355. },
  356. reset: function() {
  357. this.rows.length = 0;
  358. $('#ITP_FORM_MSTOCKMNG02010_POPUP_ITEM select').find('option:first').prop('selected', true);
  359. $('#ITP_FORM_MSTOCKMNG02010_POP_ITEM_KEYWORD').val('');
  360. $('#ITP_POP_MSTOCKMNG02010_TABLE_AREA .table_body').remove();
  361. }
  362. },
  363. show: function(popId) {
  364. $('button[id$="_CLOSE"]').off('click').on('click', function() {
  365. if($(this).hasClass('btn-pop-close')) {
  366. mobPopObj.hide(popId);
  367. }
  368. });
  369. $('#' + popId).show();
  370. },
  371. hide: function(popId) {
  372. $('#' + popId).closest('.mobile-pop-close').hide();
  373. }
  374. };