01. 提供基础的商品详情布局(轮播图、详情介绍内容、分享按钮等);
02. 提供了详情和评论切换功能;
03. 提供商品购买前的属性、数量相关功能;
| H5 | APP | 小程序 | NVUE |
| ✔ | ✔ | ✔ | ✔ |
<template>
<view>
<!-- 轮播图 -->
<view>
<gui-swiper :swiperItems="swiperItems"
:spacing="0" :padding="0" borderRadius="0rpx"
:width="750" :height="330"></gui-swiper>
</swiper>
</view>
<!-- 商品标题 分享按钮 -->
<view class="gui-padding gui-margin-top gui-flex gui-rows gui-space-between gui-align-items-center">
<text class="gui-h5 gui-block-text product-name gui-block-text">{{product.name}}</text>
<view class="product-share" @tap="share">
<text class="product-share gui-icons gui-color-orange"></text>
</view>
</view>
<view class="gui-common-line gui-margin-top"></view>
<!-- 价格 -->
<view class="gui-padding" style="margin-top:10rpx;">
<view class="gui-flex gui-rows gui-nowrap gui-align-items-center">
<text class="product-price">¥{{product.price}}</text>
<text class="gui-text gui-color-gray gui-line-through" style="margin-left:30rpx;">¥{{product.priceMarket}}</text>
</view>
<view class="gui-flex gui-rows gui-nowrap gui-align-items-center gui-space-between">
<text class="gui-text-small gui-color-gray">运费 ¥0.00</text>
<text class="gui-text-small gui-color-gray">已售 21008 件</text>
<text class="gui-text-small gui-color-gray">浏览 36万次</text>
</view>
</view>
<view class="gui-common-line gui-margin-top"></view>
<!-- 切换导航 -->
<view class="gui-padding gui-margin-top">
<gui-switch-navigation :items="navItems" lineHeight="80rpx" :isCenter="true"
:size="200" activeLineBg="linear-gradient(to right, #FF7900, #FF7900)" textAlign="center"
activeColor="#FF7900" activeLineWidth="200rpx" activeLineHeight="2rpx"
:margin="10" @change="navChange"></gui-switch-navigation>
</view>
<!-- 详情 请根据项目情况自行改进 可以使用 富文本-->
<view class="gui-padding gui-margin-top" v-if="active == 0">
<image style="width:690rpx;"
:src="item" mode="widthFix" v-for="(item,index) in product.imgs" :key="index"></image>
</view>
<!-- 评论 请复制我们提供的评论布局来实现 -->
<view class="gui-padding gui-margin-top" v-if="active == 1">
<text class="gui-text-small gui-color-gray gui-text-center gui-block-text">请复制我们提供的评论布局来实现</text>
</view>
<!-- 底部 -->
<view class="product-footer gui-bg-white gui-border-t">
<!-- 属性选择 -->
<scroll-view class="product-attr"
:scroll-y="true" v-if="attrShow">
<view class="gui-flex gui-rows gui-space-between">
<text class="gui-text gui-color-gray">选择颜色</text>
<text class="gui-color-gray gui-h5 gui-icons" @tap="closeAttr"></text>
</view>
<view class="gui-margin-top">
<gui-stags :tags="colors" @change="colorChange"></gui-stags>
</view>
<view class="gui-margin-top">
<text class="gui-text gui-color-gray">选择尺寸</text>
</view>
<view class="gui-margin-top">
<gui-stags :tags="sizes" @change="sizeChange"></gui-stags>
</view>
<view class="gui-margin-top">
<text class="gui-text gui-color-gray">购买数量</text>
</view>
<view class="gui-margin-top">
<gui-step-box :value="1" @change="numberChange"></gui-step-box>
</view>
</scroll-view>
<!-- 底部按钮栏 -->
<view class="gui-flex gui-rows gui-space-between gui-align-items-center gui-border-t">
<!-- 2个底部按钮 -->
<view class="gui-footer-icon-buttons" style="margin-left:30rpx;" hover-class="gui-tap" @tap="goHome">
<text class="gui-footer-icon-buttons-icon gui-block-text gui-icons gui-primary-color"></text>
<text class="gui-footer-icon-buttons-text gui-block-text gui-icons gui-primary-color">首页</text>
</view>
<view class="gui-footer-icon-buttons" hover-class="gui-tap" @tap="kf">
<text class="gui-footer-icon-buttons-icon gui-block-text gui-icons gui-primary-color"></text>
<text class="gui-footer-icon-buttons-text gui-block-text gui-icons gui-primary-color">按钮</text>
</view>
<!-- 2个大按钮 -->
<view class="gui-flex1 gui-footer-large-buttons gui-flex gui-rows gui-nowrap gui-justify-content-end">
<view class=" gui-footer-large-button gui-text-center gui-bg-add-card" @tap="addtocard"
style="border-bottom-left-radius:50rpx; border-top-left-radius:50rpx;" hover-class="gui-tap">
<text class="gui-text gui-color-white gui-footer-large-button-text gui-block-text gui-text-center">加入购物车</text>
</view>
<view class="gui-footer-large-button gui-text-center gui-bg-buy" @tap="buynow"
style="border-bottom-right-radius:50rpx; border-top-right-radius:50rpx;" hover-class="gui-tap">
<text class="gui-text gui-color-white gui-footer-large-button-text gui-block-text gui-text-center">立即购买</text>
</view>
</view>
</view>
<gui-iphone-bottom></gui-iphone-bottom>
</view>
<!-- 底部占位 -->
<view style="height:120rpx;"></view>
</view>
</template>
<script>
export default {
data() {
return {
// 轮播图
swiperItems : [
{
img : 'https://cmsuse.oss-cn-beijing.aliyuncs.com/g5/1.png',
url : '',
opentype : 'navigate'
},
{
img : 'https://cmsuse.oss-cn-beijing.aliyuncs.com/g5/2.png',
url : '',
opentype : 'navigate'
}],
// 商品信息
product : {
name: "小米 MIX3 一面科技 一面艺术 ( 磁动力滑盖全面屏 | 故宫特别版 )",
logo : "../../static/logo.png",
price : 3188,
priceMarket : 3200,
imgs : [
'https://img30.360buyimg.com/sku/jfs/t21838/18/2275707529/311540/cba1d04c/5b4f155fNac3aa2f0.jpg',
'https://img30.360buyimg.com/sku/jfs/t22021/327/2281785192/48707/57806074/5b4f1579Nae7adb49.jpg',
'https://img30.360buyimg.com/sku/jfs/t21682/256/2344553276/204456/cf7a2ddb/5b4ffbbfN48c54307.jpg'
]
},
// 切换导航
navItems : [{id:0, name:'商品详情'}, {id:1, name:'相关评论'}],
// 切换索引
active : 0,
// 属性选择
attrShow : false,
colors : [
{id:1,text:"红色",checked:false},
{id:2,text:"黑色",checked:false},
{id:3,text:"蓝色",checked:false}
],
sizes : [
{id:1,text:"10 cm",checked:false},
{id:2,text:"20 cm",checked:false},
{id:3,text:"40 cm",checked:false}
],
// 属性记录
attrRes : {color:null, size:null, number:1}
}
},
methods: {
// 分享
share: function(){uni.showToast({title:'请自行完善分享代码', icon: "none"});},
// 导航切换
navChange : function(e){ this.active = e; },
// 返回首页
goHome : function () {uni.switchTab({ url:"首页路径" });},
// 返回首页
kf : function () {uni.showToast({title:'请自行完善分享代码', icon: "none"});},
// 加入购物车
addtocard : function () {
// 选择属性
this.selectAttr();
},
// 购买
buynow : function () {
// 选择属性
this.selectAttr();
},
// 属性选择
selectAttr : function () {
// 未选择属性弹出选择
if(!this.attrShow){
this.attrShow = true;
return ;
}
// 已选择属性进行订单提交
// 属性在 attrRes 变量内保存
if(this.attrRes.color == null || this.attrRes.size == null){
uni.showToast({icon:"none", title:"请选择属性"});
}
console.log('请完善提交代码');
},
colorChange : function (e) {
this.attrRes.color = e.text;
},
sizeChange : function (e) {
this.attrRes.size = e.text;
},
numberChange : function (e) {
this.attrRes.number = e[0];
},
closeAttr : function () {
this.attrShow = false;
}
}
}
</script>
<style scoped>
.product-name{width:560rpx; line-height:50rpx;}
.product-share{width:80rpx; height:80rpx; text-align:center; font-size:50rpx; color:#FF7900; line-height:80rpx;}
.product-price{color:#FF7900; line-height:60rpx; font-size:30rpx; font-weight:bold;}
.gui-common-line{height:18rpx;}
.product-footer{position:fixed; z-index:99; left:0; bottom:0; width:750rpx;}
.product-attr{width:700rpx; margin:25rpx; height:580rpx;}
</style>