hot.js 4.9 KB

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