hot.js 4.9 KB

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