hot.js 4.6 KB

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