(function () { "use strict"; angular .module('codeAPLEBOX.client.user.employee.customer.monthlystatus') .controller('monthlystatusController', monthlystatusController); /* @ngInject */ function monthlystatusController($state, appConfig, $log, Auth, WEB_API_EMPLOYEE, $cookies, moment) { var vm = this; $(".monthpicker").monthpicker({ monthNames: ['1월(JAN)', '2월(FEB)', '3월(MAR)', '4월(APR)', '5월(MAY)', '6월(JUN)', '7월(JUL)', '8월(AUG)', '9월(SEP)', '10월(OCT)', '11월(NOV)', '12월(DEC)'], monthNamesShort: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'], //showOn: "button", //buttonImage: "../../Images/Goods/calendar.jpg", buttonImageOnly: true, changeYear: false, yearRange: 'c-2:c+2', dateFormat: 'yy년 mm월', onSelect: function(e) { vm.selectMonth = e; vm.searchForBoard(); } }); $(".monthpicker").monthpicker('setDate', new Date()); // ======================================================================= // 초기데이터 // ======================================================================= iniData(); // ======================================================================= // Angularjs Function // ======================================================================= vm.goDatailMonthlyStatus = function(customerInfo){ $state.go("employee.detailmonthlystatus",{ selectedCustomerInfo: customerInfo }) } vm.resetBoard = function () { // board 초기화 $(".monthpicker").monthpicker('setDate', new Date()); vm.flag = true; vm.curPage = 1; // 현재 페이지 vm.startRange = 1; // 시작 페이지 번호 vm.endRange = 1; // 마지막 페이지 번호 var selectMonth = moment(vm.selectMonth, 'yyyy년 MM월').format('YYYY-MM').toString(); vm.searchInfo = { selectMonth: selectMonth, nameOrCustomerNumber: null, } vm.orderInfo = null; getMonthlyList(); } vm.iniBoard = function(){ vm.flag = true; vm.curPage = 1; // 현재 페이지 vm.startRange = 1; // 시작 페이지 번호 vm.endRange = 1; // 마지막 페이지 번호 } vm.searchForBoard = function(){ if(vm.searchNameOrCustomerNumber == null || vm.searchNameOrCustomerNumber == ''){ vm.searchNameOrCustomerNumber = null; } var selectMonth = moment(vm.selectMonth, 'yyyy년 MM월').format('YYYY-MM').toString(); vm.searchInfo = { selectMonth: selectMonth, nameOrCustomerNumber: vm.searchNameOrCustomerNumber } vm.iniBoard(); getMonthlyList(); } vm.calcMonth = function(index){ if(index == 0){ // 이번달 vm.selectMonth = moment(new Date()).format("yyyy년 MM월"); }else if(index == 1){ // 이전달 vm.selectMonth = moment(vm.selectMonth, 'yyyy년 MM월').add(-1,'month').format('yyyy년 MM월').toString(); }else if(index == 2){ // 다음달 vm.selectMonth = moment(vm.selectMonth, 'yyyy년 MM월').add(1,'month').format('yyyy년 MM월').toString(); } vm.searchForBoard(); } vm.searchForNameOrCustomerNumber = function(check){ if(check == 0){ vm.searchNameOrCustomerNumber = null; } vm.searchForBoard(); } vm.selectBoardCnt = function(number){ vm.boardCnt = number; vm.iniBoard(); getMonthlyList(); } // ======================================================================= // Common Function // ======================================================================= function iniData(){ vm.checkSearchResult = true; /* start dialog */ vm.checkActive = true; vm.activeStr = "활성" vm.checkDialogActive = false; // 활성화 선택 vm.checkDialogNewMember = false; // 신규 직원 등록 vm.checkDialogModifyMember = 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.selectMonth = moment(new Date()).format("yyyy년 MM월"); vm.searchNameOrCustomerNumber = null; var selectMonth = moment(vm.selectMonth, 'yyyy년 MM월').format('YYYY-MM').toString(); vm.searchInfo = { selectMonth: selectMonth, nameOrCustomerNumber: null, } vm.orderInfo = null; // function vm.selectedEmployee = null; // 선택된 직원 getMonthlyList(); } /* start: monthlyList*/ function getMonthlyList() { if( vm.searchInfo.nameOrCustomerNumber== null ){ vm.checkSearchResult = false; }else{ vm.checkSearchResult = true; } WEB_API_EMPLOYEE.getMonthlyList({ curPage: vm.curPage, boardCnt: vm.boardCnt, searchInfo: vm.searchInfo, orderInfo: vm.orderInfo }).then(function (result) { vm.monthlyList = 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; } getMonthlyList(); }; // 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; } } getMonthlyList(); }; // 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; getMonthlyList(); }; // 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; getMonthlyList(); }; // 페이지 직접 클릭 vm.clickPage = function (index) { vm.curPage = index; getMonthlyList(); }; /* end: monthlyList*/ } })();