perry-mall/pagesB/shopDetail/shopDetail.vue

684 lines
23 KiB
Vue
Raw Normal View History

2022-02-12 11:33:47 +00:00
<template>
<view>
<!-- 状态栏 -->
<!-- 状态栏 -->
<status-nav
:ifTitle="true"
:ifReturn="true"
:ifCenter="true"
:navBarTitle="'商品详情'"></status-nav>
<!-- 容器 -->
<container-subgroup>
<view style="margin: 0 -30rpx;">
2022-02-12 11:33:47 +00:00
<swiper-pu v-if="cateCurrent==0" :isplay="isAutoPlay" :browseP="true" :bannerList="bannerList" :newHeight="swiperHeight" :newRadius="'0'" :newBottom="'5'"></swiper-pu>
</view>
<!-- 标题 -->
<view class="mar-s30 mar-x20 fon36 bold clips2 line-h50">New Farandole项链小号New Farandole项链小号New Farandole项链小号New Farandole项链小号</view>
<!-- 描述 -->
<view class="colpeili fon30 clips3 line-h50">于亿年宝藏中臻选1的宝石级钻石每年开采数亿克拉的钻石中 仅有1%的宝石级钻石才可作为...LOVE100 星座极光的原石挑选 </view>
<view class="disac mar-s20">
<!-- 是否限时优惠 -->
<view class="fon24 colf pad-zy10 pad-s10 pad-x20 activity-img">限时优惠</view>
<!-- 价格 -->
<view class="disac">
<view class="fon40 bold col0 mar-y10">20,000</view>
<view class="fon30 colpeili" style="text-decoration: line-through;">16,000</view>
2022-02-12 11:33:47 +00:00
</view>
</view>
<!-- 颜色 -->
<view class="mar-s50"><drop-down></drop-down></view>
<!-- 尺寸 -->
<drop-down :dropObj="dropObj" @chooseItem="chooseItem"></drop-down>
<!-- 作品介绍 -->
<view class="mar-s100 mar-x30 fon36 bold col0 tcenter">作品介绍</view>
<!-- 富文本 -->
<rich-text :nodes="shopRich"></rich-text>
</container-subgroup>
<!-- 底部导航 -->
<bottom-nav></bottom-nav>
<!-- 全局客服 -->
<public-customer
:nbottom="180"
:backgroundColor="'#FFFFFF'"
:radiusNum="'40rpx'"
:showText="false"
:iconNum="1"
:iconColor="'#000000'"></public-customer>
<view class="pad-x180" :style="{paddingTop: isNei!=3?(statusHNH+60)+'px':statusHNH+'px'}">
2022-02-12 11:33:47 +00:00
<!-- 立即购买加入购物车弹框 -->
<view v-if="showTK" class="posAll" style="z-index: 1000;" @tap="showTK=false">
<view class="bacf posixzy bottom-popu" @tap.stop="showTK=true">
<view class="disjb pad-zy50">
<image :src="zhuImg" mode="aspectFill"></image>
<view class="disjbac width100">
<view v-if="isNei!=3">
<view class="fon40 mar-sx10 colf8">{{skuDetail.price/100}}</view>
<!-- <view v-if="isNei!=10"><span class="yuan-price">{{skuDetail.original_price/100}}</span></view> -->
<view><span class="yuan-price">{{skuDetail.original_price/100}}</span></view>
</view>
<view v-else><view class="fon40 mar-sx10 colf8">积分{{skuDetail.score}}</view></view>
<image @tap.stop="showTK=false" src="/static/public/cha-close.png" style="margin-right: 0rpx;" mode=""></image>
</view>
</view>
<!-- 标题 -->
<view class="fon36 col3 bold clips3 pad-zy30 mar-s20 shop-title-box line-h50">
<view style="margin-top: -8rpx;margin-right: 10rpx;">
<span class="radius15 colf fon20" :style="{background:publicColor}">{{detailObj.disease_name}}</span>
<span class="radius15 colf fon20 mar-z10" v-if="isNei==0"></span>
<span class="radius15 colf fon20 mar-z10" v-if="isNei==1"></span>
<span class="radius15 colf fon20 mar-z10" v-if="isNei==2"></span>
</view>
<span>{{detailObj.name}}</span>
</view>
<view class="dis mar-sx40 pad-zy30 col3">
<view class="fon28 flexs" style="margin-top: 6rpx;">类型</view>
<view class="fon26 disac fw width100" style="justify-content: flex-end;">
<view @tap="chooselei(indexl)" class="mar-x20" v-for="(item,indexl) in allRes.sku" :key="indexl" :class="leiIndex==indexl?'activelei':'molei'" :style="{background:leiIndex==indexl?publicColor:'#F2F2F2'}">{{item.title}}</view>
</view>
</view>
<view class="disjbac mar-sx40 pad-zy30 fon28">
<view class="col3">库存</view>
<view class="fon26 col3" style="color: #5B5B5B;">{{skuDetail.stock}}</view>
</view>
<view class="disjbac mar-sx40 pad-zy30 fon28">
<view class="col3">购买数量</view>
<view class="fon26 col3 disac bold">
<image @tap="buyNum!=1?buyNum--:''" src="/static/public/del.png" class="del-btn" mode=""></image>
<input type="text" @input="inputNum" v-model="buyNum" class="num-input"/>
<image @tap="buyNum++" src="/static/public/add.png" class="add-btn" mode=""></image>
</view>
</view>
<!-- 加入购物车立即购买 -->
<view v-if="isNei!=1" class="disjbac pad-zy30 colf fon32 mar-x50">
<view @tap="addCart" class="ev-btn pbackc">加入购物车</view>
<view v-if="isNei!=3" @tap.stop="goGetReadyDan(0)" class="ev-btn bcf8"></view>
<view v-else @tap.stop="goGetReadyDan(0)" class="ev-btn bcf8">立即兑换</view>
</view>
<!-- 单独购买立即拼团 -->
<view v-else class="disjbac pad-zy30 colf fon32 mar-x50">
<view @tap.stop="goGetReadyDan(2)" class="ev-btn" style="background: #C8C8C8;">单独购买</view>
<view @tap.stop="goGetReadyDan(0)" class="ev-btn bcf8">发起拼团</view>
</view>
</view>
</view>
<!-- 返回顶部 -->
<!-- <back-top :showTop="showTop" @backTop="backTop"></back-top> -->
<!-- 弹框授权 -->
<!-- <empower @buttonH="buttonH" :vision="vision" :isWhere="2"></empower> -->
2022-02-12 11:33:47 +00:00
<!-- 弹框 -->
<!-- <auth-phone v-if="isShowP"></auth-phone> -->
2022-02-12 11:33:47 +00:00
</view>
</view>
</template>
<script>
import listDoctor from '@/components/list-doctor.vue';
import swiperPu from '@/components/swiper-pu.vue';
import {cancleCollectionShopEV,collectionShopEV} from '@/jsFile/publicAPI.js';
import shopList from '@/components/shop-list.vue';
import dropDown from '@/components/drop-downs/drop-down.vue';
import bottomNav from '@/components/detail-bottom-nav/bottom-nav.vue';
2022-02-12 11:33:47 +00:00
export default {
components:{
listDoctor,
swiperPu,
shopList,
dropDown,
bottomNav
2022-02-12 11:33:47 +00:00
},
data() {
return {
statusBarHeight:uni.getSystemInfoSync().statusBarHeight,
isLoading:false,
statusHNH:uni.getStorageSync('statusHNH'),
publicColor:uni.getStorageSync('publicColor') || '#3875F6',//主题颜色
cateCurrent:0,
dropObj:{
title:'尺寸',
childrenList:[
{
id:1,
childrenTitle:'1.2'
},
{
id:1,
childrenTitle:'6'
}
]
},
shopRich:'',//商品富文本
2022-02-12 11:33:47 +00:00
swiperHeight:uni.getSystemInfoSync().windowWidth,
haveImg:true,
cateList:[{
id:1,
title:'商品详情',
pid:11,
sort:4
}],
bannerList:[{
imgSrc:'https://s6.jpg.cm/2022/02/14/L4oDhy.jpg',
url:'',
isVideo:false,
poster:'',
}],//轮播
2022-02-12 11:33:47 +00:00
//相关推荐
xgList:[],
//产品推荐
dataList:[],
showTop:false,
isDetailConllection:false,//是否已收藏
isNum:0,
listArrone:[],//问题
//案例日记
listArrtwo:[],
//效果模拟
listArrthree:[],
//科普视频
listArrfour:[],
//医生列表
doctorList:[],
detailObj:{},//详情
detailInfo:'',//富文本
category_id:'',//栏目ID
active:'',//是否是详情页
share_id:0,
invite_code:'',
showTK:false,
leiIndex:0,
showPD:false,
isNei:'',//什么类型的商品
pingArr:[],//拼团列表
len:0,//正在拼团人数
pinInfo:{},//拼单人信息
allRes:{},//所有订单信息
zhuImg:'',//cover图
skuDetail:{},//sku详情
buyNum:1,//购买数量
daoTime:'',//储存倒计时
csNum:0,//点击次数,
isBuy:0,//
ispt:0,//拼团的方式0默认发起拼团1参与平台 2单独购买
isScore:0,//是否是积分
cartNum:0,
skuCate:[],//类型
pinDao:'',//平团倒计时
serverTime:'',//服务器时间
timerServer:null,
timerp:null,
timera:null,
pinUserId:0,//发起拼单人ID
isAutoPlay:false,
vision:false,
isShowP:false,
page:1,
size:20,
total:0,
isZanw:true,
allList:[],
isactivity:0,//是不是活动商品0不是1
orderId:'',//商品id
timeout:null,
}
},
onReachBottom() { //触底事件
if(this.cateCurrent!=this.isNum){
if(this.total!=this.allList.length){
this.page++
this.checkList(this.cateCurrent)//调用自主预约列表事件
} else {
if(this.isZanw) this.$toolAll.tools.showToast('暂无更多列表','none',1000)
this.isZanw = false
}
}
},
onPageScroll(e) {
e.scrollTop > 360 ? this.showTop = true : this.showTop = false
},
onShareAppMessage(res) {
var ya = this;
this.$requst.post('user/record',{type:this.detailObj.is_activity==0 ? 'spu':'activity',action:'share',id:this.detailObj.id}).then(res=>{console.log('分享成功:',res);},error=>{})
let maiOjb = {
e:this.detailObj.is_activity==0 ? 10 : 11,//商品分享10普通商品11活动商品
c: this.detailObj.is_activity==0 ? this.detailObj.id*1 : this.detailObj.activity_id,
t:new Date().getTime()//当前时间戳
}
this.$toolAll.tools.maiDian(maiOjb)
if(ya.detailObj.share_img==null) ya.detailObj.share_img = ya.detailObj.cover;
var shareObj = {
     title: `${ya.detailObj.name}`, // 默认是小程序的名称(可以写slogan等)
     path: `/pagesB/shopDetail/shopDetail?id=${this.detailObj.is_activity==1?this.detailObj.activity_id:this.detailObj.id}&category_id=${this.category_id}&is_activity=${this.detailObj.is_activity==0 ? 0 : 1}&share_id=${uni.getStorageSync('userId')}&invite_code=${uni.getStorageSync('invite_code')}`, // 默认是当前页面,必须是以‘/’开头的完整路径
     imageUrl: ya.$http + ya.detailObj.share_img//自定义图片路径可以是本地文件路径、代码包文件路径或者网络图片路径支持PNG及JPG不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  };
  return shareObj;
},
onShow() {
uni.removeStorageSync('chooseAddress');
this.isAutoPlay = true;
},
onHide() {
this.isAutoPlay = false;
},
onUnload() {
clearInterval(this.timera);
clearInterval(this.timerp);
clearInterval(this.timerServer);
this.isAutoPlay = false;
},
onLoad(options) {
if(uni.getStorageSync('is_active')!=1){
this.vision = true;
this.loginEv(options);
} else {
this.cartNumEv();
//查询过期时间和是否有token并调用登录事件
this.$toolAll.tools.overdue();
}
if(options.category_id!=undefined) {
this.category_id = options.category_id
this.invite_code = options.invite_code
}
if(options.share_id!=undefined) this.share_id = options.share_id
if(options.isIntegral=="true"){this.isScore = 3;}
this.isactivity = options.is_activity;
this.orderId = options.id;
// 如果链接是拼团链接,则调起发起拼团人的商品
if(options.shareCate==1) {
// options.checkGrounpI商品id
// options.share_id:拼团人id
this.sharePin(options.checkGrounpId,options.share_id);
}
},
methods: {
// 尺寸选择事件
chooseItem(e){
this.log(e);
},
2022-02-12 11:33:47 +00:00
// 数量输入事件
inputNum(e){
clearTimeout(this.timeout);
let str = e.detail.value;
this.timeout = setTimeout(()=>{
if(str=='' || str==0){
this.buyNum = 1;
}
},500)
},
sharePin(id,u_id){
// id:商品id
this.$requst.post('spu/group-list',{id:id}).then(res=>{
if(res.code==0){
if(res.data.length){
res.data.forEach(item=>{
console.log(item.id,u_id);
if(item.id==u_id){
this.pinInfo = {
id:item.id,
imgSrc:item.cover,
name:item.name,
num:item.num
}
this.showPD = true;
this.detailPTime(item.time);
}
})
}
} else this.$toolAll.tools.showToast(res.msg);
})
},
loginEv(options){
uni.login({
provider: 'weixin',
success: (res)=> {
var params = {
code:res.code,
invite_code:options.invite_code || '',//用户邀请码
source_code:options.source_code || '',
channel:options.channel || ''
}
this.$requst.post('user/login',params).then(res => {
if(res.data.token!=''){
if(res.data.is_active==0) {
this.haveImg = false;
}
}
},error => {})
},
});
},
buttonH(e){//授权成功
this.haveImg = e
if(e) {
this.vision = false;
this.isShowP = true;
}
},
cartNumEv(){//购物车数量
let ntype = 'spu'
if(this.isScore==3) ntype = 'score';
this.$requst.post('order/shopping-cart-count',{type:ntype}).then(res=>{
if(res.code==0){
this.cartNum = res.data.count;
}
})
},
checkPTList(id){//查询正在拼团的人数
uni.request({
url:`${uni.getStorageSync('hostapi')}spu/group-list`,
2022-02-12 11:33:47 +00:00
data:{id:id},
method:'post',
header:{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer '+uni.getStorageSync('token') || ''
},
success: (res) => {
if(res.data.code==0){
let ntime = new Date(res.header.Date).getTime();//服务器时间
this.timerServer = setInterval(()=>{
ntime = ntime + 1000
this.serverTime = new Date(ntime);
},1000);
if(res.data.data.length!=0){
res.data.data.forEach(item=>{
let pObj = {
id:item.id,
imgSrc:item.cover,
name:item.name,
num:item.num,//剩余拼团数量
time:item.time,//拼团截止时间
time_text:item.time_text//拼团截止时间展示文本
}
this.pingArr.push(pObj);
})
this.len = this.pingArr.length;
let n = 2; //假设每行显示2个
let lineNum = this.len % 2 === 0 ? this.len / 2 : Math.floor( (this.len / 2) + 2 );
let newPArr = [];
for (let i = 0; i < lineNum; i++) {
let temp = this.pingArr.slice(i*n, i*n+n);
newPArr.push(JSON.parse(JSON.stringify(temp)));
}
this.pingArr = newPArr;
}
} else this.$toolAll.tools.showToast(res.msg);
}
})
},
goGetReadyDan(index){//弹框中的立即购买
this.showTK = false;
// {id:1,imgSrc:'/static/tabbar/mya.png',title:'【99皮皮节】【种植发际线】',price:3888,num:1,isActive:false},
let nprice = '';
if(this.isNei==3) {
nprice = this.skuDetail.score;
} else nprice = this.skuDetail.price/100;
this.ispt = index;
if(index==2){nprice = this.skuDetail.original_price/100;}
let params = {
id:this.detailObj.spu_id,
imgSrc:this.$http + this.detailObj.cover,
coding:this.skuDetail.coding,
price:nprice,
num:this.buyNum || 1,
title:this.detailObj.name,
sku_name:this.skuDetail.title,
is_score:this.detailObj.is_score,
group_id:this.ispt,//0发起拼团 1参与拼团 2单独购买
is_only:this.ispt,
pin_user_id:this.pinUserId,//发起拼单人ID
category_id:this.category_id,//病种ID
cateNum:this.isNei,
checkGrounpId:this.detailObj.id,//查询拼团列表ID
}
let newList = [params];
uni.setStorageSync('orderList',newList);
uni.navigateTo({
url:`/pagesA/getReadyDan/getReadyDan?isNei=${this.isNei}&isVirtual=${this.detailObj.spu_type}`
})
},
addCart(){//添加购物车事件
if(this.csNum==0){
this.csNum++;
this.$toolAll.tools.showToast('正在加入购物车...');
this.$requst.post('order/shopping-cart-add',{sku_id:this.skuDetail.id,num:this.buyNum}).then(res=>{
if(res.code==0) {
this.showTK = false;
this.$toolAll.tools.showToast('添加购物车成功(*^▽^*)');
this.cartNumEv();
this.csNum = 0;
}
})
}
},
comeTuan(pinId,index,index2){//去拼单
this.showPD = true;
this.pinInfo = this.pingArr[index][index2];
this.pinDao = this.$toolAll.tools.dayTime(this.pinInfo.time,this.serverTime);
this.timerp = setInterval(()=>{
if((new Date(this.pinInfo.time).getTime()) - (new Date(this.serverTime).getTime())<=0){
this.pinDao = '已结束';
this.checkPTList(this.detailObj.id);
this.showPD = false;
clearInterval(this.timerp);
} else {
this.pinDao = this.$toolAll.tools.dayTime(this.pinInfo.time,this.serverTime);
}
},1000)
},
detailPTime(endtime){
this.pinDao = this.$toolAll.tools.dayTime(endtime,new Date());
this.timerp = setInterval(()=>{
if((new Date(endtime).getTime()) - (new Date().getTime())<=0){
this.pinDao = '已结束';
this.checkPTList(this.detailObj.id);
this.showPD = false;
clearInterval(this.timerp);
} else {
this.pinDao = this.$toolAll.tools.dayTime(endtime,new Date());
}
},1000)
},
atOnceSpellOrder(index){//参与拼单
if(index==1){
this.showTK = true;
this.pinUserId = this.pinInfo.id;
}
this.showPD = false;
clearInterval(this.timerp);
this.daoTime = '';
},
chooselei(index){//类型选择
this.leiIndex = index;
this.skuDetail = this.allRes.sku[index];
},
lianK(){//客服
// if(!this.jieDuan){
// let isAuth = this.$toolAll.tools.returnAuth()
// if(!isAuth){
if(this.haveImg == false) {
this.vision = true
} else {
this.$requst.post('user/rand-bind-service').then(res=>{})
this.$requst.post('user/record',{type:'other',action:'ask',id:0}).then(res=>{},error=>{})
let maiOjb = {
e:this.detailObj.is_activity==0 ? 13:14,//商品咨询13普通商品14活动商品
t:new Date().getTime()//当前时间戳
}
this.$toolAll.tools.maiDian(maiOjb)
}
// } else this.jieDuan = true
// }
},
chooseLike(e) { //收藏事件
// console.log(this.dataList[e].is_collected);
if (this.allList[e].is_collected == 0) {
this.allList[e].is_collected = 1
// 调用收藏事件
collectionEV({
action: 'collect',
archive_id: this.allList[e].id
})
}
},
comfirmev(e) { //确认取消收藏事件
this.allList[e].is_collected = 0;
this.$toolAll.tools.showToast('正在取消...', 'loading')
// 调用取消收藏事件
cancleCollectionEV({
action: 'collect',
archive_id: this.allList[e].id
})
},
backHome(){
uni.navigateTo({
url:'/pages/tabbar/pagehome/pagehome'
})
},
shareEv(){
if(this.haveImg == false) {
this.vision = true
}
},
checkShopList(){// 产品推荐
let params = {
keyword:'',//商品关键字 支持模糊搜索
page:1,
size:10,
doctor_role:'',//医生从职位标识 从商品筛选条件接口获取 目前为doctor=医生 design=设计师
doctor_name:'',//医生姓名 模糊搜索
activity:'',//活动类型 不填为普通商品+活动商品 normal=普通商品group_make=拼团group_buy=团购;limit_time=限时促销
disease_id:''//病种ID
}
uni.request({
url:`${uni.getStorageSync('hostapi')}spu/list`,
2022-02-12 11:33:47 +00:00
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,//已经参团人数
activity_id:item.activity_id
}
this.dataList.push(obj)
})
}
}
}
})
},
goShopCart(){//去购物车事件
let isScore = '';
if(this.isNei==3) isScore = 'score';
uni.navigateTo({
url:`/pagesA/shopCart/shopCart?isScore=${isScore}`
})
},
goDoctor(id){
uni.navigateTo({
url:`/pagesB/doctorDetail/doctorDetail?doctor_id=${id}`
})
},
choosecateEv(e){//分类列表事件
this.$requst.post('archives/category', {
category_id: this.cateList[e].id,
keyword: '',
page:this.page,
size:this.size
}).then(res => {
// console.log('该分类下的列表:',res);
if (res.code == 0) {
if(this.page==1) {
if(this.active != e) this.allList = [];
uni.pageScrollTo({
scrollTop:0,
duration:0
})
}
this.total = res.data.list.total;
if (res.data.list.list.length != 0) {
res.data.list.list.forEach(item => {
let num = item.video.search(".mp4")
let isVideo = false
if (num != '-1') isVideo = true
let fabImg = '';
if (item.published_headimgurl != '' && item.published_headimgurl != null)
fabImg = this.$http + item.published_headimgurl
let arrObj = {
category_id: item.category_id, //栏目ID
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: fabImg || '/static/public/logo.png', //发布者头像
name: item.published_by || '恒美植发', //发布者昵称
isVideo: isVideo //是否是视频
}
if (item.cover != '') {
this.allList.push(arrObj);
}
})
}
this.cateCurrent = e;
} else this.$toolAll.tools.showToast(res.msg);
}, error => {})
},
tapConllection(){//收藏、取消收藏事件
let isLikeCon = 'collect';
let nid = '';
if(this.detailObj.is_activity==1) nid=this.detailObj.spu_id;
else nid=this.detailObj.id;
// 调用收藏事件
if(!this.isDetailConllection) collectionShopEV({action:isLikeCon,id:nid})
// 调用取消收藏事件
else cancleCollectionShopEV({action:isLikeCon,id:nid})
this.isDetailConllection = !this.isDetailConllection
},
backTop(){//回到顶部事件
uni.pageScrollTo({
scrollTop: 0,
duration: 300
});
},
}
}
</script>
<style>
</style>