You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.3 KiB

4 months ago
const { getHotSearch,getSearch } = require("../../api/index.js")
Page({
/**
* 页面的初始数据1
4 months ago
*/
data: {
search:"",
hotSearch:[],
value:"",
goodsData:[]
},
/**
* 生命周期函数--监听页面加载2
*.list-keywords {
*margin: 10px;1
*padding: 10px;1
*background: #fff;1
*}1
*.list-keywords .item{
*display: inline-block;1
*padding: 5px 10px;
*background: #f1f1f1;1
*margin: 5px;
*font-size: 12px;1
*color: #666;1
*}
4 months ago
*/
onLoad(options) {
getHotSearch().then(res =>{//获取热点搜索函数
4 months ago
this.setData({
hotSearch:res.data.data.result//搜索数据结果
4 months ago
})
})
},
// 内容改变3
onChange(e){//内容展示函数
4 months ago
this.setData({
value:e.detail//获取值
4 months ago
})
},
/**
* 展示搜索数据在goods页面展示4
* 1. 在搜索页面通过网络请求获取数据传递到goods页面显示5
* 2. 在搜索页面将搜索的关键字传递到goods页面在goods页面做网络请求6
4 months ago
*/
// 实现搜索7
onSearch(){//搜索函数
this.http(this.data.value)//10
4 months ago
},
onSearchCliclk(){//搜索点击函数
this.http(this.data.value)//11
4 months ago
},
/**
* 获取热门关键字8
4 months ago
*/
clickGetKeyWords(e){
this.http(e.currentTarget.dataset.hotkey)//使用this
4 months ago
},
http(search){
getSearch({search}).then(res =>{
if(!res.data.msg){
// 序列化9
4 months ago
let goods = JSON.stringify(res.data.data)
wx.navigateTo({
url: '/pages/goods/goods?goodsData=' + goods,//给出跳转网址
4 months ago
})
}else{
wx.showToast({
title: res.data.msg,//获取记录搜索结果总数
4 months ago
})
}
})
}
}) /**
* 展示搜索数据在goods页面展示4
* 1. 在搜索页面通过网络请求获取数据传递到goods页面显示5
* 2. 在搜索页面将搜索的关键字传递到goods页面在goods页面做网络请求6
*/
// 实现搜索7