scheduleSubject.js 2.6 KB

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