controllers.js 39 KB

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