hot.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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: false,
  11. swiperCurrent: 0,
  12. interval: 5000,
  13. duration: 700,
  14. circular: true,
  15. hotWareCardFirst: 'hotWareCardFirst',
  16. hotWareCard: 'hotWareCard',
  17. hotSearch: '',
  18. banner: [],
  19. recommend: [],
  20. hotWorks: [],
  21. winH: that.data.winH,
  22. searchIcon: true,
  23. unReadMessageNum: 0,
  24. myCourse: [],
  25. inputFocus: false,
  26. inputValue: ''
  27. // circular: true
  28. }
  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. const str = 'hotData.inputValue';
  39. that.setData({
  40. [str]: ''
  41. })
  42. },
  43. // 输入框获取焦点 放大镜消失
  44. that.searchIconDisappear = () => {
  45. const str = 'hotData.searchIcon'
  46. that.setData({
  47. [str]: false
  48. })
  49. },
  50. that.searchIconCome = () => {
  51. const str = 'hotData.searchIcon'
  52. that.setData({
  53. [str]: true
  54. })
  55. }
  56. // 输入框输入
  57. that.inputHandler = (e) => {
  58. that.setData({
  59. hotInput: e.detail.value
  60. });
  61. },
  62. // 输入框聚焦
  63. that.inputFocus = () => {
  64. const str = 'hotData.inputFocus'
  65. that.setData({
  66. [str]: true
  67. });
  68. console.log(that.data.hotData.inputFocus)
  69. },
  70. // 打开全部课本
  71. that.openBooks = (e) => {
  72. wx.navigateTo({
  73. url: `../main/books/books`
  74. })
  75. }
  76. // 打开更多页面
  77. that.openMore = () => {
  78. wx.navigateTo({
  79. url: `../main/week/week`
  80. })
  81. }
  82. // 打开课程页面
  83. that.openClass = (e, lessonId) => {
  84. if (lessonId) {
  85. wx.navigateTo({
  86. url: `../main/class/class?id=${lessonId}`
  87. })
  88. } else {
  89. let id = e.currentTarget.dataset.classid;
  90. let title = e.currentTarget.dataset.title;
  91. wx.navigateTo({
  92. url: `../main/class/class?id=${id}&title=${title}`
  93. })
  94. }
  95. }
  96. // 打开用户作品页面
  97. that.openWorks = (e) => {
  98. let readId = e.currentTarget.dataset.readid;
  99. let title = e.currentTarget.dataset.title;
  100. wx.navigateTo({
  101. url: `../social/works/works?id=${readId}&title=${title}`
  102. })
  103. }
  104. that.getIndex = () => {
  105. const uid = wx.getStorageSync('uid');
  106. httpRequestApi.getIndex(
  107. uid
  108. ).success((res) => {
  109. const recommend = res.data.data.recommendLesson;
  110. const recommendTemp = [];
  111. recommend.forEach(item => {
  112. const oTemp = {};
  113. oTemp.img = item.boothContent;
  114. oTemp.classId = item.operationContent;
  115. oTemp.title = item.title;
  116. oTemp.summary = item.summary;
  117. recommendTemp.push(oTemp);
  118. });
  119. let recommendIndex = 'hotData.recommend';
  120. that.setData({
  121. [recommendIndex]: recommendTemp
  122. });
  123. httpRequestApi.userIntoPage('pages/index/index', '首页推荐').success((res) => {
  124. })
  125. })
  126. }
  127. that.getHotRecommend = (uid) => {
  128. httpRequestApi.getHotRecommend(
  129. uid
  130. ).success((res) => {
  131. // 点击切换按钮时 只刷新我的课程和未读消息 官方推荐和热门不加载
  132. const recommendRes = res.data.data;
  133. console.log(that.data.hotData.hotWorks.length)
  134. if (that.data.hotData.hotWorks.length > 0) {
  135. const myCourseStr = 'hotData.myCourse'
  136. const unReadMessageNum = 'hotData.unReadMessageNum'
  137. console.log(recommendRes)
  138. that.setData({
  139. [myCourseStr]: recommendRes.myCourse,
  140. [unReadMessageNum]: recommendRes.unreadCount
  141. })
  142. return;
  143. }
  144. recommendRes.hotReader.forEach(item => {
  145. const temp = {};
  146. temp.title = item.userRead.title;
  147. temp.summary = item.userRead.summary;
  148. temp.img = item.userRead.iconImg;
  149. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  150. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  151. temp.classId = item.userRead.id;
  152. temp.time = formatDate(item.userRead.gmtCreated, 3);
  153. temp.avatar = item.user ? item.user.avatar : '';
  154. temp.profession = item.user ? item.user.profession : '';
  155. temp.uid = item.user ? item.user.uid : '';
  156. // temp.avatar = item.user.avatar;
  157. temp.nickName = item.user ? item.user.wechatName : '';
  158. // recommendWorks.push(temp);
  159. that.data.hotData.hotWorks.push(temp);
  160. });
  161. const hotStr = 'hotData.hotWorks'
  162. const myCourseStr = 'hotData.myCourse'
  163. const unReadMessageNum = 'hotData.unReadMessageNum'
  164. console.log(recommendRes)
  165. that.setData({
  166. [hotStr]: that.data.hotData.hotWorks,
  167. [myCourseStr]: recommendRes.myCourse,
  168. [unReadMessageNum]: recommendRes.unreadCount,
  169. unfinishedCount: recommendRes.unfinishedCount
  170. })
  171. })
  172. }
  173. that.getHotRecommendSecond = (uid,pageNo,pageSize) =>{
  174. httpRequestApi.getHotRecommendSecond(uid,pageNo,pageSize).success(res => {
  175. console.log(res)
  176. const recommendRes = res.data.data.list;
  177. if(recommendRes.length === 0) return;
  178. // const recommendWorks = [];
  179. recommendRes.forEach(item => {
  180. const temp = {};
  181. temp.title = item.userRead.title;
  182. temp.summary = item.userRead.summary;
  183. temp.img = item.userRead.iconImg;
  184. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  185. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  186. temp.classId = item.userRead.id;
  187. temp.time = formatDate(item.userRead.gmtCreated, 3);
  188. temp.avatar = item.user.avatar;
  189. temp.profession = item.user.profession;
  190. temp.uid = item.user.uid;
  191. // temp.avatar = item.user.avatar;
  192. temp.nickName = item.user.wechatName;
  193. // recommendWorks.push(temp);
  194. that.data.hotData.hotWorks.push(temp);
  195. });
  196. const hotStr = 'hotData.hotWorks'
  197. that.setData({
  198. [hotStr]: that.data.hotData.hotWorks,
  199. recommendTotalNo: res.data.data.totalNo
  200. })
  201. })
  202. }
  203. // 去全部课本
  204. that.goToBooks = () => {
  205. wx.navigateTo({
  206. url: `../main/books/books`
  207. })
  208. }
  209. that.bannerTap = (e) => {
  210. const type = e.currentTarget.dataset.type;
  211. const id = e.currentTarget.dataset.id;
  212. switch (type) {
  213. case 'LESSON':
  214. that.openClass('tap', id);
  215. break;
  216. }
  217. },
  218. that.goToUsers = (e) => {
  219. console.log(e)
  220. let uid = e.currentTarget.dataset.uid;
  221. wx.navigateTo({
  222. url: `../../pages/user/myworks/myworks?uid=${uid}`
  223. });
  224. }
  225. // 下拉加载
  226. that.scrollUpdate = (e) => {
  227. console.log(e)
  228. }
  229. console.log(that.data.hotData.recommend)
  230. if(wx.getStorageSync('uid')){
  231. that.getIndex();
  232. that.getHotRecommend(wx.getStorageSync('uid'));
  233. }
  234. // that.getIndex();
  235. // 获取全部课本
  236. // that.getBookList();
  237. // that.swiperChange = (e) => {
  238. // const str = 'hotData.swiperCurrent'
  239. // that.setData({
  240. // [str]: e.detail.current
  241. // });
  242. // }
  243. //跳转到课程详情
  244. that.goToBook = function (e) {
  245. console.log(e.currentTarget.dataset)
  246. let id = e.currentTarget.dataset.id;
  247. let title = e.currentTarget.dataset.title;
  248. console.log(id)
  249. wx.navigateTo({
  250. url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
  251. })
  252. }
  253. that.swiperChange = (e) => {
  254. const str = 'hotData.swiperCurrent'
  255. that.setData({
  256. [str]: e.detail.current
  257. });
  258. }
  259. }