279 lines
6.9 KiB
Vue
279 lines
6.9 KiB
Vue
<template>
|
|
<view>
|
|
<view class='bg-linear-gradient is_top d-flex'>
|
|
<view class="top_info w-90 x_margin0auto d-flex j-sb a-center">
|
|
<image src="../../static/my/left.png" mode="" style="height:30upx; width:19upx;" @click="goback()"></image>
|
|
<view class="is_top_search x-bg-white h-100 flex-1 margin-zy20">
|
|
<image src="../../static/home/search.png" mode="" class="search_img" @click="search()" ></image>
|
|
<!-- <input type="text" value="" placeholder="搜索" class="search_input h-100" v-model="keyword" /> -->
|
|
<input type="text" v-model="keyword" @input="changeInput($event)" confirm-type="search" focus="" @confirm="search" placeholder="请输入药名/厂家" class="search_input h-100"/>
|
|
<image class="closeicon" v-if="keyword!=''" @click="removewored()" src="../../static/shoppingCart/cancel.png" mode=""></image>
|
|
<view class="search_liandong bg_F2F2F2 shadow" v-if='flag==true'>
|
|
<view class="border-bottom x-bg-white search_items" v-for='(item,index) in search_liandong' :key='index' @tap='chooseSearch(item)'>{{item.name}}({{item.manufacturer_name}})</view>
|
|
</view>
|
|
</view>
|
|
|
|
<image src="../../static/my/message.png" mode="" class="message" @click="to_mes()"></image>
|
|
</view>
|
|
</view>
|
|
<view class="font-weight font_28 margin-zy20" style="line-height: 90upx;">热门搜索</view>
|
|
<view class="list d-flex flex-wrap" >
|
|
<view class="padding-zy30 list_item" v-for="(item,index) in hot" :key="index" @click="choose(item)">{{item.name}}</view>
|
|
</view>
|
|
|
|
<!-- <card headTitle="搜索记录">
|
|
<view slot="right" class="font text-danger"
|
|
@click="clearHistory">清除</view>
|
|
<uni-list-item v-for="(item,index) in historyList" :key="index"
|
|
:title="item" :showArrow="false" @click="quickSearch(item)"></uni-list-item>
|
|
</card> -->
|
|
<!-- <view class="font text-primary ml-2" @click="clearHistory">清除搜索记录</view> -->
|
|
<!-- 分割线 -->
|
|
|
|
<!-- <card headTitle="热门搜索">
|
|
|
|
<view class="px-1 mb-2">
|
|
<color-tag v-for="(item,index) in hot" :key="index" :item="item" @click.native="hotSearch(item.name)"></color-tag>
|
|
</view>
|
|
</card> -->
|
|
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import X_goods from '../../utils/models/goods.js'
|
|
import tuiIcon from "@/components/icon/icon"
|
|
import card from "@/components/common/card.vue"
|
|
import colorTag from "@/components/search/color-tag.vue"
|
|
import uniListItem from "@/components/uni-ui/uni-list-item/uni-list-item.vue"
|
|
export default {
|
|
components:{
|
|
card,
|
|
colorTag,
|
|
uniListItem,
|
|
tuiIcon,
|
|
},
|
|
data() {
|
|
return {
|
|
review:true,
|
|
historyList:[],
|
|
keyword:"",
|
|
hot:[],
|
|
cate:[],
|
|
search_liandong:'',// // 搜索联动
|
|
is_key:'',
|
|
flag:false,
|
|
manufacturer_name:'' //厂家
|
|
}
|
|
},
|
|
onNavigationBarButtonTap(e) {
|
|
if (e.index === 0) {
|
|
uni.navigateTo({
|
|
url: 'search-list',
|
|
});
|
|
}
|
|
},
|
|
// onNavigationBarSearchInputChanged(e) {
|
|
// this.keyword = e.text
|
|
// },
|
|
// onNavigationBarSearchInputConfirmed() {
|
|
// this.search()
|
|
// },
|
|
// onNavigationBarButtonTap() {
|
|
// this.search()
|
|
// },
|
|
watch: {
|
|
'$route'(to, from) {
|
|
if(to.path == '/pages/home/search' && from.path != '/pages/home/search-list'){
|
|
this.hotSearch()
|
|
}
|
|
}
|
|
},
|
|
onLoad(){
|
|
this.hotSearch()
|
|
},
|
|
methods: {
|
|
// removewored 清空输入框
|
|
removewored(){
|
|
this.keyword = ""
|
|
this.flag = false
|
|
},
|
|
// x_searchList
|
|
// 搜索联动列表
|
|
async the_searchList(){
|
|
let res = await X_goods.x_searchList(this.is_key)
|
|
this.search_liandong = res.data
|
|
|
|
this.handleError(res, res => {
|
|
|
|
})
|
|
},
|
|
// 监听搜索框的值
|
|
changeInput(event){
|
|
if(event.detail.value==''){
|
|
this.flag = false
|
|
}else{
|
|
this.flag = true
|
|
this.is_key = event.detail.value
|
|
|
|
this.the_searchList();
|
|
}
|
|
},
|
|
// 返回键
|
|
goback(){
|
|
uni.navigateBack(1)
|
|
},
|
|
//
|
|
chooseSearch(item){
|
|
this.flag = false
|
|
uni.navigateTo({
|
|
url:'./search-list?keyword='+item.name +'&manufacturer='+item.manufacturer_name
|
|
})
|
|
},
|
|
//choose
|
|
choose(item){
|
|
uni.navigateTo({
|
|
url:'./search-list?keyword='+item.name
|
|
})
|
|
},
|
|
to_mes(){
|
|
uni.navigateTo({
|
|
url:'../my/is_message'
|
|
})
|
|
},
|
|
// 搜索
|
|
search() {
|
|
if (this.keyword === '') {
|
|
uni.showToast({
|
|
title: '关键词不能为空',
|
|
icon: 'none'
|
|
});
|
|
}else{
|
|
|
|
|
|
|
|
uni.navigateTo({
|
|
url: 'search-list?keyword='+this.keyword
|
|
});
|
|
uni.hideKeyboard()
|
|
return
|
|
|
|
// indexOf -1 没匹配到; 1 匹配到
|
|
// console.log(this.keyword.indexOf(" ") != -1 );
|
|
return
|
|
if (this.keyword.indexOf(" ") == -1) {
|
|
// console.log("没有空格")
|
|
} else {
|
|
// console.log("空格")
|
|
// let str = ‘被测对象(人)>被测对象属性(心跳)>三轴振动传感器’
|
|
let index = this.keyword .lastIndexOf(" ")
|
|
this.keyword =this.keyword .substring(0,index);
|
|
// console.log(this.keyword,'截取前') //被测对象(人)>被测对象属性(心跳)
|
|
// console.log(this.keyword.length,'截取前length') //被测对象(人)>被测对象属性(心跳)
|
|
|
|
let index1 = this.keyword .lastIndexOf(" ")
|
|
this.manufacturer_name =this.keyword .substring(index1+1,this.keyword.length);
|
|
// console.log(this.manufacturer_name) //三轴振动传感器
|
|
if(this.keyword.length<=0){
|
|
|
|
}
|
|
}
|
|
|
|
// this.the_searchList(); // 大佬
|
|
// 超
|
|
uni.navigateTo({
|
|
url: 'search-list?keyword='+this.keyword
|
|
});
|
|
|
|
}
|
|
},
|
|
|
|
async hotSearch(e){
|
|
let res = await X_goods.goodsRanking()
|
|
this.handleError(res, res => {
|
|
this.hot = res.data
|
|
|
|
})
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.uni-input-placeholder{
|
|
|
|
line-height: 168upx;
|
|
}
|
|
.is_top {
|
|
height: 168upx;
|
|
padding-top: 90upx;
|
|
|
|
.top_info {
|
|
height: 60upx;
|
|
|
|
position: relative;
|
|
.is_top_search {
|
|
|
|
line-height: 27upx;
|
|
border-radius: 50upx;
|
|
position: relative;
|
|
.search_liandong{
|
|
max-height: 750upx;
|
|
overflow-y: auto;
|
|
font-size: 20upx;
|
|
color:#989898;
|
|
width:100%;
|
|
margin-top:20upx;
|
|
line-height: 80upx;
|
|
position: fixed;
|
|
left:0;
|
|
right:0upx;
|
|
.search_items{
|
|
margin-top: 2upx;
|
|
padding:0 30upx;
|
|
overflow:hidden;
|
|
|
|
text-overflow:ellipsis;
|
|
|
|
white-space:nowrap;
|
|
}
|
|
}
|
|
.search_img {
|
|
position: absolute;
|
|
left: 60upx;
|
|
top: 20upx;
|
|
height: 27upx;
|
|
width: 27upx;
|
|
}
|
|
.closeicon{
|
|
width:40upx;
|
|
height: 40upx;
|
|
position: absolute;
|
|
top:10upx;
|
|
right: 10upx;
|
|
}
|
|
.search_input {
|
|
margin-left: 70upx;
|
|
width: 70%;
|
|
font-size: 25upx;
|
|
color: #989898;
|
|
line-height: 27upx;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
.message {
|
|
margin-left: 20upx;
|
|
height: 43upx;
|
|
width: 50upx;
|
|
}
|
|
}
|
|
|
|
}
|
|
.list_item{
|
|
margin:10upx;
|
|
color:#989898;
|
|
}
|
|
</style>
|