(function () { "use strict"; angular .module('codeAPLEBOX.client.user.employee.customer.depositmanagement') .controller('depositmanagementController', depositmanagementController); /* @ngInject */ function depositmanagementController($state, appConfig, $log, WEB_API_EMPLOYEE) { var vm = this; // ======================================================================= // 초기데이터 // ======================================================================= iniData(); // ======================================================================= // Angularjs Function // ======================================================================= vm.goDetaildepositmanagement = function(selectedCustomerDepositInfo){ $state.go('employee.detaildepositmanagement',{ selectedCustomerDepositInfo: selectedCustomerDepositInfo }) } vm.resetBoard = function () { // board 초기화 vm.flag = true; vm.curPage = 1; // 현재 페이지 vm.startRange = 1; // 시작 페이지 번호 vm.endRange = 1; // 마지막 페이지 번호 vm.searchInfo = { searchDepositStatus: null, searchCustomerNameOrNumber: null } vm.searchDepositStatus = null; vm.searchCustomerNameOrNumber = null; vm.orderInfo = null; getCustomerDepositList(); } vm.iniBoard = function(){ vm.flag = true; vm.curPage = 1; // 현재 페이지 vm.startRange = 1; // 시작 페이지 번호 vm.endRange = 1; // 마지막 페이지 번호 } vm.searchForBoard = function(){ if(vm.searchCustomerNameOrNumber == null || vm.searchCustomerNameOrNumber == ''){ vm.searchCustomerNameOrNumber = null; } vm.searchInfo = { searchDepositStatus: vm.searchDepositStatus, searchCustomerNameOrNumber: vm.searchCustomerNameOrNumber } vm.iniBoard(); getCustomerDepositList(); } vm.searchForDepositStatus = function(check){ // check 0:계약중 & 대기, 1: 계약X, 취소, 종료 if(check == null){ vm.searchDepositStatus = null; }else{ vm.searchDepositStatus = check; } vm.searchForBoard(); } vm.searchForCustomerNameOrNumber = function(check){ if(check == 0){ vm.searchCustomerNameOrNumber = null; } vm.searchForBoard(); } vm.selectBoardCnt = function(number){ vm.boardCnt = number; vm.iniBoard(); getCustomerDepositList(); } // ======================================================================= // Common API // ======================================================================= function iniData(){ vm.checkSearchResult = true; vm.selectedCustomerInfo = null; // board 초기화 vm.flag = true; vm.curPage = 1; // 현재 페이지 vm.boardCnt = 15; // 한페이지에 보여지는 콘텐츠 개수 vm.arrowPageCnt = 5; vm.maxShownPageCnt = 5; // 보여지는 최대 페이지 개수 vm.startRange = 1; // 시작 페이지 번호 vm.endRange = 1; // 마지막 페이지 번호 vm.searchInfo = { searchDepositStatus: null, searchCustomerNameOrNumber: null } vm.searchDepositStatus = null; vm.searchCustomerNameOrNumber = null; getCustomerDepositList(); } /*start: getCustomerDepositList*/ function getCustomerDepositList() { if(vm.searchInfo.searchDepositStatus == null && vm.searchInfo.searchCustomerNameOrNumber== null ){ vm.checkSearchResult = false; }else{ vm.checkSearchResult = true; } WEB_API_EMPLOYEE.getCustomerDepositList({ curPage: vm.curPage, boardCnt: vm.boardCnt, searchInfo: vm.searchInfo, orderInfo: vm.orderInfo, }).then(function (result) { vm.getCustomerDepositList = result.data.rows; vm.totalBoardLen = result.data.count; vm.pageCnt = Math.ceil(vm.totalBoardLen / vm.boardCnt); if (vm.flag) { if (vm.pageCnt <= vm.maxShownPageCnt) { vm.endRange = vm.pageCnt; } else { vm.endRange = vm.maxShownPageCnt; } } vm.flag = false; }).catch(function (err) { $log.error(err); }); } // ======================================================================= // 페이지 범위 계산 // ======================================================================= vm.pageRange = function (min, max) { var input = []; for (var i = min; i <= max; i += 1) { input.push(i); } return input; }; // ======================================================================= // 버튼클릭 이벤트 // ======================================================================= // clickFirstArrow 클릭 vm.clickFirstArrow = function () { vm.curPage = 1; vm.startRange = 1; if (vm.pageCnt <= vm.maxShownPageCnt) { vm.endRange = vm.pageCnt; } else { vm.endRange = vm.maxShownPageCnt; } getCustomerDepositList(); }; // clickLastArrow 클릭 vm.clickLastArrow = function () { vm.curPage = vm.pageCnt; vm.endRange = vm.pageCnt; if (vm.pageCnt <= vm.maxShownPageCnt) { vm.startRange = 1; } else { var remainderValue = vm.pageCnt % vm.maxShownPageCnt; var value = vm.maxShownPageCnt - remainderValue; if (remainderValue != 0) { vm.startRange = vm.pageCnt - remainderValue + 1; } else { vm.startRange = vm.endRange; } } getCustomerDepositList(); }; // leftArrow 클릭 vm.clickLeftArrow = function () { if (vm.curPage > 1) { vm.curPage -= vm.arrowPageCnt; } if (vm.curPage < vm.startRange) { if ((vm.endRange % vm.maxShownPageCnt) != 0) { vm.endRange += (vm.maxShownPageCnt - (vm.endRange % vm.maxShownPageCnt)); } vm.startRange -= vm.arrowPageCnt; vm.endRange = vm.startRange + (vm.arrowPageCnt - 1); } vm.curPage = vm.endRange; getCustomerDepositList(); }; // rightArrow 클릭 vm.clickRightArrow = function () { if (vm.curPage < vm.pageCnt) { vm.curPage += vm.arrowPageCnt; } if (vm.curPage > vm.endRange) { vm.startRange += vm.arrowPageCnt; vm.endRange += vm.arrowPageCnt; if (vm.endRange >= vm.pageCnt) { vm.endRange = vm.pageCnt; } } vm.curPage = vm.startRange; getCustomerDepositList(); }; // 페이지 직접 클릭 vm.clickPage = function (index) { vm.curPage = index; getCustomerDepositList(); }; /* end: getCustomerDepositList*/ } })();