hot.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import httpRequestApi from '../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../utils/util';
  5. export const hotInit = (that) => {
  6. if (!that.data.hotData) {
  7. that.setData({
  8. hotData: {
  9. title: '热门',
  10. autoplay: true,
  11. interval: 5000,
  12. duration: 700,
  13. circular: true,
  14. hotWareCardFirst: 'hotWareCardFirst',
  15. hotWareCard: 'hotWareCard',
  16. hotSearch: '',
  17. banner: [],
  18. recommend: [],
  19. hotWorks: [],
  20. winH: that.data.winH,
  21. searchIcon: true,
  22. unReadMessageNum: 0,
  23. myCourse: [],
  24. inputFocus: false
  25. // circular: true
  26. }
  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.inputFocus = () => {
  58. const str = 'hotData.inputFocus'
  59. that.setData({
  60. [str]: true
  61. });
  62. console.log(that.data.hotData.inputFocus)
  63. },
  64. // 打开全部课本
  65. that.openBooks = (e) => {
  66. wx.navigateTo({
  67. url: `../main/books/books`
  68. })
  69. }
  70. // 打开更多页面
  71. that.openMore = () => {
  72. wx.navigateTo({
  73. url: `../main/week/week`
  74. })
  75. }
  76. // 打开课程页面
  77. that.openClass = (e, lessonId) => {
  78. if (lessonId) {
  79. wx.navigateTo({
  80. url: `../main/class/class?id=${lessonId}`
  81. })
  82. } else {
  83. let id = e.currentTarget.dataset.classid;
  84. let title = e.currentTarget.dataset.title;
  85. wx.navigateTo({
  86. url: `../main/class/class?id=${id}&title=${title}`
  87. })
  88. }
  89. }
  90. // 打开用户作品页面
  91. that.openWorks = (e) => {
  92. let readId = e.currentTarget.dataset.readid;
  93. let title = e.currentTarget.dataset.title;
  94. wx.navigateTo({
  95. url: `../social/works/works?id=${readId}&title=${title}`
  96. })
  97. }
  98. that.getIndex = () => {
  99. const uid = wx.getStorageSync('uid');
  100. httpRequestApi.getIndex(
  101. uid
  102. ).success((res) => {
  103. const recommend = res.data.data.recommendLesson;
  104. const recommendTemp = [];
  105. recommend.forEach(item => {
  106. const oTemp = {};
  107. oTemp.img = item.boothContent;
  108. oTemp.classId = item.operationContent;
  109. oTemp.title = item.title;
  110. oTemp.summary = item.summary;
  111. recommendTemp.push(oTemp);
  112. });
  113. let recommendIndex = 'hotData.recommend';
  114. that.setData({
  115. [recommendIndex]: recommendTemp
  116. });
  117. httpRequestApi.userIntoPage('pages/index/index', '首页推荐').success((res) => {
  118. })
  119. })
  120. }
  121. that.getHotRecommend = (uid) => {
  122. httpRequestApi.getHotRecommend(
  123. uid
  124. ).success((res) => {
  125. // 点击切换按钮时 只刷新我的课程和未读消息 官方推荐和热门不加载
  126. const recommendRes = res.data.data;
  127. console.log(that.data.hotData.hotWorks.length)
  128. if (that.data.hotData.hotWorks.length > 0) {
  129. const myCourseStr = 'hotData.myCourse'
  130. const unReadMessageNum = 'hotData.unReadMessageNum'
  131. console.log(recommendRes)
  132. that.setData({
  133. [myCourseStr]: recommendRes.myCourse,
  134. [unReadMessageNum]: recommendRes.unreadCount
  135. })
  136. return;
  137. }
  138. recommendRes.hotReader.forEach(item => {
  139. const temp = {};
  140. temp.title = item.userRead.title;
  141. temp.summary = item.userRead.summary;
  142. temp.img = item.userRead.iconImg;
  143. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  144. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  145. temp.classId = item.userRead.id;
  146. temp.time = formatDate(item.userRead.gmtCreated, 3);
  147. temp.avatar = item.user ? item.user.avatar : '';
  148. temp.profession = item.user ? item.user.profession : '';
  149. temp.uid = item.user ? item.user.uid : '';
  150. // temp.avatar = item.user.avatar;
  151. temp.nickName = item.user ? item.user.wechatName : '';
  152. // recommendWorks.push(temp);
  153. that.data.hotData.hotWorks.push(temp);
  154. });
  155. const hotStr = 'hotData.hotWorks'
  156. const myCourseStr = 'hotData.myCourse'
  157. const unReadMessageNum = 'hotData.unReadMessageNum'
  158. console.log(recommendRes)
  159. that.setData({
  160. [hotStr]: that.data.hotData.hotWorks,
  161. [myCourseStr]: recommendRes.myCourse,
  162. [unReadMessageNum]: recommendRes.unreadCount,
  163. unfinishedCount: recommendRes.unfinishedCount
  164. })
  165. })
  166. }
  167. // 去全部课本
  168. that.goToBooks = () => {
  169. wx.navigateTo({
  170. url: `../main/books/books`
  171. })
  172. }
  173. that.bannerTap = (e) => {
  174. const type = e.currentTarget.dataset.type;
  175. const id = e.currentTarget.dataset.id;
  176. switch (type) {
  177. case 'LESSON':
  178. that.openClass('tap', id);
  179. break;
  180. }
  181. },
  182. that.goToUsers = (e) => {
  183. console.log(e)
  184. let uid = e.currentTarget.dataset.uid;
  185. wx.navigateTo({
  186. url: `../../pages/user/myworks/myworks?uid=${uid}`
  187. });
  188. }
  189. // 下拉加载
  190. that.scrollUpdate = (e) => {
  191. console.log(e)
  192. }
  193. console.log(that.data.hotData.recommend)
  194. if(wx.getStorageSync('uid')){
  195. that.getIndex();
  196. that.getHotRecommend(wx.getStorageSync('uid'));
  197. }
  198. // that.getIndex();
  199. // 获取全部课本
  200. // that.getBookList();
  201. that.swiperChange = (e) => {
  202. const str = 'hotData.swiperCurrent'
  203. that.setData({
  204. [str]: e.detail.current
  205. });
  206. }
  207. //跳转到课程详情
  208. that.goToBook = function (e) {
  209. console.log(e.currentTarget.dataset)
  210. let id = e.currentTarget.dataset.id;
  211. let title = e.currentTarget.dataset.title;
  212. console.log(id)
  213. wx.navigateTo({
  214. url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
  215. })
  216. }
  217. that.swiperChange = (e) => {
  218. const str = 'hotData.swiperCurrent'
  219. that.setData({
  220. [str]: e.detail.current
  221. });
  222. }
  223. }