(function () { "use strict"; angular .module('codeAPLEBOX.client.user.employee.customer.customerlist') .controller('customerlistController', customerlistController); /* @ngInject */ function customerlistController($rootScope, $state, appConfig, $log, Auth,WEB_API_EMPLOYEE) { var vm = this; // ======================================================================= // 초기데이터 // ======================================================================= iniData(); // ======================================================================= // Angularjs Function // ======================================================================= vm.goIncludePage = function(index){ switch (index) { case 1: // 고객목록 vm.checkIncludeCustomerList = true; vm.resetBoard(); break; case 2: // 가입승인 관리 vm.checkIncludeCustomerList = false; vm.resetBoard(); break; default: break; } } /* start dialog */ vm.clickDialogActive = function(check, customerInfo){ vm.selectedCustomerInfo = customerInfo; vm.checkActive = check; if(check){ vm.activeStr = "활성" }else{ vm.activeStr = "비활성" } vm.checkDialogActive = true; } vm.clickSubmitActive = function(){ WEB_API_EMPLOYEE.setCustomerActive({ customerId: vm.selectedCustomerInfo.id, checkEnable: vm.checkActive }).then(function (result) { vm.checkDialogActive = false; vm.checkDialogSubmitActive = true; getCustomerList(); }).catch(function (err) { $log.error(err); }); } vm.clickDialogJoinMemberApprove = function(customerInfo){ vm.selectedCustomerInfo = customerInfo; vm.checkDialogJoinMemberApprove = true; } vm.clickSubmitJoinMemberApprove = function(check){ if(check == 1){ vm.joinStr = "승인" }else if(check == 2){ vm.joinStr = "거부" } WEB_API_EMPLOYEE.setCustomerApprove({ customerId: vm.selectedCustomerInfo.id, permissionStatus: check }).then(function (result) { var checkOfNewCustomer = result.data.check; $rootScope.checkNewCustoemr = checkOfNewCustomer; vm.checkDialogJoinMemberApprove = false; vm.checkDialogSubmitApprove = true; getCustomerList(); }).catch(function (err) { $log.error(err); }); } vm.closeDialog = function(){ vm.activeStr = "활성" vm.checkDialogActive = false; vm.checkDialogSubmitActive = false; vm.checkDialogJoinMemberApprove = false; vm.checkDialogSubmitApprove = false; vm.selectedCustomerInfo = null; } /* end dialog */ vm.resetBoard = function () { vm.checkChangeDate = false; // 날짜변경 // board 초기화 vm.flag = true; vm.curPage = 1; // 현재 페이지 vm.startRange = 1; // 시작 페이지 번호 vm.endRange = 1; // 마지막 페이지 번호 vm.searchInfo = { searchDate: { startDate: null, endDate: null, }, searchAccountStatus: null, searchCustomerJoinStatus: null, searchCustomerNameOrNumber: null } vm.startDate = null; vm.endDate = null; vm.searchAccountStatus = null; vm.searchCustomerJoinStatus= null; vm.searchCustomerNameOrNumber = null; vm.orderInfo = null; getCustomerList(); } 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 = { searchDate: { startDate: vm.startDate, endDate: vm.endDate, }, searchAccountStatus: vm.searchAccountStatus, searchCustomerJoinStatus: vm.searchCustomerJoinStatus, searchCustomerNameOrNumber: vm.searchCustomerNameOrNumber } vm.iniBoard(); getCustomerList(); } vm.checkDuring = function(check){ if(check == 1){ // 오늘 vm.checkChangeDate = false; }else{ vm.checkChangeDate = true; } } vm.searchForDate = function(check){ if(check){ vm.checkChangeDate = false; vm.startDate = null; vm.endDate = null; }else{ vm.startDate = $("#startDate").val(); vm.endDate = $("#endDate").val(); } vm.searchForBoard(); } vm.searchForAccountStatus = function(check){ // check 0:비활성, 1: 활성 if(check == null){ vm.searchAccountStatus = null; }else{ vm.searchAccountStatus = check; } vm.searchForBoard(); } vm.searchForCustomerJoinStatus = function(check){ // check 0:승인대기, 1: 가입승인, 2: 승인거부 if(check == null){ vm.searchCustomerJoinStatus = null; }else{ vm.searchCustomerJoinStatus = check; } vm.searchForBoard(); } vm.searchForCustomerNameOrNumber = function(check){ if(check == 0){ vm.searchCustomerNameOrNumber = null; } vm.searchForBoard(); } vm.selectBoardCnt = function(number){ vm.boardCnt = number; vm.iniBoard(); getCustomerList(); } // ======================================================================= // Common API // ======================================================================= function iniData(){ vm.checkSearchResult = true; vm.selectedCustomerInfo = null; vm.checkChangeDate = false; // 날짜변경 /* start include */ vm.checkIncludeCustomerList = true; /* end include */ /* start dialog */ vm.checkActive = true; vm.activeStr = "활성" vm.checkDialogActive = false; vm.checkDialogSubmitActive = false; vm.checkDialogJoinMemberApprove = false; vm.checkDialogSubmitApprove = false; /* end dialog */ // board 초기화 vm.flag = true; vm.curPage = 1; // 현재 페이지 vm.boardCnt = 15; // 한페이지에 보여지는 콘텐츠 개수 vm.arrowPageCnt = 5; vm.maxShownPageCnt = 5; // 보여지는 최대 페이지 개수 vm.startRange = 1; // 시작 페이지 번호 vm.endRange = 1; // 마지막 페이지 번호 vm.searchInfo = { searchDate: { startDate: null, endDate: null, }, searchAccountStatus: null, searchCustomerJoinStatus: null, searchCustomerNameOrNumber: null } vm.startDate = null; vm.endDate = null; vm.searchAccountStatus = null; vm.searchCustomerJoinStatus= null; vm.searchCustomerNameOrNumber = null; getCustomerList(); } /*start: getCustomerList*/ function getCustomerList() { if( vm.searchInfo.searchDate.startDate == null && vm.searchInfo.searchDate.endDate == null && vm.searchInfo.searchAccountStatus == null && vm.searchInfo.searchCustomerJoinStatus== null && vm.searchInfo.searchCustomerNameOrNumber== null ){ vm.checkSearchResult = false; }else{ vm.checkSearchResult = true; } WEB_API_EMPLOYEE.getCustomerList_customer({ currentPage: vm.checkIncludeCustomerList, curPage: vm.curPage, boardCnt: vm.boardCnt, searchInfo: vm.searchInfo, orderInfo: vm.orderInfo, }).then(function (result) { vm.getCustomerList = 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; } getCustomerList(); }; // 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; } } getCustomerList(); }; // 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; getCustomerList(); }; // 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; getCustomerList(); }; // 페이지 직접 클릭 vm.clickPage = function (index) { vm.curPage = index; getCustomerList(); }; /* end: getCustomerList*/ } })();