'use strict'; app.controller('workingHistoryFormCtr', ["$scope", "moment", "SweetAlert", "$state", "api_user_data", function ($scope, moment, SweetAlert, $state, api_user_data) { console.log($state.params) //上班记录状态 $scope.statesOn = [ { name: '全部', value: '0' }, { name: '实到', value: '1' }, { name: '迟到', value: '2' }, { name: '未打卡', value: '4' } ]; // 下班记录状态 $scope.statesOff = [ { name: '全部', value: '0' }, { name: '早退', value: '3' }, { name: '未打卡', value: '4' } ]; // 查询条件 if ($state.params.state) { var stateItem = $scope.statesOn.find(v => v.value == $state.params.state); if (stateItem) { $scope.searchkeys = { state: stateItem, date: moment().format('YYYY-MM-DD') } } else { $scope.searchkeys = { state: $scope.statesOn[0], date: moment().format('YYYY-MM-DD') } } } else { $scope.searchkeys = { state: $scope.statesOn[0], date: moment().format('YYYY-MM-DD') } } // 查询的重置条件 $scope.resetSearchkeys = { state: $scope.statesOn[0], date: moment().format('YYYY-MM-DD') } // 最大日期 $scope.maxDate = moment(); //列表数据 $scope.myData = []; $scope.itemsSaveNoOn = []; $scope.itemsSaveNoOff = []; //表格相关 $scope.gridOptions = {}; $scope.gridOptions.data = 'myData'; $scope.gridOptions.enableColumnResizing = true; $scope.gridOptions.enableFiltering = false; $scope.gridOptions.enableGridMenu = true; $scope.gridOptions.enableSelectAll = true; $scope.gridOptions.enableRowSelection = true; $scope.gridOptions.showGridFooter = true; $scope.gridOptions.showColumnFooter = false; $scope.gridOptions.fastWatch = true; $scope.gridOptions.enableSorting = true; $scope.gridOptions.useExternalSorting = true; $scope.gridOptions.useExternalFiltering = false; $scope.gridOptions.useExternalPagination = true; $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100]; $scope.gridOptions.paginationPageSize = 10; $scope.gridOptions.multiSelect = true; $scope.gridOptions.columnDefs = [ { name: 'item', displayName: '序号', width: '7%', minWidth: '45', cellTemplate: '
' + '
{{row.entity.item}}
' + '
' }, { name: 'userName', displayName: '打卡人姓名', width: '15%', minWidth: '70', enableSorting: false }, { name: 'company', displayName: '三方公司', width: '15%', minWidth: '120', enableFiltering: false }, { name: 'extra2', displayName: '状态', width: '10%', minWidth: '70', enableSorting: false, cellTemplate: '
' + '
{{row.entity.opValue?row.entity.extra2:\'未打卡\'}}
' + '
' }, { name: 'opTime', displayName: '打卡时间', width: '20%', minWidth: '140', enableFiltering: false, cellTemplate: '
' + '
{{row.entity.opTime?(row.entity.opTime|date:\'HH:mm\'):\'无\'}}
' + '
' }, { name: 'extra1', displayName: '打卡地址', width: '33%', minWidth: '280', enableFiltering: false, cellTemplate: '
' + '
{{row.entity.extra1 || \'无\'}}
' + '
' } ]; //默认选择上班记录 if ($state.params.tab) { $scope.searchstate = $state.params.tab; } else { $scope.searchstate = 'on'; } $scope.states = $scope.statesOn; // 切换tab $scope.onChange = function (searchType) { $scope.searchstate = searchType; switch (searchType) { case 'on': $scope.states = $scope.statesOn; $scope.searchkeys.state = $scope.statesOn[0]; break; case 'off': $scope.states = $scope.statesOff; $scope.searchkeys.state = $scope.statesOff[0]; break; } $scope.refreshData(); } // 点击日期框 $scope.startOpen = function ($event) { $event.preventDefault(); $event.stopPropagation(); $scope.startOpened = !$scope.startOpened; }; // 选择日期 $scope.changeDate = function () { $scope.searchkeys.date = moment($scope.searchkeys.date).format('YYYY-MM-DD'); } // 重置 $scope.clear = function () { $scope.searchkeys = angular.copy($scope.resetSearchkeys); $scope.refreshData(); } //处理过滤数据 $scope.stateChange = function (data) { var arr = []; //过滤上班记录或下班记录 if ($scope.searchstate === "on") { //上班记录 arr = data.filter(v => v.opValue === "1"); } else if ($scope.searchstate === "off") { //下班记录 arr = data.filter(v => v.opValue === "0"); } // 过滤状态 if ($scope.searchkeys.state.value === "1") { //实到 let arr1 = arr.filter(v => v.extra2 == "迟到"); let arr2 = arr.filter(v => v.extra2 == "正常"); $scope.myData = [...arr1, ...arr2]; } else if ($scope.searchkeys.state.value === "2") { //迟到 $scope.myData = arr.filter(v => v.extra2 == "迟到"); } else if ($scope.searchkeys.state.value === "3") { //早退 $scope.myData = arr.filter(v => v.extra2 == "早退"); } else if ($scope.searchkeys.state.value === "4") { //未打卡 if ($scope.searchstate === 'on') { // 上班 $scope.myData = angular.copy($scope.itemsSaveNoOn); } else if ($scope.searchstate === 'off') { // 下班 $scope.myData = angular.copy($scope.itemsSaveNoOff); } } else if ($scope.searchkeys.state.value === "0") { //全部 if ($scope.searchstate === 'on') { // 上班 $scope.myData = angular.copy(arr.concat($scope.itemsSaveNoOn)); } else if ($scope.searchstate === 'off') { // 下班 $scope.myData = angular.copy(arr.concat($scope.itemsSaveNoOff)); } } //添加序号 $scope.myData.forEach((v, i) => { v.item = i + 1; }) } //获取列表数据 $scope.refreshData = function () { $scope.myData = []; $scope.itemsSaveNoOn = []; $scope.itemsSaveNoOff = []; api_user_data.getOnlineInfo($scope.searchkeys.date).then(function (result) { if (result.data) { if (result.data.length) { $scope.itemsSaveNoOn = result.unOnlineList || []; $scope.itemsSaveNoOff = result.unOfflineList || []; // 处理过滤数据 $scope.stateChange(result.data); } } else { SweetAlert.swal({ title: "系统错误", text: "请稍后再试!", type: "error" }); } }, function () { SweetAlert.swal({ title: "系统错误", text: "请稍后再试!", type: "error" }); }); }; //进入页面初次渲染页面 $scope.refreshData(); }]);