12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- // pages/search/search.js
- import httpRequestApi from '../../utils/APIRequest';
- export const searchInit = (that) => {
- that.setData({
- searchData: {
- searchList: [],
- recommendList: []
- }
- })
- //获取输入值,并请求接口
- that.focus = ({detail}) => {
- if (detail.value) {
- httpRequestApi.getCourse({
- title: detail.value
- }).success((res)=>{
- console.log('搜索结果', res)
- that.data.searchData.searchList = res.data.data.list;
- that.data.searchData.recommendList = [];
- that.setData({
- searchData: that.data.searchData
- })
- })
- }else {
- that.data.searchData.searchList = [];
- that.data.searchData.recommendList = [];
- that.setData({
- searchData: that.data.searchData
- })
- }
- }
- //跳转到详情页
- that.details = ({ currentTarget }) => {
- const id = currentTarget.dataset.id;
- wx.navigateTo({
- url: '/pages/details/details?id=' + id
- })
- }
- httpRequestApi.getCategoryRecommend().success((res)=>{
- console.log('热门搜', res)
- that.data.searchData.recommendList = res.data.data;
- that.setData({
- searchData: that.data.searchData
- })
- })
-
- }
|