perry-mall/pagesB/myCollection/myCollection.vue

450 lines
17 KiB
Vue

<template>
<view>
<!-- 状态栏 -->
<status-nav :titleVal="'收藏'" :statusTitle="true"></status-nav>
<!-- 自定义二级分类 -->
<!-- 列表 -->
<view>
<view id="daoh" class="bacf pad-zy30 pad-sx20 isTopf fon28 col3 disja" :style="{top:statusHNH+'px'}">
<view @tap="shopCollection(0)" :class="isWen?'isWen':''" class="posir">文章收藏</view>
<view @tap="shopCollection(1)" :class="!isWen?'isWen':''" class="posir">商品收藏</view>
</view>
<view :style="{paddingTop:(statusHNH+chuTop+15)+'px'}">
<view v-if="isWen">
<view class="pad-zy32 mar-x20">
<cate-pu :newCurrent="newCurrent*1" :activeb="publicColor" :isCenter="false" :newbmo="'#F2F2F2'" @choosecateEv="chooseTwo" :newcateList="cateList"></cate-pu>
</view>
<view v-if="dataList.length!=0" class="pad-zy20 pad-s20">
<list-pu :radiu="true" @comfirmev="comfirmev" :list="dataList"></list-pu>
</view>
<view v-else class="disjcac fc" style="margin-top: 50%;">
<image class="zanw-img" src="/static/public/collection.png" style="" mode="aspectFill"></image>
<view class="fon24 col3">您还没有收藏,快去收藏吧</view>
</view>
</view>
<view v-else>
<view v-if="shopList.length!=0" style="margin-top: -20rpx;">
<view class="pad20">
<view style="width: 48.6%;float: left;">
<view v-if="index1%2==0" v-for="(item1,index1) in shopList" :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="posia list-like-box" @tap.stop="chooseLike(index1)">
<image class="animated" src="/static/public/like.png" mode="aspectFill"></image>
</view>
<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>
<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;">
<view v-if="index1%2!=0" v-for="(item1,index1) in shopList" :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="posia list-like-box" @tap.stop="chooseLike(index1)">
<image class="animated" src="/static/public/like.png" mode="aspectFill"></image>
</view>
<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>
<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" 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>
</view>
<view v-else class="disjcac fc" style="margin-top: 50%;">
<image class="zanw-img" src="/static/public/collection.png" style="" mode="aspectFill"></image>
<view class="fon24 col3">您还没有收藏,快去收藏吧</view>
</view>
</view>
</view>
</view>
<!-- 返回顶部 -->
<!-- <back-top :showTop="showTop" @backTop="backTop"></back-top> -->
<!-- 底部客服 -->
<public-customer :nbottom="100"></public-customer>
<!-- 弹框授权 -->
<empower @buttonH="buttonH" :vision="vision" :isWhere="2"></empower>
<!-- -->
<auth-phone v-if="isShowP"></auth-phone>
</view>
</template>
<script>
import {cancleCollectionEV,cancleCollectionShopEV} from '@/jsFile/publicAPI.js';
import shopList from '@/components/shop-list.vue';
export default {
components:{
shopList
},
data() {
return {
statusHNH:uni.getStorageSync('statusHNH'),
publicColor:uni.getStorageSync('publicColor'),//主题颜色
dataList:[],
showTop:false,//是否显示返回顶部
newCurrent:0,
cateList:[//所以二级分类
],
page:1,
size:10,
total:'',//总数
isZanw:true,
category_id:0,//栏目ID
chuTop:'',
isWen:true,
shopList:[],
activeIndex:0,
isShowT:false,
pu_content:'是否需要取消收藏?',
page:1,
size:10,
timeList:[],//时间列表
vision:false,
isShowP:false,
collectionTime:null
}
},
onPageScroll(e) {
e.scrollTop > 360 ? this.showTop = true : this.showTop = false
},
onReachBottom() {//触底事件
if(this.total!=this.dataList.length){
this.page++
this.checkConList(this.category_id)//调用自主预约列表事件
} else {
if(this.isZanw) this.$toolAll.tools.showToast('暂无更多列表','none',1000)
this.isZanw = false
}
},
onUnload() {
uni.removeStorageSync('cateList');
clearInterval(this.collectionTime);
},
onHide() {
clearInterval(this.collectionTime);
},
onShow() {
this.checkConList(this.category_id);
this.shopCollection();
},
onShareAppMessage() {
var shareObj = {
path: `/pagesB/myCollection/myCollection?invite_code=${uni.getStorageSync('invite_code')}`, // 默认是当前页面,必须是以‘/’开头的完整路径
};
return shareObj;
},
onLoad(options) {
if(uni.getStorageSync('is_active')!=1){this.vision = true;} else {this.$toolAll.tools.isLogin()}
if(options.invite_code!='' && options.invite_code!=undefined){
this.loginEv(options.invite_code);
} else if(options.source_code!='' && options.source_code!=undefined){
this.loginEv('',options.source_code,options.channel);
}
const query = wx.createSelectorQuery()
query.select('#daoh').boundingClientRect((rect) => {
// console.log('状态栏+标题栏:',rect);
this.chuTop = rect.height
}).exec()
},
methods: {
loginEv(invite_code='',source='',channel=''){
uni.login({
provider: 'weixin',
success: (res)=> {
if (res.code) {
var params = {
code:res.code,
invite_code:invite_code,//用户邀请码
source_code:source,
channel:channel
}
this.$requst.post('user/login',params).then(res => {
if(res.data.token!=''){
if(res.data.is_active==0) {
this.haveImg = false;
this.vision = true;
}
}
},error => {})
}
},
});
},
buttonH(e){//授权成功
this.haveImg = e
if(e) {
this.vision = false
this.isShowP = true
}
},
shopCollection(index){//查询商品的收藏列表
clearInterval(this.collectionTime);
if(index==1){
this.isWen = false;
uni.request({
url:`${getApp().globalData.domainName}spu/collection`,
data:{page:this.page,size:this.size},
method:'post',
header:{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer '+uni.getStorageSync('token') || ''
},
success: (res) => {
if(res.data.code==0){
this.shopList = [];
let nArr = [];
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,//已经参团人数
}
nArr.push(obj)
})
this.loading = true;
}
nArr.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!=0){
this.$toolAll.tools.showToast('加载中...')
this.collectionTime = setInterval(()=>{//定时器
if(this.timeList.length!=0){
this.timeList.forEach((item,index)=>{
console.log(item.id,nArr[item.nIndex].id);
if(item.id==nArr[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 活动结束
nArr[item.nIndex].activity_end_at = "活动已结束";
} else {
// 继续进行倒计时
nArr[item.nIndex].activity_end_at = this.$toolAll.tools.dayTime(this.timeList[index].time,this.timeList[index].reponseTime);
}
}
})
}
},1000)
setTimeout(()=>{
this.shopList = nArr;
},1000)
} else {
this.shopList = nArr;
}
}
}
})
} else {
this.isWen = true;
}
},
checkConList(category_id){//查询收藏列表
// this.$toolAll.tools.showToast('加载中...')
let params = {
category_id:category_id,
page:this.page,
size:this.size
}
this.$requst.post('archives/collects',params).then(res=>{
if(res.code==0){
// 栏目类别
if(uni.getStorageSync('cateList')==''){//首次渲染栏目
if(res.data.category.length!=0){
res.data.category.forEach((item,index)=>{
let cateObj = {
id:item.id,//栏目ID
title:item.title,//栏目名称
active:item.active,//是否选中
model_id:item.model_id,//模型ID
model_name:item.model_name,//模型标识
sort:item.sort,
}
this.cateList.push(cateObj)
})
uni.setStorageSync('cateList',this.cateList)
this.category_id = this.cateList[0].id
}
} else {
//获取缓存中的栏目
this.cateList = uni.getStorageSync('cateList')
}
// 获取列表
if(this.page==1) this.dataList = []
this.total = res.data.list.total
if(res.data.list.list.length!=0){
uni.hideToast()
res.data.list.list.forEach(item=>{
let fabImg = '';
if(item.published_headimgurl!='' && item.published_headimgurl!=null) fabImg = this.$http + item.published_headimgurl;
let tObj = {
category_id:item.category_id,//栏目ID
id:item.id,
is_collected:1,//是否已收藏
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: fabImg || '/static/public/logo.png',//发布者头像
name:item.published_by || '恒美植发',//发布者昵称
isVideo:item.video.includes(".mp4")//是否是视频
}
this.dataList.push(tObj);
})
}
}
},error=>{})
},
comfirmev(e){//确认取消收藏事件
this.$toolAll.tools.showToast('正在取消...','loading')
// 调用取消收藏事件
cancleCollectionEV({action:'collect',archive_id:this.dataList[e].id})
setTimeout(()=>{
this.checkConList(this.category_id)
},300)
this.dataList[e].is_collected = 0
},
chooseLike(index){
this.activeIndex = index;
this.isShowT = true;
},
submitQu(){
this.$toolAll.tools.showToast('正在取消...','loading');
// 调用取消收藏事件
cancleCollectionShopEV({action:'collect',id:this.shopList[this.activeIndex].id});
this.isShowT = false;
this.shopList.splice(this.activeIndex,1);
// this.shopCollection();
},
chooseTwo(index){//二级分类选择
this.newCurrent = index
this.isZanw = true
this.page = 1
this.category_id = this.cateList[index].id
this.checkConList(this.cateList[index].id)
// console.log('二级分类:',index);
},
backTop(){//回到顶部事件
uni.pageScrollTo({
scrollTop: 0,
duration: 300
});
},
goPage(id,index){//进入商品详情事件
uni.navigateTo({
url:`/pagesB/shopDetail/shopDetail?id=${id}&isIntegral=${this.shopList[index].isIntegral}`
})
}
}
}
</script>
<style>
.isWen{color: #3875F6;}
.isWen::after{
content: '';
display: block;
height: 4rpx;
width: 100%;
position: absolute;
bottom: -20rpx;
background: #3875F6;
}
</style>