scheduleSubject.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. var APIClient = require('../../../utils/APIClient.js');
  2. Page({
  3. data: {
  4. userInfo: wx.getStorageSync('userInfo'),
  5. swiperList: [],
  6. currentIndex: 0,
  7. currentId: '',
  8. id: '',
  9. showId: '',
  10. title: ''
  11. },
  12. onLoad(options) {
  13. console.log(wx.getStorageSync('userInfo'));
  14. this.setData({
  15. userInfo: wx.getStorageSync('userInfo'),
  16. id: options.id
  17. })
  18. if(options.title) {
  19. wx.setNavigationBarTitle({
  20. title: options.title
  21. })
  22. }
  23. if (options.showId) {
  24. this.getClassScheduleWeeklyQR(this.data.id, this.data.userInfo.id, options.showId);
  25. } else {
  26. this.getClassSchedule(this.data.id, this.data.userInfo.id);
  27. }
  28. },
  29. onShareAppMessage: function() {
  30. // 用户点击右上角分享
  31. let title = this.data.title
  32. let id = this.data.id
  33. let index = this.data.currentIndex
  34. let showId = this.data.swiperList[index].categoryId
  35. return {
  36. title: title, // 分享标题
  37. desc: title, // 分享描述
  38. path: `pages/index/index?id=${id}&showId=${showId}` // 分享路径
  39. }
  40. },
  41. switchContent(e) {
  42. console.log(e.detail.current);
  43. this.setData({
  44. currentIndex: e.detail.current
  45. })
  46. wx.setNavigationBarTitle({
  47. title: this.data.swiperList[e.detail.current].mainTitle
  48. })
  49. },
  50. // 获取课程列表
  51. getClassSchedule(itemId, userId) {
  52. APIClient.getClassScheduleWeekly(itemId, userId).success(function (res) {
  53. console.log('轮播图', res);
  54. if (res.data.success) {
  55. this.setData({
  56. swiperList: res.data.data.items,
  57. currentId: res.data.data.currentId
  58. })
  59. this.getCurrentIndex(this.data.currentId, this.data.swiperList)
  60. }
  61. }.bind(this))
  62. },
  63. // 获取课程列表qr
  64. getClassScheduleWeeklyQR(itemId, userId, showId) {
  65. APIClient.getClassScheduleWeeklyQR(itemId, userId, showId).success(function (res) {
  66. console.log('轮播图', res);
  67. if (res.data.success) {
  68. this.setData({
  69. swiperList: res.data.data.items,
  70. currentId: res.data.data.currentId
  71. })
  72. this.getCurrentIndex(this.data.currentId, this.data.swiperList)
  73. }
  74. }.bind(this))
  75. },
  76. toScheduleSubjectInner(e) {
  77. let id = e.currentTarget.dataset.id
  78. console.log(id);
  79. wx.navigateTo({
  80. url: `/pages/schedule/scheduleSubjectInner/scheduleSubjectInner?id=${id}`
  81. })
  82. },
  83. getCurrentIndex(id, arr) {
  84. let len = arr.length;
  85. for (let i = 0; i < len; i++) {
  86. if (arr[i].categoryId === id) {
  87. this.setData({
  88. currentIndex: i
  89. })
  90. return;
  91. }
  92. }
  93. }
  94. })