ITP_RTNMNG01010.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. require(['config'], function() {
  2. require([
  3. ], function($) {
  4. pageObj.init();
  5. });
  6. });
  7. /********************************************************
  8. --------------------------------------------------------
  9. - Object 목록 -
  10. --------------------------------------------------------
  11. * const gridColModel = {} : 화면 Grid Object *
  12. * let pageObj = {} : 화면공통 Object *
  13. * let listObj = {} : 목록화면 Object *
  14. * let viewObj = {} : 상세화면 Object *
  15. * let modifyObj = {} : 수정화면 Object *
  16. * let createObj = {} : 신규화면 Object *
  17. *******************************************************/
  18. /*화면 변수*/
  19. const RTNMNG01010_DETAIL_GRID_ID = '#ITP_RTNMNG01010_DETAIL_jqGrid';
  20. const RTNMNG01010_DETAIL_GRID_LIST = '#ITP_RTNMNG01010_DETAIL_jqGrid_list';
  21. const RTNMNG01010_DETAIL_GRID_PAGER = '#ITP_RTNMNG01010_DETAIL_jqGridPager';
  22. const RTNMNG01010_DETAIL_GRID_EMPTY = '#ITP_RTNMNG01010_DETAIL_jqGridEmpty'; // ==>dwkim html확인필요
  23. let RTNMNG01010_DETAIL_GRID_LAST_ROW_ID;
  24. /* 공통코드 리스트 */
  25. let ITP_COMMON_CD_RTN_DVSN = fn_make_common_cd_list(CODE_LIST, 'RTN_DVSN', false);
  26. let ITP_COMMON_CD_RTN_RSN_DVSN = fn_make_common_cd_list(CODE_LIST, 'RTN_RSN_DVSN', false);
  27. /*API URL*/
  28. let API_DETAIL_INIT_INFO = '/api/rtnmng/init-rtnReq'
  29. let API_DETAIL_SAVE = '/api/rtnmng/save-rtnReq';
  30. /*화면 Grid ColModel ==>선택박스 항목 추가 부분 */
  31. const gridColModel = {
  32. detail: [
  33. {
  34. index: 'VIEW_CD', name: 'viewCd',
  35. label: ITP_MSG_LOCALE.label.viewCd,
  36. width: '10', fixed: false, align: 'center',
  37. sortable: false, hidden: true
  38. },
  39. {
  40. index: 'RTN_REQ_UNQ_NO', name: 'rtnReqUnqNo',
  41. label: '반품요청번호',
  42. width: '10', fixed: false, align: 'center',
  43. sortable: false, editable: false, edittype: 'text', hidden: true
  44. },
  45. {
  46. index: 'RTN_REQ_DTL_NO', name: 'rtnReqDtlNo',
  47. label: '반품요청상세번호',
  48. width: '10', fixed: false, align: 'center',
  49. sortable: false, editable: false, edittype: 'text', hidden: true
  50. },
  51. {
  52. index: 'ITEM_ID', name: 'itemId',
  53. label: ITP_MSG_LOCALE.label.itemId,
  54. width: '15', fixed: false, align: 'center',
  55. sortable: false, editable: false, edittype: 'text',
  56. editrules: { required: true }
  57. },
  58. {
  59. index: 'ITEM_NM', name: 'itemNm',
  60. label: ITP_MSG_LOCALE.label.itemNm,
  61. width: '25', fixed: false, align: 'center',
  62. sortable: true, editable: false, edittype: 'text',
  63. editrules: { required: true }
  64. },
  65. {
  66. index: 'UNIT', name: 'unit',
  67. label: ITP_MSG_LOCALE.label.unit,
  68. width: '10', fixed: false, align: 'center',
  69. sortable: false, editable: false, edittype: 'text'
  70. },
  71. {
  72. index: 'UNIT_AMT', name: 'unitAmt',
  73. label: ITP_MSG_LOCALE.label.unitAmt,
  74. width: '10', fixed: false, align: 'center',
  75. sortable: false, editable: false, edittype: 'text', hidden: false,
  76. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  77. },
  78. {
  79. index: 'RTN_QTY', name: 'rtnQty',
  80. label: '반품수량', //수량
  81. width: '10', fixed: false, align: 'right',
  82. sortable: false, editable: true, edittype: 'text',
  83. editrules: { number:true },
  84. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  85. },
  86. {
  87. index: 'RTN_AMT', name: 'rtnAmt',
  88. label: '반품예상금액',
  89. width: '10', fixed: false, align: 'right',
  90. sortable: false, editable: false, edittype: 'text', hidden: false,
  91. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  92. },
  93. {
  94. index: 'RTN_DVSN', name: 'rtnDvsn',
  95. label: '반품구분',
  96. width: '10', fixed: false, align: 'center',
  97. sortable: false, editable: true, formatter: 'select', edittype: 'select',
  98. editoptions: {value: ITP_COMMON_CD_RTN_DVSN},
  99. editrules: {required: true}
  100. },
  101. {
  102. index: 'RTN_RSN_DVSN', name: 'rtnRsnDvsn',
  103. label: '사유구분',
  104. width: '10', fixed: false, align: 'center',
  105. sortable: false, editable: true, formatter: 'select', edittype: 'select',
  106. editoptions: {value: ITP_COMMON_CD_RTN_RSN_DVSN},
  107. editrules: {required: true}
  108. },
  109. {
  110. index: 'RTN_RSN', name: 'rtnRsn',
  111. label: '반품사유',
  112. width: '15', fixed: false, align: 'right',
  113. sortable: false, editable: true, edittype: 'text'
  114. },
  115. {
  116. index: 'SPPLY_ID', name: 'spplyId',
  117. label: '공급사아이디',
  118. width: '10', fixed: false, align: 'center',
  119. sortable: false, editable: false, edittype: 'text', hidden: true
  120. },
  121. {
  122. index: 'BRAND_UNIT_UNQ_NO', name: 'brandUnitUnqNo',
  123. label: ITP_MSG_LOCALE.label.brandUnitUnqNo,
  124. width: '10', fixed: false, align: 'center',
  125. sortable: false, editable: false, edittype: 'text', hidden: true
  126. },
  127. {
  128. index: 'STORE_UNIT_UNQ_NO', name: 'storeUnitUnqNo',
  129. label: ITP_MSG_LOCALE.label.storeUnitUnqNo,
  130. width: '10', fixed: false, align: 'center',
  131. sortable: false, editable: false, edittype: 'text', hidden: true
  132. },
  133. {
  134. index: 'UNIT_GUBUN', name: 'unitGubun',
  135. label: ITP_MSG_LOCALE.label.unitGubun,
  136. width: '10', fixed: false, align: 'center',
  137. sortable: false, editable: false, edittype: 'text', hidden: true
  138. }
  139. ]
  140. };
  141. /*화면공통 Object*/
  142. let pageObj = {
  143. init: function() {
  144. this.ui.init();
  145. this.event.init();
  146. this.action();
  147. },
  148. action: function () {
  149. var _this = this;
  150. // 납품장소 조회 버튼 클릭
  151. $('#ITP_FORM_RTNMNG01010_SEARCH_WHS_NM').on('click', function() {
  152. _this.popup();
  153. });
  154. // 납품장소 텍스트 삭제 버튼 클릭
  155. $('#ITP_FORM_RTNMNG01010_DELETE_WHS_NM').on('click', function() {
  156. $('#ITP_FORM_RTNMNG01010_DETAIL_RTN_WHS_NM').val('');
  157. $('#ITP_FORM_RTNMNG01010_DETAIL_RTN_WHS_ID').val('');
  158. $('#ITP_FORM_RTNMNG01010_DETAIL_RTN_LOCATION_NM').val('');
  159. $('#ITP_FORM_RTNMNG01010_DETAIL_RTN_LOCATION').val('');
  160. });
  161. },
  162. popup: function () {
  163. // 팝업
  164. var popFn = this.callback.create;
  165. var whsDvsn = "";
  166. if (fn_make_user_info.get('storeId') == '' ) {
  167. whsDvsn = "W01";
  168. } else {
  169. whsDvsn = "W02";
  170. }
  171. const key = {brandId:fn_make_user_info.get('brandId'),storeId:fn_make_user_info.get('storeId'),whsDvsn: whsDvsn};
  172. fn_call_popup('biz', 'BIZPOP_WHS_LOCATION', '#ITP_ASIDE', popFn, key, 'S');
  173. },
  174. callback: {
  175. create: function(rowDataPop) {
  176. console.log(rowDataPop);
  177. if(rowDataPop) {
  178. $('#ITP_FORM_RTNMNG01010_DETAIL_RTN_WHS_NM').val(rowDataPop.whsNm);
  179. $('#ITP_FORM_RTNMNG01010_DETAIL_RTN_WHS_ID').val(rowDataPop.whsId);
  180. $('#ITP_FORM_RTNMNG01010_DETAIL_RTN_LOCATION_NM').val(rowDataPop.locationNm);
  181. $('#ITP_FORM_RTNMNG01010_DETAIL_RTN_LOCATION').val(rowDataPop.location);
  182. }
  183. }
  184. },
  185. itp_RTNMNG01010_param: {}, // ==>dwkim
  186. itp_RTNMNG01010_search: false, // ==>dwkim
  187. ui: {
  188. init: function() {
  189. this.view();
  190. this.grid();
  191. this.ready();
  192. },
  193. view: function() {
  194. // 버튼 권한설정
  195. fn_proc_btn_auth('RTNMNG01010');
  196. // 공통코드 표시
  197. $('select').each(function() {
  198. if ($(this).data('select-code')) {
  199. fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
  200. }
  201. });
  202. // 조회일자 지정
  203. //var now = new Date(date.getDate() + 5);
  204. var now = new Date();
  205. $('#ITP_TAB_RTNMNG01010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);
  206. $('#ITP_FORM_RTNMNG01010_DETAIL_COL_REQ_DT').datepicker('setDate', new Date(now.setDate(now.getDate() + 5)));
  207. //납품장소 필드 readonly
  208. $('#ITP_FORM_RTNMNG01010_DETAIL_WHS_NM').attr('readonly', true);
  209. $('#ITP_FORM_RTNMNG01010_DETAIL_LOCATION_NM').attr('readonly', true);
  210. },
  211. grid: function() {
  212. itp_fn_jqgrid_resize(RTNMNG01010_DETAIL_GRID_ID, RTNMNG01010_DETAIL_GRID_LIST, 'lg');
  213. //listObj.empty.init();
  214. itp_fn_fire_window_resize();
  215. },
  216. ready: function() {
  217. createObj.init();
  218. }
  219. },
  220. event: {
  221. init: function() {
  222. this.button();
  223. },
  224. button: function() {
  225. // 버튼 클릭 이벤트
  226. $('button').each(function() {
  227. var id = $(this).attr('id');
  228. $(this).on('click', function() {
  229. switch (id) {
  230. case 'ITP_BTN_RTNMNG01010_REQ' : createObj.button.save("RR20"); break; // 요청
  231. case 'ITP_BTN_RTNMNG01010_TEMP_SAVE' : createObj.button.save("RR00"); break; // 임시저장
  232. case 'ITP_BTN_RTNMNG01010_DETAIL_ADDROW': pageObj.grid.button.addRow(); break; // 품목추가
  233. case 'ITP_BTN_RTNMNG01010_DETAIL_DELROW': pageObj.grid.button.delRow(); break; // 품목삭제
  234. }
  235. });
  236. });
  237. $('body').on('click', function(e) {
  238. var gridId = RTNMNG01010_DETAIL_GRID_ID.replace('#', '');
  239. var rids = $(RTNMNG01010_DETAIL_GRID_ID).jqGrid('getDataIDs');
  240. var last_row_id = rids[rids.length - 1];
  241. itp_fn_grid_reset_selection(e, last_row_id, gridId, 'RTNMNG01010_DETAIL');
  242. pageObj.grid.recal();
  243. });
  244. }
  245. },
  246. grid: {
  247. init: function(mode, gridData) {
  248. this.mode = mode;
  249. this.gridId = RTNMNG01010_DETAIL_GRID_ID;
  250. this.unload(); // ==>dwkim
  251. this.load(gridData);
  252. },
  253. mode: 'DETAIL',
  254. gridId: '',
  255. button: {
  256. addRow: function() {
  257. // 팝업
  258. var popFn = function(rowDataPop) {
  259. console.log(rowDataPop);
  260. // 기존등록 데이터
  261. var exists = '';
  262. const rowData = $(RTNMNG01010_DETAIL_GRID_ID).getRowData();
  263. $.each(rowData, function(key, value) {
  264. exists = exists + value.brandUnitUnqNo + ';';
  265. });
  266. $.each(rowDataPop, function(key, value) {
  267. if (exists.indexOf(value.brandUnitUnqNo) < 0) {
  268. value['viewCd'] = "C";
  269. $(RTNMNG01010_DETAIL_GRID_ID).jqGrid('addRowData', value.brandUnitUnqNo, value, 'last');
  270. }
  271. });
  272. $(RTNMNG01010_DETAIL_GRID_EMPTY).hide();
  273. };
  274. const key = {brandId:fn_make_user_info.get('brandId'),storeId:fn_make_user_info.get('storeId')};
  275. fn_call_popup('biz', 'BIZPOP_ITEM', '#ITP_ASIDE', popFn, key, 'S'); // ==>dwkim 추후 작업 진행 파라메타 설명필요
  276. },
  277. delRow: function() {
  278. itp_fn_grid_del_row(RTNMNG01010_DETAIL_GRID_ID);
  279. // 그리드 포문으로 금액 재계산후 구매요청금액에 넣어줌
  280. pageObj.grid.recal(); //==>dwkim 왜 호출이 안될까요
  281. }
  282. },
  283. load: function(gridData) { // ==>dwkim 오픈시 데이타 가져오는 부분 넣으면 되는건지 여부 gird가 아님
  284. var _this = this;
  285. var option = {
  286. gridId: this.gridId,
  287. colModel: gridColModel.detail,
  288. data: gridData,
  289. multiselect: true,
  290. // cellEdit: true,
  291. onCellSelect: function(rowId, cellIdx, cellValue) {
  292. RTNMNG01010_DETAIL_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowId, cellIdx, RTNMNG01010_DETAIL_GRID_LAST_ROW_ID, RTNMNG01010_DETAIL_GRID_ID, ['pchReqQty']);
  293. },
  294. loadComplete: function(data) {
  295. _this.clearData();
  296. }
  297. };
  298. itp_fn_grid_make_local(option);
  299. },
  300. clearData: function() {
  301. // console.log(this.gridId);
  302. $(RTNMNG01010_DETAIL_GRID_ID).jqGrid('clearGridData', true);
  303. $(RTNMNG01010_DETAIL_GRID_LIST).find('.ui-jqgrid .ui-jqgrid-bdiv').css('overflow-x', 'hidden');
  304. $(RTNMNG01010_DETAIL_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
  305. $(RTNMNG01010_DETAIL_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
  306. $(RTNMNG01010_DETAIL_GRID_EMPTY).show();
  307. },
  308. recal: function() {
  309. var ids = $(RTNMNG01010_DETAIL_GRID_ID).getDataIDs();
  310. $.each(ids, function(idx, rowId) {
  311. var viewCd = jQuery(RTNMNG01010_DETAIL_GRID_ID).jqGrid('getCell', rowId, 'viewCd');
  312. var unitAmt = jQuery(RTNMNG01010_DETAIL_GRID_ID).jqGrid('getCell', rowId, 'unitAmt');
  313. var pchReqQty = jQuery(RTNMNG01010_DETAIL_GRID_ID).jqGrid('getCell', rowId, 'pchReqQty');
  314. if(viewCd != 'D' && unitAmt != null && unitAmt != '' && pchReqQty != null && pchReqQty != '') {
  315. jQuery(RTNMNG01010_DETAIL_GRID_ID).jqGrid('setRowData',rowId,{pchReqAmt: parseInt(unitAmt)*parseInt(pchReqQty)});
  316. }
  317. });
  318. const rowData = $(RTNMNG01010_DETAIL_GRID_ID).getRowData();
  319. var pchReqAmt = 0 ;
  320. $.each(rowData, function(key, value) {
  321. // console.log(JSON.stringify(rowData));
  322. if (value.pchReqAmt != null && value.pchReqAmt != "" && value.viewCd != "D") {
  323. pchReqAmt = pchReqAmt + parseInt(value.pchReqAmt) ;
  324. }
  325. });
  326. $('#ITP_FORM_RTNMNG01010_DETAIL .fnPchReqAmt').text(itp_fn_number_comma(pchReqAmt));
  327. },
  328. unload: function() {
  329. $.jgrid.gridUnload(this.gridId);
  330. }
  331. }
  332. };
  333. /*신규화면 Object*/
  334. let createObj = {
  335. init: function() {
  336. $('#ITP_FORM_RTNMNG01010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
  337. $('#ITP_FORM_RTNMNG01010_DETAIL_STORE_ID').val(fn_make_user_info.get('storeId'));
  338. //let param = 'brandId=' + LOGIN_USER_INFO.brandId + "&spplyId=" + LOGIN_USER_INFO.spplyId;
  339. this.load();
  340. },
  341. newinit: function() {
  342. $('#ITP_FORM_RTNMNG01010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
  343. $('#ITP_FORM_RTNMNG01010_DETAIL_STORE_ID').val(fn_make_user_info.get('storeId'));
  344. $('#ITP_FORM_RTNMNG01010_DETAIL_NOTE').val('');
  345. var now = new Date();
  346. $('#ITP_TAB_RTNMNG01010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);
  347. $('#ITP_FORM_RTNMNG01010_DETAIL_COL_REQ_DT').datepicker('setDate', new Date(now.setDate(now.getDate() + 5)));
  348. this.load(); //==>dwkim 초기화 하여 다시 초기 데이타 가져와 뿌려줌
  349. const key = {brandId:fn_make_user_info.get('brandId'),storeId:fn_make_user_info.get('storeId')};
  350. fn_ajax_call(API_DETAIL_INIT_INFO, key, this.callback, 'GET');
  351. },
  352. button: {
  353. save: function(arg) {
  354. $('body').trigger('click');
  355. const formId = '#ITP_FORM_RTNMNG01010_DETAIL';
  356. itp_fn_form_clear_validate(null, formId);
  357. $('#ITP_FORM_RTNMNG01010_DETAIL_RTN_REQ_ST_CD').val(arg);
  358. if (itp_fn_form_event.isValid(formId)) {
  359. // 품목대상 정보 확인 필요
  360. var records = $(RTNMNG01010_DETAIL_GRID_ID).getGridParam('reccount');
  361. if (records == 0) {
  362. alert( "요청할 품목내역이 없습니다.");
  363. return ;
  364. }
  365. var saveReq = {
  366. callBack: function(args) {
  367. $(formId).val(arg);
  368. let gridInsertData = [];
  369. let gridUpdateData = [];
  370. let gridDeleteData = [];
  371. const rowData = $(RTNMNG01010_DETAIL_GRID_ID).getRowData();
  372. $.each(rowData, function(key, value) {
  373. if (value.viewCd !== 'R') {
  374. if (value.viewCd === 'C') {
  375. gridInsertData.push(value);
  376. } else if (value.viewCd === 'U') {
  377. gridUpdateData.push(value);
  378. } else if (value.viewCd === 'D') {
  379. gridDeleteData.push(value);
  380. }
  381. }
  382. });
  383. let param = $(formId).serializeObject();
  384. param.gridInsertData = gridInsertData;
  385. param.gridUpdateData = gridUpdateData;
  386. param.gridDeleteData = gridDeleteData;
  387. console.log(JSON.stringify(param));
  388. var searhFn = function() {
  389. createObj.newinit();
  390. };
  391. fn_ajax_call(API_DETAIL_SAVE, JSON.stringify(param), searhFn, 'POST');
  392. }
  393. };
  394. if (arg == 'PR20') {
  395. itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.reqSave, saveReq, null);
  396. } else {
  397. itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.tmpSave, saveReq, null);
  398. }
  399. }
  400. }
  401. },
  402. load: function() {
  403. const key = {brandId:fn_make_user_info.get('brandId'), storeId:fn_make_user_info.get('storeId')};
  404. fn_ajax_call(API_DETAIL_INIT_INFO, key, this.callback, 'GET');
  405. },
  406. callback: function(result) {
  407. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_VIEW_CD').val('C');
  408. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_BRAND_ID').val(result.brandId);
  409. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_STORE_ID').val(result.storeId);
  410. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_REQ_DEPT').val(result.reqDept);
  411. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_AUTH_TP_CD').val(result.authTpCd);
  412. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_WHS_DVSN').val(result.whsDvsn);
  413. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_RTN_WHS_ID').val(result.rtnWhsId);
  414. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_RTN_WHS_NM').val(result.rtnWhsNm);
  415. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_RTN_LOCATION').val(result.rtnLocation);
  416. $('#ITP_FORM_RTNMNG01010_DETAIL #ITP_FORM_RTNMNG01010_DETAIL_RTN_LOCATION_NM').val(result.rtnLocationNm);
  417. $('#ITP_FORM_RTNMNG01010_DETAIL .fnBrandNm').text(result.brandNm);
  418. pageObj.grid.init();
  419. }
  420. };