hot.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 isMessageNormal = 'hotData.isMessageNormal'
  137. const unReadMessageContent = 'hotData.unReadMessageContent'
  138. // unread为true时显示 未读消息,unread为false时显示通知消息,并且通知消息不可读
  139. that.setData({
  140. [myCourseStr]: recommendRes.myCourse,
  141. [isMessageNormal]: recommendRes.unread,
  142. [unReadMessageContent]: recommendRes.unread ? recommendRes.unreadMsg.content : recommendRes.annunciateMsg.content,
  143. })
  144. return;
  145. }
  146. recommendRes.hotReader.forEach(item => {
  147. const temp = {};
  148. temp.title = item.userRead.title;
  149. temp.summary = item.userRead.summary;
  150. temp.img = item.userRead.iconImg;
  151. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  152. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  153. temp.classId = item.userRead.id;
  154. temp.time = formatDate(item.userRead.gmtCreated, 3);
  155. temp.avatar = item.user ? item.user.avatar : '';
  156. temp.profession = item.user ? item.user.profession : '';
  157. temp.uid = item.user ? item.user.uid : '';
  158. // temp.avatar = item.user.avatar;
  159. temp.nickName = item.user ? item.user.wechatName : '';
  160. // recommendWorks.push(temp);
  161. that.data.hotData.hotWorks.push(temp);
  162. });
  163. const hotStr = 'hotData.hotWorks'
  164. const myCourseStr = 'hotData.myCourse'
  165. const isMessageNormal = 'hotData.isMessageNormal'
  166. const unReadMessageContent = 'hotData.unReadMessageContent'
  167. that.setData({
  168. [hotStr]: that.data.hotData.hotWorks,
  169. [myCourseStr]: recommendRes.myCourse,
  170. [isMessageNormal]: recommendRes.unread,
  171. [unReadMessageContent]: recommendRes.unread ? recommendRes.unreadMsg.content : recommendRes.annunciateMsg.content,
  172. unfinishedCount: recommendRes.unfinishedCount
  173. })
  174. })
  175. }
  176. that.getHotRecommendSecond = (uid, pageNo, pageSize) => {
  177. httpRequestApi.getHotRecommendSecond(uid, pageNo, pageSize).success(res => {
  178. console.log(res)
  179. const recommendRes = res.data.data.list;
  180. if (recommendRes.length === 0) return;
  181. // const recommendWorks = [];
  182. recommendRes.forEach(item => {
  183. const temp = {};
  184. temp.title = item.userRead.title;
  185. temp.summary = item.userRead.summary;
  186. temp.img = item.userRead.iconImg;
  187. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  188. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  189. temp.classId = item.userRead.id;
  190. temp.time = formatDate(item.userRead.gmtCreated, 3);
  191. temp.avatar = item.user.avatar;
  192. temp.profession = item.user.profession;
  193. temp.uid = item.user.uid;
  194. // temp.avatar = item.user.avatar;
  195. temp.nickName = item.user.wechatName;
  196. // recommendWorks.push(temp);
  197. that.data.hotData.hotWorks.push(temp);
  198. });
  199. const hotStr = 'hotData.hotWorks'
  200. that.setData({
  201. [hotStr]: that.data.hotData.hotWorks,
  202. recommendTotalNo: res.data.data.totalNo
  203. })
  204. })
  205. }
  206. // 去全部课本
  207. that.goToBooks = () => {
  208. wx.navigateTo({
  209. url: `../main/books/books`
  210. })
  211. }
  212. that.bannerTap = (e) => {
  213. const type = e.currentTarget.dataset.type;
  214. const id = e.currentTarget.dataset.id;
  215. switch (type) {
  216. case 'LESSON':
  217. that.openClass('tap', id);
  218. break;
  219. }
  220. },
  221. that.goToUsers = (e) => {
  222. console.log(e)
  223. let uid = e.currentTarget.dataset.uid;
  224. wx.navigateTo({
  225. url: `../../pages/user/myworks/myworks?uid=${uid}`
  226. });
  227. }
  228. // 下拉加载
  229. that.scrollUpdate = (e) => {
  230. console.log(e)
  231. }
  232. console.log(that.data.hotData.recommend)
  233. if (wx.getStorageSync('uid')) {
  234. that.getIndex();
  235. that.getHotRecommend(wx.getStorageSync('uid'));
  236. }
  237. // that.getIndex();
  238. // 获取全部课本
  239. // that.getBookList();
  240. // that.swiperChange = (e) => {
  241. // const str = 'hotData.swiperCurrent'
  242. // that.setData({
  243. // [str]: e.detail.current
  244. // });
  245. // }
  246. //跳转到课程详情
  247. that.goToBook = function (e) {
  248. console.log(e.currentTarget.dataset)
  249. let id = e.currentTarget.dataset.id;
  250. let title = e.currentTarget.dataset.title;
  251. console.log(id)
  252. wx.navigateTo({
  253. url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
  254. })
  255. }
  256. that.swiperChange = (e) => {
  257. const str = 'hotData.swiperCurrent'
  258. that.setData({
  259. [str]: e.detail.current
  260. });
  261. }
  262. }