theClasses.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.endDate;
  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. rs.map(o => {
  69. o.id = o.studentId
  70. })
  71. this.setData({ 'eventList': rs })
  72. }
  73. });
  74. util.apiPost(urls.get_holidays, { 'q.companyId': stu.orgId }).then((rs) => {
  75. if (rs && rs.length > 0) {
  76. this.setData({ 'holidayList': rs })
  77. }
  78. });
  79. }
  80. },
  81. /**
  82. * 生命周期函数--监听页面初次渲染完成
  83. */
  84. onReady: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面显示
  88. */
  89. onShow: function () {
  90. let date = this.data.bd
  91. if (date) {
  92. let t = this;
  93. setTimeout(() => { t.selectDate(date) }, 500)
  94. }
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. },
  121. selectDate: function (v) {
  122. this.setData({ curDate: v, bd: v })
  123. let vd = new Date(v);
  124. let week = this.data.weekMap[vd.getDay()];
  125. let list = this.data.eventList.filter(o => {
  126. return o.attenceDate == v;
  127. });
  128. let endDate = new Date(new Date().getTime() + 604800000)
  129. if (this.data.transferDay > 0) {
  130. const temDate = new Date();
  131. temDate.setDate(temDate.getDate() + this.data.transferDay);
  132. endDate = temDate;
  133. }
  134. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  135. endDate = util.formatTime(endDate).substring(0, 10).replace(/\//g, '-')
  136. let stu = wx.getStorageSync('student');
  137. let urls = urlDef.urls;
  138. util.apiPost(urls.get_attence_count + '&q.status=3&q.studentId=' + stu.studentId + '&q.month=' + v.substring(0, 7)).then((rs) => {
  139. this.setData({ monthCount: rs })
  140. list.map(o => {
  141. o.bt = o.beginTime.substring(11, 16);
  142. o.et = o.endTime.substring(11, 16);
  143. if (o.status == 0 && o.isAttend == 0) {
  144. if (this.data.monthCount >= this.data.transferCount) { // 本月内调过2次课的,不允许再调课
  145. o.transferFlag = false;
  146. } else {
  147. // 晚于当前时间才能调课(当天都不行) 2周内
  148. if (o.attenceDate > today && o.attenceDate <= endDate) {
  149. o.transferFlag = true;
  150. } else {
  151. o.transferFlag = false;
  152. }
  153. }
  154. }
  155. })
  156. this.setData({ 'date': v, 'week': week, 'dateList': [{ items: list, date: v, week: week }] });
  157. }).catch(e => { });
  158. },
  159. callSelectDate: function (d) {
  160. let v = d.detail.dateString;
  161. this.selectDate(v);
  162. }
  163. })