theClasses.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/theClasses/theClasses.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. aheadTime: 0,
  11. eventList: [],
  12. holidayList: [],
  13. dateList: [],
  14. date: null,
  15. week: 0,
  16. weekMap: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  17. tipList: [
  18. '1.每月仅有2次调课机会。如撤销,默认是为使用一次调整机会\r\n\r\n',
  19. '2.允许调课至原课程前后一周内。例如:今天11-30日,可调整到11.23到12.07之间的课程\r\n\r\n',
  20. '3.可提前7天进行调课\r\n\r\n',
  21. '4.调入后的课程,不可再调及请假'
  22. ],
  23. transferDay: 0,
  24. transferCount: 2,
  25. monthCount: 0,
  26. curDate: null,
  27. bd: null
  28. },
  29. getTip: function () {
  30. var str = ''
  31. for (var i in this.data.tipList) {
  32. str += this.data.tipList[i]
  33. }
  34. wx.showModal({
  35. title: '调课说明',
  36. content: str,
  37. showCancel: false,//是否显示取消按钮
  38. cancelText: "否",//默认是“取消”
  39. cancelColor: '#999999',//取消文字的颜色
  40. confirmText: "我知道了",//默认是“确定”
  41. confirmColor: 'skyblue',//确定文字的颜色
  42. })
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. let date = options.beginDate;
  49. if (date) {
  50. this.setData({ bd: date })
  51. }
  52. const urls = urlDef.urls;
  53. let stu = wx.getStorageSync('student');
  54. if (stu) {
  55. util.apiPost(urls.get_sys_params + '&q.orgId=' + stu.orgId + '&q.id=1000_8').then((rs) => {
  56. if (rs && rs.length > 0) {
  57. this.setData({ transferDay: parseInt(rs[0].sysVal, 10) })
  58. }
  59. });
  60. util.apiPost(urls.get_sys_params, { 'q.orgId': stu.orgId, 'q.id': 'f8158acabeeb44ec9ff651aade6b295f' }).then((rs) => {
  61. if (rs && rs.length > 0) {
  62. // 将分钟转为毫秒
  63. this.setData({ 'aheadTime': parseInt(rs[0].sysVal, 10) * 60 * 1000 })
  64. }
  65. });
  66. util.apiPost(urls.get_schedule_month, { 'q.studentId': stu.studentId }).then((rs) => {
  67. if (rs && rs.length > 0) {
  68. this.setData({ 'eventList': rs })
  69. }
  70. });
  71. util.apiPost(urls.get_holidays, { 'q.companyId': stu.orgId }).then((rs) => {
  72. if (rs && rs.length > 0) {
  73. this.setData({ 'holidayList': rs })
  74. }
  75. });
  76. }
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. let date = this.data.bd
  88. if (date) {
  89. let t = this;
  90. setTimeout(() => { t.selectDate(date) }, 500)
  91. }
  92. },
  93. /**
  94. * 生命周期函数--监听页面隐藏
  95. */
  96. onHide: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面卸载
  100. */
  101. onUnload: function () {
  102. },
  103. /**
  104. * 页面相关事件处理函数--监听用户下拉动作
  105. */
  106. onPullDownRefresh: function () {
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom: function () {
  112. },
  113. /**
  114. * 用户点击右上角分享
  115. */
  116. onShareAppMessage: function () {
  117. },
  118. selectDate: function (v) {
  119. this.setData({ curDate: v })
  120. let vd = new Date(v);
  121. let week = this.data.weekMap[vd.getDay()];
  122. let list = this.data.eventList.filter(o => {
  123. return o.attenceDate == v;
  124. });
  125. let endDate = new Date(new Date().getTime() + 604800000)
  126. if (this.data.transferDay > 0) {
  127. const temDate = new Date();
  128. temDate.setDate(temDate.getDate() + this.data.transferDay);
  129. endDate = temDate;
  130. }
  131. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  132. endDate = util.formatTime(endDate).substring(0, 10).replace(/\//g, '-')
  133. let stu = wx.getStorageSync('student');
  134. let urls = urlDef.urls;
  135. util.apiPost(urls.get_attence_count + '&q.status=3&q.studentId=' + stu.studentId + '&q.month=' + v.substring(0, 7)).then((rs) => {
  136. this.setData({ monthCount: rs })
  137. list.map(o => {
  138. o.bt = o.beginTime.substring(11, 16);
  139. o.et = o.endTime.substring(11, 16);
  140. if (o.status == 0 && o.isAttend == 0) {
  141. if (this.data.monthCount >= this.data.transferCount) { // 本月内调过2次课的,不允许再调课
  142. o.transferFlag = false;
  143. } else {
  144. // 晚于当前时间才能调课(当天都不行) 2周内
  145. if (o.attenceDate > today && o.attenceDate <= endDate) {
  146. o.transferFlag = true;
  147. } else {
  148. o.transferFlag = false;
  149. }
  150. }
  151. }
  152. })
  153. this.setData({ 'date': v, 'week': week, 'dateList': [{ items: list, date: v, week: week }] });
  154. }).catch(e => { });
  155. },
  156. callSelectDate: function (d) {
  157. let v = d.detail.dateString;
  158. this.selectDate(v);
  159. }
  160. })