leave.js 4.8 KB

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