schedule.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // pages/schedule/schedule.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. curStu: null,
  11. aheadTime: 0,
  12. eventList: [],
  13. holidayList: [],
  14. dateList: [],
  15. date: null,
  16. week: 0,
  17. weekMap: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  18. bd: null
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. let date = options.beginDate;
  25. if (date) {
  26. this.setData({ bd: date })
  27. }
  28. const urls = urlDef.urls;
  29. let stu = wx.getStorageSync('student');
  30. if (stu) {
  31. this.setData({ 'curStu': stu });
  32. util.apiPost(urls.get_sys_params, { 'q.orgId': stu.orgId, 'q.id': 'f8158acabeeb44ec9ff651aade6b295f' }).then((rs) => {
  33. if (rs && rs.length > 0) {
  34. // 将分钟转为毫秒
  35. this.setData({ 'aheadTime': parseInt(rs[0].sysVal, 10) * 60 * 1000 })
  36. }
  37. });
  38. util.apiPost(urls.get_schedule_month, { 'q.studentId': stu.studentId }).then((rs) => {
  39. if (rs && rs.length > 0) {
  40. this.setData({ 'eventList': rs })
  41. }
  42. });
  43. util.apiPost(urls.get_holidays, { 'q.companyId': stu.orgId }).then((rs) => {
  44. if (rs && rs.length > 0) {
  45. this.setData({ 'holidayList': rs })
  46. }
  47. });
  48. }
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. let date = this.data.bd
  60. if (date) {
  61. let t = this;
  62. setTimeout(() => { t.selectDate(date) }, 500)
  63. }
  64. },
  65. /**
  66. * 生命周期函数--监听页面隐藏
  67. */
  68. onHide: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面卸载
  72. */
  73. onUnload: function () {
  74. },
  75. /**
  76. * 页面相关事件处理函数--监听用户下拉动作
  77. */
  78. onPullDownRefresh: function () {
  79. },
  80. /**
  81. * 页面上拉触底事件的处理函数
  82. */
  83. onReachBottom: function () {
  84. },
  85. /**
  86. * 用户点击右上角分享
  87. */
  88. onShareAppMessage: function () {
  89. },
  90. selectDate: function (v) {
  91. let vd = new Date(v);
  92. let week = this.data.weekMap[vd.getDay()];
  93. let list = this.data.eventList.filter(o => {
  94. return o.attenceDate == v;
  95. });
  96. list.map(o => {
  97. o.bt = o.beginTime.substring(11, 16);
  98. o.et = o.endTime.substring(11, 16);
  99. })
  100. this.setData({ 'date': v, 'week': week, 'dateList': [{ items: list, date: v, week: week }] });
  101. },
  102. callSelectDate: function (d) {
  103. let v = d.detail.dateString;
  104. this.selectDate(v);
  105. }
  106. })