leaveDetail.js 4.3 KB

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