workingHistoryFormCtr.js 7.0 KB

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