Files
ClassContent/历届学生/front-end-team-10/项目练习/上课项目/枸杞社/js/page/search.js
2024-09-27 02:06:13 +08:00

67 lines
1.7 KiB
JavaScript

class Search {
constructor() {
footer()
this.getSearch()
this.seek()
}
async seek(newKey) {
var res = await indexService.search({
keyword: newKey,
page: 1
});
item($(".recommend .list"), res)
}
hidden (){
$(".suggest").style.display = "none"
$(".recommend").style.display = "block"
}
show (){
$(".suggest").style.display = "block"
$(".recommend").style.display = "none"
}
async getSearch() {
var res = await indexService.search({
keyword: "长裙",
page: 1
});
res.forEach(v => {
$(".suggest_list").innerHTML += `
<li class="ellipsis">${v.biaoqianlist[0].name}</li>
`
});
// item($(".recommend .list"), res)
//获取输入框值
$(".search_box").oninput = () => {
if ($(".search_box").value.length > 0) {
this.seek($(".search_box").value)
}
}
//input获得焦点
$(".search_box").onfocus = () => {
this.show()
}
$(".content").onclick = () => {
this.hidden()
}
//标签绑定点击事件
click(".suggest_list li", (v, i) => {
$(".search_box").value = v.innerText
this.seek($(".search_box").value)
this.hidden()
})
//绑定搜索按钮
click(".icon-search", async (v, i) => {
this.seek($(".search_box").value)
this.hidden()
})
click(".icon-back1", () => {
history.back()
})
}
}
new Search()