leaveDetail.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // pages/leaveDetail/leaveDetail.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. index: 0,
  11. array: ['事假', '病假', '其他'],
  12. item: {},
  13. content: ''
  14. },
  15. getText: function (e) {
  16. this.setData({ content: e.detail.value })
  17. },
  18. bindPickerChange: function (e) {
  19. const index = e.detail.value
  20. this.setData({
  21. index
  22. })
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. let o = JSON.parse(options.data)
  29. let s = o.source
  30. s.bt = s.beginTime.substring(0, 5)
  31. this.setData({ item: s })
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面隐藏
  45. */
  46. onHide: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面卸载
  50. */
  51. onUnload: function () {
  52. },
  53. /**
  54. * 页面相关事件处理函数--监听用户下拉动作
  55. */
  56. onPullDownRefresh: function () {
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. onReachBottom: function () {
  62. },
  63. /**
  64. * 用户点击右上角分享
  65. */
  66. onShareAppMessage: function () {
  67. },
  68. toSave: function () {
  69. if (this.data.item.leaveCount <= 0) {
  70. wx.showToast({
  71. title: '该课程剩余请假次数不足,请联系前台!'
  72. });
  73. return;
  74. }
  75. const urls = urlDef.urls;
  76. let stu = wx.getStorageSync('student')
  77. util.apiPost(urls.get_params + '&q.orgId=' + stu.orgId + '&q.detailId=1000_1').then((rs) => {
  78. let timeoutDay = 0;
  79. if (rs && rs.length > 0) {
  80. timeoutDay = parseInt(rs[0].sysVal, 10);
  81. }
  82. if (timeoutDay > 0) {// 计算本课程上课时间,跟当前时间相隔多少天,这个天不能超过 timeoutDay
  83. let courseDate = new Date(this.data.item.attenceDate)
  84. let now = new Date();
  85. let day = Math.ceil((courseDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
  86. if (day > timeoutDay) { // 超过请假范围了
  87. wx.showToast({ title: '只能请' + timeoutDay + '天内的假' });
  88. return;
  89. }
  90. }
  91. let that = this
  92. wx.showModal({
  93. title: '确认信息',
  94. content: '确定要执行请假申请?',
  95. showCancel: true,
  96. cancelText: "否",
  97. confirmText: "是",
  98. success: function (res) {
  99. if (res.cancel) { } else {
  100. that.doRealSave()
  101. }
  102. }
  103. })
  104. });
  105. },
  106. doRealSave: function () {
  107. const urls = urlDef.urls;
  108. let stu = wx.getStorageSync('student')
  109. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  110. let leaveReason = this.data.array[this.data.index];
  111. if (this.data.index == 2) {
  112. leaveReason = this.data.content
  113. }
  114. let attenceData = {
  115. status: '1',
  116. studentId: stu.studentId,
  117. operator: stu.studentId,
  118. orgId: stu.orgId,
  119. leaveDate: today,
  120. leaveReason: leaveReason,
  121. goodList: [
  122. {
  123. beginTime: this.data.item.beginTime,
  124. attenceStudentId: this.data.item.id,
  125. attenceTeacherId: this.data.item.attenceTeacherId,
  126. kindId: this.data.item.kindId,
  127. status: this.data.item.status,
  128. switchingId: this.data.item.switchingId
  129. }
  130. ]
  131. };
  132. util.apiPost(urls.student_leave, attenceData, 'application/json').then(rs => {
  133. if (rs.message) {
  134. wx.showToast({
  135. title: '请假失败,' + rs.message,
  136. icon: 'none'
  137. })
  138. return
  139. }
  140. wx.showModal({
  141. title: '请假申请成功',
  142. content: '需要立即预约补课吗?',
  143. showCancel: true,
  144. cancelText: "取消",
  145. confirmText: "预约补课",
  146. success: function (res) {
  147. if (res.cancel) {
  148. setTimeout(() => {
  149. wx.navigateBack({
  150. delta: 1, // 返回上一级页面。
  151. success: function () {
  152. console.log('成功!')
  153. }
  154. })
  155. }, 1000)
  156. } else {
  157. wx.redirectTo({
  158. url: "/pages/lessons/lessons"
  159. })
  160. }
  161. }
  162. })
  163. })
  164. }
  165. })