123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- 'use strict';
- app.controller('workingHistoryFormCtr', ["$scope", "moment", "SweetAlert", "api_user_data", function ($scope, moment, SweetAlert, api_user_data) {
- //上班记录状态
- $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' }
- ];
- // 查询条件
- $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: '<div>' +
- '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
- '</div>'
- },
- {
- name: 'userName',
- displayName: '打卡人姓名',
- width: '15%',
- minWidth: '70',
- enableSorting: false
- },
- {
- name: 'extra2',
- displayName: '状态',
- width: '15%',
- minWidth: '70',
- enableSorting: false,
- cellTemplate: '<div>' +
- '<div class="ui-grid-cell-contents" ng-style="{color:(row.entity.extra2 === \'正常\' && row.entity.opValue) ? \'green\' : \'red\'}">{{row.entity.opValue?row.entity.extra2:\'未打卡\'}}</div>' +
- '</div>'
- },
- {
- name: 'opTime',
- displayName: '打卡时间',
- width: '20%',
- minWidth: '140',
- enableFiltering: false,
- cellTemplate: '<div>' +
- '<div class="ui-grid-cell-contents">{{row.entity.opTime?(row.entity.opTime|date:\'HH:mm\'):\'无\'}}</div>' +
- '</div>'
- },
- {
- name: 'extra1',
- displayName: '打卡地址',
- width: '43%',
- minWidth: '280',
- enableFiltering: false,
- cellTemplate: '<div>' +
- '<div class="ui-grid-cell-contents">{{row.entity.extra1 || \'无\'}}</div>' +
- '</div>'
- }
- ];
- //默认选择上班记录
- $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();
- }]);
|