leave.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 pages = getCurrentPages();
  103. let currPage = pages[pages.length - 1];
  104. //当前页的options,啥意思呢,就是你可能某个函数需要刷新,但是他的参数正好是传过来的参数
  105. let date = this.data.bd
  106. if (date) {
  107. let t = this;
  108. setTimeout(() => {
  109. t.selectDate(date)
  110. }, 500)
  111. }
  112. },
  113. /**
  114. * 生命周期函数--监听页面隐藏
  115. */
  116. onHide: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面卸载
  120. */
  121. onUnload: function () {
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh: function () {
  127. },
  128. /**
  129. * 页面上拉触底事件的处理函数
  130. */
  131. onReachBottom: function () {
  132. },
  133. /**
  134. * 用户点击右上角分享
  135. */
  136. onShareAppMessage: function () {
  137. },
  138. selectDate: function (v) {
  139. this.setData({
  140. curDate: v, bd: v
  141. })
  142. let vd = new Date(v);
  143. let week = this.data.weekMap[vd.getDay()];
  144. let list = this.data.eventList.filter(o => {
  145. return o.attenceDate == v;
  146. });
  147. list.map(o => {
  148. o.bt = o.beginTime.substring(0, 5);
  149. o.et = o.endTime.substring(0, 5);
  150. o.leaveFlag = this.canLeave(o)
  151. })
  152. if(this.data.newItem){
  153. for(var i in list){
  154. if(list[i].id == this.data.newItem.id){
  155. list[i].leaveFlag = false
  156. this.data.newItem = null
  157. break;
  158. }
  159. }
  160. }
  161. this.setData({
  162. 'date': v,
  163. 'week': week,
  164. 'dateList': [{
  165. items: list,
  166. date: v,
  167. week: week
  168. }]
  169. });
  170. },
  171. callSelectDate: function (d) {
  172. let v = d.detail.dateString;
  173. this.selectDate(v);
  174. },
  175. canLeave(item) {
  176. let timeCheck = (item.attenceDate.replace(/-/g, '/') > this.data.curDate.replace(/-/g, '/')); // 默认要大于当前时间,就是不能请当天的假
  177. let dateCheck = (item.attenceDate.replace(/-/g, '/') > this.data.curDate.replace(/-/g, '/')); // 默认要大于当前时间,就是不能请当天的假
  178. if (this.data.leaveTime > 0) { // 允许上课前()分钟请假
  179. // 判断当前时间是否跟上课时间相差 leaveTime 分钟
  180. let attenceTime = new Date(item.attenceDate.replace(/-/g, '/') + ' ' + item.beginTime)
  181. timeCheck = Math.floor((attenceTime.getTime() - new Date().getTime()) / 60000) >= this.data.leaveTime;
  182. }
  183. if (this.data.leaveDay > 0) { // 允许提前()天请假
  184. let attenceTime = item.attenceDate + ' 00:00:00'
  185. const temDate = new Date();
  186. temDate.setDate(temDate.getDate() + this.data.leaveDay);
  187. const curTemDate = temDate.getFullYear()+ "-" + (temDate.getMonth() + 1) + "-" + temDate.getDate() + ' 00:00:00';
  188. dateCheck = (curTemDate.replace(/-/g, '/') >= attenceTime.replace(/-/g, '/'));
  189. }
  190. return (item.isAttend === 0 && item.leaveCount > 0 && timeCheck && dateCheck && (item.status === 0 || item.status === 4));
  191. },
  192. })