hot.js 5.0 KB

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