controllers.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. starter.controller('workatd-index', function ($rootScope, $interval, $scope, $state, $ionicModal, $ionicPlatform, $cordovaPreferences, $ionicPopup, $ionicActionSheet, global, showPopup, workatd, workatdcheck, formatFilter) {
  2. $scope.todayweek = workatd.todayweek;
  3. $scope.loading = false;
  4. $scope.data = {
  5. id: null, //考勤设置id
  6. checktype: null, //打卡类型
  7. content: null, //理由
  8. isoutside: false //是否在签到范围外
  9. };
  10. $scope.autocheck = {
  11. isautocheck: true,
  12. checkin: {isadvance: false, inadvance: 15},
  13. checkout: {isdelay: false, indelay: 5},
  14. time: [5, 15, 30, 60]
  15. };
  16. $scope.goBack = function () {
  17. global.goBack();
  18. };
  19. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  20. global.fetch_user().then(function (data) {
  21. $scope.roleid = global.user.roleid;
  22. if ($scope.usersetting == undefined) $scope.loading = true;
  23. getworkatddata();
  24. });
  25. });
  26. stopTime = $interval(function () {
  27. if ($scope.time) {
  28. $scope.time.setSeconds($scope.time.getSeconds() + 1);
  29. usersetting = $scope.usersetting;
  30. if (usersetting.isAtdDay)
  31. for (i = 0; i < usersetting.items.length; i++) {
  32. state = 3 //未开始
  33. item = usersetting.items[i];
  34. if (item.checktime) {
  35. item.state = 0; //已签到
  36. continue;
  37. }
  38. if (item.checktype == 2 || item.checktype == 4)
  39. if (usersetting.items[i - 1].state == 0 && item.state != 0) { //已签到,并且还未签退,就显示可签退
  40. item.state = 1;
  41. if ($scope.time > new Date(item.itemtime)) //当前时间大于下班时间时才将标志置为false
  42. item.isoutoftime = false;
  43. continue
  44. }
  45. begintime = new Date(item.itemtime);
  46. if (item.checktype == 1 || item.checktype == 3) { // 上、下午签到可提前2小时打卡
  47. begintime = begintime.setHours(begintime.getHours() - 2);
  48. } else if (item.checktype == 2 && usersetting.items[i - 1].state == 0) { // 上午签退可提前1小时打卡(前提:上午已签到)
  49. begintime = begintime.setHours(begintime.getHours() - 2);
  50. }
  51. if ($scope.time > begintime) {
  52. state = 1; //可打卡
  53. item.isoutoftime = (item.checktype == 1 || item.checktype == 3) ? $scope.time > item.itemtime : $scope.time < item.itemtime; //1,3签到:迟到;2,4签退:早退
  54. if (i < usersetting.items.length - 1) {
  55. if ($scope.time > usersetting.items[i + 1].itemtime)
  56. state = 2; //已过期
  57. }
  58. }
  59. item.state = state;
  60. }
  61. if ($scope.usersetting == undefined) {
  62. $scope.usersetting = usersetting;
  63. }
  64. }
  65. }, 1000);
  66. var flag = false;
  67. $scope.checkin = function (checktype, workatdsetid, isoutoftime) {
  68. if (flag) return;
  69. flag = true;
  70. if (window.cordovaLinker != undefined) {
  71. window.cordovaLinker.getdistance(null, function (s) {
  72. flag = false;
  73. console.log(s);
  74. $scope.data.id = workatdsetid;
  75. $scope.data.checktype = checktype;
  76. $scope.data.isoutoftime = isoutoftime;
  77. if (s.Distance > $scope.usersetting.offset) {
  78. showPopup.PopupWindow(0, '你当前位置不在考勤范围内!', false);
  79. } else if (isoutoftime) {
  80. $scope.data.isoutside = false;
  81. if (checktype == 2 || checktype == 4) {
  82. showPopup.confirm('现在是早退时间,你确定签退吗?', '是', '否').then(function (res) {
  83. if (res) $scope.showModalChkReason();
  84. });
  85. } else {
  86. $scope.showModalChkReason();
  87. }
  88. } else {
  89. checkin();
  90. }
  91. }, function (err) {
  92. flag = false;
  93. console.log(err);
  94. })
  95. }
  96. };
  97. function checkin() {
  98. showPopup.showLoading(1, '提交中');
  99. workatdcheck.checkin($scope.data).then(function (data) {
  100. showPopup.hideLoading();
  101. getworkatddata();
  102. }, function (err) {
  103. showPopup.hideLoading();
  104. JSON.stringify(err);
  105. });
  106. }
  107. $scope.isTxtNull = function (value) {
  108. };
  109. var modalIndexchkreason = $ionicModal.fromTemplateUrl('templates/indexchkreason.html', {
  110. scope: $scope,
  111. animation: 'slide-in-right'
  112. });
  113. $scope.showModalAutoChk = function () {
  114. getIsAutoCheckStatus();
  115. showPopup.modalTemplate('templates/modal-autocheck.html', 'slide-in-right', $scope).then(function (modal) {
  116. $rootScope.commons.modal = modal;
  117. $rootScope.commons.modal.show();
  118. })
  119. };
  120. $scope.closeModalAutoChk = function (rst) {
  121. $rootScope.commons.modal.hide();
  122. };
  123. $scope.showtime = function (type, time) {
  124. var btns = _.map([5, 15, 30, 60], function (item) {
  125. var color = time == item ? 'calm' : '';
  126. return {'text': '<div class="center ' + color + '" >' + item + '</div>'}
  127. });
  128. var hideSheet = $ionicActionSheet.show({
  129. buttons: btns,
  130. titleText: '<div class="center bar-balanced">提醒时间</div>',
  131. buttonClicked: function (index) {
  132. if (type == 1) {
  133. $scope.autocheck.checkin.inadvance = $scope.autocheck.time[index];
  134. // $scope.saveIsAutoCheck('inadvance', $scope.autocheck.time[index]);
  135. } else if (type == 2) {
  136. $scope.autocheck.checkout.indelay = $scope.autocheck.time[index];
  137. // $scope.saveIsAutoCheck('indelay', $scope.autocheck.time[index]);
  138. }
  139. return true;
  140. }
  141. });
  142. };
  143. $scope.saveIsAutoCheck = function (key, value) {
  144. console.log(formatFilter('{"{0}":{1}}', key, value));
  145. if (window.cordovaLinker != undefined) {
  146. window.cordovaLinker.saveIsAutoCheck(JSON.parse(formatFilter('{"{0}":{1}}', key, value)), function (s) {
  147. console.log(s);
  148. }, function (err) {
  149. alert(JSON.stringify(err));
  150. });
  151. }
  152. };
  153. //理由
  154. $scope.showModalChkReason = function (checktype) {
  155. $scope.data.checktype = checktype || $scope.data.checktype;
  156. modalIndexchkreason.then(function (modal) {
  157. $rootScope.commons.modal = modal;
  158. $rootScope.commons.modal.show();
  159. })
  160. };
  161. $scope.closeModalChkReason = function (rst) {
  162. if (rst == 'ok') {
  163. showPopup.showLoading(1, '提交中');
  164. workatdcheck.checkin($scope.data).then(function (data) {
  165. getworkatddata();
  166. $rootScope.commons.modal.hide();
  167. $scope.data.content = null;
  168. showPopup.hideLoading();
  169. });
  170. } else {
  171. $scope.data.content = null;
  172. $rootScope.commons.modal.hide();
  173. }
  174. };
  175. //签到范围外
  176. $scope.showModalChkOutside = function () {
  177. showPopup.modalTemplate('templates/indexchkoutside.html', 'slide-in-right', $scope).then(function (modal) {
  178. $rootScope.commons.modal = modal;
  179. $rootScope.commons.modal.show();
  180. });
  181. };
  182. $scope.closeModalChkOutside = function (rst, type) { //0:外勤 1:出差 2:其他
  183. if (rst == 'ok') {
  184. $scope.outsidetype = type;
  185. $rootScope.commons.modal.hide();
  186. $scope.showModalChkReason();
  187. } else {
  188. $rootScope.commons.modal.hide();
  189. }
  190. };
  191. $scope.doRefresh = function () {
  192. getworkatddata();
  193. };
  194. function getworkatddata() {
  195. workatdcheck.getCheckInfo().then(function (data) {
  196. $scope.withoutornone = false;
  197. var _now = new Date();
  198. $scope.time = new Date(data.time);
  199. $scope.data.id = data.id;
  200. _.each(data.items, function (item) {
  201. item.isoutoftime = true;
  202. item.itemtime = new Date($scope.time.getFullYear() + '/' + parseInt($scope.time.getMonth() + 1) + '/' + $scope.time.getDate() + ' ' + item.time);
  203. if (item.itemtime.getHours() < 2)
  204. item.itemtime = item.itemtime.setDate(item.itemtime.getDate() + 1)
  205. });
  206. $scope.usersetting = data;
  207. getIsAutoCheckStatus();
  208. }, function (data) {
  209. if (data.status = 404) {
  210. $scope.withoutornone = true
  211. }
  212. }).finally(function () {
  213. $scope.$broadcast('scroll.refreshComplete');
  214. $scope.loading = false;
  215. });
  216. }
  217. $scope.$on("$destroy", function () {
  218. if ($rootScope.commons.modal != null)
  219. $rootScope.commons.moda = undefined;
  220. $interval.cancel(stopTime);
  221. beforeEnter = null;
  222. });
  223. function getIsAutoCheckStatus() {
  224. if (window.cordovaLinker != undefined) {
  225. window.cordovaLinker.getIsAutoCheck(null, function (s) {
  226. //s:{isautocheck:false,isadvance:false,isdelay:false,inadvance:15,indelay:5}
  227. // s = JSON.parse(s);
  228. if (!$scope.usersetting.isallowauto) {
  229. $scope.saveIsAutoCheck('isautocheck', false);
  230. $scope.autocheck.isautocheck = false;
  231. } else {
  232. $scope.autocheck.isautocheck = s == '' ? true : JSON.parse(s).isautocheck;
  233. }
  234. // $scope.autocheck.checkin.isadvance = (s.isadvance == 'true');
  235. // $scope.autocheck.checkout.isdelay = (s.isdelay == 'true');
  236. // $scope.autocheck.checkin.inadvance = s.inadvance;
  237. // $scope.autocheck.checkout.indelay = s.indelay;
  238. }, function (err) {
  239. });
  240. }
  241. }
  242. })
  243. .controller('workatd-setting', function ($rootScope, $scope, $state, $ionicModal, global, workatd, Dept, Member, showPopup) {
  244. global.fetch_user().then(function () {
  245. workatd.getSettings().then(function (data) {
  246. $scope.settings = data;
  247. });
  248. });
  249. $scope.addnew = function () {
  250. if (_.find($scope.settings, function (item) {
  251. return item.isallcheck
  252. })) {
  253. showPopup.PopupWindow(0, '已设置了全员考勤!');
  254. return;
  255. }
  256. if (window.cordovaLinker) {
  257. var local = {
  258. NAME: "",
  259. Latitude: "",
  260. Longitude: "",
  261. Distance: ""
  262. };
  263. cordovaLinker.callMap(local, function (mapdata) {
  264. $scope.settingdetail = workatd.addnew();
  265. $scope.settingdetail.workposition = mapdata.Latitude + "," + mapdata.Longitude;
  266. $scope.settingdetail.workaddress = mapdata.NAME;
  267. $scope.showModalSettingDept();
  268. });
  269. }
  270. }
  271. $scope.showModalSettingDept = function () {
  272. Member.routename = 'workatd-settingdetail';
  273. Member.routeparams = {
  274. id: -1
  275. };
  276. Member.titlename = '选择考勤部门';
  277. Member.resourcemember = [];
  278. Member.selecteddepts = [];
  279. Member.disabled = true;
  280. Member.showall = true;
  281. Member.isallcheck = false;
  282. Member.datatype = 4;
  283. $state.go('selectdept', {
  284. id: -1
  285. });
  286. };
  287. $scope.$on("$destroy", function () {
  288. beforeEnter = null;
  289. })
  290. })
  291. .controller('workatd-settingweek', function ($scope, $state, workatd) {
  292. $scope.currentid = $state.params["id"];
  293. $scope.settingdetail = workatd.current($scope.currentid);
  294. })
  295. .controller('workatd-settingdetail', function ($rootScope, $scope, $state, $ionicModal, $ionicHistory, $cordovaDatePicker, _, workatd, Dept, Member, showPopup, Tool) {
  296. $scope.currentid = $state.params["id"];
  297. $scope.title = $scope.currentid > 0 ? '编辑考勤' : '新增考勤';
  298. $scope.save = function () {
  299. if (($scope.settingdetail.am_ontime != null && $scope.settingdetail.pm_offtime) ||
  300. ($scope.settingdetail.am_ontime != null && $scope.settingdetail.am_offtime && $scope.settingdetail.pm_offtime && $scope.settingdetail.pm_offtime)) {
  301. var workatddata = workatd.current($scope.currentid);
  302. if (!$scope.settingdetail.ischeckmonday && !$scope.settingdetail.ischecktuesday && !$scope.settingdetail.ischeckwednesday && !$scope.settingdetail.ischeckthursday && !$scope.settingdetail.ischeckfriday && !$scope.settingdetail.ischecksaturday && !$scope.settingdetail.ischecksunday) {
  303. showPopup.PopupWindow(0, '请选择考勤日期', false);
  304. return;
  305. }
  306. if (workatddata.workatddept.length == 0 && workatddata.isallcheck == 0) {
  307. showPopup.PopupWindow(0, '请选择考勤部门', false);
  308. return;
  309. }
  310. showPopup.showLoading(1, '正在提交');
  311. workatd.save($scope.currentid, workatddata).then(function (data) {
  312. $state.go('workatd-setting');
  313. showPopup.hideLoading();
  314. }, function (err) {
  315. showPopup.hideLoading();
  316. alert(JSON.stringify(err));
  317. });
  318. }
  319. };
  320. $scope.delete = function () {
  321. showPopup.confirm('是否删除该考勤?', '是', '否').then(function (res) {
  322. if (res) {
  323. showPopup.showLoading(1, '删除中');
  324. workatd.delete($scope.currentid).then(function (data) {
  325. $state.go('workatd-setting');
  326. showPopup.hideLoading();
  327. });
  328. }
  329. })
  330. };
  331. $scope.singlecheck = function () {
  332. $scope.settingdetail.isdoublecheck = 0;
  333. $scope.settingdetail.am_offtime = null;
  334. $scope.settingdetail.pm_ontime = null;
  335. $scope.settingdetail.ischeckamoff = false;
  336. $scope.settingdetail.ischeckpmon = false;
  337. };
  338. $scope.doublecheck = function () {
  339. $scope.settingdetail.isdoublecheck = 1;
  340. };
  341. function formatMinute(date) {
  342. return date.getMinutes() < 10 ? ('0' + date.getMinutes().toString()) : date.getMinutes().toString()
  343. }
  344. function choosedate(str_time, b_ischeck) {
  345. var time = {'am_ontime': '09:00:00', 'am_offtime': '12:00:00', 'pm_ontime': '13:30:00', 'pm_offtime': '18:00:00'};
  346. var options = {
  347. mode: 'time',
  348. date: new Date($scope.settingdetail[str_time] == null ? new Date('2016/10/01 ' + time[str_time]) : $scope.settingdetail[b_ischeck]),
  349. is24Hour: true,
  350. androidTheme: 3
  351. };
  352. $cordovaDatePicker.show(options).then(function (date) {
  353. var temp = $scope.settingdetail[str_time];
  354. $scope.settingdetail[str_time] = date.getHours().toString() + ':' + formatMinute(date);
  355. var ts = [];
  356. _.each([$scope.settingdetail.am_ontime, $scope.settingdetail.am_offtime, $scope.settingdetail.pm_ontime, $scope.settingdetail.pm_offtime], function (t) {
  357. if (t != null) ts.push(new Date('2016/10/01 ' + t));
  358. });
  359. if (ts.toString() != _.sortBy(ts).toString()) {
  360. $scope.settingdetail[str_time] = temp;
  361. $scope.settingdetail[b_ischeck] = false;
  362. showPopup.PopupWindow(0, '时间不符合规范!', false);
  363. }
  364. }, function (cancel) {
  365. $scope.settingdetail[b_ischeck] = false;
  366. });
  367. }
  368. $scope.choosedate = function (str_time, b_ischeck) {
  369. $scope.settingdetail[b_ischeck] ? choosedate(str_time, b_ischeck) : $scope.settingdetail[str_time] = null;
  370. };
  371. $scope.showModalSettingDept = function () {
  372. Member.titlename = '选择考勤部门';
  373. Member.resourcemember = [];
  374. Member.selecteddepts = [];
  375. Member.disabled = true;
  376. Member.hide = true;
  377. Member.isallcheck = false;
  378. if ($scope.settingdetail.isallcheck == 1) {
  379. Member.isallcheck = true;
  380. } else {
  381. _.each($scope.settingdetail.workatddept, function (item) {
  382. if (item.depname == undefined && item.id == undefined) {
  383. item.depname = item.dept__depname;
  384. item.id = item.dept__id;
  385. }
  386. Member.resourcemember.push({
  387. 'id': item.id,
  388. 'depname': item.depname
  389. });
  390. })
  391. }
  392. Member.showall = true;
  393. Member.datatype = 4;
  394. $state.go('selectdept', {
  395. id: $scope.currentid
  396. });
  397. };
  398. //无需考勤人员窗口
  399. $scope.showModalSettingWithoutusr = function () {
  400. Member.titlename = '选择无需考勤人员';
  401. Member.datatype = '0';
  402. Member.resourcemember = [];
  403. Member.selectedemplst = [];
  404. if ($scope.settingdetail.isallcheck == 0) {
  405. Member.homerenderdata = [];
  406. _.each($scope.settingdetail.workatddept, function (item) {
  407. if (item.dept__depname != undefined) {
  408. item.depname = item.dept__depname;
  409. item.id = item.dept__id;
  410. }
  411. Member.homerenderdata.push({
  412. 'id': item.id,
  413. 'depname': item.depname
  414. })
  415. });
  416. }
  417. Member.showall = false;
  418. Member.disabled = false;
  419. _.each($scope.settingdetail.workatdwithoutusr, function (item) {
  420. Member.resourcemember.push({
  421. 'user_id': item.user_id,
  422. 'username': item.user__username,
  423. 'degree': item.user__usr__degree
  424. });
  425. })
  426. console.log(Member.resourcemember)
  427. $state.go('selectmember');
  428. };
  429. //选择允许谁查看
  430. $scope.showModalSettingReportusr = function () {
  431. Member.titlename = '选择成员';
  432. Member.datatype = '1';
  433. Member.resourcemember = [];
  434. Member.selectedemplst = [];
  435. Member.disabled = false;
  436. Member.showall = false;
  437. _.each($scope.settingdetail.workatdreportusr, function (item) {
  438. Member.resourcemember.push({
  439. 'user_id': item.user_id,
  440. 'username': item.user__username,
  441. 'degree': item.user__usr__degree
  442. });
  443. })
  444. $state.go('selectmember');
  445. };
  446. //修改考勤地点
  447. $scope.showModalSettingMap = function () {
  448. if (window.cordovaLinker != undefined) {
  449. var _locals = $scope.settingdetail.workposition.split(',');
  450. var local = {
  451. NAME: $scope.settingdetail.workaddress,
  452. Latitude: _locals[0],
  453. Longitude: _locals[1],
  454. Distance: ""
  455. };
  456. cordovaLinker.callMap(local, function (mapdata) {
  457. $scope.settingdetail.workposition = mapdata.Latitude + "," + mapdata.Longitude;
  458. $scope.settingdetail.workaddress = mapdata.NAME;
  459. $state.go("workatd-settingdetail", {
  460. 'id': $scope.currentid
  461. });
  462. });
  463. }
  464. };
  465. //修改允许偏差
  466. var modalSettingoffset = $ionicModal.fromTemplateUrl('templates/settingoffsetmodal.html', {
  467. scope: $scope,
  468. animation: 'slide-in-right'
  469. });
  470. $scope.showModalSettingOffset = function () {
  471. modalSettingoffset.then(function (modal) {
  472. $rootScope.commons.modal = modal;
  473. $rootScope.commons.modal.show();
  474. })
  475. };
  476. $scope.closeModalSettingOffset = function (rst) {
  477. $rootScope.commons.modal.hide();
  478. };
  479. $scope.toSetPerson = function (type) {
  480. _.each($scope.settingdetail.workatdreportusr, function (item) {
  481. if (item.user__username) {
  482. item.username = item.user__username;
  483. item.degree = item.user__usr__degree
  484. }
  485. });
  486. _.each($scope.settingdetail.workatdwithoutusr, function (item) {
  487. if (item.user__username) {
  488. item.username = item.user__username;
  489. item.degree = item.user__usr__degree
  490. }
  491. });
  492. $state.go('workatd-settingset', {
  493. type: type,
  494. id: $state.params["id"]
  495. });
  496. };
  497. function beforeEnterData() {
  498. if (Member.dialogresult == 1) {
  499. Member.dialogresult = 0;
  500. if (Member.selectedemplst.length > 0) {
  501. if (Member.datatype == '0') {
  502. $scope.settingdetail.workatdwithoutusr = [];
  503. disposeData($scope.settingdetail.workatdwithoutusr, 0);
  504. } else if (Member.datatype == '1') {
  505. $scope.settingdetail.workatdreportusr = [];
  506. disposeData($scope.settingdetail.workatdreportusr, 0);
  507. }
  508. Member.selectedemplst = [];
  509. }
  510. if (Member.selecteddepts.length > 0) {
  511. $scope.settingdetail.workatddept = [];
  512. disposeData($scope.settingdetail.workatddept, 1);
  513. $scope.settingdetail.isallcheck = 0;
  514. Member.selecteddepts = [];
  515. }
  516. if (Member.isallcheck && $scope.settingdetail.workatddept.length > 0) {
  517. $scope.settingdetail.isallcheck = 1;
  518. $scope.settingdetail.workatddept = [];
  519. }
  520. }
  521. }
  522. function disposeData(data, type) {
  523. if (type == 0) {
  524. _.each(Member.selectedemplst, function (item) {
  525. Member.resourcemember.push(item);
  526. data.push(item);
  527. })
  528. } else if (type == 1) {
  529. _.each(Member.selecteddepts, function (item) {
  530. Member.resourcemember.push(item);
  531. data.push(item);
  532. })
  533. }
  534. }
  535. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  536. Tool.removeBackView('selectdept');
  537. Member.homerenderdata = [];
  538. Member.routename = '';
  539. Member.routeparams = {};
  540. if ($scope.currentid == -1) {
  541. //新增
  542. $scope.settingdetail = workatd.current(-1);
  543. set_check();
  544. $scope.settingdetail.isallcheck = Member.isallcheck ? 1 : 0;
  545. beforeEnterData();
  546. } else {
  547. if ($scope.settingdetail) {
  548. beforeEnterData();
  549. return
  550. }
  551. workatd.getDetail($scope.currentid).then(function (data) {
  552. console.log(data);
  553. $scope.settingdetail = data;
  554. $scope.settingdetail.isdoublecheck = !(data.am_offtime == null && data.pm_ontime == null);
  555. set_check();
  556. beforeEnterData();
  557. });
  558. }
  559. });
  560. function set_check() {
  561. $scope.settingdetail.ischeckamon = ($scope.settingdetail.am_ontime != null);
  562. $scope.settingdetail.ischeckamoff = $scope.settingdetail.am_offtime != null;
  563. $scope.settingdetail.ischeckpmon = $scope.settingdetail.pm_ontime != null;
  564. $scope.settingdetail.ischeckpmoff = $scope.settingdetail.pm_offtime != null;
  565. }
  566. $scope.$on("$destroy", function () {
  567. if ($rootScope.commons.modal != null)
  568. $rootScope.commons.moda = undefined;
  569. beforeEnter = null;
  570. })
  571. })
  572. .controller('workatd-dailyreport', function ($scope, $rootScope, $state, $ionicModal, $timeout, workatd, global, Tool) {
  573. var days = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  574. $scope.deptid = 0;
  575. $scope.index = 0;
  576. $scope.currentmonth = new Date().getMonth() + 1;
  577. $scope.datelist_old = [];
  578. $scope.init = function () {
  579. global.fetch_user().then(function () {
  580. workatd.getCountList().then(function (data) {
  581. $scope.settings = data;
  582. console.log(data);
  583. });
  584. })
  585. };
  586. $scope.getdatelist = function () {
  587. global.fetch_user().then(function () {
  588. $scope.workatdsetid = $state.params["id"];
  589. var worksetid = 0, type = 0;
  590. if (parseInt($state.params["id"]) > 0) {
  591. worksetid = $state.params["id"];
  592. type = 1;
  593. }
  594. workatd.getDateList(worksetid, type).then(function (res) {
  595. $scope.nexturl = res.next;
  596. console.log(res);
  597. $scope.datelist_old = _.map(res.results, _.clone);
  598. setdatelist(res.results)
  599. });
  600. });
  601. };
  602. $scope.loadMore = function () {
  603. workatd.getNextPage($scope.nexturl).then(function (res) {
  604. $scope.nexturl = res.next;
  605. $scope.datelist_old = $scope.datelist_old.concat(res.results);
  606. setdatelist($scope.datelist_old)
  607. }).finally(function () {
  608. $scope.$broadcast('scroll.infiniteScrollComplete')
  609. });
  610. };
  611. function setdatelist(data) {
  612. $scope.datelist = [];
  613. var sortitems = [];
  614. _.each(data, function (item) {
  615. item.check_dd = new Date(item.date);
  616. item.yearmonth = item.check_dd.getFullYear().toString() + (item.check_dd.getMonth() + 1).toString();
  617. item.day = item.check_dd.getDay();
  618. item.daystr = Tool.getTranslateByKey("weekdays", item.day); //days[item.day]
  619. sortitems.push(item.yearmonth)
  620. });
  621. sortitems = _.uniq(sortitems);
  622. var list = [];
  623. _.each(sortitems, function (item) {
  624. var temp = {year: '', month: '', items: []};
  625. _.each(data, function (item1) {
  626. if (item == item1.yearmonth) {
  627. temp.year = item1.check_dd.getFullYear();
  628. temp.month = item1.check_dd.getMonth() + 1;
  629. temp.items.push(item1)
  630. }
  631. });
  632. list.push(temp)
  633. });
  634. console.log(list);
  635. $scope.datelist = list;
  636. }
  637. $scope.getreport = function (deptid) {
  638. getReport(deptid)
  639. };
  640. $scope.seedetail = function (title, count, atdtype, type) {
  641. if (count == 0) return;
  642. $state.go('reportdetails', {
  643. 'workatdsetid': $scope.workatdsetid,
  644. 'atdtype': atdtype,
  645. 'date': $state.params["date"],
  646. 'type': type,
  647. 'deptid': $scope.deptid
  648. });
  649. }
  650. $scope.showselectdeptmodal = function () {
  651. workatd.getWorkatdDeptCount($state.params["id"]).then(function (data) {
  652. $scope.workatddepts = data;
  653. $scope.workatddepts.totalcount = 0;
  654. _.each(data, function (item) {
  655. $scope.workatddepts.totalcount += item.count;
  656. })
  657. });
  658. var m = $ionicModal.fromTemplateUrl('templates/workatddeptlist.html', {
  659. scope: $scope,
  660. animation: 'slide-in-right'
  661. });
  662. m.then(function (modal) {
  663. $rootScope.commons.modal = modal;
  664. $rootScope.commons.modal.show();
  665. })
  666. }
  667. $scope.closeModal = function () {
  668. $rootScope.commons.modal.hide();
  669. }
  670. $scope.changeDept = function (deptid) {
  671. $scope.index = deptid;
  672. $scope.deptid = deptid;
  673. getReport(deptid);
  674. $scope.closeModal()
  675. }
  676. $scope.tohistory = function () {
  677. $state.go('personhistory', {id: 0})
  678. };
  679. function getReport(deptid) {
  680. global.fetch_user().then(function () {
  681. $scope.workatdsetid = $state.params["id"];
  682. $scope.date = $state.params["date"];
  683. $scope.daystr = Tool.getTranslateByKey("weekdays", new Date($scope.date).getDay());
  684. workatd.getReport($state.params["id"], $state.params["date"], $scope.deptid).then(function (data) {
  685. $scope.usrcount = data.usrcount;
  686. _.each(data.items, function (item) {
  687. item.uncheckin_cnt = data.usrcount - item.normal_cnt - item.outof_cnt;
  688. })
  689. $scope.items = data.items;
  690. });
  691. });
  692. }
  693. })
  694. .controller('workatd-settingset', function ($rootScope, $scope, $state, $ionicPopover, global, workatd, Member) {
  695. $scope.type = $state.params['type'];
  696. $scope.data = {
  697. title: ['无需考勤成员', '允许谁看考勤统计'],
  698. showDelete: false,
  699. usrdata: []
  700. };
  701. $rootScope.commons.goBackIsDisable = false;
  702. $ionicPopover.fromTemplateUrl('templates/add.html', {
  703. scope: $scope
  704. }).then(function (popover) {
  705. $scope.popover = popover;
  706. });
  707. $scope.goBack = function () {
  708. global.goBack();
  709. }
  710. $scope.displayremove = function () {
  711. $scope.data.showDelete = !$scope.data.showDelete;
  712. $rootScope.commons.goBackIsDisable = true;
  713. $scope.popover.hide();
  714. };
  715. $scope.removeItem = function (item) {
  716. if ($scope.type == 0) {
  717. $scope.settingdetail.workatdwithoutusr.splice($scope.settingdetail.workatdwithoutusr.indexOf(item), 1);
  718. } else if ($scope.type == 1) {
  719. $scope.settingdetail.workatdreportusr.splice($scope.settingdetail.workatdreportusr.indexOf(item), 1);
  720. }
  721. };
  722. $scope.ok = function () {
  723. $scope.popover.hide();
  724. $rootScope.commons.goBackIsDisable = undefined;
  725. $scope.data.showDelete = false;
  726. };
  727. $scope.toadd = function () {
  728. $scope.popover.hide();
  729. Member.titlename = '选择成员';
  730. Member.resourcemember = [];
  731. Member.selectedemplst = [];
  732. Member.disabled = true;
  733. Member.showall = false;
  734. if ($scope.type == 0) {
  735. addData($scope.settingdetail.workatdwithoutusr);
  736. } else if ($scope.type == 1) {
  737. addData($scope.settingdetail.workatdreportusr);
  738. }
  739. if ($scope.settingdetail.isallcheck == 0 && $scope.type == 0) {
  740. Member.homerenderdata = [];
  741. _.each($scope.settingdetail.workatddept, function (itemdept) {
  742. if (itemdept.depname == undefined) {
  743. itemdept.depname = itemdept.dept__depname;
  744. }
  745. Member.homerenderdata.push({
  746. 'depname': itemdept.depname,
  747. 'id': itemdept.id
  748. })
  749. })
  750. }
  751. $state.go('selectmember');
  752. };
  753. function addData(data) {
  754. _.each(data, function (item) {
  755. Member.resourcemember.push({
  756. 'user_id': item.user_id,
  757. 'username': item.username,
  758. 'degree': item.degree
  759. });
  760. })
  761. }
  762. function enterData(data) {
  763. console.log(Member.selectedemplst);
  764. _.each(Member.selectedemplst, function (item) {
  765. Member.resourcemember.push(item);
  766. data.push(item);
  767. })
  768. $scope.data.usrdata = data;
  769. Member.selectedemplst = [];
  770. }
  771. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  772. data = workatd.current(parseInt($state.params["id"]));
  773. $scope.settingdetail = data;
  774. console.log(data);
  775. if ($scope.type == 0) {
  776. $scope.data.usrdata = $scope.settingdetail.workatdwithoutusr;
  777. } else if ($scope.type == 1) {
  778. $scope.data.usrdata = $scope.settingdetail.workatdreportusr;
  779. }
  780. if (Member.selectedemplst.length > 0) {
  781. $scope.data.usrdata = [];
  782. if ($scope.type == 0) {
  783. $scope.settingdetail.workatdwithoutusr = [];
  784. } else if ($scope.type == 1) {
  785. $scope.settingdetail.workatdreportusr = [];
  786. }
  787. }
  788. });
  789. var enter = $scope.$on("$ionicView.enter", function () {
  790. if (Member.selectedemplst.length > 0) {
  791. if ($scope.type == 0) {
  792. enterData($scope.settingdetail.workatdwithoutusr);
  793. } else if ($scope.type == 1) {
  794. enterData($scope.settingdetail.workatdreportusr);
  795. }
  796. }
  797. });
  798. $scope.$on("$destroy", function () {
  799. enter = null;
  800. beforeEnter = null;
  801. })
  802. })
  803. .controller('ReportDetailsCtrl', function ($scope, $state, workatd, global) {
  804. $scope.type = $state.params['type'];
  805. $scope.atdtype = $state.params['atdtype'];
  806. $scope.titleArr = ['准时', '迟到', '未签到'];
  807. $scope.titleArr[1] = _.contains([2, 4], parseInt($scope.atdtype)) ? '早退' : $scope.titleArr[1];
  808. $scope.titleArr[2] = _.contains([2, 4], parseInt($scope.atdtype)) ? '未签退' : $scope.titleArr[2];
  809. $scope.init = function () {
  810. global.fetch_user().then(function () {
  811. workatd.getReportDetail($state.params['workatdsetid'], $state.params['date'], $state.params['atdtype'], $state.params['type'], $state.params['deptid']).then(function (data) {
  812. $scope.countDetails = data;
  813. })
  814. });
  815. }
  816. })
  817. .controller('CheckinDetailCtrl', function ($scope, $state, workatd, global) {
  818. global.fetch_user().then(function () {
  819. var sortitems = [];
  820. $scope.todayweek = workatd.weeknames[new Date($state.params['check_dd']).getDay()];
  821. $scope.time = new Date($state.params['check_dd']);
  822. workatd.getCheckinDetail($state.params['check_dd']).then(function (data) {
  823. $scope.data = data;
  824. console.log(data);
  825. })
  826. });
  827. })
  828. .controller('PersonMonthCountCtrl', function ($scope, $state, workatd, global) {
  829. global.fetch_user().then(function () {
  830. $scope.year = $state.params['year'];
  831. $scope.month = $state.params['month'];
  832. workatd.getPersonMonthCount($scope.year, $scope.month).then(function (data) {
  833. console.log(data)
  834. $scope.data = data;
  835. })
  836. });
  837. $scope.seedetail = function (count, type) {
  838. console.log(type)
  839. if (count == 0)
  840. return;
  841. $state.go('person-monthcountdetail', {'type': type, 'year': $scope.year, 'month': $scope.month})
  842. }
  843. })
  844. .controller('PersonMonthCountDetailCtrl', function ($scope, $state, workatd, global, Tool) {
  845. $scope.titleArr = workatd.titleArr;
  846. var year = $state.params['year'], month = $state.params['month'];
  847. $scope.type = $state.params['type'] == 5 ? 0 : $state.params['type'];
  848. global.fetch_user().then(function () {
  849. workatd.getPersonMonthCountDetail(year, month, $state.params['type']).then(function (data) {
  850. console.log(data);
  851. $scope.data = [];
  852. if ($scope.type == 1) {
  853. set_data(data, 'isam_ontime', 'ispm_ontime', 'reason_am_ontime', 'check_am_on', 'reason_pm_ontime', 'check_pm_on')
  854. } else if ($scope.type == 2) {
  855. set_data(data, 'isam_offtime', 'ispm_offtime', 'reason_am_offtime', 'check_am_off', 'reason_pm_offtime', 'check_pm_off')
  856. } else {
  857. _.each(data, function (item) {
  858. item.check_dd = new Date(item.date);
  859. item.day = item.check_dd.getDay();
  860. item.daystr = Tool.getTranslateByKey("weekdays", item.day);
  861. });
  862. $scope.data = data
  863. }
  864. })
  865. });
  866. // isam_ontime,ispm_ontime,reason_am_ontime,check_am_on,reason_pm_ontime,check_pm_on,
  867. function set_data(data) {
  868. var args = arguments;
  869. _.each(data, function (item) {
  870. var temp = {'username': item.user__username, 'degree': item.user__usr__degree, 'reason': '', 'check_dd': '', 'address': item.workatdsetting__workaddress};
  871. if (item[args[1]] == 1 && item[args[2]] == 1) {
  872. temp.reason = item[args[3]];
  873. temp.check_dd = item[args[4]];
  874. var temp1 = _.clone(temp);
  875. temp1.reason = item[args[5]];
  876. temp1.check_dd = item[args[6]];
  877. $scope.data.push(temp1);
  878. } else {
  879. temp.reason = item[args[3]] == null ? item[args[5]] : item[args[3]];
  880. temp.check_dd = item[args[4]] == null ? item[args[6]] : item[args[4]];
  881. $scope.data.push(temp)
  882. }
  883. })
  884. }
  885. // 参考
  886. // function set_earlydata(data) {
  887. // _.each(data, function (item) {
  888. // var temp = {'username': item.user__username, 'degree': item.user__usr__degree, 'reason': '', 'check_dd': ''};
  889. // if (item.isam_offtime == 1 && item.ispm_offtime == 1) {
  890. // temp.reason = item.reason_am_offtime;
  891. // temp.check_dd = item.check_am_off;
  892. // var temp1 = _.clone(temp);
  893. // temp1.reason = item.reason_pm_offtime;
  894. // temp1.reason = item.check_pm_off;
  895. // $scope.data.push(temp1);
  896. // } else {
  897. // temp.reason = item.reason_am_offtime == null ? item.reason_pm_offtime : item.reason_am_offtime
  898. // temp.check_dd = item.check_am_on == null ? item.check_pm_on : item.check_am_on;
  899. // }
  900. // $scope.data.push(temp)
  901. // })
  902. // }
  903. })
  904. .controller('MonthCountCtrl', function ($scope, $state, workatd, global) {
  905. global.fetch_user().then(function () {
  906. $scope.year = $state.params['year'];
  907. $scope.month = $state.params['month'];
  908. workatd.getMonthCount($scope.year, $scope.month).then(function (data) {
  909. $scope.data = data;
  910. })
  911. });
  912. $scope.seedetail = function (count, type) {
  913. if (count == 0)
  914. return;
  915. $state.go('monthcountdetail', {'type': type, 'year': $scope.year, 'month': $scope.month})
  916. }
  917. })
  918. .controller('MonthCountDetailCtrl', function ($scope, $state, workatd, global, Tool) {
  919. $scope.titleArr = workatd.titleArr;
  920. var year = $state.params['year'], month = $state.params['month'];
  921. $scope.type = $state.params['type'] == 5 ? 0 : $state.params['type'];
  922. global.fetch_user().then(function () {
  923. workatd.getMonthCountDetail(year, month, $state.params['type']).then(function (data) {
  924. console.log(data);
  925. $scope.data = [];
  926. if ($scope.type == 1) {
  927. set_data(data, 'isam_ontime', 'ispm_ontime', 'reason_am_ontime', 'check_am_on', 'reason_pm_ontime', 'check_pm_on')
  928. } else if ($scope.type == 2) {
  929. set_data(data, 'isam_offtime', 'ispm_offtime', 'reason_am_offtime', 'check_am_off', 'reason_pm_offtime', 'check_pm_off')
  930. } else {
  931. $scope.data = data
  932. }
  933. })
  934. });
  935. function set_data(data) {
  936. var args = arguments;
  937. _.each(data, function (item) {
  938. var temp = _.pick(item, 'user__username', 'user__usr__degree', 'check_dd');
  939. temp.address = item.workatdsetting__workaddress;
  940. temp.reason = '';
  941. if (item[args[1]] == 1 && item[args[2]] == 1) {
  942. temp.reason = item[args[3]];
  943. temp.check_dd = item[args[4]];
  944. var temp1 = _.clone(temp);
  945. temp1.reason = item[args[5]];
  946. temp1.check_dd = item[args[6]];
  947. $scope.data.push(temp1);
  948. } else {
  949. temp.reason = item[args[3]] == null ? item[args[5]] : item[args[3]];
  950. temp.check_dd = item[args[4]] == null ? item[args[6]] : item[args[4]];
  951. $scope.data.push(temp)
  952. }
  953. })
  954. }
  955. })