hot.js 5.1 KB

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