leave.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // pages/leave/leave.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. curStu: null,
  11. aheadTime: 0,
  12. eventList: [],
  13. holidayList: [],
  14. dateList: [],
  15. date: null,
  16. week: 0,
  17. weekMap: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  18. leaveTime: 0,
  19. leaveDay: 0,
  20. curDate: null,
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. const urls = urlDef.urls;
  27. let stu = wx.getStorageSync('student');
  28. if (stu) {
  29. this.setData({ 'curStu': stu });
  30. util.apiPost(urls.get_sys_params + '&q.orgId=' + stu.orgId + '&q.id=1000_2').then((rs) => {
  31. if (rs && rs.length > 0) {
  32. this.setData({ leaveTime: parseInt(rs[0].sysVal, 10) })
  33. }
  34. });
  35. // this.leaveDay = 14; // 允许提前()天请假
  36. util.apiPost(urls.get_sys_params + '&q.orgId=' + stu.orgId + '&q.id=1000_1').then((rs) => {
  37. if (rs && rs.length > 0) {
  38. this.setData({ leaveDay: parseInt(rs[0].sysVal, 10) })
  39. }
  40. });
  41. util.apiPost(urls.get_sys_params, { 'q.orgId': stu.orgId, 'q.id': 'f8158acabeeb44ec9ff651aade6b295f' }).then((rs) => {
  42. if (rs && rs.length > 0) {
  43. // 将分钟转为毫秒
  44. this.setData({ 'aheadTime': parseInt(rs[0].sysVal, 10) * 60 * 1000 })
  45. }
  46. });
  47. util.apiPost(urls.leave_get_classes_info, { 'q.studentId': stu.studentId }).then((rs) => {
  48. if (rs && rs.length > 0) {
  49. this.setData({ 'eventList': rs })
  50. }
  51. });
  52. util.apiPost(urls.get_holidays, { 'q.companyId': stu.orgId }).then((rs) => {
  53. if (rs && rs.length > 0) {
  54. this.setData({ 'holidayList': rs })
  55. }
  56. });
  57. }
  58. },
  59. /**
  60. * 生命周期函数--监听页面初次渲染完成
  61. */
  62. onReady: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面隐藏
  71. */
  72. onHide: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面卸载
  76. */
  77. onUnload: function () {
  78. },
  79. /**
  80. * 页面相关事件处理函数--监听用户下拉动作
  81. */
  82. onPullDownRefresh: function () {
  83. },
  84. /**
  85. * 页面上拉触底事件的处理函数
  86. */
  87. onReachBottom: function () {
  88. },
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage: function () {
  93. },
  94. selectDate: function (v) {
  95. this.setData({ curDate: v })
  96. let vd = new Date(v);
  97. let week = this.data.weekMap[vd.getDay()];
  98. let list = this.data.eventList.filter(o => {
  99. return o.attenceDate == v;
  100. });
  101. list.map(o => {
  102. o.bt = o.beginTime.substring(0, 5);
  103. o.et = o.endTime.substring(0, 5);
  104. o.leaveFlag = this.canLeave(o)
  105. })
  106. this.setData({ 'date': v, 'week': week, 'dateList': [{ items: list, date: v, week: week }] });
  107. },
  108. callSelectDate: function (d) {
  109. let v = d.detail.dateString;
  110. this.selectDate(v);
  111. },
  112. canLeave(item) {
  113. let timeCheck = (item.attenceDate > this.data.curDate); // 默认要大于当前时间,就是不能请当天的假
  114. let dateCheck = (item.attenceDate > this.data.curDate); // 默认要大于当前时间,就是不能请当天的假
  115. if (this.data.leaveTime > 0) { // 允许上课前()分钟请假
  116. // 判断当前时间是否跟上课时间相差 leaveTime 分钟
  117. let attenceTime = new Date(item.attenceDate + ' ' + item.beginTime)
  118. timeCheck = Math.floor((attenceTime.getTime() - new Date().getTime()) / 60000) >= this.data.leaveTime;
  119. }
  120. if (this.data.leaveDay > 0) { // 允许提前()天请假
  121. let attenceTime = new Date(item.attenceDate + ' 00:00:00')
  122. const temDate = new Date();
  123. temDate.setDate(temDate.getDate() + this.data.leaveDay);
  124. dateCheck = (temDate >= attenceTime);
  125. }
  126. return (item.isAttend === 0 && item.leaveCount > 0 && timeCheck && dateCheck && (item.status === 0 || item.status === 4));
  127. }
  128. })