ITP_STINFO06010.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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_NEW = '/api/itemunit/new-info-storeitemunit'; // 신규
  36. let API_DETAIL_SAVE = '/api/itemunit/save-store-itemunit'; // 저장
  37. /*화면 Grid ColModel*/
  38. const gridColModel = {
  39. list: [
  40. {
  41. index: 'BRAND_ID', name: 'brandId',
  42. label: ITP_MSG_LOCALE.label.brandId, //브랜드ID
  43. width: '10', fixed: false, align: 'center',
  44. sortable: false, hidden: true
  45. },
  46. {
  47. index: 'STORE_ID', name: 'storeId',
  48. label: ITP_MSG_LOCALE.label.storeId, //매장ID
  49. width: '10', fixed: false, align: 'center',
  50. sortable: false, hidden: true
  51. },
  52. {
  53. index: 'STORE_NM', name: 'storeNm',
  54. label: ITP_MSG_LOCALE.label.storeNm, //매장명
  55. width: '10', fixed: false, align: 'center',
  56. sortable: false, hidden: false
  57. },
  58. {
  59. index: 'CONT_STT_DT', name: 'contSttDt',
  60. label: ITP_MSG_LOCALE.label.contSttDt, //계약시작일
  61. width: '15', fixed: false, align: 'center',
  62. sortable: false, hidden: false
  63. },
  64. {
  65. index: 'CONT_END_DT', name: 'contEndDt',
  66. label: ITP_MSG_LOCALE.label.contEndDt, //계약종료일
  67. width: '6', fixed: false, align: 'center',
  68. sortable: false, hidden: false
  69. },
  70. {
  71. index: 'SYS_REG_DTTM', name: 'sysRegDttm',
  72. label: ITP_MSG_LOCALE.label.sysRegDt, //계약생성일
  73. width: '6', fixed: false, align: 'center',
  74. sortable: false, hidden: false
  75. },
  76. {
  77. index: 'ITEM_CNT', name: 'itemCnt',
  78. label: ITP_MSG_LOCALE.label.itemCnt, //계약품목수
  79. width: '10', fixed: false, align: 'center',
  80. sortable: false, hidden: false
  81. }
  82. ],
  83. detail: [
  84. {
  85. index: 'VIEW_CD', name: 'viewCd',
  86. label: ITP_MSG_LOCALE.label.brandId, //공급단가
  87. width: '6', fixed: false, align: 'center',
  88. sortable: false, hidden: true
  89. },
  90. {
  91. index: 'BRAND_ID', name: 'brandId',
  92. label: ITP_MSG_LOCALE.label.brandId, //브랜드ID
  93. width: '10', fixed: false, align: 'center',
  94. sortable: false, hidden: true
  95. },
  96. {
  97. index: 'BRAND_UNIT_UNQ_NO', name: 'brandUnitUnqNo',
  98. label: ITP_MSG_LOCALE.label.brandId, //브랜드ID
  99. width: '10', fixed: false, align: 'center',
  100. sortable: false, hidden: true
  101. },
  102. {
  103. index: 'STORE_UNIT_UNQ_NO', name: 'storeUnitUnqNo',
  104. label: ITP_MSG_LOCALE.label.storeId, //브랜드ID
  105. width: '10', fixed: false, align: 'center',
  106. sortable: false, hidden: true
  107. },
  108. {
  109. index: 'ITEM_ID', name: 'itemId',
  110. label: ITP_MSG_LOCALE.label.itemId, //품목번호
  111. width: '10', fixed: false, align: 'center',
  112. sortable: false, hidden: false
  113. },
  114. {
  115. index: 'ITEM_NM', name: 'itemNm',
  116. label: ITP_MSG_LOCALE.label.itemNm, //품목명
  117. width: '13', fixed: false, align: 'center',
  118. sortable: false, hidden: false
  119. },
  120. {
  121. index: 'CONT_STT_DT', name: 'contSttDt',
  122. label: ITP_MSG_LOCALE.label.contSttDt, //계약시작일
  123. width: '10', fixed: false, align: 'center',
  124. sortable: false, hidden: false
  125. },
  126. {
  127. index: 'CONT_END_DT', name: 'contEndDt',
  128. label: ITP_MSG_LOCALE.label.contEndDt, //계약종료일
  129. width: '10', fixed: false, align: 'center',
  130. sortable: false, hidden: false
  131. },
  132. {
  133. index: 'UNIT', name: 'unit',
  134. label: ITP_MSG_LOCALE.label.unit, //기본단위
  135. width: '9', fixed: false, align: 'center',
  136. sortable: false, editable: true, formatter: 'select', edittype: 'select',
  137. editoptions: {value: ITP_COMMON_CD_DSTRBT_COST_UNIT},
  138. editrules: {required: true}
  139. },
  140. {
  141. index: 'STDD_QYT', name: 'stddQty',
  142. label: ITP_MSG_LOCALE.label.stddQty, //기준수량
  143. width: '6', fixed: false, align: 'center',
  144. sortable: true, editable: true, edittype: 'text',
  145. editrules: {required: true}
  146. },
  147. {
  148. index: 'CURR', name: 'curr',
  149. label: ITP_MSG_LOCALE.label.curr, //통화
  150. width: '9', fixed: false, align: 'center',
  151. sortable: false, editable: true, formatter: 'select', edittype: 'select',
  152. editoptions: {value: ITP_COMMON_CD_CURR},
  153. editrules: {required: true}
  154. },
  155. {
  156. index: 'UNIT_AMT', name: 'unitAmt',
  157. label: ITP_MSG_LOCALE.label.unitAmt, //단가
  158. width: '10', fixed: false, align: 'center',
  159. sortable: true, editable: true, edittype: 'text',
  160. editrules: {required: true}
  161. },
  162. {
  163. index: 'UNIT_TARGET_CD', name: 'unitTargetCd',
  164. label: ITP_MSG_LOCALE.label.unitTargetCd, //대상여부
  165. width: '10', fixed: false, align: 'center',
  166. sortable: false, editable: true, formatter: 'select', edittype: 'select',
  167. editoptions: {value: ITP_COMMON_CD_UNIT_TARGET_CD},
  168. editrules: {required: true}
  169. },
  170. {
  171. index: 'SPPLY_UNIT_AMT', name: 'spplyUnitAmt',
  172. label: ITP_MSG_LOCALE.label.spplyUnitAmt, //공급단가
  173. width: '6', fixed: false, align: 'center',
  174. sortable: false, hidden: false
  175. }
  176. ]
  177. };
  178. /*화면공통 Object*/
  179. let pageObj = {
  180. init: function () {
  181. this.ui.init();
  182. this.event.init();
  183. },
  184. screenMode: 'LIST',
  185. ui: {
  186. init: function () {
  187. this.view();
  188. this.grid();
  189. this.ready();
  190. },
  191. view: function() {
  192. // 버튼 권한설정
  193. fn_proc_btn_auth('STINFO06010');
  194. // 공통코드 표시
  195. $('select').each(function() {
  196. if($(this).data('select-code')) {
  197. fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
  198. }
  199. });
  200. // 조회일자 지정
  201. var now = new Date();
  202. $('#ITP_TAB_STINFO06010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);
  203. $('#ITP_FORM_STINFO06010_SEARCH_FROM_DT').datepicker('setDate', new Date(now.setMonth(now.getMonth() - 1)));
  204. $('#ITP_FORM_STINFO06010_SEARCH_TO_DT').datepicker('setDate', new Date());
  205. },
  206. grid: function() {
  207. itp_fn_jqgrid_resize(STINFO06010_GRID_ID, STINFO06010_GRID_LIST, 'lg');
  208. listObj.empty.init();
  209. itp_fn_fire_window_resize();
  210. },
  211. ready: function() {
  212. listObj.init();
  213. }
  214. },
  215. event: {
  216. init: function () {
  217. this.button();
  218. },
  219. button: function () {
  220. // 버튼 클릭 이벤트
  221. $('button').each(function() {
  222. var id = $(this).attr('id');
  223. $(this).on('click', function() {
  224. switch (id) {
  225. case 'ITP_BTN_STINFO06010_SRH' : listObj.button.search(); break; // 조회 버튼 클릭
  226. case 'ITP_BTN_STINFO06010_NEWREG' : listObj.button.create(); break; // 신규등록 버튼
  227. case 'ITP_BTN_STINFO06010_CANCELLIST' : listObj.grid.search(); break; // 취소/목록 버튼
  228. case 'ITP_BTN_STINFO06010_SAVE' : createObj.button.save(); break; // 저장 버튼
  229. }
  230. });
  231. });
  232. $('body').on('click', function(e) {
  233. var gridId = STINFO06010_DETAIL_GRID_ID.replace('#', '');
  234. itp_fn_grid_reset_selection(e, STINFO06010_GRID_LAST_ROW_ID, gridId, 'STINFO06010');
  235. });
  236. }
  237. },
  238. switchScreen: function(mode) {
  239. this.screenMode = mode;
  240. $('.itp_det_head').find('button[id^="ITP_BTN_STINFO06010_"]').each(function(i) {
  241. $(this).hide();
  242. });
  243. $('#ITP_TAB_STINFO06010').find('div[id$="_CONTAINER"]').each(function(i) {
  244. $(this).hide();
  245. });
  246. if(mode == 'ADD') {
  247. $('#ITP_FORM_STINFO06010_DETAIL .contDt').show();
  248. } else {
  249. $('#ITP_FORM_STINFO06010_DETAIL .contDt').hide();
  250. }
  251. if(mode == 'LIST') { // 목록
  252. $('#ITP_AJAX_STINFO06010_LIST_CONTAINER').show();
  253. if(fn_make_user_info.get('authTpCd') === '50') {
  254. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_SRH']);
  255. $('#ITP_FORM_STINFO06010_SEARCH_STORE_ID').val(fn_make_user_info.get('storeId'));
  256. $('#ITP_FORM_STINFO06010_SEARCH_STORE').hide();
  257. } else {
  258. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_SRH', '#ITP_BTN_STINFO06010_NEWREG']);
  259. }
  260. $('#ITP_FORM_STINFO06010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId'));
  261. } else if(mode == 'ADD') { // 등록
  262. itp_fn_form_clear_validate(null, '#ITP_FORM_STINFO07010_DETAIL');
  263. $('#ITP_FORM_STINFO06010_DETAIL').find('input, textarea, select, checkbox').each(function(i, elem) {
  264. $(this).attr('id') === 'ITP_FORM_STINFO06010_DETAIL_VIEW_CD' ? $(this).val('C') : $(this).val('');
  265. if(elem.type === 'select') {
  266. $(this).val('').prop('selected', true);
  267. }
  268. });
  269. $('#ITP_AJAX_STINFO06010_DETAIL_CONTAINER').show();
  270. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_CANCELLIST', '#ITP_BTN_STINFO06010_SAVE']);
  271. $('#ITP_BTN_STINFO06010_DETAIL_SEARCH_STORE').removeAttr('disabled');
  272. $('#ITP_BTN_STINFO06010_DETAIL_DELETE_STORE').removeAttr('disabled');
  273. // 가맹점 정보 설정
  274. $('#ITP_FORM_STINFO06010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
  275. } else if(mode == 'MODIFY') { // 수정
  276. $('#ITP_AJAX_STINFO06010_DETAIL_CONTAINER').show();
  277. if(fn_make_user_info.get('authTpCd') === '50') {
  278. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_CANCELLIST']);
  279. } else {
  280. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_CANCELLIST', '#ITP_BTN_STINFO06010_SAVE']);
  281. }
  282. $('#ITP_BTN_STINFO06010_DETAIL_SEARCH_STORE').attr('disabled', true);
  283. $('#ITP_BTN_STINFO06010_DETAIL_DELETE_STORE').attr('disabled', true);
  284. // 가맹점 정보 설정
  285. $('#ITP_FORM_STINFO06010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
  286. } else if(mode == 'VIEW') { // 보기
  287. $('#ITP_AJAX_STINFO06010_VIEW_CONTAINER').show();
  288. fn_show_btn_auth_array(['#ITP_BTN_STINFO06010_MODIFY', '#ITP_BTN_STINFO06010_CANCELLIST']);
  289. }
  290. this.screenMode = mode;
  291. }
  292. };
  293. /*목록화면 Object*/
  294. let listObj = {
  295. init: function () {
  296. this.grid.init();
  297. },
  298. itp_STINFO06010_search: false,
  299. button: {
  300. search: function() {
  301. listObj.itp_STINFO06010_search = true;
  302. let param = $('#ITP_FORM_STINFO06010_SEARCH').serializeObject();
  303. param.gridSize = $.jgrid.defaults.rowNum;
  304. param.gridPage = $.jgrid.defaults.page;
  305. $(STINFO06010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
  306. },
  307. create: function() {
  308. createObj.init();
  309. }
  310. },
  311. empty: {
  312. init: function() {
  313. var _this = this;
  314. this.push();
  315. $(STINFO06010_GRID_EMPTY).on('click', function() {
  316. _this.back();
  317. _this.itp_STINFO06010_param.gridSize = $.jgrid.defaults.rowNum;
  318. $(STINFO06010_GRID_ID).setGridParam({'postData': JSON.stringify(_this.itp_STINFO06010_param)}).trigger('reloadGrid');
  319. });
  320. },
  321. itp_STINFO06010_param: {},
  322. push: function() {
  323. let param = $('#ITP_FORM_STINFO06010_SEARCH').serializeObject();
  324. listObj.itp_STINFO06010_param = param;
  325. },
  326. back: function() {
  327. $('#ITP_FORM_STINFO06010_SERVICE_ST_CD').val(this.itp_STINFO06010_param.sstoreNm);
  328. }
  329. },
  330. grid: {
  331. init: function () {
  332. // 데이터 없을때
  333. listObj.empty.push();
  334. this.search();
  335. },
  336. search: function() {
  337. pageObj.switchScreen('LIST');
  338. this.unload();
  339. this.load();
  340. },
  341. load: function() {
  342. let param = $('#ITP_FORM_STINFO06010_SEARCH').serializeObject();
  343. param.gridSize = $.jgrid.defaults.rowNum;
  344. param.sbrandId = fn_make_user_info.get('brandId');
  345. var option = {
  346. gridId: STINFO06010_GRID_ID,
  347. colModel: gridColModel.list,
  348. param: param,
  349. url: DOMAIN + API_DETAIL_GRID_LIST,
  350. pager: STINFO06010_GRID_PAGER,
  351. onCellSelect: function(rowId, cellIdx, cellValue) {
  352. var cm = $(this).jqGrid('getGridParam', 'colModel');
  353. var colNm = cm[cellIdx].name;
  354. if (colNm === 'contSttDt') {
  355. const storeId = $(this).jqGrid('getCell', rowId, 'storeId');
  356. const storeNm = $(this).jqGrid('getCell', rowId, 'storeNm');
  357. const contSttDt = $(this).jqGrid('getCell', rowId, 'contSttDt');
  358. const contEndDt = $(this).jqGrid('getCell', rowId, 'contEndDt');
  359. $('#ITP_FORM_STINFO06010_DETAIL_STORE_ID').val(storeId);
  360. $('#ITP_FORM_STINFO06010_DETAIL_STORE_NM').val(storeNm);
  361. const key = {brandId:fn_make_user_info.get('brandId'), storeId: storeId, contSttDt: contSttDt, contEndDt: contEndDt, viewCd: 'R'};
  362. var param = $.param(key);
  363. modifyObj.init(param);
  364. }
  365. },
  366. loadComplete: function(data) {
  367. console.log(data);
  368. itp_fn_grid_load_complete(data, STINFO06010_GRID_ID, true, 'number', 'STINFO06010', listObj.itp_STINFO06010_search, listObj.empty, true, data.gridRecords, true);
  369. var ids = $(STINFO06010_GRID_ID).getDataIDs();
  370. $.each(ids, function(idx, rowId) {
  371. $(STINFO06010_GRID_ID).jqGrid('setCell', rowId, 'contSttDt', '', ITP_GRID_COL_STYLE.link);
  372. });
  373. },
  374. onPaging: function(action) {
  375. itp_fn_grid_paging(STINFO06010_GRID_ID, action, param);
  376. }
  377. };
  378. itp_fn_grid_make_remote(option);
  379. },
  380. clearData : function() {
  381. $(STINFO06010_GRID_ID).jqGrid('clearGridData', true);
  382. $(STINFO06010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
  383. $(STINFO06010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
  384. $(STINFO06010_GRID_EMPTY).show();
  385. },
  386. unload : function() {
  387. $.jgrid.gridUnload(STINFO06010_GRID_ID);
  388. }
  389. }
  390. };
  391. /*수정화면 Object*/
  392. let modifyObj = {
  393. init: function (param) {
  394. pageObj.switchScreen('MODIFY');
  395. // var param = $.param($('#ITP_FORM_STINFO06010_DETAIL').serializeObject());
  396. this.grid.init(param);
  397. },
  398. itp_STINFO06010_search: false,
  399. search: function() {
  400. listObj.itp_STINFO06010_search = true;
  401. let param = $('#ITP_FORM_STINFO06010_DETAIL').serializeObject();
  402. param.gridSize = $.jgrid.defaults.rowNum;
  403. param.gridPage = $.jgrid.defaults.page;
  404. $(STINFO06010_DETAIL_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
  405. },
  406. button: {
  407. },
  408. empty: {
  409. init: function() {
  410. var _this = this;
  411. this.push();
  412. $(STINFO06010_DETAIL_GRID_EMPTY).on('click', function() {
  413. _this.back();
  414. _this.itp_STINFO06010_param.gridSize = $.jgrid.defaults.rowNum;
  415. $(STINFO06010_DETAIL_GRID_ID).setGridParam($.param(_this.itp_STINFO06010_param)).trigger('reloadGrid');
  416. });
  417. },
  418. itp_STINFO06010_param: {},
  419. push: function() {
  420. let param = $('#ITP_FORM_STINFO06010_DETAIL').serializeObject();
  421. listObj.itp_STINFO06010_param = param;
  422. },
  423. back: function() {
  424. }
  425. },
  426. grid: {
  427. init: function (param) {
  428. // 데이터 없을때
  429. listObj.empty.push();
  430. this.unload();
  431. this.load(param);
  432. },
  433. prevRowId: null,
  434. load: function(param) {
  435. var _this = this;
  436. console.log(param);
  437. var option = {
  438. gridId: STINFO06010_DETAIL_GRID_ID,
  439. colModel: gridColModel.detail,
  440. param: param,
  441. url: DOMAIN + API_DETAIL_INFO,
  442. loadComplete: function(data) {
  443. console.log(data);
  444. createObj.rows = data.gridRows;
  445. itp_fn_grid_load_complete(data, STINFO06010_DETAIL_GRID_ID, false, 'number', 'STINFO06010', modifyObj.itp_STINFO06010_search, modifyObj.empty, true, data.gridRecords, true);
  446. },
  447. onCellSelect: function(rowid, cellIdx, cellValue) {
  448. if(fn_make_user_info.get('authTpCd') !== '50') {
  449. STINFO06010_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowid, cellIdx, STINFO06010_GRID_LAST_ROW_ID, STINFO06010_DETAIL_GRID_ID, ['actionId']);
  450. }
  451. },
  452. onPaging: function(action) {
  453. itp_fn_grid_paging(STINFO06010_GRID_ID, action, param);
  454. }
  455. };
  456. itp_fn_grid_make_remote(option);
  457. },
  458. clearData : function() {
  459. $(STINFO06010_DETAIL_GRID_ID).jqGrid('clearGridData', true);
  460. $(STINFO06010_DETAIL_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
  461. $(STINFO06010_DETAIL_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
  462. $(STINFO06010_DETAIL_GRID_EMPTY).show();
  463. },
  464. unload : function() {
  465. $.jgrid.gridUnload(STINFO06010_DETAIL_GRID_ID);
  466. }
  467. }
  468. };
  469. /*신규화면 Object*/
  470. let createObj = {
  471. init: function () {
  472. pageObj.switchScreen('ADD');
  473. var param = $.param($('#ITP_FORM_STINFO06010_DETAIL').serializeObject());
  474. this.grid.init(param);
  475. this.button.init();
  476. },
  477. button: {
  478. init: function() {
  479. // 가맹점 조회 버튼 클릭
  480. $('#ITP_BTN_STINFO06010_DETAIL_SEARCH_STORE').one('click', function() {
  481. createObj.popup();
  482. });
  483. // 가맹점 텍스트 삭제 버튼 클릭
  484. $('#ITP_BTN_STINFO06010_DETAIL_DELETE_STORE').one('click', function() {
  485. $('#ITP_FORM_STINFO06010_DETAIL_BRAND_ID').val('');
  486. $('#ITP_FORM_STINFO06010_DETAIL_STORE_ID').val('');
  487. $('#ITP_FORM_STINFO06010_DETAIL_STORE_NM').val('');
  488. });
  489. },
  490. cancel: function() {
  491. listObj.grid.search();
  492. },
  493. save: function() {
  494. const formId = '#ITP_FORM_STINFO06010_DETAIL';
  495. var isValid = true;
  496. if(pageObj.screenMode === 'ADD') {
  497. isValid = itp_fn_form_event.isValid(formId)
  498. }
  499. if (isValid) {
  500. itp_fn_grid_save_rows(STINFO06010_DETAIL_GRID_ID);
  501. var rows = $(STINFO06010_DETAIL_GRID_ID).getRowData();
  502. let param = {};
  503. var gridInsertData = [];
  504. var gridUpdateData = [];
  505. var changeRows = createObj.changeRows(rows);
  506. $.each(changeRows, function (index, item) {
  507. if(pageObj.screenMode === 'ADD') {
  508. item['contSttDt'] = $('#ITP_FORM_STINFO06010_DETAIL_FROM_DT').val();
  509. item['contEndDt'] = $('#ITP_FORM_STINFO06010_DETAIL_TO_DT').val();
  510. gridInsertData.push(item);
  511. } else {
  512. if(item.viewCd === 'C') {
  513. gridInsertData.push(item);
  514. } else if(item.viewCd === 'U') {
  515. gridUpdateData.push(item);
  516. }
  517. }
  518. });
  519. param['viewCd'] = 'U';
  520. param['brandId'] = fn_make_user_info.get('brandId');
  521. param['storeId'] = $('#ITP_FORM_STINFO06010_DETAIL_STORE_ID').val();
  522. param['gridInsertData'] = gridInsertData;
  523. param['gridUpdateData'] = gridUpdateData;
  524. console.log(JSON.stringify(param));
  525. var searhFn = function() {
  526. listObj.grid.search();
  527. };
  528. fn_ajax_call(API_DETAIL_SAVE, JSON.stringify(param), searhFn, 'POST');
  529. }
  530. }
  531. },
  532. grid: {
  533. init: function (param) {
  534. // 데이터 없을때
  535. listObj.empty.push();
  536. this.unload();
  537. this.load(param);
  538. },
  539. rows: [],
  540. prevRowId: null,
  541. load: function(param) {
  542. var _this = this;
  543. console.log(param);
  544. var option = {
  545. gridId: STINFO06010_DETAIL_GRID_ID,
  546. colModel: gridColModel.detail,
  547. mtype: 'GET',
  548. param: param,
  549. url: DOMAIN + API_DETAIL_NEW,
  550. loadComplete: function(data) {
  551. console.log(data);
  552. createObj.rows = data.gridRows;
  553. itp_fn_grid_load_complete(data, STINFO06010_DETAIL_GRID_ID, false, 'number', 'STINFO06010', modifyObj.itp_STINFO06010_search, modifyObj.empty, true, data.gridRecords, true);
  554. },
  555. onCellSelect: function(rowid, cellIdx, cellValue) {
  556. STINFO06010_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowid, cellIdx, STINFO06010_GRID_LAST_ROW_ID, STINFO06010_DETAIL_GRID_ID, ['actionId']);
  557. },
  558. onPaging: function(action) {
  559. itp_fn_grid_paging(STINFO06010_GRID_ID, action, param);
  560. }
  561. };
  562. itp_fn_grid_make_remote(option);
  563. },
  564. clearData : function() {
  565. $(STINFO06010_DETAIL_GRID_ID).jqGrid('clearGridData', true);
  566. $(STINFO06010_DETAIL_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
  567. $(STINFO06010_DETAIL_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
  568. $(STINFO06010_DETAIL_GRID_EMPTY).show();
  569. },
  570. unload : function() {
  571. $.jgrid.gridUnload(STINFO06010_DETAIL_GRID_ID);
  572. }
  573. },
  574. popup: function() {
  575. var popFn = function(rowDataPop) {
  576. console.log(rowDataPop);
  577. if(rowDataPop && rowDataPop.length > 0) {
  578. $('#ITP_FORM_STINFO06010_DETAIL_BRAND_ID').val(rowDataPop[0].brandId);
  579. $('#ITP_FORM_STINFO06010_DETAIL_STORE_ID').val(rowDataPop[0].storeId);
  580. $('#ITP_FORM_STINFO06010_DETAIL_STORE_NM').val(rowDataPop[0].storeNm);
  581. }
  582. };
  583. fn_call_popup('biz', 'BIZPOP_BRAND_STORE', '#ITP_ASIDE', popFn, null, 'S');
  584. },
  585. rows: [],
  586. changeRows: function(gridRows) {
  587. var modifyRows = [];
  588. var chkColumns = ['unit', 'stddQty', 'curr', 'unitAmt', 'unitTargetCd'];
  589. $.each(this.rows, function(index, item) {
  590. var row = gridRows[index];
  591. if(row.viewCd === 'C') {
  592. modifyRows.push(item);
  593. } else {
  594. if(row.itemId === item.itemId) {
  595. $.each(chkColumns, function(index, column) {
  596. if(row[column].toString() !== item[column].toString()) {
  597. row.viewCd = 'U';
  598. modifyRows.push(row);
  599. return false;
  600. }
  601. });
  602. }
  603. }
  604. });
  605. return modifyRows;
  606. }
  607. };