ITP_MRTNMNG01010.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. require(['config'], function() {
  2. require([
  3. ], function($) {
  4. mobPageObj.init();
  5. });
  6. });
  7. /*API URL*/
  8. const API_MOBILE_INIT_INFO = '/api/rtnmng/init-rtnReq';
  9. const API_MOBILE_SAVE = '/api/rtnmng/save-rtnReq';
  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 ID_ITP_POP_MRTNMNG01010_REQ_AREA = "ITP_POP_MRTNMNG01010_REQ_AREA";
  13. const ID_ITP_POP_MRTNMNG01010_WHS_AREA = "ITP_POP_MRTNMNG01010_WHS_AREA";
  14. const ID_ITP_POP_MRTNMNG01010_ITEM_AREA = "ITP_POP_MRTNMNG01010_ITEM_AREA";
  15. const RTN_REQ_ST_CD_TEMP_SAVE ="RR00";
  16. const RTN_REQ_ST_CD_REQUEST_SAVE ="RR20";
  17. let mobPageObj = {
  18. isPrevPage: false,
  19. pageParam: null,
  20. init: function () {
  21. this.ui.init();
  22. this.event.init();
  23. this.ready();
  24. },
  25. ui: {
  26. init: function () {
  27. this.info();
  28. this.view();
  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. },
  34. view: function() {
  35. // 조회일자 지정
  36. $('#ITP_FORM_MRTNMNG01010_DETAIL_DLV_REQ_DT').val(itp_fn_date_add('M', 1));
  37. }
  38. },
  39. event: {
  40. init: function() {
  41. this.button();
  42. },
  43. button: function() {
  44. $('button[id^="ITP_BTN_MRTNMNG01010_DETAIL"]').on('click', function() {
  45. if($(this).is('[data-call-popup]')) {
  46. mobPopObj.show($(this).data('call-popup'), $(this).attr('id'));
  47. } else {
  48. var id = $(this).attr('id');
  49. switch (id) {
  50. case 'ITP_BTN_MRTNMNG01010_DETAIL_DELROW' : mobContObj.list.delRow(); break;
  51. case 'ITP_BTN_MRTNMNG01010_DETAIL_SEARCH_WHS_NM' : mobPopObj.popWhsNm.init(); break;
  52. case 'ITP_BTN_MRTNMNG01010_DETAIL_DELETE_WHS_NM' : mobPopObj.popWhsNm.delete(); break;
  53. case 'ITP_BTN_MRTNMNG01010_DETAIL_CANCEL' : mobContObj.cancel(); break;
  54. }
  55. }
  56. return false;
  57. });
  58. }
  59. },
  60. ready: function() {
  61. mobContObj.init();
  62. }
  63. };
  64. let mobContObj = {
  65. init: function() {
  66. this.button();
  67. this.data.load();
  68. },
  69. button: function() {
  70. var _this = this;
  71. $(document).on('click', '.DETAIL_ITEM_PLUS', function() {
  72. _this.list.actPlus($(this));
  73. });
  74. $(document).on('click', '.DETAIL_ITEM_MINUS', function() {
  75. _this.list.actMinus($(this));
  76. });
  77. },
  78. data: {
  79. initPchReq: null,
  80. load: function() {
  81. var _this = this;
  82. var callbackFn = function(result) {
  83. console.log(result);
  84. _this.initPchReq = result;
  85. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_BRAND_ID').val(result.brandId);
  86. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_STORE_ID').val(result.storeId);
  87. // $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_RTN_WHS_ID').val(result.rtnWhsId);
  88. // $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_RTN_LOCATION').val(result.rtnLocation);
  89. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_DVSN').val(result.whsDvsn);
  90. };
  91. const param = {brandId:fn_make_user_info.get('brandId'), storeId:fn_make_user_info.get('storeId')};
  92. fn_ajax_call(API_MOBILE_INIT_INFO, param, callbackFn, 'GET');
  93. }
  94. },
  95. list: {
  96. rows: [],
  97. addRow: function() {
  98. },
  99. delRow: function() {
  100. this.detachRow();
  101. },
  102. attachRow: function (item) {
  103. console.log(item);
  104. var fnIsExist = function(rows) {
  105. var isExist = false;
  106. $.each(rows, function(i, row) {
  107. if(row.brandUnitUnqNo === item.brandUnitUnqNo) {
  108. isExist = true;
  109. return false;
  110. }
  111. });
  112. return isExist;
  113. };
  114. if(!fnIsExist(this.rows)) {
  115. this.rows.push(item);
  116. $('#ITP_LIST_MRTNMNG01010_ITEM_AREA .panel-group').append($('#ITP_LIST_MRTNMNG01010_DETAIL_ROWCOPY').html());
  117. var $li = $('#ITP_LIST_MRTNMNG01010_ITEM_AREA .panel-group > .row_2:last');
  118. $li.find('.fnBrandUnitUnqNo').val(item.brandUnitUnqNo);
  119. $li.find('.fnItemNm').text(item.itemNm);
  120. $li.find('.fnPchReqQty').text(item.pchReqQty);
  121. $li.find('.fnUnitAmt').text(CommonObj.currency.add(item.unitAmt));
  122. this.pchReqAmtTot();
  123. }
  124. },
  125. detachRow: function () {
  126. if($('#ITP_LIST_MRTNMNG01010_ITEM_AREA input:checkbox[name=brandUnitUnqNo]:checked').length > 0) {
  127. var _this = this;
  128. $('#ITP_LIST_MRTNMNG01010_DETAIL_ROWS li').each(function(index, elem) {
  129. var isChecked = $(this).find('input[type="checkbox"]').is(':checked');
  130. if(isChecked) {
  131. $(this).remove();_this.rows.splice(index, 1);
  132. }
  133. });
  134. this.pchReqAmtTot();
  135. }
  136. },
  137. actPlus: function(elem) {
  138. var $div = $(elem).siblings('div');
  139. var num = Number($div.text());
  140. $($div).text((num + 1).toString());
  141. this.rows[$div.parents('li').index()]['pchReqQty'] = $($div).text();
  142. this.pchReqAmtTot();
  143. },
  144. actMinus: function(elem) {
  145. var $div = $(elem).siblings('div');
  146. var num = Number($div.text());
  147. if(num <= 1) {
  148. alert('주문수량을 확인하세요.');
  149. } else {
  150. $($div).text((num - 1).toString());
  151. this.rows[$div.parents('li').index()]['pchReqQty'] = $($div).text();
  152. this.pchReqAmtTot();
  153. }
  154. },
  155. pchReqAmtTot: function() {
  156. var reqAmt = 0;
  157. $.each(this.rows, function(index, item) {
  158. var qty = item.pchReqQty;
  159. var amt = item.unitAmt;
  160. reqAmt += Number(qty) * amt;
  161. });
  162. $('#ITP_AJAX_MRTNMNG01010_DETAIL_CONTAINER').find('.fnRtnReqAmt').text(CommonObj.currency.add(reqAmt));
  163. }
  164. },
  165. cancel: function () {
  166. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/main.html');
  167. }
  168. };
  169. let mobPopObj = {
  170. init: function(popId, parentId) {
  171. console.log(popId);
  172. switch (popId) {
  173. case 'ITP_POP_MRTNMNG01010_RTN_AREA' : this.popReqConfirm.init(parentId); break;
  174. case 'ITP_POP_MRTNMNG01010_WHS_AREA' : this.popWhsNm.init(); break;
  175. case 'ITP_POP_MRTNMNG01010_ITEM_AREA' : this.popItem.init(); break;
  176. }
  177. $('#' + popId).show();
  178. },
  179. popItem: {
  180. // rows: null,
  181. init: function() {
  182. this.search();
  183. },
  184. search: function() {
  185. $('#ITP_LIST_MRTNMNG01010_POP_ITEM_AREA .panel-group').empty();
  186. var callbackFn = function(result) {
  187. console.log(result);
  188. mobPopObj.popItem.rows = result.gridRows;
  189. $.each(mobPopObj.popItem.rows, function (i, item) {
  190. $('#ITP_LIST_MRTNMNG01010_POP_ITEM_AREA .panel-group').append($('#ITP_LIST_MRTNMNG01010_POP_ITEM_ROWCOPY').html());
  191. var $li = $('#ITP_LIST_MRTNMNG01010_POP_ITEM_AREA .panel-group > .row_2:last');
  192. $li.find('#ITP_FORM_MRTNMNG01010_POP_ITEM_CHECKBOX').val(item.itemId);
  193. $li.find('.fnItemNm').text(item.itemNm);
  194. $li.find('.fnUnitAmt').text(CommonObj.currency.add(item.unitAmt));
  195. });
  196. mobPopObj.popItem.addRow.init();
  197. };
  198. let param = $('#ITP_FORM_MRTNMNG01010_POPUP_ITEM').serializeObject();
  199. fn_ajax_call(API_POP_ITEM_LIST, JSON.stringify(param), callbackFn, 'POST');
  200. },
  201. addRow: {
  202. init: function() {
  203. this.button.init();
  204. },
  205. button: {
  206. init: function() {
  207. var _this = this;
  208. $('button[id^="ITP_BTN_MRTNMNG01010_POP_ITEM_"]').off('click').on('click', function() {
  209. var id = $(this).attr('id');
  210. switch (id) {
  211. case 'ITP_BTN_MRTNMNG01010_POP_ITEM_PLUS' : _this.actPlus($(this)); break;
  212. case 'ITP_BTN_MRTNMNG01010_POP_ITEM_MINUS' : _this.actMinus($(this)); break;
  213. case 'ITP_BTN_MRTNMNG01010_POP_ITEM_ADD' : _this.actItemAdd($(this)); break;
  214. case 'ITP_BTN_MRTNMNG01010_POP_ITEM_SEARCH' : mobPopObj.popItem.search(); break;
  215. case 'ITP_BTN_MRTNMNG01010_POP_ITEM_CLOSE' : mobPopObj.hide(id); break;
  216. }
  217. return false;
  218. });
  219. },
  220. actPlus: function(elem) {
  221. var $div = $(elem).siblings('div');
  222. var num = Number($div.text());
  223. $($div).text((num + 1).toString());
  224. },
  225. actMinus: function(elem) {
  226. var $div = $(elem).siblings('div');
  227. var num = Number($div.text());
  228. if(num <= 1) {
  229. alert('주문수량을 확인하세요.');
  230. } else {
  231. $($div).text((num - 1).toString());
  232. }
  233. },
  234. actItemAdd: function(elem) {
  235. var index = $(elem).closest('li').index();
  236. var item = mobPopObj.popItem.rows[index];
  237. item['pchReqQty'] = $(elem).closest('li').find('.fnPchReqQty').html();
  238. mobContObj.list.attachRow(item);
  239. }
  240. }
  241. },
  242. delRow: function() {
  243. }
  244. },
  245. popWhsNm: {
  246. init: function () {
  247. this.rows.length = 0;
  248. this.search();
  249. this.action();
  250. },
  251. rows: [],
  252. search: function () {
  253. var _this = this;
  254. $('#ITP_LIST_MRTNMNG01010_POP_WHS_AREA .panel-group').empty();
  255. var callbackFn = function(result) {
  256. console.log(result);
  257. _this.view(result.gridRows);
  258. };
  259. const param = $('#ITP_FORM_MRTNMNG01010_POP_WHS').serializeObject();
  260. fn_ajax_call(API_POP_SEARCH_LIST, JSON.stringify(param), callbackFn, 'POST');
  261. },
  262. view: function(gridRows) {
  263. this.rows = gridRows;
  264. $.each(gridRows, function (i, item) {
  265. $('#ITP_LIST_MRTNMNG01010_POP_WHS_AREA .panel-group').append($('#ITP_LIST_MRTNMNG01010_POP_WHS_ROWCOPY').html());
  266. var $li = $('#ITP_LIST_MRTNMNG01010_POP_WHS_AREA .panel-group > .row_2:last');
  267. $li.find('.fnWhsNm').text(item.whsNm);
  268. $li.find('.fnLocationNm').text(item.locationNm);
  269. $li.find('.fnWhsId').data('whs-id', item.whsId);
  270. });
  271. },
  272. action: function() {
  273. var _this = this;
  274. $('#ITP_LIST_MRTNMNG01010_POP_WHS_AREA button[id$="POP_WHS_CHOICE"]').off('click').on('click', function() {
  275. var whsId = $(this).data('whs-id');
  276. $.each(_this.rows, function (i, item) {
  277. if(whsId === item.whsId) {
  278. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_ID').val(item.whsId);
  279. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_NM').val(item.whsNm);
  280. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_LOCATION').val(item.location);
  281. mobPopObj.hide(ID_ITP_POP_MRTNMNG01010_WHS_AREA);
  282. itp_fn_form_clear_validate(null, '#ITP_FORM_MRTNMNG01010_DETAIL');
  283. return false;
  284. }
  285. });
  286. });
  287. $('#ITP_FORM_MRTNMNG01010_POP_WHS button[id="ITP_BTN_MRTNMNG01010_POP_WHS_SEARCH"]').off('click').on('click', function() {
  288. _this.search();
  289. });
  290. },
  291. delete: function() {
  292. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_ID').val('');
  293. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_WHS_NM').val('');
  294. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_LOCATION').val('');
  295. }
  296. },
  297. popReqConfirm: {
  298. init: function (parentId) {
  299. this.rtnReqStCd = (parentId === 'ITP_BTN_MRTNMNG01010_DETAIL_RTN_ORDER') ? RTN_REQ_ST_CD_REQUEST_SAVE : RTN_REQ_ST_CD_TEMP_SAVE;
  300. this.view();
  301. this.action();
  302. },
  303. view: function() {
  304. console.log(this.rtnReqStCd);
  305. if(this.rtnReqStCd === RTN_REQ_ST_CD_REQUEST_SAVE) {
  306. $('#ITP_POP_MRTNMNG01010_RTN_AREA .msg_save').text('빈품요청 하시겠습니까?');
  307. } else {
  308. $('#ITP_POP_MRTNMNG01010_RTN_AREA .msg_save').text('임시저장 하시겠습니까?');
  309. }
  310. $('#ITP_POP_MRTNMNG01010_RTN_AREA .fnRtnReqDt').text($('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_DLV_REQ_DT').val());
  311. $('#ITP_POP_MRTNMNG01010_RTN_AREA .fnItemQty').text(CommonObj.currency.add(mobContObj.list.rows.length, '개'));
  312. $('#ITP_POP_MRTNMNG01010_RTN_AREA .fnRtnAmt').text($('#ITP_FORM_MRTNMNG01010_DETAIL .fnRtnReqAmt').text());
  313. $('#ITP_FORM_MRTNMNG01010_DETAIL #ITP_FORM_MRTNMNG01010_DETAIL_RTN_REQ_ST_CD').val(this.rtnReqStCd);
  314. },
  315. action: function() {
  316. var _this = this;
  317. $('#ITP_POP_MRTNMNG01010_RTN_AREA button[id="ITP_BTN_MRTNMNG01010_POP_RTN_CONFIRM"]').off('click').on('click', function() {
  318. _this.save('#ITP_FORM_MRTNMNG01010_DETAIL');
  319. });
  320. },
  321. save: function(formId) {
  322. let param = $(formId).serializeObject();
  323. var gridInsertData = [];
  324. $.each(mobContObj.list.rows, function(index, row) {
  325. var item = {};
  326. item['viewCd'] = 'C';
  327. item['brandUnitUnqNo'] = row.brandUnitUnqNo;
  328. item['itemId'] = row.itemId;
  329. item['itemNm'] = row.itemNm;
  330. item['rtnAmt'] = parseInt(row.unitAmt) * parseInt(row.pchReqQty);
  331. item['rtnDvsn'] = row.rtnDvsn;
  332. item['rtnQty'] = row.pchReqQty;
  333. item['rtnReqDtlNo'] = row.rtnReqDtlNo;
  334. item['rtnReqUnqNo'] = row.rtnReqUnqNo;
  335. item['rtnRsn'] = row.rtnRsn;
  336. item['rtnRsnDvsn'] = row.rtnRsnDvsn;
  337. item['spplyId'] = row.spplyId;
  338. item['storeUnitUnqNo'] = row.storeUnitUnqNo;
  339. item['unit'] = row.unit;
  340. item['unitAmt'] = row.unitAmt;
  341. item['unitGubun'] = row.unitGubun;
  342. gridInsertData.push(item);
  343. });
  344. param.gridInsertData = gridInsertData;
  345. param['colReqDt'] = param.colReqDt.replace(/[^0-9]/g, "");
  346. console.log(JSON.stringify(param));
  347. var saveFn = function (result) {
  348. console.log(result);
  349. mobPopObj.hide('ITP_POP_MRTNMNG01010_RTN_AREA');
  350. $('#ITP_LIST_MRTNMNG01010_DETAIL_ROWS').empty();
  351. };
  352. fn_ajax_call(API_MOBILE_SAVE, JSON.stringify(param), saveFn, 'POST');
  353. }
  354. },
  355. show: function(popId, parentId) {
  356. var _this = this;
  357. $('button[id$="CLOSE"]').off('click').on('click', function() {
  358. var id = $(this).attr('id');
  359. if($(this).hasClass('btn-pop-close')) {
  360. _this.hide(id);
  361. }
  362. });
  363. if(parentId === 'ITP_BTN_MRTNMNG01010_DETAIL_RTN_ORDER' || parentId === 'ITP_BTN_MRTNMNG01010_DETAIL_TEMP_SAVE') {
  364. var formId = '#ITP_FORM_MRTNMNG01010_DETAIL';
  365. itp_fn_form_clear_validate(null, formId);
  366. if (itp_fn_form_event.isValid(formId)) {
  367. mobPopObj.init(popId, parentId);
  368. }
  369. } else {
  370. mobPopObj.init(popId, parentId);
  371. }
  372. },
  373. hide: function(id) {
  374. $('#' + id).closest('.mobile-pop-close').hide();
  375. }
  376. };