search.js 944 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // pages/search/search.js
  2. import httpRequestApi from '../../utils/APIRequest';
  3. export const searchInit = (that) => {
  4. that.setData({
  5. searchData: {
  6. searchList: [],
  7. recommendList: []
  8. }
  9. })
  10. //获取输入值,并请求接口
  11. that.focus = ({detail}) => {
  12. httpRequestApi.getCourse({
  13. title: detail.value
  14. }).success((res)=>{
  15. that.data.searchData.searchList = res.data.data.list;
  16. that.data.searchData.recommendList = [];
  17. that.setData({
  18. searchData: that.data.searchData
  19. })
  20. })
  21. }
  22. //跳转到详情页
  23. that.details = ({ currentTarget }) => {
  24. const id = currentTarget.dataset.id;
  25. wx.navigateTo({
  26. url: '/pages/details/details?id=' + id
  27. })
  28. }
  29. httpRequestApi.getCategoryRecommend().success((res)=>{
  30. console.log('搜', res)
  31. that.data.searchData.recommendList = res.data.data;
  32. that.setData({
  33. searchData: that.data.searchData
  34. })
  35. })
  36. }