hot.js 4.0 KB

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