ITP_STINFO06010.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 STINFO06010_GRID_ID = '#ITP_STINFO06010_jqGrid';
  20. const STINFO06010_GRID_LIST = '#ITP_STINFO06010_jqGrid_list';
  21. const STINFO06010_GRID_PAGER = '#ITP_STINFO06010_jqGridPager';
  22. const STINFO06010_GRID_EMPTY = '#ITP_STINFO06010_jqGridEmpty';
  23. const STINFO06010_DETAIL_GRID_ID = '#ITP_STINFO06010_DETAIL_jqGrid';
  24. const STINFO06010_DETAIL_GRID_LIST = '#ITP_STINFO06010_DETAIL_jqGrid_list';
  25. const STINFO06010_DETAIL_GRID_PAGER = '#ITP_STINFO06010_DETAIL_jqGridPager';
  26. const STINFO06010_DETAIL_GRID_EMPTY = '#ITP_STINFO06010_DETAIL_jqGridEmpty';
  27. let STINFO06010_GRID_LAST_ROW_ID;
  28. /* 공통코드 리스트 */
  29. let ITP_COMMON_CD_DSTRBT_COST_UNIT = fn_make_common_cd_list(CODE_LIST, 'DSTRBT_COST_UNIT', true, '기본단위');
  30. let ITP_COMMON_CD_CURR = fn_make_common_cd_list(CODE_LIST, 'CURR', true, '통화');
  31. let ITP_COMMON_CD_UNIT_TARGET_CD = fn_make_common_cd_list(CODE_LIST, 'UNIT_TARGET_CD', true, '대상여부');
  32. /*API URL*/
  33. let API_DETAIL_GRID_LIST = '/api/itemunit/store-unit-grid-list'; // 목록
  34. let API_DETAIL_INFO = '/api/itemunit/info-storeitemunit'; // 상세
  35. let API_DETAIL_SAVE = '/api/itemunit/save-store-itemunit'; // 저장
  36. /*화면 Grid ColModel*/
  37. const gridColModel = {
  38. list: [
  39. {
  40. index: 'BRAND_ID', name: 'brandId',
  41. label: ITP_MSG_LOCALE.label.brandId, //브랜드ID
  42. width: '10', fixed: false, align: 'center',
  43. sortable: false, hidden: true
  44. },
  45. {
  46. index: 'BRAND_NM', name: 'brandNm',
  47. label: ITP_MSG_LOCALE.label.brandNm, //브랜드명
  48. width: '13', fixed: false, align: 'center',
  49. sortable: false, hidden: false
  50. },
  51. {
  52. index: 'STORE_ID', name: 'storeId',
  53. label: ITP_MSG_LOCALE.label.storeId, //매장ID
  54. width: '10', fixed: false, align: 'center',
  55. sortable: false, hidden: true
  56. },
  57. {
  58. index: 'STORE_NM', name: 'storeNm',
  59. label: ITP_MSG_LOCALE.label.storeNm, //매장명
  60. width: '10', fixed: false, align: 'center',
  61. sortable: false, hidden: true
  62. },
  63. {
  64. index: 'CONT_STT_DT', name: 'contSttDt',
  65. label: ITP_MSG_LOCALE.label.contSttDt, //계약시작일
  66. width: '15', fixed: false, align: 'center',
  67. sortable: false, hidden: false
  68. },
  69. {
  70. index: 'CONT_END_DT', name: 'contEndDt',
  71. label: ITP_MSG_LOCALE.label.contEndDt, //계약종료일
  72. width: '6', fixed: false, align: 'center',
  73. sortable: false, hidden: false
  74. },
  75. {
  76. index: 'SYS_REG_DTTM', name: 'sysRegDttm',
  77. label: ITP_MSG_LOCALE.label.sysRegDt, //계약생성일
  78. width: '6', fixed: false, align: 'center',
  79. sortable: false, hidden: false
  80. },
  81. {
  82. index: 'ITEM_CNT', name: 'itemCnt',
  83. label: ITP_MSG_LOCALE.label.itemCnt, //계약품목수
  84. width: '10', fixed: false, align: 'center',
  85. sortable: false, hidden: false
  86. }
  87. ],
  88. detail: [
  89. {
  90. index: 'BRAND_ID', name: 'brandId',
  91. label: ITP_MSG_LOCALE.label.brandId, //브랜드ID
  92. width: '10', fixed: false, align: 'center',
  93. sortable: false, hidden: true
  94. },
  95. {
  96. index: 'ITEM_ID', name: 'itemId',
  97. label: ITP_MSG_LOCALE.label.itemId, //품목번호
  98. width: '10', fixed: false, align: 'center',
  99. sortable: false, hidden: false
  100. },
  101. {
  102. index: 'ITEM_NM', name: 'itemNm',
  103. label: ITP_MSG_LOCALE.label.itemNm, //품목명
  104. width: '13', fixed: false, align: 'center',
  105. sortable: false, hidden: false
  106. },
  107. {
  108. index: 'CONT_STT_DT', name: 'contSttDt',
  109. label: ITP_MSG_LOCALE.label.contSttDt, //계약시작일
  110. width: '10', fixed: false, align: 'center',
  111. sortable: false, hidden: false
  112. },
  113. {
  114. index: 'CONT_END_DT', name: 'contEndDt',
  115. label: ITP_MSG_LOCALE.label.contEndDt, //계약종료일
  116. width: '10', fixed: false, align: 'center',
  117. sortable: false, hidden: false
  118. },
  119. {
  120. index: 'UNIT', name: 'unit',
  121. label: ITP_MSG_LOCALE.label.unit, //기본단위
  122. width: '9', fixed: false, align: 'center',
  123. sortable: false, editable: true, formatter: 'select', edittype: 'select',
  124. editoptions: {value: ITP_COMMON_CD_DSTRBT_COST_UNIT},
  125. editrules: {required: true}
  126. },
  127. {
  128. index: 'STDD_QYT', name: 'stddQty',
  129. label: ITP_MSG_LOCALE.label.stddQty, //기준수량
  130. width: '6', fixed: false, align: 'center',
  131. sortable: true, editable: true, edittype: 'text',
  132. editrules: {required: true}
  133. },
  134. {
  135. index: 'CURR', name: 'curr',
  136. label: ITP_MSG_LOCALE.label.curr, //통화
  137. width: '9', fixed: false, align: 'center',
  138. sortable: false, editable: true, formatter: 'select', edittype: 'select',
  139. editoptions: {value: ITP_COMMON_CD_CURR},
  140. editrules: {required: true}
  141. },
  142. {
  143. index: 'UNIT_AMT', name: 'unitAmt',
  144. label: ITP_MSG_LOCALE.label.unitAmt, //단가
  145. width: '10', fixed: false, align: 'center',
  146. sortable: true, editable: true, edittype: 'text',
  147. editrules: {required: true}
  148. },
  149. {
  150. index: 'UNIT_TARGET_CD', name: 'unitTargetCd',
  151. label: ITP_MSG_LOCALE.label.unitTargetCd, //대상여부
  152. width: '10', fixed: false, align: 'center',
  153. sortable: false, editable: true, formatter: 'select', edittype: 'select',
  154. editoptions: {value: ITP_COMMON_CD_UNIT_TARGET_CD},
  155. editrules: {required: true}
  156. },
  157. {
  158. index: 'SPPLY_UNIT_AMT', name: 'spplyUnitAmt',
  159. label: ITP_MSG_LOCALE.label.spplyUnitAmt, //공급단가
  160. width: '6', fixed: false, align: 'center',
  161. sortable: false, hidden: false
  162. },
  163. {
  164. index: 'EDIT_STATUS', name: 'editStatus',
  165. label: ITP_MSG_LOCALE.label.spplyUnitAmt, //공급단가
  166. width: '6', fixed: false, align: 'center',
  167. sortable: false, hidden: true
  168. }
  169. ]
  170. };
  171. /*화면공통 Object*/
  172. let pageObj = {
  173. init: function () {
  174. this.ui.init();
  175. this.event.init();
  176. },
  177. screenMode: 'LIST',
  178. ui: {
  179. init: function () {
  180. this.view();
  181. this.grid();
  182. this.ready();
  183. },
  184. view: function() {
  185. // 버튼 권한설정
  186. fn_proc_btn_auth('STINFO06010');
  187. // 공통코드 표시
  188. $('select').each(function() {
  189. if($(this).data('select-code')) {
  190. fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
  191. }
  192. });
  193. // 조회일자 지정
  194. $('#ITP_TAB_STINFO06010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);
  195. },
  196. grid: function() {
  197. itp_fn_jqgrid_resize(STINFO06010_GRID_ID, STINFO06010_GRID_LIST, 'lg');
  198. listObj.empty.init();
  199. itp_fn_fire_window_resize();
  200. },
  201. ready: function() {
  202. listObj.init();
  203. }
  204. },
  205. event: {
  206. init: function () {
  207. this.button();
  208. },
  209. button: function () {
  210. // 버튼 클릭 이벤트
  211. $('button').each(function() {
  212. var id = $(this).attr('id');
  213. $(this).on('click', function() {
  214. switch (id) {
  215. case 'ITP_BTN_STINFO06010_SRH' : (this.screenMode === 'List') ? listObj.button.search() : modifyObj.search(); break; // 조회 버튼 클릭
  216. case 'ITP_BTN_STINFO06010_NEWREG' : listObj.button.create(); break; // 신규등록 버튼
  217. case 'ITP_BTN_STINFO06010_CANCELLIST' : listObj.grid.search(); break; // 취소/목록 버튼
  218. case 'ITP_BTN_STINFO06010_SAVE' : modifyObj.button.save(); break; // 저장 버튼
  219. }
  220. });
  221. });
  222. }
  223. },
  224. switchScreen: function(mode) {
  225. $('.itp_det_head').find('button[id^="ITP_BTN_STINFO06010_"]').each(function(i) {
  226. $(this).hide();
  227. });
  228. $('#ITP_TAB_STINFO06010').find('div[id$="_CONTAINER"]').each(function(i) {
  229. $(this).hide();
  230. });
  231. if(mode == 'LIST') { // 목록
  232. $('#ITP_AJAX_STINFO06010_LIST_CONTAINER').show();
  233. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_SRH', '#ITP_BTN_STINFO06010_NEWREG']);
  234. } else if(mode == 'ADD') { // 등록
  235. $('#ITP_AJAX_STINFO06010_DETAIL_CONTAINER').show();
  236. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_CANCELLIST', '#ITP_BTN_STINFO06010_SAVE']);
  237. $('#ITP_FORM_STINFO06010_DETAIL').find('input, textarea, select, checkbox').each(function(i, elem) {
  238. $(this).attr('id') === 'ITP_FORM_STINFO06010_DETAIL_VIEW_CD' ? $(this).val('C') : $(this).val('');
  239. if(elem.type === 'select') {
  240. $(this).val('').prop('selected', true);
  241. }
  242. });
  243. // 가맹점 정보 설정
  244. $('#ITP_FORM_STINFO06010_DETAIL_AFFL_SHOP_ID').val(fn_make_user_info.get('afflShopId'));
  245. $('#ITP_FORM_STINFO06010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
  246. $('#ITP_FORM_STINFO06010_DETAIL_STORE_ID').removeAttr('readonly');
  247. $('#ITP_FORM_STINFO06010_DETAIL_DUP').removeAttr('disabled');
  248. $('#ITP_FORM_STINFO06010_DETAIL .fnStoreNm').text('(자동부여)');
  249. } else if(mode == 'MODIFY') { // 수정
  250. $('#ITP_AJAX_STINFO06010_DETAIL_CONTAINER').show();
  251. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_CANCELLIST', '#ITP_BTN_STINFO06010_SAVE', '#ITP_BTN_STINFO06010_RESET_PW']);
  252. // 가맹점 정보 설정
  253. $('#ITP_FORM_STINFO06010_DETAIL_AFFL_SHOP_ID').val(fn_make_user_info.get('afflShopId'));
  254. $('#ITP_FORM_STINFO06010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
  255. } else if(mode == 'VIEW') { // 보기
  256. $('#ITP_AJAX_STINFO06010_VIEW_CONTAINER').show();
  257. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_MODIFY', '#ITP_BTN_STINFO06010_CANCELLIST']);
  258. }
  259. this.screenMode = mode;
  260. }
  261. };
  262. /*목록화면 Object*/
  263. let listObj = {
  264. init: function () {
  265. this.grid.init();
  266. },
  267. itp_STINFO06010_search: false,
  268. button: {
  269. search: function() {
  270. listObj.itp_STINFO06010_search = true;
  271. let param = $('#ITP_FORM_STINFO06010_SEARCH').serializeObject();
  272. param.gridSize = $.jgrid.defaults.rowNum;
  273. param.gridPage = $.jgrid.defaults.page;
  274. $(STINFO06010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
  275. },
  276. create: function() {
  277. if(!fn_make_user_info.isEmpty()) {
  278. let param = $('#ITP_FORM_STINFO06010_DETAIL').serializeObject();
  279. modifyObj.init($.param(param));
  280. }
  281. }
  282. },
  283. empty: {
  284. init: function() {
  285. var _this = this;
  286. this.push();
  287. $(STINFO06010_GRID_EMPTY).on('click', function() {
  288. _this.back();
  289. _this.itp_STINFO06010_param.gridSize = $.jgrid.defaults.rowNum;
  290. $(STINFO06010_GRID_ID).setGridParam({'postData': JSON.stringify(_this.itp_STINFO06010_param)}).trigger('reloadGrid');
  291. });
  292. },
  293. itp_STINFO06010_param: {},
  294. push: function() {
  295. let param = $('#ITP_FORM_STINFO06010_SEARCH').serializeObject();
  296. listObj.itp_STINFO06010_param = param;
  297. },
  298. back: function() {
  299. $('#ITP_FORM_STINFO06010_SERVICE_ST_CD').val(this.itp_STINFO06010_param.sstoreNm);
  300. }
  301. },
  302. grid: {
  303. init: function () {
  304. // 데이터 없을때
  305. listObj.empty.push();
  306. this.search();
  307. },
  308. search: function() {
  309. pageObj.switchScreen('LIST');
  310. this.unload();
  311. this.load();
  312. },
  313. load: function() {
  314. let param = $('#ITP_FORM_STINFO06010_SEARCH').serializeObject();
  315. param.gridSize = $.jgrid.defaults.rowNum;
  316. param.sbrandId = fn_make_user_info.get('brandId');
  317. var option = {
  318. gridId: STINFO06010_GRID_ID,
  319. colModel: gridColModel.list,
  320. param: JSON.stringify(param),
  321. url: DOMAIN + API_DETAIL_GRID_LIST,
  322. pager: STINFO06010_GRID_PAGER,
  323. onCellSelect: function(rowId, cellIdx, cellValue) {
  324. var cm = $(this).jqGrid('getGridParam', 'colModel');
  325. var colNm = cm[cellIdx].name;
  326. if (colNm == 'contSttDt') {
  327. const storeId = $(this).jqGrid('getCell', rowId, 'storeId');
  328. const contSttDt = $(this).jqGrid('getCell', rowId, 'contSttDt');
  329. const contEndDt = $(this).jqGrid('getCell', rowId, 'contEndDt');
  330. const key = {brandId:fn_make_user_info.get('brandId'), storeId: storeId, contSttDt: contSttDt, contEndDt: contEndDt, viewCd: 'R'};
  331. var param = $.param(key);
  332. modifyObj.init(param);
  333. }
  334. },
  335. loadComplete: function(data) {
  336. console.log(data);
  337. itp_fn_grid_load_complete(data, STINFO06010_GRID_ID, true, 'number', 'STINFO06010', listObj.itp_STINFO06010_search, listObj.empty, true, data.gridRecords, true);
  338. var ids = $(STINFO06010_GRID_ID).getDataIDs();
  339. $.each(ids, function(idx, rowId) {
  340. $(STINFO06010_GRID_ID).jqGrid('setCell', rowId, 'contSttDt', '', ITP_GRID_COL_STYLE.link);
  341. });
  342. },
  343. onPaging: function(action) {
  344. itp_fn_grid_paging(STINFO06010_GRID_ID, action, param);
  345. }
  346. };
  347. itp_fn_grid_make_remote(option);
  348. },
  349. clearData : function() {
  350. $(STINFO06010_GRID_ID).jqGrid('clearGridData', true);
  351. $(STINFO06010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
  352. $(STINFO06010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
  353. $(STINFO06010_GRID_EMPTY).show();
  354. },
  355. unload : function() {
  356. $.jgrid.gridUnload(STINFO06010_GRID_ID);
  357. }
  358. }
  359. };
  360. /*수정화면 Object*/
  361. let modifyObj = {
  362. init: function (param) {
  363. pageObj.switchScreen('MODIFY');
  364. this.grid.init(param);
  365. },
  366. itp_STINFO06010_search: false,
  367. search: function() {
  368. listObj.itp_STINFO06010_search = true;
  369. let param = $('#ITP_FORM_STINFO06010_DETAIL').serializeObject();
  370. param.gridSize = $.jgrid.defaults.rowNum;
  371. param.gridPage = $.jgrid.defaults.page;
  372. $(STINFO06010_DETAIL_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
  373. },
  374. button: {
  375. save: function() {
  376. itp_fn_grid_save_rows(STINFO06010_DETAIL_GRID_ID);
  377. var rows = $(STINFO06010_DETAIL_GRID_ID).getRowData();
  378. let param = {};
  379. var gridUpdateData = [];
  380. $.each(rows, function (key, value) {
  381. if(value.editStatus === 'U') {
  382. gridUpdateData.push(value);
  383. }
  384. });
  385. param['viewCd'] = 'U';
  386. param['brandId'] = fn_make_user_info.get('brandId');
  387. param['storeId'] = fn_make_user_info.get('userId');
  388. param['gridUpdateData'] = gridUpdateData;
  389. console.log(JSON.stringify(param));
  390. var searhFn = function() {
  391. listObj.grid.search();
  392. };
  393. fn_ajax_call(API_DETAIL_SAVE, JSON.stringify(param), searhFn, 'POST');
  394. }
  395. },
  396. empty: {
  397. init: function() {
  398. var _this = this;
  399. this.push();
  400. $(STINFO06010_DETAIL_GRID_EMPTY).on('click', function() {
  401. _this.back();
  402. _this.itp_STINFO06010_param.gridSize = $.jgrid.defaults.rowNum;
  403. $(STINFO06010_DETAIL_GRID_ID).setGridParam($.param(_this.itp_STINFO06010_param)).trigger('reloadGrid');
  404. });
  405. },
  406. itp_STINFO06010_param: {},
  407. push: function() {
  408. let param = $('#ITP_FORM_STINFO06010_DETAIL').serializeObject();
  409. listObj.itp_STINFO06010_param = param;
  410. },
  411. back: function() {
  412. }
  413. },
  414. grid: {
  415. init: function (param) {
  416. // 데이터 없을때
  417. listObj.empty.push();
  418. this.unload();
  419. this.load(param);
  420. },
  421. load: function(param) {
  422. var option = {
  423. gridId: STINFO06010_DETAIL_GRID_ID,
  424. colModel: gridColModel.detail,
  425. mtype: 'GET',
  426. param: param,
  427. url: DOMAIN + API_DETAIL_INFO,
  428. loadComplete: function(data) {
  429. console.log(data);
  430. itp_fn_grid_load_complete(data, STINFO06010_DETAIL_GRID_ID, false, 'number', 'STINFO06010', modifyObj.itp_STINFO06010_search, modifyObj.empty, true, data.gridRecords, true);
  431. },
  432. // onCelSelect: function(rowId, cellIdx, cellValue) {
  433. // STINFO06010_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowId, cellIdx, STINFO06010_GRID_LAST_ROW_ID, STINFO06010_DETAIL_GRID_ID, ['itemId']);
  434. // },
  435. ondblClickRow : function (rowid, iRow, iCol) {
  436. console.log('rowId ===> ' + rowid);
  437. STINFO06010_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowid, iRow, STINFO06010_GRID_LAST_ROW_ID, STINFO06010_DETAIL_GRID_ID, ['itemId']);
  438. $('#' + rowid + "_stddQty").blur(function(){
  439. console.log('_stddQty ===> ' + '#' + rowid + "_stddQty");
  440. $(STINFO06010_DETAIL_GRID_ID).jqGrid('saveRow', rowid, true, 'clientArray');
  441. if($(STINFO06010_DETAIL_GRID_ID).jqGrid('getRowData', rowid, 'editStatus') !== 'U') {
  442. $(STINFO06010_DETAIL_GRID_ID).jqGrid('setRowData', rowid, {editStatus: 'U'});
  443. }
  444. });
  445. },
  446. onPaging: function(action) {
  447. itp_fn_grid_paging(STINFO06010_GRID_ID, action, param);
  448. }
  449. };
  450. itp_fn_grid_make_remote(option);
  451. },
  452. clearData : function() {
  453. $(STINFO06010_DETAIL_GRID_ID).jqGrid('clearGridData', true);
  454. $(STINFO06010_DETAIL_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
  455. $(STINFO06010_DETAIL_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
  456. $(STINFO06010_DETAIL_GRID_EMPTY).show();
  457. },
  458. unload : function() {
  459. $.jgrid.gridUnload(STINFO06010_DETAIL_GRID_ID);
  460. }
  461. }
  462. };