hot.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. }
  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.openBooks = (e) => {
  58. wx.navigateTo({
  59. url: `../main/books/books`
  60. })
  61. }
  62. // 打开更多页面
  63. that.openMore = () => {
  64. wx.navigateTo({
  65. url: `../main/week/week`
  66. })
  67. }
  68. // 打开课程页面
  69. that.openClass = (e, lessonId) => {
  70. if (lessonId) {
  71. wx.navigateTo({
  72. url: `../main/class/class?id=${lessonId}`
  73. })
  74. } else {
  75. let id = e.currentTarget.dataset.classid;
  76. let title = e.currentTarget.dataset.title;
  77. wx.navigateTo({
  78. url: `../main/class/class?id=${id}&title=${title}`
  79. })
  80. }
  81. }
  82. // 打开用户作品页面
  83. that.openWorks = (e) => {
  84. let readId = e.currentTarget.dataset.readid;
  85. let title = e.currentTarget.dataset.title;
  86. wx.navigateTo({
  87. url: `../social/works/works?id=${readId}&title=${title}`
  88. })
  89. }
  90. that.getIndex = () => {
  91. const uid = wx.getStorageSync('uid');
  92. httpRequestApi.getIndex(
  93. uid
  94. ).success((res) => {
  95. const banner = res.data.data.banner;
  96. const recommend = res.data.data.recommendLesson;
  97. const bannerTemp = [];
  98. banner.forEach(item => {
  99. const temp = {};
  100. temp.url = item.boothContent;
  101. temp.type = item.operationType;
  102. temp.id = item.operationContent;
  103. bannerTemp.push(temp);
  104. });
  105. const recommendTemp = [];
  106. recommend.forEach(item => {
  107. const oTemp = {};
  108. oTemp.img = item.boothContent;
  109. oTemp.classId = item.operationContent;
  110. oTemp.title = item.title;
  111. oTemp.summary = item.summary;
  112. recommendTemp.push(oTemp);
  113. });
  114. let bannerIndex = 'hotData.banner';
  115. let recommendIndex = 'hotData.recommend';
  116. that.setData({
  117. [bannerIndex]: bannerTemp,
  118. [recommendIndex]: recommendTemp
  119. });
  120. httpRequestApi.userIntoPage('pages/index/index','首页推荐').success((res)=>{
  121. })
  122. })
  123. }
  124. that.getHotRecommend = (uid, pageNo, pageSize) => {
  125. httpRequestApi.getHotRecommend(
  126. uid,
  127. pageNo,
  128. pageSize
  129. ).success((res) => {
  130. console.log(res)
  131. const recommendRes = res.data.data.list;
  132. // const recommendWorks = [];
  133. recommendRes.forEach(item => {
  134. const temp = {};
  135. temp.title = item.userRead.title;
  136. temp.summary = item.userRead.summary;
  137. temp.img = item.userRead.iconImg;
  138. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  139. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  140. temp.classId = item.userRead.id;
  141. temp.time = formatDate(item.userRead.gmtCreated, 3);
  142. temp.avatar = item.user.avatar;
  143. temp.profession = item.user.profession;
  144. temp.uid = item.user.uid;
  145. // temp.avatar = item.user.avatar;
  146. temp.nickName = item.user.wechatName;
  147. // recommendWorks.push(temp);
  148. that.data.hotData.hotWorks.push(temp);
  149. });
  150. const hotStr = 'hotData.hotWorks'
  151. that.setData({
  152. [hotStr]: that.data.hotData.hotWorks,
  153. recommendTotalNo: res.data.data.totalNo
  154. })
  155. })
  156. }
  157. // 去全部课本
  158. that.goToBooks = () => {
  159. wx.navigateTo({
  160. url: `../main/books/books`
  161. })
  162. }
  163. that.bannerTap = (e) => {
  164. const type = e.currentTarget.dataset.type;
  165. const id = e.currentTarget.dataset.id;
  166. switch (type) {
  167. case 'LESSON':
  168. that.openClass('tap', id);
  169. break;
  170. }
  171. },
  172. that.goToUsers = (e) => {
  173. console.log(e)
  174. let uid = e.currentTarget.dataset.uid;
  175. wx.navigateTo({
  176. url: `../../pages/user/myworks/myworks?uid=${uid}`
  177. });
  178. }
  179. // 下拉加载
  180. that.scrollUpdate = (e) => {
  181. console.log(e)
  182. }
  183. that.getIndex();
  184. that.getHotRecommend(that.uid, 1, 3)
  185. }