schedule.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.endDate;
  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. this.initList()
  43. });
  44. util.apiPost(urls.get_holidays, { 'q.companyId': stu.orgId }).then((rs) => {
  45. if (rs && rs.length > 0) {
  46. this.setData({ 'holidayList': rs })
  47. }
  48. });
  49. }
  50. },
  51. initList:function(){
  52. let date = this.data.bd
  53. if (date) {
  54. let t = this;
  55. t.selectDate(date)
  56. }
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面显示
  65. */
  66. onShow: function () {
  67. let date = this.data.bd
  68. if (date) {
  69. let t = this;
  70. t.selectDate(date)
  71. }
  72. },
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面卸载
  80. */
  81. onUnload: function () {
  82. },
  83. /**
  84. * 页面相关事件处理函数--监听用户下拉动作
  85. */
  86. onPullDownRefresh: function () {
  87. },
  88. /**
  89. * 页面上拉触底事件的处理函数
  90. */
  91. onReachBottom: function () {
  92. },
  93. /**
  94. * 用户点击右上角分享
  95. */
  96. onShareAppMessage: function () {
  97. },
  98. selectDate: function (v) {
  99. let vd = new Date(v);
  100. let week = this.data.weekMap[vd.getDay()];
  101. let list = this.data.eventList.filter(o => {
  102. return o.attenceDate == v;
  103. });
  104. list.map(o => {
  105. o.bt = o.beginTime.substring(11, 16);
  106. o.et = o.endTime.substring(11, 16);
  107. })
  108. this.setData({ 'date': v, 'week': week, 'dateList': [{ items: list, date: v, week: week }] });
  109. },
  110. callSelectDate: function (d) {
  111. let v = d.detail.dateString;
  112. this.selectDate(v);
  113. }
  114. })