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.
 
 
 
 
 
 

301 lines
7.0 KiB

<template>
<view>
<view class="status_bar"></view>
<view class="search_title">
<navigator data="1" open-type="navigateBack">
<image src="../../static/img/left_white.png" mode=""></image>
</navigator>
<uni-search-bar @confirm="search" backgroundColor="#000" v-model="searchValue" class="search_title_input" cancelText="Cancel" placeholder="search" color="#fff"></uni-search-bar>
</view>
<view class="history">
<view class="history_title">
<text>Recently Searched</text>
<image src="../../static/img/delete.png" mode="" @click="empty()"></image>
</view>
<view class="history_lable" >
<view class="lable_item" v-for="(item,index) in searchHistoryList" :key="index" @click="tapSearch(item)">{{ item }}</view>
</view>
</view>
<view class="history">
<view class="history_title">
<text>Figured you’d want it</text>
</view>
<view class="history_lable">
<view class="lable_item" v-for="(item,index) in searchHot" :key="item.block_title" @click="TapHot(item.block_title)">{{item.block_title}}</view>
</view>
<!-- <scroll-view class="spike1 page_padding_left" scroll-x="true" :show-scrollbar="false">
<view class="spike1_item" v-for="(item,index) in catList" :key="index" @click="goDetails(item.id)">
<view class="spike1_item_img">
<image :src="item.thumb" mode=""></image>
</view>
<view class="spike1_item_bottom">
<text>US${{item.is_promote==0? item.shop_price :item.promote_price}}</text>
<view class="spike1_item_text" v-if="item.is_promote==1">US${{ item.shop_price }}</view>
</view>
</view>
</scroll-view> -->
</view>
</view>
</template>
<script>
import {defaultRequest,defaultRequest4} from '../../api/index.js'
export default {
data() {
return {
searchValue:'',
// 获取该分类的其他商品的请求参数
catQuery:{
_action:'getgoods',
page_index:1,
page_size:30,
type:'best'
},
searchHistoryList:[],
catList:[],
searchHot:[]
}
},
methods:{
goDetails(id){
uni.navigateTo({
url:'/pages/productDetails/index?goods_id='+id
})
},
// 获取的推荐商品数据
// getCatList(type){
// defaultRequest4(this.catQuery).then(res=>{
// console.info(res)
// if(res.error==0){
// if(res.data){
// this.catList=res.data
// }
// }
// })
// },
// 获取首页数据配置
getIndex(){
let searchHot =[]
let data={_action:'getpagedata',pagecode:'CLASS'}
defaultRequest(data).then(res=>{
console.info(res.data.zones,'有毒')
if(res.error==0){
// this.indexDate=res.data
// res.data.zones.map(item=>{
// if(item.zone_code=='ICON'){
// item.content=''
// this.info.push(item)
// }
// })
res.data.zones.map(item =>{
if(item.zone_code=='SEARCHHOT'){
searchHot= item
}
console.log(searchHot.blocks,'pp')
this.searchHot = searchHot.blocks
})
}
})
},
search(){
if(this.searchValue=='')return
// this.$store.commit('addSave', this.searchValue)
// console.log(this.$store.state)
if (!this.searchHistoryList.includes(this.searchValue)) {
this.searchHistoryList.unshift(this.searchValue);
uni.setStorage({
key: 'searchList',
data: JSON.stringify(this.searchHistoryList)
});
} else {
//有搜索记录和之前搜索记录一样,删除之前的旧记录,将新搜索值重新push到数组首位
let i = this.searchHistoryList.indexOf(this.searchValue);
this.searchHistoryList.splice(i, 1);
this.searchHistoryList.unshift(this.searchValue);
uni.setStorage({
key: 'searchList',
data: JSON.stringify(this.searchHistoryList)
});
}
let data ={
_action:'getgoods',keyword:this.searchValue
}
// defaultRequest(data).then(res=>{
// console.log(res,'ke')
// })
console.log(this.catQuery)
uni.navigateTo({
url:'../category/productList?keyword='+this.searchValue+'&type=1'
})
},
tapSearch(i){
this.searchValue = i
console.log(this.catQuery)
uni.navigateTo({
url:'../category/productList?keyword='+this.searchValue+'&type=1'
})
},
// 清空搜索记录
empty() {
uni.showToast({
title: 'emptied'
});
uni.removeStorage({
key: 'searchList'
});
this.searchHistoryList = [];
},
TapHot(e){
this.searchValue = e
uni.navigateTo({
url:'../category/productList?keyword='+this.searchValue+'&type=1'
})
}
},
async onLoad() {
this.getIndex()
// this.getCatList()
let list = await uni.getStorage({
key: 'searchList'
});
if (list.length>1) {
// console.log(list[1].data);
this.searchHistoryList = JSON.parse(list[1].data);
}
}
}
</script>
<style lang="scss" scoped>
.status_bar{
background-color: #000000;
}
.search_title{
width: 100%;
background-color: #000000;
// height: 135.33rpx;
padding: 0 26.67rpx;
display: flex;
align-items: center;
image{
width: 36rpx;
height: 36rpx;
}
.search_title_input{
width: 85%;
color:#fff !important;
}
/deep/ .uni-searchbar__box{
border-radius: 50rpx !important;
}
}
/deep/ .uni-searchbar__cancel{
color:#fff !important;
}
.history{
margin-top: 62.67rpx;
padding: 0 26.67rpx;
margin-bottom: 85.33rpx;
.history_title{
display: flex;
align-items: center;
justify-content: space-between;
font-size: 28rpx;
font-weight: 500;
margin-bottom: 26.67rpx;
image{
width: 29.33rpx;
height: 29.33rpx;
}
}
.history_lable{
display: flex;
flex-wrap: wrap;
.lable_item{
padding: 13.33rpx 16rpx;
background-color: #F5F6FA;
color: #565656;
font-size: 24rpx;
margin-right: 24.67rpx;
border-radius: 5px;
}
.lable_item:last-child{
margin-right:0
}
}
.spike1{
white-space: nowrap;
width: 100%;
margin-bottom: 70.67rpx;
margin-top: 32rpx;
::-webkit-scrollbar {
width: 0;
height: 0;
background-color: transparent;
}
.spike1_item{
color: #191919;
font-size: 26.67rpx;
margin-right: 16.67rpx;
width: 200rpx;
display: inline-block;
font-weight: 500;
.spike1_item_img{
width: 200rpx;
height: 200rpx;
background-color: #999999;
image{
width: 100%;
height: 100%;
}
}
.spike1_item_bottom{
padding-left: 9.33rpx;
margin-top: 22.67rpx;
.spike1_item_text{
color: #9D9D9D;
font-size: 21.33rpx;
text-decoration: line-through;
}
}
.spike1_item_bottom1{
padding-left: 9.33rpx;
margin-top: 19.33rpx;
font-weight: bold;
.spike1_item_text{
color: #000000;
font-size: 16rpx;
font-weight: 400;
margin-bottom: 20.67rpx;
white-space: break-spaces;
}
}
}
.spike1_item:last-child{
margin-right: 0;
}
}
}
</style>