main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. require(['config'], function() {
  2. require([
  3. 'jquery'
  4. ], function($) {
  5. setTimeout(function() {
  6. // mobMainObj.init();
  7. }, 100);
  8. });
  9. });
  10. let MOBILE_APP_VERSION = '';
  11. let NTICE_DETAIL_GRID_LIST = '/api/ntice/main-detail-grid-list';
  12. let MAIN_CHART_COUNT = '/api/main/chart/count';
  13. let MAIN_CHART_PCH_REQ_CHART = '/api/main/chart/pch-req-chart';
  14. let MAIN_CHART_PCH_ODR_CHART = '/api/main/chart/pch-odr-chart';
  15. let MAIN_CHART_PR_RANK_CHART = '/api/main/chart/pr-rank-chart';
  16. let MAIN_CHART_STL_CHART = '/api/main/chart/stl-chart';
  17. let MAIN_CHART_SFT_STCK_CHART = '/api/main/chart/sft-stck-chart';
  18. let MAIN_CHART_DELI_CHART = '/api/main/chart/deli-chart';
  19. var chartCnt=0;
  20. var chartWidth=window.offsetWidth-16;
  21. function clickNotify(nticeNo) {
  22. mobPopObj.popNotice.open(nticeNo);
  23. }
  24. var mobMainObj = {
  25. init: function () {
  26. this.ui();
  27. this.notice.init();
  28. this.count.init();
  29. this.chart.init();
  30. },
  31. ui: function() {
  32. var authTpCd = fn_make_user_info.get('authTpCd');
  33. if(authTpCd === '40' ) {
  34. $('#ITP_MAIN_HEADER_BRAND').show();
  35. } else if(authTpCd === '50') {
  36. $('#ITP_MAIN_HEADER_STORE').show();
  37. } else if(authTpCd === '60') {
  38. $('#ITP_MAIN_HEADER_SPPLY').show();
  39. }
  40. },
  41. notice: {
  42. init: function () {
  43. this.load();
  44. },
  45. load: function () {
  46. var searhFn = function(result) {
  47. if(Array.isArray(result.gridRows) && result.gridRows.length ) {
  48. var s='', idx=1;
  49. for(var c of result.gridRows ) {
  50. let title=c.nticeTitl;
  51. if(title.length>62) {
  52. title=title.substr(0,62)+'...';
  53. }
  54. s+=`<li>
  55. <div class="itp_note_info">
  56. <label>공지제목</label>
  57. <span>:</span>
  58. <div class="under fnNoteTitle"><a href="javascript:clickNotify('${c.nticeNo}')">${title}</a></div>
  59. </div>
  60. <div class="itp_note_info">
  61. <label>공지일</label>
  62. <span>:</span>
  63. <div class="fnNoteDt">${c.addDt}</div>
  64. </div>
  65. </li>`;
  66. }
  67. $('#ITP_NOTE_ROW').html(s);
  68. } else {
  69. $('#ITP_NOTE_ROW').html('<div class="itp_note_bar" style="display: block;"> <h1>등록된 게시물이 없습니다.</h1> </div>')
  70. }
  71. };
  72. fn_ajax_call(NTICE_DETAIL_GRID_LIST, "{}", searhFn, 'POST');
  73. }
  74. },
  75. count: {
  76. init: function () {
  77. this.load();
  78. },
  79. load: function () {
  80. var brandId = fn_make_user_info.get('brandId');
  81. var storeId = fn_make_user_info.get('storeId');
  82. var spplyId = fn_make_user_info.get('spplyId');
  83. if(brandId == '' && storeId == '' && spplyId == '') {
  84. return;
  85. }
  86. const key = { brandId:brandId, storeId:storeId, spplyId:spplyId };
  87. var param = $.param(key);
  88. fn_ajax_call(MAIN_CHART_COUNT, param, function(result) {
  89. console.log(result);
  90. $('#ITP_MAIN_CONTAINER .fnPr20Count').text( CommonObj.currency.add( result.pr20Count, '건' ));
  91. $('#ITP_MAIN_CONTAINER .fnDp02Amt').text( CommonObj.currency.add( result.dp02Amt ));
  92. $('#ITP_MAIN_CONTAINER .fnUnpaidAmt').text( CommonObj.currency.add( result.unpaidAmt ));
  93. $('#ITP_MAIN_CONTAINER .fnPo30Count').text( CommonObj.currency.add( result.po30Count, '건' ));
  94. $('#ITP_MAIN_CONTAINER .fnPoEndCount').text( CommonObj.currency.add( result.poEndCount, '건' ));
  95. $('#ITP_MAIN_CONTAINER .fnPoPsblAmt').text( CommonObj.currency.add( result.poPsblAmt ));
  96. $('#ITP_MAIN_CONTAINER .fnOrdersCount').text( CommonObj.currency.add( result.ordersCount, '건' ) );
  97. $('#ITP_MAIN_CONTAINER .fnOrdersAmt').text( CommonObj.currency.add( result.ordersAmt ));
  98. $('#ITP_MAIN_CONTAINER .fnSttlReqAmt').text( CommonObj.currency.add( result.sttlReqAmt ));
  99. }, 'GET');
  100. }
  101. },
  102. chart: {
  103. init: function () {
  104. //그래프
  105. google.charts.load('current', {'packages':['corechart']});
  106. google.charts.load('current', {'packages':['bar']});
  107. this.view();
  108. },
  109. view:function() {
  110. $('div[id^="ITP_MAIN_DRAW"]').hide();
  111. var authTpCd = fn_make_user_info.get('authTpCd');
  112. if(authTpCd === '40' || authTpCd === '10') {
  113. this.brand.init();
  114. } else if(authTpCd === '50') {
  115. this.store.init();
  116. } else if(authTpCd === '60') {
  117. this.spply.init();
  118. }
  119. },
  120. brand: {
  121. init: function() {
  122. $('#ITP_MAIN_DRAW_CHART_REQ').show();
  123. google.charts.setOnLoadCallback(this.drawChartReq); // 구매요청
  124. $('#ITP_MAIN_DRAW_CHART_PODR').show();
  125. google.charts.setOnLoadCallback(this.drawChartPodr); // 구매발주
  126. $('#ITP_MAIN_DRAW_CHART_REQ_UP').show();
  127. google.charts.setOnLoadCallback(this.drawChartReqUp); // 매출순위
  128. if(fn_make_user_info.get('brandId')) {
  129. $('#ITP_MAIN_DRAW_CHART_CORE').show();
  130. google.charts.setOnLoadCallback(this.drawChartcore); // 정산
  131. chartCnt=4;
  132. } else {
  133. chartCnt=3;
  134. }
  135. const me=this;
  136. $('#ITP_FORM_MAIN_SEARCH_PR_TYPE').on('change', function() {
  137. me.drawChartReq();
  138. });
  139. $('#ITP_FORM_MAIN_SEARCH_PO_TYPE').on('change', function() {
  140. me.drawChartPodr();
  141. });
  142. $('#ITP_FORM_MAIN_SEARCH_ITEM_CNT_TYPE').on('change', function() {
  143. me.drawChartReqUp();
  144. });
  145. $('#ITP_FORM_MAIN_SEARCH_DELI_TYPE').on('change', function() {
  146. // this.drawChartDeli();
  147. });
  148. $('#ITP_FORM_MAIN_SEARCH_RELEASE_TYPE').on('change', function() {
  149. // this.drawChartRelease();
  150. });
  151. $('#ITP_FORM_MAIN_SEARCH_ORDERS_TYPE').on('change', function() {
  152. // this.drawChartOrders();
  153. });
  154. $('#ITP_MAIN_DRAW_LINE').show();
  155. $('#ITP_MAIN_DRAW_LINE .itp_main_draw_line').show();
  156. google.charts.setOnLoadCallback(this.drawLine); // 안전재고
  157. },
  158. drawChartReq: function() {
  159. const key = { brandId:fn_make_user_info.get('brandId'), storeId:fn_make_user_info.get('storeId'), prType: $('#ITP_FORM_MAIN_SEARCH_PR_TYPE').val() };
  160. var param = $.param(key);
  161. fn_ajax_call(MAIN_CHART_PCH_REQ_CHART, param, function(result) {
  162. var data = google.visualization.arrayToDataTable( eval(result.chartData) );
  163. var options = {
  164. legend: { position: 'left' },
  165. bar: { groupWidth: "50%" },
  166. width: chartWidth,
  167. };
  168. var chart = new google.charts.Bar(document.getElementById('ITP_PCH_REQ_GRAPH'));
  169. // chart.draw(data, options);
  170. console.log("xx draw char req xx", param, data, chart)
  171. chart.draw(data, google.charts.Bar.convertOptions(options));
  172. }, 'GET');
  173. },
  174. drawChartPodr: function() {
  175. const key = { brandId:fn_make_user_info.get('brandId'), storeId:fn_make_user_info.get('storeId'), poType: $('#ITP_FORM_MAIN_SEARCH_PO_TYPE').val() };
  176. var param = $.param(key);
  177. fn_ajax_call(MAIN_CHART_PCH_ODR_CHART, param, function(result) {
  178. var data = google.visualization.arrayToDataTable( eval(result.chartData) );
  179. var options = {
  180. legend: { position: 'left' },
  181. bar: { groupWidth: "50%" },
  182. width: chartWidth,
  183. };
  184. var chart = new google.charts.Bar(document.getElementById('ITP_PCH_PODR_GRAPH'));
  185. // chart.draw(data, options);
  186. chart.draw(data, google.charts.Bar.convertOptions(options));
  187. }, 'GET');
  188. },
  189. drawChartReqUp: function() {
  190. const key = { brandId:fn_make_user_info.get('brandId'), storeId:fn_make_user_info.get('storeId'), spplyId:fn_make_user_info.get('spplyId'), prType: $('#ITP_FORM_MAIN_SEARCH_ITEM_CNT_TYPE').val() };
  191. var param = $.param(key);
  192. fn_ajax_call(MAIN_CHART_PR_RANK_CHART, param, function(result) {
  193. var data = google.visualization.arrayToDataTable( eval(result.chartData) );
  194. var options = {
  195. title: '구매요청 상위 품목',
  196. legend: { position: 'left' },
  197. bars: 'horizontal',
  198. width: chartWidth,
  199. };
  200. console.log("xxxxxxxxxxx drawChartReqUp xxxxxxxxxxx")
  201. var chart = new google.charts.Bar(document.getElementById('ITP_PCH_REQ_UP_ITEM_GRAPH'));
  202. chart.draw(data, options);
  203. }, 'GET');
  204. },
  205. drawChartcore: function() {
  206. const key = { brandId:fn_make_user_info.get('brandId'), storeId:fn_make_user_info.get('storeId'), spplyId:fn_make_user_info.get('spplyId') };
  207. var param = $.param(key);
  208. fn_ajax_call(MAIN_CHART_STL_CHART, param, function(result) {
  209. // var data = google.visualization.arrayToDataTable([ [' ', ' '], ['요청', 25], ['확인', 65], ['반려', 10] ]);
  210. var data = google.visualization.arrayToDataTable( eval(result.chartData) );
  211. var options = {
  212. // title: '정산',
  213. legend: { position: 'left' },
  214. width: chartWidth,
  215. };
  216. var chart = new google.visualization.PieChart(document.getElementById('ITP_STTL_GRAPH'));
  217. console.log("xxxxxxxxxxx drawChartcore xxxxxxxxxxx", data, options )
  218. chart.draw(data, options);
  219. }, 'GET');
  220. },
  221. drawLine: function() {
  222. const key = { brandId:fn_make_user_info.get('brandId'), storeId:fn_make_user_info.get('storeId') };
  223. var param = $.param(key);
  224. fn_ajax_call(MAIN_CHART_SFT_STCK_CHART, param, function(result) {
  225. var data = google.visualization.arrayToDataTable( eval(result.chartData) );
  226. var options = {
  227. title: '',
  228. width: chartWidth + 100,
  229. legend: { position: 'top' }
  230. };
  231. var chart = new google.visualization.LineChart(document.getElementById('ITP_SAFE_STCK_GRAPH'));
  232. chart.draw(data, options);
  233. }, 'GET');
  234. }
  235. },
  236. store: {
  237. init: function() {
  238. }
  239. },
  240. spply: {
  241. init: function() {
  242. }
  243. }
  244. }
  245. };
  246. function appCallFnVersion(version) {
  247. MOBILE_APP_VERSION = version;
  248. console.log(MOBILE_APP_VERSION);
  249. }
  250. let mobPopObj = {
  251. popNotice: {
  252. popId: 'ITP_POP_NOTICE',
  253. open: function (nticeNo) {
  254. mobPopObj.show(this.popId);
  255. this.search(nticeNo);
  256. },
  257. close: function() {
  258. mobPopObj.hide(this.popId);
  259. },
  260. search: function (nticeNo) {
  261. const me=this;
  262. fn_ajax_call('/api/ntice/info-ntice', {nticeNo}, function(result) {
  263. // 브랜드그룹 셋팅
  264. $('#ITP_POP_NOTICE_AREA .fnNoteNm').html(result.nticeTitl);
  265. $('#ITP_POP_NOTICE_AREA .fnNote').html(result.nticeDesc);
  266. $('#ITP_POP_NOTICE_AREA .fnNoteFromTo').html(result.notiStDay+' ~ '+result.notiEdDay);
  267. me.makeFileDownloadTable($('#ITP_POP_NOTICE_AREA .fnNoteFile'),result.fileNo);
  268. /*
  269. $('#ITP_FORM_NOTICE_INFO_POPUP_AFFL_SHOP_NM').html(result.afflShopNm);
  270. $('#ITP_FORM_NOTICE_INFO_POPUP_BRAND_NM').html(result.brandNm);
  271. */
  272. }, 'GET');
  273. },
  274. makeFileDownloadTable: function (el, fileNo) {
  275. var searhFn = function(result) {
  276. var html = '';
  277. html += '<table class="table fileupload-download">';
  278. html += '<tbody>';
  279. $.each(result, function (key, value) {
  280. html += '<tr class="fileupload-downloadrow no-thumb row">';
  281. html += '<td class="col-xs-9 itp_file_info" data-file-no="' + value.fileNo + '" data-file-seq="' + value.fileSeq + '">';
  282. html += '<a href="' + DOMAIN + '/api/file/download/' + value.fileNo + '/' + value.fileSeq + '">';
  283. html += value.fileOrgNm + '</a></td>';
  284. html += '<td class="col-xs-3">' + value.fileSize + '</td>';
  285. html += '</tr>';
  286. });
  287. html += '</tbody>';
  288. html += '</table>';
  289. el.html(html);
  290. }
  291. fn_ajax_call('/api/file/list', {fileNo}, searhFn, 'GET');
  292. }
  293. },
  294. show: function(popId) {
  295. console.log("popup show id=="+popId)
  296. $('#' + popId+' .btn-pop-close').on('click', function() {
  297. mobPopObj.hide(popId);
  298. });
  299. $('#' + popId).show();
  300. },
  301. hide: function(popId) {
  302. $('#' + popId).closest('.mobile-pop-close').hide();
  303. }
  304. };
  305. function appCallFnConnKey(connKey) {
  306. if(connKey) {
  307. sessionStorage.setItem('itp_login_info', JSON.stringify({
  308. timestamp: new Date(),
  309. connKey: connKey
  310. }));
  311. itp_fn_session_data(connKey);
  312. } else {
  313. location.replace('app:logout');
  314. }
  315. }