hengmei-two/pages/tabbar/shop/shop.vue

589 lines
23 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="'商城'" :statusBack="false" :statusTitle="true"></status-nav>
<!-- 自定义轮播 -->
<view :style="{marginTop:statusHNH+'px'}">
<swiper-pu :bannerList="bannerList" :isplay="isAutoPlay"></swiper-pu>
</view>
<!-- 搜索输入框 -->
<view class="search-input-box bacf shop-nav-box" :style="{top: statusHNH+'px',position:positionMode}" style="padding-top: 10rpx;left: 0;right: 0;z-index: 3;">
<view class="disac pad-zy30 mar-s20">
<!-- 输入框 -->
<input class="width100 fon34 radius10" type="text" @confirm="searchEv" v-model="searchVal" placeholder="请输入商品名称"/>
<!-- 搜索 -->
<view class="flexs mar-z30 radius10 pad-zy40 fon34 colf" @tap="searchEv" :style="{background:publicColor}">搜索</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-if="bingVal!=''">{{bingVal}}<view class="mar-z10" @tap="deleteSX(0)">×</view></view>
<view v-if="doctorVal!=''">{{doctorVal}}<view class="mar-z10" @tap="deleteSX(1)">×</view></view>
<view v-if="activityVal!=''">{{activityVal}}<view class="mar-z10" @tap="deleteSX(2)">×</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.stop="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>
<view class="posir">
<input disabled @tap="chooseEv" type="text" class="mar-x40" v-model="doctor_name" placeholder="请输入医生姓名并选择" />
<view v-if="showDoctor" class="posia" style="top: 52px;left: 0;right: 0;border: 1rpx solid #E6E6E6;padding: 20rpx;background: #FFFFFF;">
<view @tap="chooseDoctor(index)" class="disjbac fon28 col9" v-for="(item,index) in doctorList" :key="index">
<span>姓名:{{item.doctor_extra.name}}</span>
<!-- <span>部门:{{item.doctor_extra.skill}}</span> -->
</view>
</view>
</view>
</view>
</view>
<!-- 重置、筛选 -->
<view class="disjbac pad-zy20 mar-s50 mar-x30 pad-s20">
<view @tap="chongz">重置</view>
<view @tap.stop="shaix">筛选</view>
</view>
</view>
</view>
<view v-if="isXiao" @tap="isXiao=false" class="moban"></view>
<!-- 数据列表 -->
<!-- <view v-if="loading" :style="{marginTop:statusHNH+titleHeight+(isClick?52:0)+'px'}"> -->
<view v-if="loading" :style="{marginTop:(gaodu==200?titleHeight : 0)+'px'}">
<view v-if="dataList.length!=0 && search_result" class="pad20 ">
<view style="width: 48.6%;float: left;" class="pad-x180">
<view v-if="index1%2==0" v-for="(item1,index1) in dataList" :key="index1" class="bacf radius15 mar-x20 animated fadeIn posir" @tap="goPage(item1.id,index1)">
<image :src="item1.imgSrc" mode="aspectFill" style="width: 100%;border-top-left-radius: 15rpx;border-top-right-radius: 15rpx;height: 325rpx;"></image>
<view class="pad-zy20 pad-s10 pad-x30">
<view class="fon28 bold col3 clips2">{{item1.title}}</view>
<view class="disac fon20 mar-sx20" v-if="!item1.isIntegral">
<view class="radius10 colf mar-y10" style="padding: 6rpx 10rpx;" :style="{background:publicColor}">{{item1.disease_name}}</view>
<view class="radius10 colf" v-if="item1.isTuan" style="padding: 6rpx 10rpx;background: #F85050;">团购</view>
<view class="radius10 colf" v-if="item1.isPing" style="padding: 6rpx 10rpx;background: #F85050;">拼团活动</view>
<view class="radius10 colf" v-if="item1.isXian" style="padding: 6rpx 10rpx;background: #F85050;">限时促销</view>
</view>
<view class="disac">
<view class="fon28 bold" style="color: #F85050;margin-right: 8rpx;">
<view v-if="item1.isIntegral" class="mar-s20">
<view>积分:{{item1.integral}}</view>
<view class="disac mar-s20" v-if="item1.grade!=0">
<image src="/static/public/huiy.png" style="width: 40rpx;height: 33rpx;" mode=""></image>
<view class="fon24 col3 mar-z10">{{item1.level_text}}</view>
</view>
</view>
<view v-else>
<span v-if="item1.isPing">拼团价</span>
<span v-if="item1.isXian">促销价</span>
¥{{item1.zhePrice}}
</view>
</view>
<!-- <view v-if="item1.isXian || item1.isPing || item1.isTuan" class="fon24" style="text-decoration: line-through;color: #C7C7C7;">¥{{item1.yuanPrice}}</view> -->
<view class="fon24" style="text-decoration: line-through;color: #C7C7C7;">¥{{item1.yuanPrice}}</view>
</view>
<view v-if="item1.isPing" class="disjbac mar-s20">
<view class="fon24 col80">已拼团{{item1.activity_group_num}}组</view>
<view class="disac">
<image v-for="(itemm,indexm) in item1.activity_group_cover" :key="indexm" :src="itemm" mode="" style="width: 40rpx;height: 40rpx;border-radius: 100%;margin-left: -20rpx;"></image>
</view>
</view>
<view v-if="item1.isXian || item1.isPing || item1.isTuan" class="fon24 col80 mar-s20">结束时间:{{item1.activity_end_at}}</view>
</view>
</view>
</view>
<view style="width: 48.6%;float: right;" class="pad-x180">
<view v-if="index1%2!=0" v-for="(item1,index1) in dataList" :key="index1" class="bacf radius15 mar-x20 animated fadeIn posir" @tap="goPage(item1.id,index1)">
<image :src="item1.imgSrc" mode="aspectFill" style="width: 100%;border-top-left-radius: 15rpx;border-top-right-radius: 15rpx;height: 325rpx;"></image>
<view class="pad-zy20 pad-s10 pad-x30">
<view class="fon28 bold col3 clips2">{{item1.title}}</view>
<view class="disac fon20 mar-sx20" v-if="!item1.isIntegral">
<view class="radius10 colf mar-y10" style="padding: 6rpx 10rpx;" :style="{background:publicColor}">{{item1.disease_name}}</view>
<view class="radius10 colf" v-if="item1.isTuan" style="padding: 6rpx 10rpx;background: #F85050;">团购</view>
<view class="radius10 colf" v-if="item1.isPing" style="padding: 6rpx 10rpx;background: #F85050;">拼团活动</view>
<view class="radius10 colf" v-if="item1.isXian" style="padding: 6rpx 10rpx;background: #F85050;">限时促销</view>
</view>
<view class="disac">
<view class="fon28 bold" style="color: #F85050;margin-right: 8rpx;">
<view v-if="item1.isIntegral" class="mar-s20">
<view>积分:{{item1.integral}}</view>
<view class="disac mar-s20" v-if="item1.grade!=0">
<image src="/static/public/huiy.png" style="width: 40rpx;height: 33rpx;" mode=""></image>
<view class="fon24 col3 mar-z10">{{item1.level_text}}</view>
</view>
</view>
<view v-else>
<span v-if="item1.isPing">拼团价</span>
<span v-if="item1.isXian">促销价</span>
¥{{item1.zhePrice}}
</view>
</view>
<!-- <view v-if="item1.isTuan || item1.isPing || item1.isXian" class="fon24" style="text-decoration: line-through;color: #C7C7C7;">¥{{item1.yuanPrice}}</view> -->
<view class="fon24" style="text-decoration: line-through;color: #C7C7C7;">¥{{item1.yuanPrice}}</view>
</view>
<view v-if="item1.isPing" class="disjbac mar-s20">
<view class="fon24 col80">已拼团{{item1.activity_group_num}}组</view>
<view class="disac">
<image v-for="(itemm,indexm) in item1.activity_group_cover" :key="indexm" :src="itemm" mode="" style="width: 40rpx;height: 40rpx;border-radius: 100%;margin-left: -20rpx;"></image>
</view>
</view>
<view v-if="item1.isXian || item1.isPing || item1.isTuan" class="fon24 col80 mar-s20">结束时间:{{item1.activity_end_at}}</view>
</view>
</view>
</view>
<!-- 弹框 -->
<pu-po :isShowT="isShowT" :contentVal="pu_content" @comfirmev="submitQu" @cancleev="isShowT=false"></pu-po>
</view>
<nothing-page v-if="dataList.length==0" :content="`暂无更多商品列表`"></nothing-page>
</view>
<!-- 底部tab -->
<foot-tab :titleList="titleList" :imgList="imgList" :newcurrent='3'></foot-tab>
<!-- 购物车 -->
<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>
<!-- 弹框授权 -->
<auth-userInfo-mobile :optionObj="optionObj"></auth-userInfo-mobile>
</view>
</template>
<script>
import shopList from '@/components/shop-list.vue';
import swiperPu from '@/components/swiper-pu.vue';
import {cartNum,checkBanner} from '@/jsFile/publicAPI.js';
export default {
components:{
shopList,
swiperPu
},
data() {
return {
titleList:[],
imgList:[],
statusHNH:uni.getStorageSync('statusHNH'),
publicColor:uni.getStorageSync('publicColor'),
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,
doctorList:[],
showDoctor:false,
timeList:[],//时间列表
zanArr:[],
timer:null,
search_result:false,
bingVal:'',
doctorVal:'',
activityVal:'',
bannerList:[],//轮播图
isAutoPlay:false,
optionObj:{},
positionMode:'sticky',
gaodu:0
}
},
onHide() {
this.isAutoPlay = false;
},
onUnload() {
this.isAutoPlay = false;
},
onShow() {
this.$toolAll.tools.isLogin();
this.cartNumEv();//查询购物车数量
this.isAutoPlay = true;
},
onPageScroll(e) {
if(e.scrollTop>=200){
this.positionMode = "fixed";
this.gaodu = 200;
} else {
this.positionMode = "sticky";
this.gaodu = 0;
}
},
onShareAppMessage() {
var shareObj = {
path: `/pages/tabbar/shop/shop?invite_code=${uni.getStorageSync('invite_code')}`, // 默认是当前页面,必须是以‘/’开头的完整路径
};
return shareObj;
},
onLoad(options) {
this.optionObj = options;
// 缓存状态栏+标题栏的高度
const query = wx.createSelectorQuery()
query.select('.search-input-box').boundingClientRect((rect) => {
// console.log('状态栏+标题栏:',rect.height);
this.titleHeight = rect.height;
}).exec()
this.checkSX();
let maiOjb = {
e:12,//进入商城
t:new Date().getTime()//当前时间戳
}
this.$toolAll.tools.maiDian(maiOjb);
this.$requst.post('index/mini-program-setting').then(res=>{
// log('数据:',res);
if(res.code==0){
if(res.data.length!=0){
if(res.data.footBar.length!=0){//底部导航
res.data.footBar.forEach(item=>{
let newName = item.name
let newObj = {
iconPath:this.$http + item.icon[0],
selectedIconPath:this.$http + item.icon[1],
}
if(item.key=="home"){
this.imgList[0] = newObj
this.titleList[0] = newName
}
if(item.key=="category"){
this.imgList[1] = newObj
this.titleList[1] = newName
}
if(item.key=="service"){
this.imgList[2] = newObj
this.titleList[2] = newName
}
if(item.key=="shop"){
this.imgList[3] = newObj
this.titleList[3] = newName
}
if(item.key=="my"){
this.imgList[4] = newObj
this.titleList[4] = newName
}
})
uni.setStorageSync('footTitle',this.titleList)
uni.setStorageSync('footimg',this.imgList)
this.titleList = uni.getStorageSync('footTitle')
this.imgList = uni.getStorageSync('footimg')
}
}
}
},error=>{})
// 调用查询轮播事件
this.checkSwi();
},
methods: {
// 顶部轮播查询事件
checkSwi(){
checkBanner({position:'home-banner'}).then(res=>{
if(res.code==0){
if(res.data.length!=0){
res.data.forEach(item=>{
let isVideo = false
if(item.type!='img') isVideo = true
let banObj = {
imgSrc:this.$http + item.src,
url:item.url,
isVideo:isVideo,
poster:this.$http + item.src,
}
this.bannerList.push(banObj)
})
console.log(this.bannerList);
}
}
})
},
chooseDoctor(index){//选择医生
this.shaiList = [];
this.doctor_name = this.doctorList[index].doctor_extra.name;
this.shaiList.push(this.doctor_name);
this.showDoctor = false;
},
chooseEv(){//查询医生列表
this.$requst.post('user/doctor-list',{page:1,size:1000}).then(res=>{
if(res.code==0){
this.doctor_name = '';
if(res.data.list.length!=0){
this.showDoctor = true;
this.doctorList = res.data.list;
} else this.$toolAll.tools.showToast('暂无医生可选');
} else this.$toolAll.tools.showToast(res.msg);
})
},
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.doctor_name = '';//清空医生列表
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 keyWord = this.searchVal;
if(this.shaiList.length!=0) keyWord = this.shaiList.filter(item=>item!=null).join(',');
let params = {
keyword:'',//商品关键字 支持模糊搜索
page:1,
size:2000,
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:`${uni.getStorageSync('hostapi')}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){
clearInterval(this.timer);
// if(this.page==1) {
this.zanArr = [];
this.dataList = [];
this.timeList = [];
// }
this.total = res.data.total;
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,//病种名称
reponseTime:res.header.Date,//接口响应时间
activity_end_at:item.activity_end_at,//限时结束时间
activity_group_cover:group_cover,//参团人的头像
activity_group_num:item.activity_group_num,//已经参团人数
activity_id:item.activity_id,
spu_type:item.spu_type//是否是虚拟商品
}
this.zanArr.push(obj)
})
this.zanArr.forEach((item,index)=>{
if(item.activity_end_at!='') {
let obj = {
id:item.id,
reponseTime:item.reponseTime,
time:item.activity_end_at,
nIndex:index
}
this.timeList.push(obj);
}
})
if(this.timeList.length!=0){
this.$toolAll.tools.showToast('加载中...')
this.timer = setInterval(()=>{//定时器
if(this.timeList.length!=0){
this.timeList.forEach((item,index)=>{
if(item.id==this.zanArr[item.nIndex].id){
let endTime = new Date(this.timeList[index].time).getTime();//把结束时间转时间戳
this.timeList[index].reponseTime = new Date(this.timeList[index].reponseTime).getTime() + 1000;//请求接口的时间递增,即:开始时间
if(this.timeList[index].reponseTime - endTime >=0) {//如果开始时间的时间戳 - 结束时间的时间戳 >= 0 活动结束
this.zanArr[item.nIndex].activity_end_at = "活动已结束";
} else {
// 继续进行倒计时
this.zanArr[item.nIndex].activity_end_at = this.$toolAll.tools.dayTime(this.timeList[index].time,this.timeList[index].reponseTime);
}
}
})
}
},1000)
setTimeout(()=>{
this.dataList = this.zanArr;
this.search_result = true;
this.loading = true;
},1000)
} else {
this.dataList = this.zanArr;
this.search_result = true;
this.loading = true;
}
} else {
this.search_result = true;
}
}
}
})
},
goPage(id,index){//进入商品详情事件
let is_activity = 0;
let shopId = 0;
if(this.dataList[index].isTuan==true || this.dataList[index].isPing==true || this.dataList[index].isXian==true) {
is_activity = 1;
shopId = this.dataList[index].activity_id;
} else {
shopId = id;
}
uni.navigateTo({
url:`/pagesB/shopDetail/shopDetail?id=${shopId}&isIntegral=${this.dataList[index].isIntegral}&is_activity=${is_activity}`
})
},
chooseBing(index){//小分类选择事件
this.bingzList.forEach(item=>{
item.isActive = false;
})
this.bingzList[index].isActive = true;
// 病种id
if(this.activeIndex===0) {
this.disease_id = this.bingzList[index].id;
this.bingVal = this.bingzList[index].title;
}
// 医生职位
if(this.activeIndex===1) {
this.doctor_role = this.bingzList[index].name;
this.doctorVal = this.bingzList[index].title;
}
// 活动type
if(this.activeIndex===2) {
this.activity = this.bingzList[index].name;
this.activityVal = this.bingzList[index].title;
}
},
chongz(){//重置
this.isClick = false;
this.bingVal = '';
this.doctorVal = '';
this.activityVal = '';
},
shaix(){//筛选
this.isXiao = false
this.isClick = true;
this.checkShopList();
},
deleteSX(index){//删除筛选
if(index==0) {
this.disease_id = '';
this.bingVal = '';
}
if(index==1) {
this.doctor_role = '';
this.doctorVal = '';
}
if(index==2) {
this.activity = '';
this.activityVal = '';
}
if(this.activity=='' && this.doctorVal == '' && this.activityVal == ''){
this.isClick = false;
}
this.checkShopList();
},
searchEv(){//搜索事件
uni.navigateTo({
url:`/pagesB/shopSearch/shopSearch?keyWorld=${this.searchVal}`
})
}
}
}
</script>
<style>
page{background: #F5F5F5;}
.activecate,.shopMo{width: 216rpx;height: 65rpx;border-radius: 20rpx;line-height: 65rpx;text-align: center;background-color: #f2f2f2;color: #333333;}
.activecate{color: #FFFFFF;}
.shopMo span::after,.activecate span::after{display: inline-block;content: '';width: 16rpx;height: 13rpx;margin-left: 6rpx;}
.shopMo span::after{background: url(/static/public/shopSJ.png) no-repeat;background-size: 100% 90%;}
.activecate span::after{background: url(/static/public/shopSJ-active.png) no-repeat;background-size: 100% 90%;transform: rotate(180deg);background-position: 0 2rpx;}
</style>