(function () { "use strict"; angular .module('codeAPLEBOX.client.user.customer.transfer.customersearch') .controller('customersearchController', customersearchController); /* @ngInject */ function customersearchController($state, $cookies, $stateParams, appConfig, $log, WEB_API_CUSTOMER) { var vm = this; // ======================================================================= // 초기데이터 // ======================================================================= vm.customerInfo = $cookies.getObject("customerInfo"); iniData(); // ======================================================================= // Angularjs Function // ======================================================================= vm.goBack = function(){ // 다른페이지 $state.go('customer.transfer'); } vm.goRequestTransfer = function(customer){ /*if($stateParams.transferCustomer != null){ $cookies.putObject('transferCustomer', $stateParams.transferCustomer); }*/ $state.go('customer.requesttransfer',{ transferCustomer: customer }) } /* start customerList board search */ vm.searchForBoard_customerList = function(){ if(vm.searchCustomerUniqueNumber_customerList == null || vm.searchCustomerUniqueNumber_customerList == ''){ vm.searchCustomerUniqueNumber_customerList = null; } vm.searchInfo_customerList = { searchCustomerUniqueNumber: vm.searchCustomerUniqueNumber_customerList } vm.iniBoard_customerList(); getCustomerList(); } vm.searchForCustomerUniqueNumber_customerList = function(check){ if(check == 0){ vm.searchCustomerUniqueNumber_customerList = null; } vm.searchForBoard_customerList(); } /* end customerList board search */ /* start customerList board function */ vm.resetBoard_customerList = function () { // board 초기화 vm.flag_customerList = true; vm.curPage_customerList = 1; // 현재 페이지 vm.startRange_customerList = 1; // 시작 페이지 번호 vm.endRange_customerList = 1; // 마지막 페이지 번호 vm.searchInfo_customerList = { searchCustomerUniqueNumber: vm.searchCustomerUniqueNumber_customerList } vm.startDate_customerList = null; vm.endDate_customerList = null; vm.searchAccountStatus_customerList = null; vm.searchCustomerUniqueNumber_customerList = null; vm.orderInfo_customerList = null; getCustomerList(); } vm.iniBoard_customerList = function(){ vm.flag_customerList = true; vm.curPage_customerList = 1; // 현재 페이지 vm.startRange_customerList = 1; // 시작 페이지 번호 vm.endRange_customerList = 1; // 마지막 페이지 번호 } /* end customerList board function */ // ======================================================================= // Common API // ======================================================================= function iniData(){ /* start customerList board 초기화*/ vm.flag_customerList = true; vm.curPage_customerList = 1; // 현재 페이지 vm.boardCnt_customerList = 10; // 한페이지에 보여지는 콘텐츠 개수 vm.arrowPageCnt_customerList = 5; vm.maxShownPageCnt_customerList = 5; // 보여지는 최대 페이지 개수 vm.startRange_customerList = 1; // 시작 페이지 번호 vm.endRange_customerList = 1; // 마지막 페이지 번호 vm.searchInfo_customerList = { searchCustomerUniqueNumber: null } vm.startDate_customerList = null; vm.endDate_customerList = null; vm.searchCustomerUniqueNumber_customerList = null; /* end customerList board 초기화*/ getCustomerList(); } /* start: customerList board */ function getCustomerList() { WEB_API_CUSTOMER.getCustomerList({ customerId: vm.customerInfo.id, curPage: vm.curPage_customerList, boardCnt: vm.boardCnt_customerList, searchInfo: vm.searchInfo_customerList, orderInfo: vm.orderInfo_customerList, }).then(function (result) { vm.getCustomerList = result.data.rows; vm.totalBoardLen_customerList = result.data.count; vm.pageCnt_customerList = Math.ceil(vm.totalBoardLen_customerList / vm.boardCnt_customerList); if (vm.flag_customerList) { if (vm.pageCnt_customerList <= vm.maxShownPageCnt_customerList) { vm.endRange_customerList = vm.pageCnt_customerList; } else { vm.endRange_customerList = vm.maxShownPageCnt_customerList; } } vm.flag_customerList = false; }).catch(function (err) { $log.error(err); }); } // ======================================================================= // 페이지 범위 계산 // ======================================================================= vm.pageRange_customerList = function (min, max) { var input = []; for (var i = min; i <= max; i += 1) { input.push(i); } return input; }; // ======================================================================= // 버튼클릭 이벤트 // ======================================================================= // clickFirstArrow 클릭 vm.clickFirstArrow_customerList = function () { vm.curPage_customerList = 1; vm.startRange_customerList = 1; if (vm.pageCnt_customerList <= vm.maxShownPageCnt_customerList) { vm.endRange_customerList = vm.pageCnt_customerList; } else { vm.endRange_customerList = vm.maxShownPageCnt_customerList; } getCustomerList(); }; // clickLastArrow 클릭 vm.clickLastArrow_customerList = function () { vm.curPage_customerList = vm.pageCnt_customerList; vm.endRange_customerList = vm.pageCnt_customerList; if (vm.pageCnt_customerList <= vm.maxShownPageCnt_customerList) { vm.startRange_customerList = 1; } else { var remainderValue = vm.pageCnt_customerList % vm.maxShownPageCnt_customerList; var value = vm.maxShownPageCnt_customerList - remainderValue; if (remainderValue != 0) { vm.startRange_customerList = vm.pageCnt_customerList - remainderValue + 1; } else { vm.startRange_customerList = vm.endRange_customerList; } } getCustomerList(); }; // leftArrow 클릭 vm.clickLeftArrow_customerList = function () { if (vm.curPage_customerList > 1) { vm.curPage_customerList -= vm.arrowPageCnt_customerList; } if (vm.curPage_customerList < vm.startRange_customerList) { if ((vm.endRange_customerList % vm.maxShownPageCnt_customerList) != 0) { vm.endRange_customerList += (vm.maxShownPageCnt_customerList - (vm.endRange_customerList % vm.maxShownPageCnt_customerList)); } vm.startRange_customerList -= vm.arrowPageCnt_customerList; vm.endRange_customerList = vm.startRange_customerList + (vm.arrowPageCnt_customerList - 1); } vm.curPage_customerList = vm.endRange_customerList; getCustomerList(); }; // rightArrow 클릭 vm.clickRightArrow_customerList = function () { if (vm.curPage_customerList < vm.pageCnt_customerList) { vm.curPage_customerList += vm.arrowPageCnt_customerList; } if (vm.curPage_customerList > vm.endRange_customerList) { vm.startRange_customerList += vm.arrowPageCnt_customerList; vm.endRange_customerList += vm.arrowPageCnt_customerList; if (vm.endRange_customerList >= vm.pageCnt_customerList) { vm.endRange_customerList = vm.pageCnt_customerList; } } vm.curPage_customerList = vm.startRange_customerList; getCustomerList(); }; // 페이지 직접 클릭 vm.clickPage_customerList = function (index) { vm.curPage_customerList = index; getCustomerList(); }; /* end: customerList board */ } })();