workingHistoryFormCtr.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. 'use strict';
  2. app.controller('workingHistoryFormCtr', ["$scope", "moment", "SweetAlert", "api_user_data", function ($scope, moment, SweetAlert, api_user_data) {
  3. //上班记录状态
  4. $scope.statesOn = [
  5. { name: '全部', value: '0' },
  6. { name: '实到', value: '1' },
  7. { name: '迟到', value: '2' },
  8. { name: '未打卡', value: '4' }
  9. ];
  10. // 下班记录状态
  11. $scope.statesOff = [
  12. { name: '全部', value: '0' },
  13. { name: '早退', value: '3' },
  14. { name: '未打卡', value: '4' }
  15. ];
  16. // 查询条件
  17. $scope.searchkeys = {
  18. state: $scope.statesOn[0],
  19. date: moment().format('YYYY-MM-DD')
  20. }
  21. // 查询的重置条件
  22. $scope.resetSearchkeys = {
  23. state: $scope.statesOn[0],
  24. date: moment().format('YYYY-MM-DD')
  25. }
  26. // 最大日期
  27. $scope.maxDate = moment();
  28. //列表数据
  29. $scope.myData = [];
  30. $scope.itemsSaveNoOn = [];
  31. $scope.itemsSaveNoOff = [];
  32. //表格相关
  33. $scope.gridOptions = {};
  34. $scope.gridOptions.data = 'myData';
  35. $scope.gridOptions.enableColumnResizing = true;
  36. $scope.gridOptions.enableFiltering = false;
  37. $scope.gridOptions.enableGridMenu = true;
  38. $scope.gridOptions.enableSelectAll = true;
  39. $scope.gridOptions.enableRowSelection = true;
  40. $scope.gridOptions.showGridFooter = true;
  41. $scope.gridOptions.showColumnFooter = false;
  42. $scope.gridOptions.fastWatch = true;
  43. $scope.gridOptions.enableSorting = true;
  44. $scope.gridOptions.useExternalSorting = true;
  45. $scope.gridOptions.useExternalFiltering = false;
  46. $scope.gridOptions.useExternalPagination = true;
  47. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  48. $scope.gridOptions.paginationPageSize = 10;
  49. $scope.gridOptions.multiSelect = true;
  50. $scope.gridOptions.columnDefs = [
  51. {
  52. name: 'item',
  53. displayName: '序号',
  54. width: '7%',
  55. minWidth: '45',
  56. cellTemplate: '<div>' +
  57. '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
  58. '</div>'
  59. },
  60. {
  61. name: 'userName',
  62. displayName: '打卡人姓名',
  63. width: '15%',
  64. minWidth: '70',
  65. enableSorting: false
  66. },
  67. {
  68. name: 'extra2',
  69. displayName: '状态',
  70. width: '15%',
  71. minWidth: '70',
  72. enableSorting: false,
  73. cellTemplate: '<div>' +
  74. '<div class="ui-grid-cell-contents" ng-style="{color:(row.entity.extra2 === \'正常\' && row.entity.opValue) ? \'green\' : \'red\'}">{{row.entity.opValue?row.entity.extra2:\'未打卡\'}}</div>' +
  75. '</div>'
  76. },
  77. {
  78. name: 'opTime',
  79. displayName: '打卡时间',
  80. width: '20%',
  81. minWidth: '140',
  82. enableFiltering: false,
  83. cellTemplate: '<div>' +
  84. '<div class="ui-grid-cell-contents">{{row.entity.opTime?(row.entity.opTime|date:\'HH:mm\'):\'无\'}}</div>' +
  85. '</div>'
  86. },
  87. {
  88. name: 'extra1',
  89. displayName: '打卡地址',
  90. width: '43%',
  91. minWidth: '280',
  92. enableFiltering: false,
  93. cellTemplate: '<div>' +
  94. '<div class="ui-grid-cell-contents">{{row.entity.extra1 || \'无\'}}</div>' +
  95. '</div>'
  96. }
  97. ];
  98. //默认选择上班记录
  99. $scope.searchstate = 'on';
  100. $scope.states = $scope.statesOn;
  101. // 切换tab
  102. $scope.onChange = function (searchType) {
  103. $scope.searchstate = searchType;
  104. switch (searchType) {
  105. case 'on':
  106. $scope.states = $scope.statesOn;
  107. $scope.searchkeys.state = $scope.statesOn[0];
  108. break;
  109. case 'off':
  110. $scope.states = $scope.statesOff;
  111. $scope.searchkeys.state = $scope.statesOff[0];
  112. break;
  113. }
  114. $scope.refreshData();
  115. }
  116. // 点击日期框
  117. $scope.startOpen = function ($event) {
  118. $event.preventDefault();
  119. $event.stopPropagation();
  120. $scope.startOpened = !$scope.startOpened;
  121. };
  122. // 选择日期
  123. $scope.changeDate = function(){
  124. $scope.searchkeys.date = moment($scope.searchkeys.date).format('YYYY-MM-DD');
  125. }
  126. // 重置
  127. $scope.clear = function () {
  128. $scope.searchkeys = angular.copy($scope.resetSearchkeys);
  129. $scope.refreshData();
  130. }
  131. //处理过滤数据
  132. $scope.stateChange = function(data){
  133. var arr = [];
  134. //过滤上班记录或下班记录
  135. if ($scope.searchstate === "on") {
  136. //上班记录
  137. arr = data.filter(v => v.opValue === "1");
  138. } else if ($scope.searchstate === "off") {
  139. //下班记录
  140. arr = data.filter(v => v.opValue === "0");
  141. }
  142. // 过滤状态
  143. if ($scope.searchkeys.state.value === "1") {
  144. //实到
  145. let arr1 = arr.filter(v => v.extra2 == "迟到");
  146. let arr2 = arr.filter(v => v.extra2 == "正常");
  147. $scope.myData = [...arr1,...arr2];
  148. } else if ($scope.searchkeys.state.value === "2") {
  149. //迟到
  150. $scope.myData = arr.filter(v => v.extra2 == "迟到");
  151. } else if ($scope.searchkeys.state.value === "3") {
  152. //早退
  153. $scope.myData = arr.filter(v => v.extra2 == "早退");
  154. } else if ($scope.searchkeys.state.value === "4") {
  155. //未打卡
  156. if($scope.searchstate === 'on'){
  157. // 上班
  158. $scope.myData = angular.copy($scope.itemsSaveNoOn);
  159. }else if($scope.searchstate === 'off'){
  160. // 下班
  161. $scope.myData = angular.copy($scope.itemsSaveNoOff);
  162. }
  163. } else if ($scope.searchkeys.state.value === "0") {
  164. //全部
  165. if($scope.searchstate === 'on'){
  166. // 上班
  167. $scope.myData = angular.copy(arr.concat($scope.itemsSaveNoOn));
  168. }else if($scope.searchstate === 'off'){
  169. // 下班
  170. $scope.myData = angular.copy(arr.concat($scope.itemsSaveNoOff));
  171. }
  172. }
  173. //添加序号
  174. $scope.myData.forEach((v, i) => {
  175. v.item = i + 1;
  176. })
  177. }
  178. //获取列表数据
  179. $scope.refreshData = function () {
  180. $scope.myData = [];
  181. $scope.itemsSaveNoOn = [];
  182. $scope.itemsSaveNoOff = [];
  183. api_user_data.getOnlineInfo($scope.searchkeys.date).then(function (result) {
  184. if (result.data) {
  185. if (result.data.length) {
  186. $scope.itemsSaveNoOn = result.unOnlineList || [];
  187. $scope.itemsSaveNoOff = result.unOfflineList || [];
  188. // 处理过滤数据
  189. $scope.stateChange(result.data);
  190. }
  191. } else {
  192. SweetAlert.swal({
  193. title: "系统错误",
  194. text: "请稍后再试!",
  195. type: "error"
  196. });
  197. }
  198. }, function () {
  199. SweetAlert.swal({
  200. title: "系统错误",
  201. text: "请稍后再试!",
  202. type: "error"
  203. });
  204. });
  205. };
  206. //进入页面初次渲染页面
  207. $scope.refreshData();
  208. }]);