|
|
<template> <view> <lf-nav title="商品详情" titleColor="#fff" :spreadOut="false" :showIcon="true" bgColor="transparent"></lf-nav> <skeleton :loading="skeletonLoading" :row="12" :showAvatar="false" :showTitle="true"> <block> <!-- 商品图片轮播 --> <swiper :current="current" :indicator-dots="2 > 1 ? false : true" :circular="true" class="swiper-box" indicator-active-color="#1998FE"> <swiper-item v-for="(item, index) in pictures" :key="index"> <image mode="aspectFill" :src="item" style="width: 100%; height: 100%;" @click="lookImg(index)"></image> <view class="seckill-box" v-if="type == 'seckill'"> <view>距离结束还剩余</view> <view> <countdown-timer :time="time" :autoStart="true"> <template v-slot="{hour, minute, second}"> <view class="lf-flex"> <view>{{ hour >= 10 ? hour : "0" + hour }}</view> <view>时</view> <view>{{ minute >= 10 ? minute : "0" + minute }}</view> <view>分</view> <view>{{ second >= 10 ? second : "0" + second }}</view> <view>秒</view> </view> </template> </countdown-timer> </view> </view> </swiper-item> </swiper> <!-- 商品主要信息 --> <view class="head-info"> <view class="lf-row-between"> <view v-if="type == 'point'"> <text class="lf-font-48 lf-color-primary lf-font-bold">8493</text> <text class="lf-font-28 lf-color-777 lf-m-l-10">个兑换</text> </view> <lf-price :iftext="false" :price="111" v-else></lf-price> <text class="lf-iconfont icon-fenxiang lf-font-40" @click="shareGraphic()"></text> </view> <view class="lf-row-between lf-font-24 lf-m-t-20 lf-p-b-20"> <view class="lf-font-bold lf-font-32 lf-color-222">颐莲喷雾 500ml</view> </view> <view class="lf-row-between lf-font-24 lf-p-b-30"> <view class="lf-font-28 lf-color-777" v-if="type == 'self'">门店自提</view> <view class="lf-font-28 lf-color-777 lf-row-between" v-else>可自提/可邮寄</view> <view v-if="type == 'seckill'">已有38人购买</view> </view> </view> <self-line></self-line> <view class="bg-white" v-if="type == 'self'"> <view class="cu-bar padding-lr"> <view class="lf-flex"> <text class="lf-color-777 lf-font-28">优惠</text> <view v-if="orderDetails.coupon == ''"> <text class="lf-color-price lf-font-28 lf-m-l-10" v-for="(item,index) of orderDetails.coupon">{{item.tag}}</text> </view> <view v-else> <text class="lf-color-222 lf-font-26 lf-m-l-30">化妆品教师节满1200减200</text> </view> </view> <view> <text class="lf-font-24 lf-color-777 lf-iconfont icon-xiangyou"></text> </view> </view> </view> <self-line></self-line> <view class="bg-white" v-if="type == 'self'"> <view class="cu-bar padding-lr"> <view class="lf-flex"> <text class="lf-color-777 lf-font-28">服务</text> <view style="width: 600rpx;flex-wrap: wrap;display: flex;margin-top: 32rpx;"> <view class="lf-m-l-30" v-for="i of 5"> <text class="lf-iconfont icon-xuanzhong lf-font-30" style="color: #15716E;"></text> <text class="lf-m-l-10 lf-font-26 lf-color-black">正品保障</text> </view> </view> </view> <view> <text class="lf-font-24 lf-color-777 lf-iconfont icon-xiangyou"></text> </view> </view> </view> <block v-else> <view class="bg-white"> <view class="cu-bar padding-lr"> <view class="lf-flex"> <view class="lf-color-777 lf-font-28">送至</view> <view class="lf-color-222 lf-font-26 lf-m-l-30" style="width: 550rpx;">广西壮族自治区-南宁市-青秀区-民族大道180号</view> </view> <view> <text class="lf-font-24 lf-color-777 lf-iconfont icon-xiangyou"></text> </view> </view> </view> <view class="bg-white"> <view class="cu-bar padding-lr"> <view class="lf-flex"> <view class="lf-color-777 lf-font-28">运费</view> <view class="lf-color-222 lf-font-26 lf-m-l-30 lf-line-1" style="width: 550rpx;">在5kg~10kg内,包含5kg;重量在5kg以内按3kg</view> </view> <view> <text class="lf-font-24 lf-color-777 lf-iconfont icon-xiangyou"></text> </view> </view> </view> </block> <view class="bg-white"> <view class="cu-bar padding-lr" @click="shoot(2)"> <view class="lf-flex"> <text class="lf-color-777 lf-font-28">已选</text> <text class="lf-color-222 lf-font-26 lf-m-l-30">已选500ml x1</text> </view> <view> <text class="lf-font-24 lf-color-777 lf-iconfont icon-xiangyou"></text> </view> </view> </view> <self-line></self-line> <view> <view class="user-top"> <view class="lf-row-between lf-w-100"> <view class="lf-flex" @click="$url('/pages/shop/shopdetail')"> <view class="tag-father"> <image src="https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png" mode="aspectFill" class="head-img"></image> </view> <view class="lf-flex-column lf-m-l-20"> <text class="lf-font-28 lf-color-black lf-font-bold">颐莲官方店</text> <view class="lf-font-24 lf-color-777"><u-icon name="map" class="lf-m-r-10"></u-icon>L2</view> </view> </view> <view> <button class="head-btn" @click="$url('/pages/user/my/chatonline')"> <u-icon name="chat" class="lf-m-r-10"></u-icon> <text>客服</text> </button> </view> </view> </view> <scroll-view class="scroll-view" :scroll-x="true"> <view class="scroll-content"> <view class="goods-item" v-for="(item, index) in 5" :key="index" @click="$url('/pages/shop/goodsdetail?type='+ this.type)"> <image class="goods-img"></image> <view class="goods-info"> <view class="lf-line-1">猪大肠卖咯 5毛钱一斤咯</view> <view>¥0.5</view> </view> </view> <view class="goods-item" @click="$url('/pages/shop/shopdetail')"> <view class="more-box"> <text>查看更多</text> <text class="lf-iconfont icon--2 lf-text-vertical"></text> </view> </view> </view> </scroll-view> </view> <!-- 商品详情 --> <view class="goods-detail"> <view class="lf-font-32 lf-font-bold lf-m-b-20">商品详情</view> <rich-text :nodes="formatRichText('商品详情商品详情商品详情商品详情商品详情商品详情商品详情商品详情商品详情商品详情商品详情商品详情')"></rich-text> <!-- <image class="goods-img" :src="item" v-for="(item, index) in goods_detail.content" :key="index" v-if="goods_detail.content_type == 'img'"></image> --> </view> <!-- 修饰专用 --> <view class="extra"></view> <!-- 吸底操作按钮 --> <view class="lf-row-between fixed-bottom"> <view class="lf-flex lf-p-t-10 lf-p-b-10"> <view class="lf-flex-column lf-row-center icon-item" open-type="contact"> <text class="lf-iconfont icon-shoucang icon-img"></text> <view class="lf-m-t-1">客服</view> </view> <view class="lf-flex-column lf-row-center icon-item" @click="switchCollect"> <text class="lf-iconfont icon-shoucang icon-img" v-if="is_collect"></text> <text class="lf-iconfont icon-shoucang icon-img" v-else></text> <view class="lf-m-t-1">{{ is_collect ? '已收藏' : '收藏' }}</view> </view> <button class="lf-flex-column lf-row-center icon-item"> <text class="lf-iconfont icon-shoucang icon-img"></text> <view class="lf-m-t-1">购物车</view> </button> </view> <view v-if="type == 'seckill'"> <button class="btn" style="width: 349rpx;">立即秒杀</button> </view> <view v-else-if="type == 'point'"> <button class="btn" style="width: 349rpx;">立即兑换</button> </view> <view class="lf-flex" v-else> <button class="btn1" @click="shoot(1)">加入购物车</button> <button class="btn lf-m-l-15" @click="shoot(2)">立即购买</button> </view> </view> <!-- 加入购物车、立即购买模态框选规格 --> <u-popup v-model="show_popup" mode="bottom"> <view class="popup-content"> <!-- 商品信息及关闭按钮 --> <view class="popup-head"> <view class="lf-flex"> <image class="goods-img" src="https://picsum.photos/200"></image> <view class="goods-info"> <view class="price">¥5.8</view> <view class="goods-name">桃子</view> </view> </view> <view @click="show_popup = false"> <text class="lf-iconfont icon-cuo lf-font-50"></text> </view> </view> <!-- 规格 --> <view class="spec-title">重量</view> <view class="lf-flex-wrap"> <view :class="{ 'spec-item': true, 'spec-active': spec_current == index}" @click="activeSpec(index)" v-for="(item, index) in 5" :key="index">{{ item +'0克' }} </view> </view> <!-- 数量 --> <view class="lf-row-between lf-m-t-40"> <view class="lf-font-28 lf-color-555">数量</view> <view class="lf-flex"> <view class="num-btn"> <text class="lf-iconfont icon-xiangyou lf-font-24"></text> </view> <view> <input class="input" value="1" /> </view> <view class="num-btn lf-text-right"> <text class="lf-iconfont icon-xiangyou lf-font-24"></text> </view> </view> </view> <!-- 操作按钮 --> <button class="comfirm-btn" @click="confirm">{{ click_type == 1 ? '加入购物车' : '立即购买' }}</button> </view> </u-popup> <!-- 回到顶部 --> <u-back-top :scroll-top="pageScrollTop"></u-back-top> </block> </skeleton> </view></template>
<script> import countdownTimer from '@/components/countdown-timer/countdown-timer'; export default { components: { countdownTimer }, data(){ return { current: 0, // 轮播下标
goods_id: 0, goods_detail: {}, is_collect: false, // 1为当前收藏商品了,0为否
skeletonLoading: false, pictures: [ 'https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png', 'https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png', 'https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png' ], show_popup: false, // 是否显示选规格模态框
spec_current: null, // 规格下标
click_type: null, // 当前点击的是加入购物车[1]还是立即购买[2]
type: 'mail', // 页面显示类型,mail普通可邮寄商品,self自提商品,point积分商品,seckill秒杀商品
time: new Date('2021/09/8 14:15:00').getTime() - new Date('2021/09/8 13:10:00').getTime() } }, onLoad(options){ this.goods_id = options.goods_id; this.type = options.type || 'mail'; console.log('商品',this.goods_id) // this.getGoodsDetail();
}, computed: { isRight() { return function(val) { return this.$shared.isRight(val); } } }, methods: { shoot(type){ // TODO 判断type做不同的逻辑
this.click_type = type; this.show_popup = true; }, activeSpec(index){ if(this.spec_current == index){ this.spec_current = null; }else{ this.spec_current = index; } }, confirm(){ if(this.click_type == 2){ this.$url('/pages/order/confirm/confirm'); } }, shareGraphic(){ this.getCreateShareImg(); }, //请求h5的图片接口
getCreateShareImg(){ wx.showLoading({ title:"生成中", mask:true }) let origin = window.location.origin; let share_url = origin+'/pages/store/detail/detail'; this.$http.get({ api:'api/distribution/createH5ShareImg', data:{ goods_id:this.id, share_url:share_url } }).then(res=>{ res = res.data; if(res.status){ this.qr_code_image = res.data.image; if(this.qr_code_image){ this.share_gaphic =!this.share_gaphic; this.is_toggle_share = false; } } else{ wx.showModal({ content: res.message || '请求失败,请重试', showCancel: false }); } wx.hideLoading() }).catch(rej=>{ wx.hideLoading() wx.showModal({ content: rej.message || '内部错误,请重试', showCancel: false }); }) }, getGoodsDetail(){ this.$http(this.API.API_ADVICEDETAILS, {id: this.goods_id}).then(res => { this.skeletonLoading = false; this.goods_detail = res.data; this.is_collect = Boolean(res.data.is_collect) || false; }).catch(err => { this.skeletonLoading = false; setTimeout(() => { this.$toBack(); }, 1000); }) }, // 切换商品收藏
switchCollect(){ let userInfo = uni.getStorageSync('userinfo') || {}; if(!userInfo.id || !userInfo.nickname || !userInfo.avatar){ this.$url('/pages/login/index?type=userinfo'); return; } if(this.is_collect) { this.$http(this.API.API_DELCOLLECT, {agent_product_id:this.goods_id}).then(res => { this.$msg('取消收藏成功!') this.is_collect = false console.log(res) }) }else { this.$http(this.API.API_ADDCOLLECT, {agent_product_id:this.goods_id}).then(res => { this.$msg('添加收藏成功!') this.is_collect = true console.log(res) }) } }, // 拨打电话
makePhoneCall(phoneStr){ uni.makePhoneCall({ phoneNumber: String(phoneStr) }) }, // 打开地图
openMap(){ let { address, lat, lng } = this.goods_detail?.store || {}; uni.openLocation({ longitude: Number(lat), latitude: Number(lng), scale: 20, name: address }); }, // 跳转到确认下单页面
toAddOrder(){ let goods_id = this.goods_detail.id; this.$url('/pages/order/confirm_order?goods_id='+ goods_id); }, // 预览图片
lookImg(index){ this.$u.throttle(() => { let goods_banner = this.goods_detail.banners || []; let banners = goods_banner.map(item => item.cover); uni.previewImage({ urls: banners, current: index }) }, 200); }, // 富文本处理
formatRichText(richText){ if(richText != null){ let newRichText= richText.replace(/<img[^>]*>/gi, function(match, capture){ match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); return match; }); newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){ match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;'); return match; }); newRichText = newRichText.replace(/<br[^>]*\/>/gi, ''); newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"'); return newRichText; }else{ return null; } } }, onShareAppMessage(){ let goods = this.goods_detail; let title = goods.name; let imageUrl = goods.share_cover || goods.cover; let path = '/pages/route/index?route=goods_detail&id='+ goods.id; return { title, path, imageUrl } } }</script>
<style> page{ background-color: #f5f5f5; overflow-x: hidden; }</style><style lang="scss" scoped="scoped"> //商品上去scrollview部分
.scroll-view{ height: 310rpx; width: 100%; // margin-top: 20rpx;
padding: 0 30rpx 30rpx 30rpx; background-color: white; .scroll-content{ display: flex; width: 100%; .goods-item{ margin-right: 15rpx; width: 180rpx; } .goods-img{ width: 180rpx; height: 180rpx; background-color: #EEEEEE; } .goods-info{ text-align: center; color: #222222; &>view:nth-child(1n){ font-size: 24rpx; } &>view:nth-child(2n){ font-size: 28rpx; font-weight: bold; text-align: left; color: #F63434; } } .more-box{ width: 180rpx; height: 180rpx; background-color: #EEEEEE; text-align: center; line-height: 180rpx; font-size: 24rpx; } } } //scrollview结束
.tag-father { position: relative; } .head-tag { color: white; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 24rpx; width: 36rpx; height: 36rpx; border-radius: 50%; background-color: #15716E; border: 1rpx solid #FFFFFF; position: absolute; left: 76rpx; top: 86rpx; z-index: 99; } .qzone-img { width: 220rpx; height: 220rpx; border-radius: 10rpx; margin-right: 12rpx; &:nth-child(3n) { margin-right: 0; } &:nth-child(n + 4) { margin-top: 12rpx; } } .user-top { background-color: #F3F8F8; padding: 30rpx; display: flex; align-items: center; background-color: white; } .head-img { width: 80rpx; height: 80rpx; border-radius: 50%; } .head-btn { display: flex; width: max-content; height: 45rpx; background: white; border: 2rpx solid #15716E; align-items: center; font-size: 22rpx; color: #15716E; justify-content: space-between; border-radius: 35rpx; padding: 10rpx!important; } .swiper-box{ width: 750rpx; height: 750rpx; background-color: #FFFFFF; position: relative; .seckill-box{ position: absolute; bottom: 0; left: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 32rpx; width: 100%; height: 77rpx; background-color: #15716E; color: #FFFFFF; font-size: 26rpx; } } .head-info{ width: 750rpx; height: auto; box-sizing: border-box; padding: 0 32rpx; padding-top: 20rpx; background-color: #FFFFFF; // .price>view:nth-of-type(1){
// color: #FF0000;
// margin-right: 22rpx;
// font-weight: bold;
// }
.price>view:nth-of-type(1){ text-decoration: line-through; color: #777777; margin-right: 22rpx; } .price>view:nth-of-type(2){ width: max-content; padding: 0 18rpx; height: 46rpx; background-color: #1998FE; border-radius: 10rpx; display: flex; justify-content: center; align-items: center; color: #FFFFFF; } .label-box{ min-height: 130rpx; width: 100%; border-top: 1rpx solid #E5E5E5; display: flex; flex-wrap: wrap; padding: 30rpx 0 10rpx 0; .label-item{ width: max-content; padding: 20rpx; height: 70rpx; border-radius: 10rpx; border: 2rpx solid #1998FE; display: flex; justify-content: center; align-items: center; font-size: 28rpx; color: #1998FE; margin-right: 20rpx; margin-bottom: 20rpx; } } } .address-box{ width: 750rpx; height: auto; box-sizing: border-box; background-color: #FFFFFF; padding: 32rpx; margin-top: 20rpx; .shop-img{ width: 60rpx; height: 60rpx; border-radius: 50%; } } .goods-detail{ width: 750rpx; height: auto; background-color: #FFFFFF; padding: 32rpx; box-sizing: border-box; margin-top: 20rpx; .goods-img{ width: 100%; } } .extra{ width: 100%; height: 110rpx; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); box-sizing: content-box; } .fixed-bottom{ position: fixed; bottom: 0; left: 0; background-color: #FFFFFF; width: 100%; height: auto; padding: 0 32rpx; border-top: 1rpx solid #e5e5e5; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); .icon-item{ text-align: center; margin-right: 16rpx; background-color: transparent; margin: 0; line-height: initial; font-size: 28rpx; font-weight: inherit; margin-right: 10rpx; padding: 0; width: 88rpx; position: relative; &:first-child{ padding-left: 0; } .icon-img{ height: 50rpx; width: 50rpx; } } .btn1{ margin: 0; width: max-content; height: 80rpx; background-color: rgba(21, 113, 110, 0.1); color: #15716E; line-height: 80rpx; font-size: 32rpx; padding: 0 20rpx; border-radius: 42rpx; font-size: 26rpx; border: 2rpx solid #15716E; } .btn{ margin: 0; padding: 0 20rpx; width: max-content; height: 80rpx; background-color: #15716E; color: #FFFFFF; line-height: 80rpx; font-size: 26rpx; border-radius: 42rpx; } } .popup-content{ height: max-content; width: 750rpx; background: #FFFFFF; border-radius: 20rpx 20rpx 0rpx 0rpx !important; padding: 40rpx 32rpx; .popup-head{ display: flex; justify-content: space-between; .goods-img{ width: 150rpx; height: 150rpx; border-radius: 2rpx; margin-right: 20rpx; } .goods-info{ width: 400rpx; height: 150rpx; display: flex; flex-direction: column; justify-content: space-around; .price{ font-size: 48rpx; font-weight: bold; color: #F63434; line-height: 1; } .goods-name{ font-size: 32rpx; color: #222222; line-height: 1.4; } } } .spec-title{ font-size: 28rpx; color: #555555; margin-top: 40rpx; margin-bottom: 20rpx; } .spec-item{ width: 142rpx; height: 64rpx; border-radius: 33rpx; border: 2rpx solid #555555; font-size: 28rpx; color: #555555; display: flex; justify-content: center; align-items: center; margin-right: 20rpx; &:nth-child(4n){ margin-right: 0rpx; } &:nth-child(n+5){ margin-top: 20rpx; } } .spec-active{ border: none; background-color: #15716E; color: #FFFFFF; } .input{ width: 40rpx; height: 45rpx; border-radius: 2rpx; background-color: #F3F8F7; text-align: center; } .num-btn{ width: 36rpx; } .comfirm-btn{ width: 550rpx; height: 100rpx; background: #15716E; border-radius: 50rpx; color: #FFFFFF; line-height: 100rpx; margin-top: 62rpx; } }</style>
|