parent
c1d37358dd
commit
8aef6cdc7a
@ -1,69 +1,192 @@
|
||||
<template>
|
||||
<view>
|
||||
<d-search-log @onSearchNameApi="onSearchNameApi"></d-search-log>
|
||||
<view>
|
||||
<view class="serach-list" v-for="(data,i) in dishList" :key="i">
|
||||
|
||||
<view class="dish-item">
|
||||
<image class="dish-image" :src="data[i].dish_src"></image>
|
||||
</view>
|
||||
|
||||
<view class="search-box">
|
||||
<uni-search-bar @input="input" :radius="100" cancelButton="none" :focus="true"></uni-search-bar>
|
||||
<button class="search" @click="goToSearchList">搜索</button>
|
||||
</view>
|
||||
<!--搜索建议-->
|
||||
<view class="sugest-list" v-if="searchresult.length !== 0">
|
||||
<view class="sugest-item" v-for="(item,i) in searchresult" :key="i" @click="gotodetail(item)">
|
||||
<view class="dish-name">{{item.dish_name}}</view>
|
||||
<uni-icons type="arrowright" size="16"></uni-icons>
|
||||
</view>
|
||||
</view>
|
||||
<!--搜索历史-->
|
||||
<view class="history-box" v-else>
|
||||
<!--标题区域-->
|
||||
<view class="history-title">
|
||||
<text>搜索历史</text>
|
||||
<uni-icons type="trash" size="17" @click="clean"></uni-icons>
|
||||
</view>
|
||||
<!--列表区域-->
|
||||
<view class="history-list">
|
||||
<uni-tag v-for="(item,i) in histories" :text="item" :key="i" @click="gotosearchdetail(item)"></uni-tag>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Vue from 'vue'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
dishList: [],
|
||||
timer: null,
|
||||
kw: '',
|
||||
searchresult: [],
|
||||
//搜索结果
|
||||
searchlist: [],
|
||||
//搜索历史的数组
|
||||
historylist: [],
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
|
||||
this.historylist = JSON.parse(uni.getStorageSync('kw') || '[]')
|
||||
this.cnt = this.historylist.length
|
||||
console.log(this.historylist)
|
||||
},
|
||||
methods: {
|
||||
async onSearchNameApi(e) {
|
||||
async goToSearchList() {
|
||||
this.getsearchresult()
|
||||
this.savesearchhistory()
|
||||
let that = this
|
||||
let data = []
|
||||
setTimeout(()=>{
|
||||
uni.$emit('item',this.searchresult)
|
||||
},500)
|
||||
uni.navigateTo({
|
||||
url:'/subpkg/searchList/searchList?searchlist=' + encodeURIComponent(JSON.stringify(this.searchresult))
|
||||
})
|
||||
},
|
||||
//input输入事件的处理函数
|
||||
input(e) {
|
||||
//延时器
|
||||
clearTimeout(this.timer)
|
||||
this.timer = setTimeout(
|
||||
() => {
|
||||
this.kw = e
|
||||
this.getsearchresult()
|
||||
}, 500)
|
||||
},
|
||||
async getsearchresult() {
|
||||
let that = this
|
||||
//判断搜索关键词是否为空
|
||||
if (this.kw.length === 0) {
|
||||
this.searchresult = []
|
||||
return
|
||||
}
|
||||
uniCloud.callFunction({
|
||||
name: 'getDishes',
|
||||
data: {
|
||||
api: 'getByName',
|
||||
dish_name: e
|
||||
name:'getDishes',
|
||||
data:{
|
||||
api:'getByName',
|
||||
dish_name:that.kw
|
||||
},
|
||||
success: function(res) {
|
||||
|
||||
/*that.dishList.splice(0)
|
||||
data = [res.result.data]
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
Vue.set(that.dishList, i, data[i])
|
||||
}*/
|
||||
|
||||
console.log(res)
|
||||
success:function(res){
|
||||
that.searchresult = res.result.data
|
||||
that.searchlist = res.result.data
|
||||
}
|
||||
})
|
||||
},
|
||||
gotodetail(item) {
|
||||
this.savesearchhistory()
|
||||
console.log(item._id)
|
||||
uni.navigateTo({
|
||||
url: '/subpkg/dishDetail/dishDetail?_id=' +encodeURIComponent(JSON.stringify(item._id))
|
||||
})
|
||||
},
|
||||
savesearchhistory() {
|
||||
const set = new Set(this.historylist)
|
||||
set.delete(this.kw)
|
||||
set.add(this.kw)
|
||||
this.historylist = Array.from(set)
|
||||
uni.setStorageSync('kw', JSON.stringify(this.historylist))
|
||||
},
|
||||
//清空本地历史记录
|
||||
clean() {
|
||||
this.historylist = []
|
||||
uni.setStorageSync('kw', '[]')
|
||||
this.cnt = 0
|
||||
},
|
||||
gotosearchdetail(item) {
|
||||
let historyresult = []
|
||||
uniCloud.callFunction({
|
||||
name:'getDishes',
|
||||
data:{
|
||||
api:'getByName',
|
||||
dish_name:item
|
||||
},
|
||||
success:function(res){
|
||||
historyresult = res.result.data
|
||||
}
|
||||
})
|
||||
setTimeout(()=>{
|
||||
uni.$emit('item',historyresult)
|
||||
},500)
|
||||
uni.navigateTo({
|
||||
url:'/subpkg/searchList/searchList?searchlist=' + encodeURIComponent(JSON.stringify(historyresult))
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
histories() {
|
||||
return [...this.historylist].reverse()
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.searchbox {
|
||||
width: 500;
|
||||
display: flex;
|
||||
.search-box {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
.search-list {
|
||||
display: flex;
|
||||
.sugest-list {
|
||||
padding: 0 5px;
|
||||
|
||||
.sugest-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 12px;
|
||||
padding: 13px 0;
|
||||
border-bottom: 1 px solid #efefef;
|
||||
|
||||
.dish-name {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dish_image {
|
||||
width: 100rpx;
|
||||
height: 70rpx;
|
||||
.history-box {
|
||||
padding: 0 5px;
|
||||
|
||||
.history-title {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
height: 40px;
|
||||
align-items: center;
|
||||
font-size: 13px;
|
||||
border-bottom: 1px solid #efefef;
|
||||
}
|
||||
|
||||
.history-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.uni-tag {
|
||||
margin-top: 5px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.search{
|
||||
height: 50rpx;
|
||||
width: 200rpx;
|
||||
font-size: 20rpx;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,83 @@
|
||||
<template>
|
||||
<view>
|
||||
<view class="search-list" v-for="data in dishList" :key="data._id">
|
||||
|
||||
<view class="dish-item" @click="goToDetail(data)">
|
||||
<image class="dish-image" :src="data.dish_src"></image>
|
||||
</view>
|
||||
<view class="dish-intro">
|
||||
<text>{{'菜名:' + data.dish_name + '\n'}}</text>
|
||||
<text>{{'地点:' + data.location + '\n'}}</text>
|
||||
<text>{{'窗口:' + data.window_name + '\n'}}</text>
|
||||
<text>{{'评分:' + data.avg_score + '\n'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
dishList: []
|
||||
};
|
||||
},
|
||||
onLoad(e) {
|
||||
let that = this
|
||||
uni.$on('item', (res) => {
|
||||
that.dishList = res
|
||||
console.log(res)
|
||||
})
|
||||
//this.dishList = JSON.parse(decodeURIComponent(e.searchlist))
|
||||
|
||||
},
|
||||
methods:{
|
||||
goToDetail(item) {
|
||||
console.log(item._id)
|
||||
uni.navigateTo({
|
||||
url: '/subpkg/dishDetail/dishDetail?_id=' +encodeURIComponent(JSON.stringify(item._id))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.search-list {
|
||||
padding-left: 5rpx;
|
||||
padding-right: 5rpx;
|
||||
border-style: solid;
|
||||
border-radius: 5px;
|
||||
border-color: #65654b;
|
||||
border-width: 3rpx;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
|
||||
}
|
||||
|
||||
.dish-intro {
|
||||
padding-left: 5rpx;
|
||||
padding-right: 5rpx;
|
||||
border-style: solid;
|
||||
border-radius: 5px;
|
||||
border-color: #65654b;
|
||||
border-width: 3rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
height: 256rpx;
|
||||
font-size: 18rpx;
|
||||
}
|
||||
|
||||
.dish-image {
|
||||
padding-left: 5rpx;
|
||||
padding-right: 5rpx;
|
||||
border-style: solid;
|
||||
border-radius: 5px;
|
||||
border-color: #65654b;
|
||||
border-width: 3rpx;
|
||||
width: 475rpx;
|
||||
height: 256rpx;
|
||||
display: flex;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"uni-search-bar.cancel": "cancel",
|
||||
"uni-search-bar.placeholder": "Search enter content"
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import en from './en.json'
|
||||
import zhHans from './zh-Hans.json'
|
||||
import zhHant from './zh-Hant.json'
|
||||
export default {
|
||||
en,
|
||||
'zh-Hans': zhHans,
|
||||
'zh-Hant': zhHant
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"uni-search-bar.cancel": "cancel",
|
||||
"uni-search-bar.placeholder": "请输入搜索内容"
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"uni-search-bar.cancel": "cancel",
|
||||
"uni-search-bar.placeholder": "請輸入搜索內容"
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
{
|
||||
"id": "uni-search-bar",
|
||||
"displayName": "uni-search-bar 搜索栏",
|
||||
"version": "1.2.3",
|
||||
"description": "搜索栏组件,通常用于搜索商品、文章等",
|
||||
"keywords": [
|
||||
"uni-ui",
|
||||
"uniui",
|
||||
"搜索框",
|
||||
"搜索栏"
|
||||
],
|
||||
"repository": "https://github.com/dcloudio/uni-ui",
|
||||
"engines": {
|
||||
"HBuilderX": ""
|
||||
},
|
||||
"directories": {
|
||||
"example": "../../temps/example_temps"
|
||||
},
|
||||
"dcloudext": {
|
||||
"category": [
|
||||
"前端组件",
|
||||
"通用组件"
|
||||
],
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "无",
|
||||
"data": "无",
|
||||
"permissions": "无"
|
||||
},
|
||||
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui"
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [
|
||||
"uni-scss",
|
||||
"uni-icons"
|
||||
],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "y",
|
||||
"aliyun": "y"
|
||||
},
|
||||
"client": {
|
||||
"App": {
|
||||
"app-vue": "y",
|
||||
"app-nvue": "y"
|
||||
},
|
||||
"H5-mobile": {
|
||||
"Safari": "y",
|
||||
"Android Browser": "y",
|
||||
"微信浏览器(Android)": "y",
|
||||
"QQ浏览器(Android)": "y"
|
||||
},
|
||||
"H5-pc": {
|
||||
"Chrome": "y",
|
||||
"IE": "y",
|
||||
"Edge": "y",
|
||||
"Firefox": "y",
|
||||
"Safari": "y"
|
||||
},
|
||||
"小程序": {
|
||||
"微信": "y",
|
||||
"阿里": "y",
|
||||
"百度": "y",
|
||||
"字节跳动": "y",
|
||||
"QQ": "y"
|
||||
},
|
||||
"快应用": {
|
||||
"华为": "u",
|
||||
"联盟": "u"
|
||||
},
|
||||
"Vue": {
|
||||
"vue2": "y",
|
||||
"vue3": "y"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue