hengmei-two/pagesB/shopSearch/shopSearch.vue

468 lines
15 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<view>
<!-- 状态栏 -->
<status-nav :titleVal="'商品搜索'" :statusTitle="true"></status-nav>
<!-- 输入框 -->
<view class="search-input-box bacf" :style="{paddingTop: statusHNH+'px'}">
<view class="disac pad-zy30 mar-s20">
<!-- 输入框 -->
<input @confirm="searchEv" style="border: 2rpx solid #E0E0E0;padding: 0rpx 20rpx;height: 80rpx;line-height: 80rpx;" class="width100 fon34 radius10" type="text" v-model="searchVal" placeholder="请输入商品名称"/>
<!-- 搜索 -->
<view @tap="searchEv" class="flexs mar-z30 radius10 pad-zy40 fon34 colf" style="height: 80rpx;line-height: 80rpx;" :style="{background:publicColor}">搜索</view>
</view>
<view>
<!-- 分类标题 -->
<view style="background: #FFFFFF;font-size: 24rpx;" class="disjbac pad-zy20 pad-s20">
<view v-for="(item,index) in shopCate" @tap="chooseShopCate(index)" :class="activeIndex==index?'activecate':'shopMo'" :style="{background:activeIndex==index?publicColor:'#F2F2F2'}" :key="index"><span>{{item}}</span></view>
</view>
<!-- 筛选结果 -->
<view v-if="isClick" class="pad-zy50 disac fw pad-x20">
<view class="col3 fon28 mar-s30">筛选:</view>
<view v-for="(item,indexx) in shaiList" :key="indexx">{{item}} <view class="mar-z10" @tap="deleteSX(indexx)">×</view></view>
</view>
<view v-if="isXiao">
<view class="pad-zy30">
<view class="mar-s50 mar-x20 fon28 bold">{{cateTitle}}</view>
<view class="disac fw">
<view @tap="chooseBing(indexb)" v-for="(itemb,indexb) in bingzList" class="mar-y30 fon26 mar-s30" :key="indexb" :class="itemb.isActive?'activebcate':'shopBMo'" :style="{background:itemb.isActive?publicColor:'#F2F2F2'}">{{itemb.title}}</view>
</view>
<view v-if="activeIndex==1">
<view class="fon28 bold mar-sx40">医生选择</view>
<input type="text" class="mar-x40" value="" placeholder="请输入医生姓名并选择" />
</view>
</view>
<!-- 重置、筛选 -->
<view class="disjbac pad-zy20 mar-s50 mar-x30 pad-s20">
<view @tap="chongz">重置</view>
<view @tap="shaix">筛选</view>
</view>
</view>
</view>
</view>
<view v-if="isXiao" @tap="isXiao=false" class="moban"></view>
<!-- 数据列表 -->
<view v-if="loading" :style="{marginTop:statusHNH+titleHeight+'px'}">
<shopList :dataList="dataList" v-if="dataList.length!=0"></shopList>
<nothing-page v-if="dataList.length==0" :content="`暂无更多${searchVal}商品`"></nothing-page>
</view>
<!-- 购物车 -->
<navigator url="/pagesA/shopCart/shopCart?isScore=false" hover-class="none">
<view class="cart-box">
<view class="posir">
<image src="/static/public/cart.png" mode="aspectFill"></image>
<view class="posia" v-if="cartNum!=0"><view>{{cartNum}}</view></view>
</view>
</view>
</navigator>
<!-- 历史搜索和热门搜索 -->
<view class="pad-z30 mar-s30" v-if="isList">
<cate-tu :list="reSearchList" @delev='delev'></cate-tu>
</view>
<view v-else class="pad-zy20 mar-s20">
<!-- 列表 -->
<view v-if="dataList.length!=0">
</view>
<view v-else class="disjcac fc" style="margin-top: 40%;">
<image class="zanw-img" src="/static/public/nothing.png" mode="aspectFill"></image>
<view class="fon24 col3">您搜索的内容暂无结果,换个关键词试试吧</view>
</view>
</view>
<!-- 弹框 -->
<pu-po :isShowT="isShowT" @comfirmev="comfirmev" @cancleev="cancleev"></pu-po>
<!-- 返回顶部 -->
<!-- <back-top :showTop="showTop" @backTop="backTop"></back-top> -->
</view>
</template>
<script>
import cateTu from '@/components/cate-items/cate-tu.vue';
import shopList from '@/components/shop-list.vue';
import {cartNum} from '@/jsFile/publicAPI.js';
export default {
components:{
cateTu,
shopList
},
data() {
return {
statusHNH:uni.getStorageSync('statusHNH'),
searchVal:'',//输入框的值
publicColor:uni.getStorageSync('publicColor'),//主题颜色
reSearchList:[//历史记录列表
{
title:'历史搜索',
src:'/static/public/del-icon.png',
list:[]
},
{
title:'热门搜索',
src:'',
list:[
// {content:'秃顶种植需要的条件'},
// {content:'眉毛种植的是什么'},
// {content:'那些人能种植'},
// {content:'眉毛种植需要多少钱'},
// {content:'那些人能种植'},
]
},
],
isShowT:false,//是否显示弹框
isList:true,//是否显示默认显示
dataList:[//小课堂数据列表
],
showTop:false,//是否显示返回顶部
newCurrent:0,
page:1,
size:10,
total:'',//总数
isZanw:true,
activeIndex:'-1',
shopCate:['全部病种','全部医生','全部活动'],
cateTitle:'',
bingzList:[],//小分类列表
zanBingArr:[],//暂存小分类
isXiao:false,//
titleHeight:'',//标题高度
shaiList:[],//筛选后的结果列表
isClick:false,//是否点击了筛选
dataList:[],
searchVal:'',//关键词
doctor_role:'',//医生从职位标识 从商品筛选条件接口获取 目前为doctor=医生 design=设计师
doctor_name:'',//医生姓名 模糊搜索
activity:'',//活动类型 不填为普通商品+活动商品 normal=普通商品group_make=拼团group_buy=团购;limit_time=限时促销
disease_id:'',//病种ID
loading:false,
cartNum:0
}
},
onPageScroll(e) {
e.scrollTop > 360 ? this.showTop = true : this.showTop = false
},
onReachBottom() {//触底事件
if(this.total!=this.dataList.length){
this.page++
this.searchEv()//调用自主预约列表事件
} else {
if(this.isZanw) this.$toolAll.tools.showToast('暂无更多列表','none',1000)
this.isZanw = false
}
},
onLoad(options) {
if(options.keyWorld!=undefined && options.keyWorld!='') {
this.searchVal = options.keyWorld
this.searchEv()
}
this.checkSearchHistory()
this.checkKey()
// 缓存状态栏+标题栏的高度
const query = wx.createSelectorQuery()
query.select('.search-input-box').boundingClientRect((rect) => {
// console.log('状态栏+标题栏:',rect.height);
this.titleHeight = rect.height
}).exec()
this.checkSX();
},
onShow() {
this.$toolAll.tools.isLogin()
if(this.searchVal!=undefined && this.searchVal!='') this.searchEv();
this.cartNumEv();//查询购物车数量
},
methods: {
cartNumEv(){//购物车数量
this.$requst.post('order/shopping-cart-count',{type:'spu'}).then(res=>{
if(res.code==0){
this.cartNum = res.data.count;
}
})
},
async checkSX(){//商品筛选条件
this.$requst.get('spu/condition').then(res=>{
if(res.code==0){
this.zanBingArr = res.data;
}
})
await this.checkShopList();
},
chooseShopCate(index){//大分类选择事件
if(this.activeIndex==index && this.isXiao) {
this.isXiao = false;
} else this.isXiao = true;
this.bingzList = [];
this.isClick = false;
this.activeIndex = index;
let arr = [];
let obj = {};
if(this.activeIndex==0) {
this.cateTitle = '病种选择';
this.zanBingArr.disease.forEach(item=>{
obj = {
pid: item.pid,
title: item.name,
id: item.id,
sort: item.sort,
isActive:false
}
arr.push(obj);
})
this.bingzList = arr;
this.bingzList.unshift({pid: '', title: "全部", id: '', sort: '',isActive:true});
this.bingzList.push({pid: '', title: "其他", id: '', sort: ''});
}
if(this.activeIndex==1) {
this.cateTitle = '职位选择';
this.zanBingArr.doctor_roles.forEach(item=>{
obj = {
id: item.id,
name: item.name,
title: item.title,
pid: item.pid,
is_group: item.is_group,
isActive:false
}
arr.push(obj);
})
this.bingzList = arr;
this.bingzList.unshift({id: '', name: '', title: "全部", pid: '', is_group: '',isActive:true});
}
if(this.activeIndex==2) {
this.cateTitle = '活动选择';
this.zanBingArr.activity.forEach(item=>{
obj = {
name: item.name,
title: item.title,
isActive:false
}
arr.push(obj);
})
this.bingzList = arr;
this.bingzList.unshift({name: '', title: "全部",isActive:true});
}
},
checkShopList(){
let params = {
keyword:this.searchVal,//商品关键字 支持模糊搜索
page:1,
size:10,
doctor_role:this.doctor_role,//医生从职位标识 从商品筛选条件接口获取 目前为doctor=医生 design=设计师
doctor_name:this.doctor_name,//医生姓名 模糊搜索
activity:this.activity,//活动类型 不填为普通商品+活动商品 normal=普通商品group_make=拼团group_buy=团购;limit_time=限时促销
disease_id:this.disease_id//病种ID
}
uni.request({
url:'https://hengmei.scdxtc.cn/api/spu/list',
data:params,
method:'post',
header:{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer '+uni.getStorageSync('token') || ''
},
success: (res) => {
if(res.data.code==0){
this.dataList = [];
if(res.data.data.list.length!=0){
res.data.data.list.forEach(item=>{
let tuan = false,ping = false,xian = false,integral = false;
if(item.activity_type=='group_make') ping = true;
if(item.activity_type=='group_buy') tuan = true;
if(item.activity_type=='limit_time') xian = true;
let group_cover = [];
if(item.activity_group_cover.length!=0) {
item.activity_group_cover.forEach(item=>{
group_cover.push(this.$http + item)
})
}
let obj = {
id:item.id,
imgSrc: this.$http + item.cover,
title: item.name,
zhePrice:item.price/100,
yuanPrice:item.original_price/100,
integral:'',
isTuan:tuan,//是否是团购
isPing:ping,//是否是拼团活动
isXian:xian,//是否是限时活动
isIntegral:integral,//是否是积分
grade:'',
disease_name:item.disease_name,//病种名称
disease_id:item.disease_id,//病种ID
reponseTime:res.header.Date,//接口响应时间
activity_end_at:item.activity_end_at,//限时结束时间
activity_group_cover:group_cover,//参团人的头像
activity_group_num:item.activity_group_num,//已经参团人数
}
this.dataList.push(obj)
})
this.loading = true;
}
}
}
})
// this.$requst.post('spu/list',params).then(res=>{
// if(res.code==0){
// this.dataList = [];
// if(res.data.list.length!=0){
// res.data.list.forEach(item=>{
// let tuan = false,ping = false,xian = false,integral = false;
// if(item.activity_type=='group_make') ping = true;
// if(item.activity_type=='group_buy') tuan = true;
// if(item.activity_type=='limit_time') xian = true;
// let group_cover = [];
// if(item.activity_group_cover.length!=0) {
// item.activity_group_cover.forEach(item=>{
// group_cover.push(this.$http + item)
// })
// }
// let obj = {
// id:item.id,
// imgSrc: this.$http + item.cover,
// title: item.name,
// zhePrice:item.price/100,
// yuanPrice:item.original_price/100,
// integral:'',
// isTuan:tuan,//是否是团购
// isPing:ping,//是否是拼团活动
// isXian:xian,//是否是限时活动
// isIntegral:integral,//是否是积分
// grade:'',
// disease_name:item.disease_name,//病种名称
// disease_id:item.disease_id,//病种ID
// activity_end_at:item.activity_end_at,//限时结束时间
// activity_group_cover:group_cover,//参团人的头像
// activity_group_num:item.activity_group_num,//已经参团人数
// }
// this.dataList.push(obj)
// })
// this.loading = true;
// }
// }
// })
},
chooseBing(index){//小分类选择事件
this.bingzList.forEach(item=>{
item.isActive = false;
})
this.bingzList[index].isActive = true;
this.shaiList[this.activeIndex] = this.bingzList[index].title;
console.log(this.shaiList);
},
chongz(){//重置
this.isClick = false;
this.shaiList = []
},
shaix(){//筛选
this.isXiao = false
this.isClick = true;
this.checkShopList();
},
deleteSX(index){//删除筛选
this.shaiList.splice(index,1);
if(this.shaiList.length==0){
this.isClick = false;
}
},
checkKey(){//查询热搜关键词事件
this.$requst.get('index/hot-keywords').then(res=>{
// console.log('关键词列表:',res);
if(res.code==0){
if(res.data.length!=0){
res.data.forEach(item=>{
let reObj = {
id:item.id,
content:item.keyword
}
this.reSearchList[1].list.push(reObj)
})
}
}
},error=>{})
},
checkSearchHistory(){//查询历史搜索的搜索记录
this.$requst.post('user/search-history',{page:this.page,size:this.size}).then(res=>{
// console.log(res);
if(res.code==0){
if(res.data.list.length!=0){
res.data.list.forEach(item=>{
if(item.keyword!=null){
let searchObj = {
id:item.id,
content:item.keyword
}
this.reSearchList[0].list.push(searchObj)
}
})
}
}
},error=>{})
},
searchEv(){//搜索事件
this.$toolAll.tools.showToast('搜索中...')
this.$requst.post('archives/category',{page:this.page,size:this.size,keyword:this.searchVal}).then(res=>{
// console.log('搜索提交:',res);
if(res.code==0){
// 获取列表
if(this.page==1) this.dataList = []
this.total = res.data.list.total
if(res.data.list.list.length!=0){
res.data.list.list.forEach(item=>{
let tObj = {
id:item.id,
is_collected:item.is_collected,//是否已收藏
collects:item.collects,//收藏量
views:item.views,//查看量
main_img:this.$http + item.cover,//封面图
video:this.$http + item.video,//视频地址
title:item.title,//标题
content:item.subtitle,//副标题
head_img:'/static/public/logo.png',//发布者头像
name:'恒美植发',//发布者昵称
isVideo:item.video.includes(".mp4")//是否是视频
}
this.dataList.push(tObj)
})
}
let obj = {
content:this.searchVal
}
this.reSearchList[0].list.push(obj)
this.isList = false
}
},error=>{})
},
delev(){//删除事件
this.isShowT = true
},
comfirmev(){//清空历史搜索确认事件
this.isShowT = false
this.$requst.post('user/clear-search').then(res=>{
if(res.code==0){
this.$toolAll.tools.showToast('已清空')
this.reSearchList[0].list = []//清空搜索历史
}
},error=>{})
},
cancleev(){//取消事件
this.isShowT = false
},
chooseTwo(index){//二级分类选择
// console.log('二级分类:',index);
this.isZanw = true
this.page = 1
this.newCurrent = index
this.searchEv()
},
backTop(){//回到顶部事件
uni.pageScrollTo({
scrollTop: 0,
duration: 300
});
},
}
}
</script>
<style>
</style>