hot_20190129191712.js 8.2 KB

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