hot.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. winH: that.data.winH
  23. }
  24. }),
  25. // 搜索方法
  26. that.searchHandler = () => {
  27. if (that.data.hotInput.lenght !== 0) {
  28. wx.navigateTo({
  29. url: `../main/searchResult/searchResult?keyWords=${that.data.hotInput}`
  30. })
  31. }
  32. },
  33. // 输入框输入
  34. that.inputHandler = (e) => {
  35. that.setData({
  36. hotInput: e.detail.value
  37. });
  38. }
  39. // 打开全部课本
  40. that.openBooks = (e) => {
  41. wx.navigateTo({
  42. url: `../main/books/books`
  43. })
  44. }
  45. // 打开更多页面
  46. that.openMore = () => {
  47. wx.navigateTo({
  48. url: `../main/week/week`
  49. })
  50. }
  51. // 打开课程页面
  52. that.openClass = (e, lessonId) => {
  53. if (lessonId) {
  54. wx.navigateTo({
  55. url: `../main/class/class?id=${lessonId}`
  56. })
  57. } else {
  58. let id = e.currentTarget.dataset.classid;
  59. let title = e.currentTarget.dataset.title;
  60. wx.navigateTo({
  61. url: `../main/class/class?id=${id}&title=${title}`
  62. })
  63. }
  64. }
  65. // 打开用户作品页面
  66. that.openWorks = (e) => {
  67. let readId = e.currentTarget.dataset.readid;
  68. let title = e.currentTarget.dataset.title;
  69. wx.navigateTo({
  70. url: `../social/works/works?id=${readId}&title=${title}`
  71. })
  72. }
  73. that.getIndex = () => {
  74. const uid = wx.getStorageSync('uid');
  75. httpRequestApi.getIndex(
  76. uid
  77. ).success((res) => {
  78. const banner = res.data.data.banner;
  79. const recommend = res.data.data.recommendLesson;
  80. const bannerTemp = [];
  81. banner.forEach(item => {
  82. const temp = {};
  83. temp.url = item.boothContent;
  84. temp.type = item.operationType;
  85. temp.id = item.operationContent;
  86. bannerTemp.push(temp);
  87. });
  88. const recommendTemp = [];
  89. recommend.forEach(item => {
  90. const oTemp = {};
  91. oTemp.img = item.boothContent;
  92. oTemp.classId = item.operationContent;
  93. oTemp.title = item.title;
  94. oTemp.summary = item.summary;
  95. recommendTemp.push(oTemp);
  96. });
  97. let bannerIndex = 'hotData.banner';
  98. let recommendIndex = 'hotData.recommend';
  99. that.setData({
  100. [bannerIndex]: bannerTemp,
  101. [recommendIndex]: recommendTemp
  102. })
  103. })
  104. }
  105. that.getHotRecommend = (uid, pageNo, pageSize) => {
  106. httpRequestApi.getHotRecommend(
  107. uid,
  108. pageNo,
  109. pageSize
  110. ).success((res) => {
  111. console.log(res)
  112. const recommendRes = res.data.data.list;
  113. // const recommendWorks = [];
  114. recommendRes.forEach(item => {
  115. const temp = {};
  116. temp.title = item.userRead.title;
  117. temp.summary = item.userRead.summary;
  118. temp.img = item.userRead.iconImg;
  119. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  120. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  121. temp.classId = item.userRead.id;
  122. // recommendWorks.push(temp);
  123. that.data.hotData.hotWorks.push(temp);
  124. });
  125. const hotStr = 'hotData.hotWorks'
  126. that.setData({
  127. [hotStr]: that.data.hotData.hotWorks,
  128. recommendTotalNo: res.data.data.totalNo
  129. })
  130. })
  131. }
  132. // 去全部课本
  133. that.goToBooks = () => {
  134. wx.navigateTo({
  135. url: `../main/books/books`
  136. })
  137. }
  138. that.bannerTap = (e) => {
  139. const type = e.currentTarget.dataset.type;
  140. const id = e.currentTarget.dataset.id;
  141. switch (type) {
  142. case 'LESSON':
  143. that.openClass('tap', id);
  144. break;
  145. }
  146. }
  147. // 下拉加载
  148. that.scrollUpdate = (e) => {
  149. console.log(e)
  150. }
  151. that.getIndex();
  152. that.getHotRecommend(that.uid, 1, 3)
  153. }