hot.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. export const hotInit = (that) => {
  2. that.setData({
  3. hotData: {
  4. nav: [],
  5. hotIndex: 0,
  6. hotList: [],
  7. left: ''
  8. }
  9. })
  10. //点击更改数据
  11. that.hotChoice = ({ currentTarget }) => {
  12. that.data.hotData.hotInd = currentTarget.dataset.index;
  13. if (that.data.hotData.nav.length > 3 && currentTarget.dataset.index == 2) {
  14. that.data.hotData.left = currentTarget.dataset.index * 225;
  15. }
  16. if (that.data.hotData.nav.length > 3 && currentTarget.dataset.index == 1) {
  17. that.data.hotData.left = '';
  18. }
  19. that.setData({
  20. hotData: that.data.hotData
  21. })
  22. //数据请求
  23. that.httpList(currentTarget.dataset.index + 1)
  24. }
  25. //滑动更改数据
  26. that.lookSlide = ({ detail }) => {
  27. that.data.hotData.hotInd = detail.current;
  28. if (that.data.hotData.nav.length > 3 && detail.current == 2) {
  29. that.data.hotData.left = detail.current * 225;
  30. }
  31. if (that.data.hotData.nav.length > 3 && detail.current == 1) {
  32. that.data.hotData.left = '';
  33. }
  34. // console.log(detail.current);
  35. that.setData({
  36. hotData: that.data.hotData
  37. })
  38. that.httpList(detail.current + 1)
  39. }
  40. //跳转到详情页
  41. that.details = ({ currentTarget }) => {
  42. const id = currentTarget.dataset.id;
  43. wx.navigateTo({
  44. url: '/pages/details/details?id=' + id
  45. })
  46. }
  47. //请求数据封装
  48. that.httpList = (ind) => {
  49. httpRequestApi.getCourse({
  50. categoryId: ind
  51. }).success((res)=>{
  52. console.log('课程列表', res);
  53. that.data.hotData.hotList = res.data.data.list;
  54. that.setData({
  55. hotData: that.data.hotData
  56. })
  57. })
  58. }
  59. //初始数据
  60. that.httpList(1)
  61. }