leave.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.endDate;
  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. this.initList()
  74. });
  75. util.apiPost(urls.get_holidays, {
  76. 'q.companyId': stu.orgId
  77. }).then((rs) => {
  78. if (rs && rs.length > 0) {
  79. this.setData({
  80. 'holidayList': rs
  81. })
  82. }
  83. });
  84. }
  85. },
  86. initList:function(){
  87. let date = this.data.bd
  88. if (date) {
  89. let t = this;
  90. t.selectDate(date)
  91. }
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onShow: function () {
  102. let date = this.data.bd
  103. if (date) {
  104. let t = this;
  105. setTimeout(() => {
  106. t.selectDate(date)
  107. }, 500)
  108. }
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function () {
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {
  134. },
  135. selectDate: function (v) {
  136. this.setData({
  137. curDate: v, bd: v
  138. })
  139. let vd = new Date(v);
  140. let week = this.data.weekMap[vd.getDay()];
  141. let list = this.data.eventList.filter(o => {
  142. return o.attenceDate == v;
  143. });
  144. list.map(o => {
  145. o.bt = o.beginTime.substring(0, 5);
  146. o.et = o.endTime.substring(0, 5);
  147. o.leaveFlag = this.canLeave(o)
  148. })
  149. this.setData({
  150. 'date': v,
  151. 'week': week,
  152. 'dateList': [{
  153. items: list,
  154. date: v,
  155. week: week
  156. }]
  157. });
  158. },
  159. callSelectDate: function (d) {
  160. let v = d.detail.dateString;
  161. this.selectDate(v);
  162. },
  163. canLeave(item) {
  164. let timeCheck = (item.attenceDate.replace(/-/g, '/') > this.data.curDate.replace(/-/g, '/')); // 默认要大于当前时间,就是不能请当天的假
  165. let dateCheck = (item.attenceDate.replace(/-/g, '/') > this.data.curDate.replace(/-/g, '/')); // 默认要大于当前时间,就是不能请当天的假
  166. if (this.data.leaveTime > 0) { // 允许上课前()分钟请假
  167. // 判断当前时间是否跟上课时间相差 leaveTime 分钟
  168. let attenceTime = new Date(item.attenceDate.replace(/-/g, '/') + ' ' + item.beginTime)
  169. timeCheck = Math.floor((attenceTime.getTime() - new Date().getTime()) / 60000) >= this.data.leaveTime;
  170. }
  171. if (this.data.leaveDay > 0) { // 允许提前()天请假
  172. let attenceTime = item.attenceDate + ' 00:00:00'
  173. const temDate = new Date();
  174. temDate.setDate(temDate.getDate() + this.data.leaveDay);
  175. const curTemDate = temDate.getFullYear()+ "-" + (temDate.getMonth() + 1) + "-" + temDate.getDate() + ' 00:00:00';
  176. dateCheck = (curTemDate.replace(/-/g, '/') >= attenceTime.replace(/-/g, '/'));
  177. }
  178. return (item.isAttend === 0 && item.leaveCount > 0 && timeCheck && dateCheck && (item.status === 0 || item.status === 4));
  179. },
  180. })