theClasses.js 4.6 KB

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