hot.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import httpRequestApi from '../../utils/APIClient';
  2. export const hotInit = (that) => {
  3. that.setData({
  4. hotData: {
  5. title: '热门',
  6. imgUrls: [
  7. '../../static/image/timg.jpg',
  8. '../../static/image/timg.jpg',
  9. '../../static/image/timg.jpg'
  10. ],
  11. indicatorDots: true,
  12. autoplay: true,
  13. interval: 5000,
  14. duration: 700,
  15. circular: true,
  16. hotWareCardFirst: 'hotWareCardFirst',
  17. hotWareCard: 'hotWareCard',
  18. hotSearch: '鹅鹅鹅',
  19. banner: [],
  20. recommend: [],
  21. hotWorks: [],
  22. }
  23. }),
  24. // 搜索方法
  25. that.searchHandler = () => {
  26. if (that.data.hotInput.lenght !== 0) {
  27. wx.navigateTo({
  28. url: `../main/searchResult/searchResult?keyWords=${that.data.hotInput}`
  29. })
  30. }
  31. },
  32. // 输入框输入
  33. that.inputHandler = (e) => {
  34. that.setData({
  35. hotInput: e.detail.value
  36. });
  37. }
  38. // 打开课程页面
  39. that.openBooks = (e) => {
  40. wx.navigateTo({
  41. url: `../main/books/books`
  42. })
  43. }
  44. // 打开课程页面
  45. that.openClass = (e, lessonId) => {
  46. if (lessonId) {
  47. wx.navigateTo({
  48. url: `../main/class/class?id=${lessonId}`
  49. })
  50. } else {
  51. let id = e.currentTarget.dataset.classid;
  52. let title = e.currentTarget.dataset.title;
  53. wx.navigateTo({
  54. url: `../main/class/class?id=${id}&title=${title}`
  55. })
  56. }
  57. }
  58. // 打开用户作品页面
  59. that.openWorks = (e) => {
  60. let readId = e.currentTarget.dataset.readid;
  61. let title = e.currentTarget.dataset.title;
  62. wx.navigateTo({
  63. url: `../social/works/works?id=${readId}&title=${title}`
  64. })
  65. }
  66. that.getIndex = () => {
  67. const uid = wx.getStorageSync('uid');
  68. httpRequestApi.getIndex(
  69. uid
  70. ).success((res) => {
  71. const banner = res.data.data.banner;
  72. const recommend = res.data.data.recommendLesson;
  73. const bannerTemp = [];
  74. banner.forEach(item => {
  75. const temp = {};
  76. temp.url = item.boothContent;
  77. temp.type = item.operationType;
  78. temp.id = item.operationContent;
  79. bannerTemp.push(temp);
  80. });
  81. const recommendTemp = [];
  82. recommend.forEach(item => {
  83. const oTemp = {};
  84. oTemp.img = item.boothContent;
  85. oTemp.classId = item.operationContent;
  86. oTemp.title = item.title;
  87. oTemp.grade = item.summary;
  88. recommendTemp.push(oTemp);
  89. });
  90. let bannerIndex = 'hotData.banner';
  91. let recommendIndex = 'hotData.recommend';
  92. that.setData({
  93. [bannerIndex]: bannerTemp,
  94. [recommendIndex]: recommendTemp
  95. })
  96. })
  97. }
  98. that.getHotRecommend = (uid, pageNo, pageSize) => {
  99. httpRequestApi.getHotRecommend(
  100. uid,
  101. pageNo,
  102. pageSize
  103. ).success((res) => {
  104. const recommendRes = res.data.data.list;
  105. const recommendWorks = [];
  106. recommendRes.forEach(item => {
  107. const temp = {};
  108. temp.title = item.userRead.title;
  109. temp.grade = item.userRead.title;
  110. temp.img = item.userRead.iconImg;
  111. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  112. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  113. temp.classId = item.userRead.id;
  114. recommendWorks.push(temp);
  115. });
  116. const hotStr = 'hotData.hotWorks'
  117. that.setData({
  118. [hotStr]: recommendWorks
  119. })
  120. })
  121. }
  122. // 去全部课本
  123. that.goToBooks = () => {
  124. wx.navigateTo({
  125. url: `../main/books/books`
  126. })
  127. }
  128. that.bannerTap = (e) => {
  129. const type = e.currentTarget.dataset.type;
  130. const id = e.currentTarget.dataset.id;
  131. switch (type) {
  132. case 'LESSON':
  133. that.openClass('tap',id);
  134. break;
  135. }
  136. }
  137. that.getIndex();
  138. that.getHotRecommend(1, 1, 3)
  139. }