// component/look/look.js import httpRequestApi from '../../utils/APIRequest'; export const lookInit = (that) => { that.setData({ lookData: { nav: [], lookInd: 0, lookList: [], left: '' } }) //点击更改数据 that.lookChoice = ({ currentTarget }) => { that.data.lookData.lookInd = currentTarget.dataset.index; if (that.data.lookData.nav.length > 3 && currentTarget.dataset.index == 2) { that.data.lookData.left = currentTarget.dataset.index * 225; } if (that.data.lookData.nav.length > 3 && currentTarget.dataset.index == 1) { that.data.lookData.left = ''; } that.setData({ lookData: that.data.lookData }) //数据请求 that.httpList(currentTarget.dataset.index + 1) } //滑动更改数据 that.lookSlide = ({ detail }) => { that.data.lookData.lookInd = detail.current; if (that.data.lookData.nav.length > 3 && detail.current == 2) { that.data.lookData.left = detail.current * 225; } if (that.data.lookData.nav.length > 3 && detail.current == 1) { that.data.lookData.left = ''; } // console.log(detail.current); that.setData({ lookData: that.data.lookData }) that.httpList(detail.current + 1) } //跳转到详情页 that.details = ({ currentTarget }) => { const id = currentTarget.dataset.id; wx.navigateTo({ url: '/pages/details/details?id=' + id }) } //请求数据封装 that.httpList = (ind) => { httpRequestApi.getCourse({ categoryId: ind }).success((res)=>{ console.log('课程列表', res); that.data.lookData.lookList = res.data.data.list; that.setData({ lookData: that.data.lookData }) }) } httpRequestApi.getCategory().success((res)=>{ that.data.lookData.nav = res.data.data; that.setData({ lookData: that.data.lookData }) }) //初始数据 that.httpList(1) }