leave.js 4.2 KB

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