look.js 1.9 KB

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