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.
hezhiying/pages/search/search.vue

108 lines
2.6 KiB

1 year ago
<template>
<view class="page">
<!-- 搜索 -->
<view class="search-head">
<view class="back" @click="onBack">
<text></text>
</view>
<view class="search">
<text class="iconfont icon-fadajing"></text>
1 year ago
<input type="text" v-model="keyword" placeholder="请输入关键字搜索" />
1 year ago
</view>
<view class="btn" @click="onSearch">
<text>搜索</text>
</view>
</view>
<!-- 搜索历史 -->
<view class="search-record">
<view class="search-title">
<view class="title">搜索历史</view>
<view class="iconfont icon-laji"></view>
</view>
<view class="record-list">
<view class="list" v-for="(item,index) in SearchRecordArr"
@click="onRecord(item)"
:key="index">
<text>{{item}}</text>
</view>
</view>
</view>
<!-- 搜索发现 -->
<view class="search-found">
<view class="search-title">
<view class="title">搜索发现</view>
<!-- <view class="iconfont icon-laji"></view> -->
</view>
<view class="found-list">
1 year ago
<view class="list" @click="onRecord(item)" v-for="(item,index) in searchList" :key="index">
<view class="searchItem">
<view class="num">{{index+1}}</view>
<text>{{item}}</text>
</view>
1 year ago
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
SearchRecordArr: [],
keyword: '',
1 year ago
searchList:['手镯','项链','吊坠','耳环','钻石','翡翠','沉香','天然水晶']
1 year ago
};
},
onLoad() {
if(uni.getStorageSync('SearchRecordArr')){
this.SearchRecordArr = JSON.parse(uni.getStorageSync('SearchRecordArr'));
}
},
methods:{
/**
* 返回点击
*/
onBack(){
uni.navigateBack();
},
/**
* 搜索点击
*/
onSearch(){
if(!this.keyword){
uni.showToast({
title:'请输入搜索内容',
icon:'none',
})
return;
}
for (var i = 0; i < this.SearchRecordArr.length; i++) {
if (this.SearchRecordArr[i] == this.keyword) {
this.SearchRecordArr.splice(i, 1);
}
}
this.SearchRecordArr.unshift(this.keyword);
uni.setStorageSync('SearchRecordArr', JSON.stringify(this.SearchRecordArr));
uni.navigateTo({
url: '/pages/SearchGoodsList/SearchGoodsList?keyword=' + encodeURIComponent(this.keyword),
})
},
/**
* 记录点击
*/
onRecord(val){
uni.navigateTo({
1 year ago
//url: '/pages/SearchGoodsList/SearchGoodsList?keyword=' + encodeURIComponent(val),
url: '/pages/SearchGoodsList/SearchGoodsList?keyword=' + val
1 year ago
})
}
}
}
</script>
<style scoped lang="scss">
@import 'search.scss';
</style>