scheduleSubject.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. if(options.scene) {
  15. // let id = util.convertObject(decodeURIComponent(options.scene)).id;
  16. this.setData({
  17. userInfo: wx.getStorageSync('userInfo'),
  18. // id: id
  19. id: options.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. this.setData({
  52. currentIndex: e.detail.current
  53. })
  54. wx.setNavigationBarTitle({
  55. title: this.data.swiperList[e.detail.current].mainTitle
  56. })
  57. },
  58. // 获取课程列表
  59. getClassSchedule(itemId, userId) {
  60. APIClient.getClassScheduleWeekly(itemId, userId).success(function (res) {
  61. console.log('轮播图', res);
  62. if (res.data.success) {
  63. this.setData({
  64. swiperList: res.data.data.items,
  65. currentId: res.data.data.currentId
  66. })
  67. this.getCurrentIndex(this.data.currentId, this.data.swiperList)
  68. }
  69. }.bind(this))
  70. },
  71. // 获取课程列表qr
  72. getClassScheduleWeeklyQR(itemId, userId, showId) {
  73. APIClient.getClassScheduleWeeklyQR(itemId, userId, showId).success(function (res) {
  74. if (res.data.success) {
  75. this.setData({
  76. swiperList: res.data.data.items,
  77. currentId: res.data.data.currentId
  78. })
  79. this.getCurrentIndex(this.data.currentId, this.data.swiperList)
  80. }
  81. }.bind(this))
  82. },
  83. toScheduleSubjectInner(e) {
  84. let id = e.currentTarget.dataset.id
  85. wx.navigateTo({
  86. url: `/pages/schedule/scheduleSubjectInner/scheduleSubjectInner?id=${id}`
  87. })
  88. },
  89. getCurrentIndex(id, arr) {
  90. let len = arr.length;
  91. for (let i = 0; i < len; i++) {
  92. if (arr[i].categoryId === id) {
  93. this.setData({
  94. currentIndex: i
  95. })
  96. return;
  97. }
  98. }
  99. }
  100. })