秦佳浩 2 months ago
commit e39c8f6350

@ -1,38 +1,48 @@
/* 容器样式 */
.container { .container {
background: #f4f4f4; background: #f4f4f4; /* 设置背景颜色为浅灰色 */
min-height: 100vh; min-height: 100vh; /* 最小高度为视口高度,确保内容不满屏时也有足够的空间 */
padding: 7px; padding: 7px; /* 内边距,给容器内的元素留出一定的空间 */
} }
/* 固定在顶部的线条 */
.line-fix { .line-fix {
width: 100%; width: 100%; /* 线条宽度为100%,覆盖整个屏幕宽度 */
height: 2rpx; height: 2rpx; /* 线条高度为2rpx响应式单位非常细的一条线 */
background: #e1e1e1; background: #e1e1e1; /* 线条颜色为浅灰色 */
position: fixed; position: fixed; /* 将线条固定在页面顶部,不会随页面滚动而移动 */
top: 0; top: 0; /* 线条距离页面顶部0像素 */
} }
/* 标题背景样式 */
.tit-background { .tit-background {
width: 100%; width: 100%; /* 背景宽度为100%,覆盖整个屏幕宽度 */
height: 20rpx; height: 20rpx; /* 背景高度为20rpx响应式单位 */
background: #f4f4f4; background: #f4f4f4; /* 背景颜色为浅灰色 */
} }
/* 商品列表样式 */
.prod-list { .prod-list {
display: flex; display: flex; /* 使用弹性布局,使子元素可以灵活排列 */
flex-wrap: wrap; flex-wrap: wrap; /* 允许子元素换行显示 */
justify-content: space-between; justify-content: space-between; /* 子元素之间均匀分布,两端对齐 */
} }
/* 深度选择器,用于修改子组件的样式 */
:deep(.prod-items) { :deep(.prod-items) {
display: inline-block; display: inline-block; /* 将商品项设置为行内块级元素,允许在同一行中显示多个商品 */
width: 345rpx !important; width: 345rpx !important; /* 设置商品项的宽度为345rpx并使用!important确保优先级 */
&:nth-child(2n) { &:nth-child(2n) { /* 对于每第二个商品项 */
margin-left: 30rpx; margin-left: 30rpx; /* 左边距为30rpx使第二列的商品与第一列保持一定间距 */
} }
} }
/* 空 */
/* 空状态提示样式 */
.empty { .empty {
display: block; display: block; /* 将空状态提示设置为块级元素 */
width: 100%; width: 100%; /* 提示宽度为100%,覆盖整个父容器 */
font-size: 26rpx; font-size: 26rpx; /* 字体大小为26rpx响应式单位 */
color: #999; color: #999; /* 文字颜色为浅灰色 */
margin-top: 20vh; margin-top: 20vh; /* 上边距为视口高度的20%,将提示居中显示 */
text-align: center; text-align: center; /* 文字水平居中 */
} }

@ -1,16 +1,13 @@
<template> <template>
<view class="container"> <view class="container">
<view> <view>
<block <!-- 使用v-for循环渲染商品列表 -->
v-for="(item, index) in prodList" <block v-for="(item, index) in prodList" :key="index">
:key="index" <!-- 将每个商品项传递给production组件 -->
>
<production :item="item" /> <production :item="item" />
</block> </block>
<view <!-- 如果没有商品数据则显示暂无数据的提示信息 -->
v-if="!prodList.length" <view v-if="!prodList.length" class="empty">
class="empty"
>
暂无数据 暂无数据
</view> </view>
</view> </view>
@ -18,65 +15,66 @@
</template> </template>
<script setup> <script setup>
const sts = ref(0) //
const title = ref('') const sts = ref(0) //
const current = ref(1) const title = ref('') //
const size = ref(10) const current = ref(1) //
const pages = ref(0) const size = ref(10) //
const tagid = ref(0) const pages = ref(0) //
const tagid = ref(0) // ID
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad((options) => { onLoad((options) => {
//
current.value = 1 current.value = 1
pages.value = 0 pages.value = 0
// ststitle
sts.value = options.sts sts.value = options.sts
title.value = options.title ? options.title : '' title.value = options.title ? options.title : ''
// tagidID
if (options.tagid) { if (options.tagid) {
tagid.value = options.tagid tagid.value = options.tagid
} }
// ststagid
if (sts.value == 0) { if (sts.value == 0) {
if (options.tagid == 1) { switch (options.tagid) {
uni.setNavigationBarTitle({ case '1':
title: '每日上新' uni.setNavigationBarTitle({ title: '每日上新' })
}) break
} else if (options.tagid == 2) { case '2':
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({ title: '商城热卖' })
title: '商城热卖' break
}) case '3':
} else if (options.tagid == 3) { uni.setNavigationBarTitle({ title: '更多宝贝' })
uni.setNavigationBarTitle({ break
title: '更多宝贝'
})
} }
} else if (sts.value == 1) {
uni.setNavigationBarTitle({
title: '新品推荐'
})
} else if (sts.value == 2) {
uni.setNavigationBarTitle({
title: '限时特惠'
})
} else if (sts.value == 3) {
uni.setNavigationBarTitle({
title: '每日疯抢'
})
} else if (sts.value == 4) {
uni.setNavigationBarTitle({
title: '优惠券活动商品'
})
} else if (sts.value == 5) {
uni.setNavigationBarTitle({
title: '我的收藏商品'
})
} else { } else {
uni.setNavigationBarTitle({ switch (sts.value) {
title: title.value case 1:
}) uni.setNavigationBarTitle({ title: '新品推荐' })
break
case 2:
uni.setNavigationBarTitle({ title: '限时特惠' })
break
case 3:
uni.setNavigationBarTitle({ title: '每日疯抢' })
break
case 4:
uni.setNavigationBarTitle({ title: '优惠券活动商品' })
break
case 5:
uni.setNavigationBarTitle({ title: '我的收藏商品' })
break
default:
uni.setNavigationBarTitle({ title: title.value })
}
} }
//
loadProdData(options) loadProdData(options)
}) })
@ -84,8 +82,9 @@ onLoad((options) => {
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom(() => { onReachBottom(() => {
//
if (current.value < pages.value) { if (current.value < pages.value) {
current.value = current.value + 1 current.value++
loadProdData() loadProdData()
} }
}) })
@ -96,6 +95,7 @@ onReachBottom(() => {
const loadProdData = (options) => { const loadProdData = (options) => {
const stsParam = sts.value const stsParam = sts.value
// stsParam
if (stsParam == 0) { if (stsParam == 0) {
// //
getTagProd() getTagProd()
@ -120,9 +120,17 @@ const loadProdData = (options) => {
} }
} }
//
const prodList = ref([]) const prodList = ref([])
/**
* 获取活动商品列表
*/
const getActProd = (url) => { const getActProd = (url) => {
//
uni.showLoading() uni.showLoading()
// HTTP
http.request({ http.request({
url, url,
method: 'GET', method: 'GET',
@ -130,17 +138,18 @@ const getActProd = (url) => {
current: current.value, current: current.value,
size: size.value size: size.value
} }
}) }).then(({ data }) => {
.then(({ data }) => {
let list let list
//
if (data.current === 1) { if (data.current === 1) {
list = data.records list = data.records
} else { } else {
list = prodList.value list = prodList.value.concat(data.records)
list = list.concat(data.records)
} }
//
prodList.value = list prodList.value = list
pages.value = data.pages pages.value = data.pages
//
uni.hideLoading() uni.hideLoading()
}) })
} }
@ -149,7 +158,10 @@ const getActProd = (url) => {
* 获取我的收藏商品 * 获取我的收藏商品
*/ */
const getCollectionProd = () => { const getCollectionProd = () => {
//
uni.showLoading() uni.showLoading()
// HTTP
http.request({ http.request({
url: '/p/user/collection/prods', url: '/p/user/collection/prods',
method: 'GET', method: 'GET',
@ -157,26 +169,30 @@ const getCollectionProd = () => {
current: current.value, current: current.value,
size: size.value size: size.value
} }
}) }).then(({ data }) => {
.then(({ data }) => {
let list let list
//
if (data.current == 1) { if (data.current == 1) {
list = data.records list = data.records
} else { } else {
list = prodList.value list = prodList.value.concat(data.records)
list = list.concat(data.records)
} }
//
prodList.value = list prodList.value = list
pages.value = data.pages pages.value = data.pages
//
uni.hideLoading() uni.hideLoading()
}) })
} }
/** /**
* 获取标签列表 * 获取标签商品列表
*/ */
const getTagProd = () => { const getTagProd = () => {
//
uni.showLoading() uni.showLoading()
// HTTP
http.request({ http.request({
url: '/prod/prodListByTagId', url: '/prod/prodListByTagId',
method: 'GET', method: 'GET',
@ -185,16 +201,18 @@ const getTagProd = () => {
current: current.value, current: current.value,
size: size.value size: size.value
} }
}) }).then(({ data }) => {
.then(({ data }) => {
let list let list
//
if (data.current === 1) { if (data.current === 1) {
list = data.records list = data.records
} else { } else {
list = prodList.value.concat(data.records) list = prodList.value.concat(data.records)
} }
//
prodList.value = list prodList.value = list
pages.value = data.pages pages.value = data.pages
//
uni.hideLoading() uni.hideLoading()
}) })
} }
@ -203,7 +221,10 @@ const getTagProd = () => {
* 获取优惠券商品列表 * 获取优惠券商品列表
*/ */
const getProdByCouponId = (id) => { const getProdByCouponId = (id) => {
//
uni.showLoading() uni.showLoading()
// HTTP
http.request({ http.request({
url: '/coupon/prodListByCouponId', url: '/coupon/prodListByCouponId',
method: 'GET', method: 'GET',
@ -212,21 +233,23 @@ const getProdByCouponId = (id) => {
current: current.value, current: current.value,
size: size.value size: size.value
} }
}) }).then(({ data }) => {
.then(({ data }) => {
let list let list
//
if (data.current === 1) { if (data.current === 1) {
list = data.records list = data.records
} else { } else {
list = prodList.value.concat(data.records) list = prodList.value.concat(data.records)
} }
//
prodList.value = list prodList.value = list
pages.value = data.pages pages.value = data.pages
//
uni.hideLoading() uni.hideLoading()
}) })
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@use './prod-classify.scss'; @use './prod-classify.scss'; /* 引入外部样式文件 */
</style> </style>

@ -1,26 +1,35 @@
.container { .c /* 100%150rpx */
container {
background: #f4f4f4; background: #f4f4f4;
height: 100%; height: 100%;
padding-bottom: 150rpx; padding-bottom: 150rpx;
} }
/* 轮播图组件,设定了高度、宽度以及下边框。内部图片也设定了相同的高度和宽度以确保适应轮播图容器 */
swiper { swiper {
height: 750rpx; height: 750rpx;
width: 100%; width: 100%;
border-bottom: 2rpx solid #f8f8f8; border-bottom: 2rpx solid #f8f8f8;
image { image {
height: 750rpx; height: 750rpx;
width: 100%; width: 100%;
} }
} }
/* 产品信息区域,设置了上下左右的内边距,相对定位,白色背景 */
.prod-info { .prod-info {
padding: 30rpx 30rpx 0 30rpx; padding: 30rpx 30rpx 0 30rpx;
position: relative; position: relative;
background: #fff; background: #fff;
} }
/* 标题包装器,使用了相对定位来放置子元素,并定义了行高和右边距 */
.tit-wrap { .tit-wrap {
position: relative; position: relative;
line-height: 40rpx; line-height: 40rpx;
padding-right: 104rpx; padding-right: 104rpx;
/* 列元素,绝对定位在标题包装器的右上角,作为额外的信息展示,如收藏按钮等 */
.col { .col {
position: absolute; position: absolute;
top: 0; top: 0;
@ -30,12 +39,14 @@ swiper {
font-size: 20rpx; font-size: 20rpx;
padding-left: 20rpx; padding-left: 20rpx;
text-align: center; text-align: center;
/* 列内的图标,设置为块级元素并居中显示 */
image { image {
display: block; display: block;
margin: auto; margin: auto;
width: 40rpx; width: 40rpx;
height: 40rpx; height: 40rpx;
} }
/* 在列元素左侧添加一条竖线装饰 */
&::after { &::after {
content: ""; content: "";
display: block; display: block;
@ -49,11 +60,15 @@ swiper {
} }
} }
} }
/* 产品标题,设定字体大小、颜色和右边距 */
.prod-tit { .prod-tit {
font-size: 32rpx; font-size: 32rpx;
color: #333; color: #333;
padding-right: 20rpx; padding-right: 20rpx;
} }
/* 销量段落,设置了背景色、行高、颜色、字体大小、上边距和右边距 */
.sales-p { .sales-p {
background: #fff; background: #fff;
line-height: 40rpx; line-height: 40rpx;
@ -62,29 +77,38 @@ swiper {
margin-top: 6rpx; margin-top: 6rpx;
margin-right: 104rpx; margin-right: 104rpx;
} }
/* 产品价格部分,包含新旧价格对比 */
.prod-price { .prod-price {
font-size: 30rpx; font-size: 30rpx;
height: 100rpx; height: 100rpx;
line-height: 100rpx; line-height: 100rpx;
} /* 新价格的颜色、字体大小、加粗和右边距 */
.price { .price {
color: #eb2444; color: #eb2444;
font-size: 24rpx; font-size: 24rpx;
font-weight: 600; font-weight: 600;
margin-right: 30rpx; margin-right: 30rpx;
} }
/* 新价格的数字部分,加大字体 */
.price-num { .price-num {
font-size: 46rpx; font-size: 46rpx;
font-weight: 400; font-weight: 400;
} }
/* 原价,较小字体,灰色,带删除线 */
.ori-price { .ori-price {
font-size: 25rpx; font-size: 25rpx;
color: #999; color: #999;
text-decoration: line-through; text-decoration: line-through;
} }
}
/* 销量文字的颜色 */
.sales { .sales {
color: #999; color: #999;
} }
/* 更多选项按钮,绝对定位在右侧,设置了宽度、顶部位置、文本对齐、字体大小和颜色 */
.more { .more {
position: absolute; position: absolute;
right: 20rpx; right: 20rpx;
@ -95,13 +119,15 @@ swiper {
color: #999; color: #999;
letter-spacing: 1px; letter-spacing: 1px;
} }
/* SKU库存保有单位信息设置了内边距、背景色、外边距、相对定位和行高 */
.sku { .sku {
padding: 20rpx; padding: 20rpx;
background: #fff; background: #fff;
margin-top: 20rpx; margin-top: 20rpx;
position: relative; position: relative;
line-height: 48rpx; line-height: 48rpx;
} /* SKU标题绝对定位在左上角作为SKU信息的标签 */
.sku-tit { .sku-tit {
position: absolute; position: absolute;
display: inline-block; display: inline-block;
@ -111,6 +137,7 @@ swiper {
top: 20rpx; top: 20rpx;
color: #999; color: #999;
} }
/* SKU内容从标题右侧开始单行显示超出部分用省略号代替 */
.sku-con { .sku-con {
margin: 0 80rpx; margin: 0 80rpx;
white-space: nowrap; white-space: nowrap;
@ -119,25 +146,27 @@ swiper {
font-size: 28rpx; font-size: 28rpx;
font-weight: bold; font-weight: bold;
} }
}
/* 评论区包裹,设置了背景色、外边距、相对定位和行高 */
.cmt-wrap { .cmt-wrap {
background: #fff; background: #fff;
margin-top: 20rpx; margin-top: 20rpx;
position: relative; position: relative;
line-height: 48rpx; line-height: 48rpx;
} /* 评论区标题,较大字体,带有下边框,内边距 */
.cmt-tit { .cmt-tit {
font-size: 32rpx; font-size: 32rpx;
position: relative; position: relative;
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
padding: 20rpx; padding: 20rpx;
} }
.cmt-t { /* 评论区的好评率,红色字体,稍小字号 */
width: 300rpx;
}
.cmt-good { .cmt-good {
color: #eb2444; color: #eb2444;
font-size: 24rpx; font-size: 24rpx;
} }
/* 评论数量,绝对定位在右上角,设置了字体大小和颜色 */
.cmt-count { .cmt-count {
position: absolute; position: absolute;
right: 20rpx; right: 20rpx;
@ -145,6 +174,7 @@ swiper {
font-size: 24rpx; font-size: 24rpx;
color: #666; color: #666;
} }
/* 展示更多评论的箭头图标,通过旋转创建 */
.cmt-more { .cmt-more {
width: 20rpx; width: 20rpx;
height: 20rpx; height: 20rpx;
@ -154,13 +184,16 @@ swiper {
margin-left: 10rpx; margin-left: 10rpx;
display: inline-block; display: inline-block;
} }
/* 评论内容区,设置了左右内边距 */
.cmt-cont { .cmt-cont {
padding: 0 20rpx; padding: 0 20rpx;
} }
/* 评论标签,设置了相对定位,允许内部元素浮动或绝对定位 */
.cmt-tag { .cmt-tag {
position: relative; position: relative;
padding: 14px 3px 0 0; padding: 14px 3px 0 0;
margin: 0; margin: 0;
/* 每个标签,设置了背景色、内边距、圆角、行高、字体大小和颜色 */
text { text {
margin: 0 10px 10px 0; margin: 0 10px 10px 0;
background: #fdf0f0; background: #fdf0f0;
@ -170,17 +203,19 @@ swiper {
border-radius: 3px; border-radius: 3px;
line-height: 25px; line-height: 25px;
font-size: 12px; font-size: 12px;
font-family: -apple-system, Helvetica, sans-serif;
color: #666; color: #666;
} /* 当标签被选中时,改变背景色和字体颜色 */
text.selected { &.selected {
color: #fff; color: #fff;
background: #e93b3d; background: #e93b3d;
} }
} }
}
/* 单条评论项,设置了相对定位,添加了底部边框 */
.cmt-item { .cmt-item {
position: relative; position: relative;
padding: 10px 0; padding: 10px 0;
/* 使用伪元素添加底部边框 */
&::after { &::after {
content: ""; content: "";
height: 0; height: 0;
@ -193,25 +228,27 @@ swiper {
border-bottom-color: #e5e5e5; border-bottom-color: #e5e5e5;
} }
} }
.cmt-items { /* 评论列表为空时的提示 */
.empty { .cmt-items .empty {
display: block; display: block;
font-size: 24rpx; font-size: 24rpx;
text-align: center; text-align: center;
color: #aaa; color: #aaa;
margin-top: 5vh; margin-top: 5vh;
} }
} /* 用户信息,设置了行高、底边距、字体大小 */
.cmt-user { .cmt-user {
line-height: 25px; line-height: 25px;
margin-bottom: 8px; margin-bottom: 8px;
font-size: 12px; font-size: 12px;
/* 用户头像,圆形,设置了宽度、高度、圆角和垂直对齐方式 */
.user-img { .user-img {
width: 25px; width: 25px;
height: 25px; height: 25px;
border-radius: 50%; border-radius: 50%;
vertical-align: middle; vertical-align: middle;
} }
/* 用户昵称,设置了左边距、显示方式、颜色、最大宽度和高度 */
.nickname { .nickname {
margin-left: 10px; margin-left: 10px;
display: inline-block; display: inline-block;
@ -220,17 +257,20 @@ swiper {
height: 25px; height: 25px;
line-height: 27px; line-height: 27px;
} }
/* 评论日期,设置为右侧浮动,颜色和左边距 */
.date { .date {
float: right; float: right;
color: #999; color: #999;
margin-left: -60px; margin-left: -60px;
} }
} }
/* 用户信息容器使用flex布局对齐项目中心设置了宽度 */
.cmt-user-info { .cmt-user-info {
display: flex; display: flex;
align-items: center; align-items: center;
width: 400rpx; width: 400rpx;
} }
/* 评论内容,设置了溢出隐藏、文本溢出处理、弹性盒子模型属性、相对定位、行高、字体大小、边距、单词断开和最大高度 */
.cmt-cnt { .cmt-cnt {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
@ -244,10 +284,12 @@ swiper {
word-break: break-all; word-break: break-all;
max-height: 126px; max-height: 126px;
} }
/* 评论中的商品属性展示,设置了高度、宽度和白空间处理 */
.cmt-attr { .cmt-attr {
height: 85px; height: 85px;
width: 100%; width: 100%;
white-space: nowrap; white-space: nowrap;
/* 商品图片,设置了宽高、右边距、底边距、圆角和背景色 */
image { image {
display: inline-block; display: inline-block;
width: 80px; width: 80px;
@ -258,10 +300,12 @@ swiper {
background: #f3f3f3; background: #f3f3f3;
} }
} }
/* 查看更多评论按钮,居中对齐,设置了背景色、字体大小、内边距、边框、圆角 */
.cmt-more-v { .cmt-more-v {
text-align: center; text-align: center;
background-color: #fff; background-color: #fff;
font-size: 12px; font-size: 12px;
/* 按钮文本,设置了高度、行高、字体大小、文本对齐、颜色、内边距、边框、圆角 */
text { text {
height: 25px; height: 25px;
line-height: 25px; line-height: 25px;
@ -275,6 +319,7 @@ swiper {
display: inline-block; display: inline-block;
} }
} }
/* 弹出层用于查看完整评论设置了固定定位、z-index、背景色、内边距 */
.cmt-popup { .cmt-popup {
position: fixed; position: fixed;
top: 0; top: 0;
@ -284,19 +329,23 @@ swiper {
z-index: 998; z-index: 998;
background-color: #fff; background-color: #fff;
padding-bottom: 98rpx; padding-bottom: 98rpx;
/* 弹出层内的评论内容,设置了高度、溢出滚动 */
.cmt-cont { .cmt-cont {
height: calc(100% - 80rpx); height: calc(100% - 80rpx);
overflow: auto; overflow: auto;
} }
/* 弹出层内的评论内容,增加了行数限制和最大高度 */
.cmt-cnt { .cmt-cnt {
-webkit-line-clamp: 20; -webkit-line-clamp: 20;
max-height: 500px; max-height: 500px;
} }
/* 加载更多按钮,设置了字体大小、内边距、文本对齐、边距、边框、圆角 */
.load-more { .load-more {
font-size: 14px; font-size: 14px;
padding: 20px; padding: 20px;
text-align: center; text-align: center;
margin-bottom: 10px; margin-bottom: 10px;
/* 按钮文本,设置了边框、内边距、圆角和颜色 */
text { text {
border: 1px solid #ddd; border: 1px solid #ddd;
padding: 5px 10px; padding: 5px 10px;
@ -305,33 +354,45 @@ swiper {
} }
} }
} }
}
. /* 线 */
.cmt-reply { .cmt-reply {
font-size: 14px; font-size: 14px;
border-top: 1px dashed #ddd; border-top: 1px dashed #ddd;
padding: 5px 0; padding: 5px 0;
/* 回复标题,红色字体强调 */
.reply-tit { .reply-tit {
color: #eb2444; color: #eb2444;
} }
} }
/* 产品详情部分,设置了背景色、上外边距、相对定位和行高 */
.prod-detail { .prod-detail {
background: #fff; background: #fff;
margin-top: 20rpx; margin-top: 20rpx;
position: relative; position: relative;
line-height: 48rpx; line-height: 48rpx;
/* 详情图片宽度设为750rpx并确保是块级元素显示 */
image { image {
width: 750rpx !important; width: 750rpx !important;
display: block; display: block;
} }
} }
/* 富文本组件内的图片确保宽度为100%以适应父容器 */
rich-text { rich-text {
image { image {
width: 100% !important; width: 100% !important;
} }
} }
/* 深度选择器用于覆盖第三方组件或库的样式确保图片宽度为100%并作为块级元素显示 */
:deep(.img) { :deep(.img) {
width: 100% !important; width: 100% !important;
display: block; display: block;
} }
/* 购物车底部固定栏设置了固定位置、底部对齐、宽度、弹性布局、高度、z-index和阴影效果 */
.cart-footer { .cart-footer {
position: fixed; position: fixed;
bottom: 0; bottom: 0;
@ -342,6 +403,7 @@ rich-text {
height: 98rpx; height: 98rpx;
z-index: 999; z-index: 999;
box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05); box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
/* 按钮,设置了相对定位、弹性增长、内容居中、宽度、背景色、字体大小和列式布局 */
.btn { .btn {
position: relative; position: relative;
display: flex; display: flex;
@ -352,6 +414,7 @@ rich-text {
background-color: #fff; background-color: #fff;
font-size: 28rpx; font-size: 28rpx;
flex-flow: column; flex-flow: column;
/* 徽章,绝对定位的小圆圈,用于展示数字,如购物车商品数量 */
.badge { .badge {
position: absolute; position: absolute;
top: 20rpx; top: 20rpx;
@ -366,30 +429,37 @@ rich-text {
font-size: 18rpx; font-size: 18rpx;
color: #fff; color: #fff;
} }
/* 稍大一点的徽章 */
.badge-1 { .badge-1 {
width: 36rpx; width: 36rpx;
} }
} }
/* 图标按钮,不随其他按钮拉伸,设置了固定宽度、字体大小和颜色 */
.btn.icon { .btn.icon {
flex-grow: 0; flex-grow: 0;
flex-shrink: 0; flex-shrink: 0;
width: 125rpx; width: 125rpx;
font-size: 20rpx; font-size: 20rpx;
color: #666; color: #666;
/* 图标按钮内的图片,设置了宽度和高度 */
image { image {
width: 50rpx; width: 50rpx;
height: 50rpx; height: 50rpx;
} }
} }
/* 购物车按钮,设置了背景色和文字颜色 */
.btn.cart { .btn.cart {
background: #584e61; background: #584e61;
color: #fff; color: #fff;
} }
/* 立即购买按钮,设置了背景色和文字颜色 */
.btn.buy { .btn.buy {
background: #eb2444; background: #eb2444;
color: #fff; color: #fff;
} }
} }
/* 关闭按钮,设置了颜色、圆角、行高、文本对齐、高度、宽度、字体大小、内边距、位置和伪元素内容 */
.close { .close {
color: #aaa; color: #aaa;
border-radius: 12px; border-radius: 12px;
@ -402,15 +472,20 @@ rich-text {
top: 10px; top: 10px;
right: 10px; right: 10px;
position: absolute; position: absolute;
/* 伪元素,设置关闭符号 */
&::before { &::before {
content: "\2716"; content: "\2716";
} }
} }
/* 弹出层内容区,设置了最大高度、溢出滚动和左右内边距 */
.popup-cnt { .popup-cnt {
max-height: 429px; max-height: 429px;
overflow: auto; overflow: auto;
padding: 0 10px; padding: 0 10px;
} }
/* SKU弹出层背景设置了固定位置、全屏尺寸、z-index和半透明黑色背景 */
.pup-sku { .pup-sku {
position: fixed; position: fixed;
top: 0; top: 0;
@ -420,6 +495,8 @@ rich-text {
z-index: 999; z-index: 999;
background-color: rgba(0, 0, 0, 0.3); background-color: rgba(0, 0, 0, 0.3);
} }
/* SKU弹出层主要内容绝对定位在屏幕底部设置了宽度、最小和最大高度、白色背景 */
.pup-sku-main { .pup-sku-main {
position: absolute; position: absolute;
bottom: 0; bottom: 0;
@ -428,6 +505,8 @@ rich-text {
max-height: 475px; max-height: 475px;
background-color: #fff; background-color: #fff;
} }
/* SKU弹出层头部设置了相对定位、行高、字体大小、颜色、高度、内边距和背景色 */
.pup-sku-header { .pup-sku-header {
position: relative; position: relative;
line-height: 46px; line-height: 46px;
@ -437,6 +516,8 @@ rich-text {
padding: 0 0 10px 110px; padding: 0 0 10px 110px;
background-color: #fff; background-color: #fff;
} }
/* SKU弹出层中的产品图片设置了绝对定位、左上偏移、圆角、宽度、高度和垂直对齐 */
.pup-sku-img { .pup-sku-img {
position: absolute; position: absolute;
left: 10px; left: 10px;
@ -447,6 +528,8 @@ rich-text {
border: 0 none; border: 0 none;
vertical-align: top; vertical-align: top;
} }
/* SKU弹出层价格设置了行内块显示、高度、行高、颜色和字体大小 */
.pup-sku-price { .pup-sku-price {
display: inline-block; display: inline-block;
height: 40px; height: 40px;
@ -454,9 +537,13 @@ rich-text {
color: #e4393c; color: #e4393c;
font-size: 10px; font-size: 10px;
} }
/* SKU弹出层价格整数部分加大字体 */
.pup-sku-price-int { .pup-sku-price-int {
font-size: 16px; font-size: 16px;
} }
/* SKU弹出层属性描述允许单词断开设置了字体大小、颜色、行高、右边距、溢出隐藏、文本溢出处理和弹性盒子模型属性 */
.pup-sku-prop { .pup-sku-prop {
word-break: break-all; word-break: break-all;
font-size: 12px; font-size: 12px;
@ -468,17 +555,22 @@ rich-text {
display: -webkit-box; display: -webkit-box;
-webkit-line-clamp: 2; -webkit-line-clamp: 2;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
/* 属性描述中的文本,设置了颜色和右边距 */
text { text {
color: #999; color: #999;
margin-right: 5px; margin-right: 5px;
} }
} }
/* SKU弹出层主体内容设置了盒模型属性、最大高度、下内边距和溢出滚动 */
.pup-sku-body { .pup-sku-body {
box-sizing: border-box; box-sizing: border-box;
max-height: 379px; max-height: 379px;
padding-bottom: 100px; padding-bottom: 100px;
overflow: auto; overflow: auto;
} }
/* SKU区域设置了字体大小、颜色、内外边距和高度 */
.pup-sku-area { .pup-sku-area {
.sku-kind { .sku-kind {
font-size: 12px; font-size: 12px;
@ -487,11 +579,14 @@ rich-text {
height: 40px; height: 40px;
line-height: 40px; line-height: 40px;
} }
/* SKU选择项容器设置了溢出隐藏和底边距 */
.sku-choose { .sku-choose {
overflow: hidden; overflow: hidden;
margin-bottom: 3px; margin-bottom: 3px;
} }
} }
/* SKU选择项设置了行内块显示、内边距、最小和最大宽度、高度、文本对齐、左边距、底边距、圆角、颜色、背景色和字体大小 */
.sku-choose-item { .sku-choose-item {
display: inline-block; display: inline-block;
padding: 0 10px; padding: 0 10px;
@ -508,23 +603,31 @@ rich-text {
background-color: #f7f7f7; background-color: #f7f7f7;
font-size: 14px; font-size: 14px;
} }
/* 当SKU选择项被选中时改变背景色和字体颜色 */
.sku-choose-item.active { .sku-choose-item.active {
background-color: #eb2444; background-color: #eb2444;
color: #fff; color: #fff;
} }
/* 当SKU选择项不可用时改变背景色和字体颜色 */
.sku-choose-item.gray { .sku-choose-item.gray {
background-color: #f9f9f9; background-color: #f9f9f9;
color: #ddd; color: #ddd;
} }
/* SKU弹出层数量选择部分设置了内边距和字体大小 */
.pup-sku-count { .pup-sku-count {
padding: 0 10px 13px; padding: 0 10px 13px;
font-size: 12px; font-size: 12px;
/* 数量名称标签,设置了颜色、高度、行高和宽度 */
.count-name { .count-name {
color: #999; color: #999;
height: 31px; height: 31px;
line-height: 31px; line-height: 31px;
width: 100rpx; width: 100rpx;
} }
/* 数量选择器包裹,设置了相对定位、宽度、浮动和垂直对齐 */
.num-wrap { .num-wrap {
position: relative; position: relative;
z-index: 0; z-index: 0;
@ -533,11 +636,13 @@ rich-text {
vertical-align: middle; vertical-align: middle;
display: flex; display: flex;
} }
/* 输入框包裹设置了相对定位、宽度、z-index和左右内边距 */
.text-wrap { .text-wrap {
position: relative; position: relative;
width: 45px; width: 45px;
z-index: 0; z-index: 0;
margin: 0 1px; margin: 0 1px;
/* 输入框,设置了高度、宽度、颜色、背景、字体大小、文本对齐、无边框和背景色 */
input { input {
height: 30px; height: 30px;
width: 100%; width: 100%;
@ -550,8 +655,11 @@ rich-text {
} }
} }
} }
/* 数量选择器的减号和加号按钮,设置了相对定位、最大最小宽度、高度、行高、背景色、文本对齐、圆角 */
.num-wrap { .num-wrap {
.minus { .minus,
.plus {
position: relative; position: relative;
max-width: 30px; max-width: 30px;
min-width: 30px; min-width: 30px;
@ -559,20 +667,18 @@ rich-text {
line-height: 30px; line-height: 30px;
background: #f7f7f7; background: #f7f7f7;
text-align: center; text-align: center;
}
/* 减号按钮,设置了左上和左下圆角 */
.minus {
border-top-left-radius: 3px; border-top-left-radius: 3px;
border-bottom-left-radius: 3px; border-bottom-left-radius: 3px;
} }
/* 加号按钮,设置了右上和右下圆角 */
.plus { .plus {
position: relative;
max-width: 30px;
min-width: 30px;
height: 30px;
line-height: 30px;
background: #f7f7f7;
text-align: center;
border-top-right-radius: 3px; border-top-right-radius: 3px;
border-bottom-right-radius: 3px; border-bottom-right-radius: 3px;
} }
/* 行元素,创建加号的横线,设置了圆角、绝对定位、顶部和左侧偏移、宽度、高度和背景色 */
.row { .row {
border-radius: 20px; border-radius: 20px;
position: absolute; position: absolute;
@ -584,6 +690,7 @@ rich-text {
height: 2px; height: 2px;
background-color: #ccc; background-color: #ccc;
} }
/* 列元素,创建加号的竖线,设置了圆角、绝对定位、顶部和左侧偏移、宽度、高度和背景色 */
.col { .col {
border-radius: 20px; border-radius: 20px;
position: absolute; position: absolute;
@ -596,6 +703,8 @@ rich-text {
background-color: #999; background-color: #999;
} }
} }
/* SKU弹出层底部固定栏设置了固定位置、底部对齐、宽度、弹性布局、高度、z-index和阴影效果 */
.pup-sku-footer { .pup-sku-footer {
position: fixed; position: fixed;
bottom: 0; bottom: 0;
@ -606,6 +715,7 @@ rich-text {
height: 98rpx; height: 98rpx;
z-index: 999; z-index: 999;
box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05); box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
/* 按钮,设置了相对定位、弹性增长、内容居中、宽度、背景色、字体大小和列式布局 */
.btn { .btn {
position: relative; position: relative;
display: flex; display: flex;
@ -617,10 +727,12 @@ rich-text {
font-size: 28rpx; font-size: 28rpx;
flex-flow: column; flex-flow: column;
} }
/* 购物车按钮,设置了背景色和文字颜色 */
.btn.cart { .btn.cart {
background: #584e61; background: #584e61;
color: #fff; color: #fff;
} }
/* 立即购买按钮,设置了背景色和文字颜色 */
.btn.buy { .btn.buy {
background: #eb2444; background: #eb2444;
color: #fff; color: #fff;

@ -1,260 +1,157 @@
<template> <template>
<!-- 商品详情 --> <!-- 商品详情页面容器 -->
<view class="container"> <view class="container">
<!-- 轮播图 --> <!-- 轮播图组件用于展示商品图片 -->
<swiper <swiper :indicator-dots="indicatorDots" <!-- -->
:indicator-dots="indicatorDots" :autoplay="autoplay" <!-- 是否自动播放 -->
:autoplay="autoplay" :indicator-color="indicatorColor" <!-- 未选中指示点的颜色 -->
:indicator-color="indicatorColor" :interval="interval" <!-- 自动切换时间间隔 -->
:interval="interval" :duration="duration" <!-- 滑动动画时长 -->
:duration="duration" :indicator-active-color="indicatorActiveColor" <!-- 当前选中指示点颜色 -->
:indicator-active-color="indicatorActiveColor" >
> <!-- 循环生成轮播项 -->
<block <block v-for="(item, index) in imgs" :key="index">
v-for="(item, index) in imgs"
:key="index"
>
<swiper-item> <swiper-item>
<image :src="item" /> <image :src="item" /> <!-- 显示每一张商品图片 -->
</swiper-item> </swiper-item>
</block> </block>
</swiper> </swiper>
<!-- end 轮播图 --> <!-- end 轮播图 -->
<!-- 商品信息 --> <!-- 商品信息展示区 -->
<view class="prod-info"> <view class="prod-info">
<!-- 标题与收藏按钮 -->
<view class="tit-wrap"> <view class="tit-wrap">
<view class="prod-tit"> <view class="prod-tit">{{ prodName }}</view> <!-- 商品名称 -->
{{ prodName }} <view class="col" @tap="addOrCannelCollection">
</view> <!-- 收藏/取消收藏按钮 -->
<view <image v-if="!isCollection" src="@/static/images/icon/prod-col.png" /> <!-- 未收藏图标 -->
class="col" <image v-if="isCollection" src="@/static/images/icon/prod-col-red.png" /> <!-- 已收藏图标 -->
@tap="addOrCannelCollection"
>
<image
v-if="!isCollection"
src="@/static/images/icon/prod-col.png"
/>
<image
v-if="isCollection"
src="@/static/images/icon/prod-col-red.png"
/>
收藏 收藏
</view> </view>
</view> </view>
<view class="sales-p"> <view class="sales-p">{{ brief }}</view> <!-- 商品简短描述 -->
{{ brief }} <!-- 商品价格信息 -->
</view>
<view class="prod-price"> <view class="prod-price">
<text <text v-if="defaultSku && defaultSku.price" class="price">
v-if="defaultSku && defaultSku.price" <!-- 当前售价 -->
class="price"
>
<text class="price-num"> <text class="price-num">{{ wxs.parsePrice(defaultSku.price)[0] }}</text> <!-- 整数部分 -->
{{ wxs.parsePrice(defaultSku.price)[0] }} .{{ wxs.parsePrice(defaultSku.price)[1] }} <!-- 小数部分 -->
</text> </text>
.{{ wxs.parsePrice(defaultSku.price)[1] }} <text v-if="defaultSku && defaultSku.oriPrice" class="ori-price">
</text> <!-- 原价 -->
<text
v-if="defaultSku && defaultSku.oriPrice"
class="ori-price"
>
{{ wxs.parsePrice(defaultSku.oriPrice)[0] }}.{{ wxs.parsePrice(defaultSku.oriPrice)[1] }} {{ wxs.parsePrice(defaultSku.oriPrice)[0] }}.{{ wxs.parsePrice(defaultSku.oriPrice)[1] }}
</text> </text>
<text class="sales" /> <text class="sales"></text> <!-- 销量等其他信息预留 -->
</view> </view>
</view> </view>
<!-- 已选规格 -->
<view <!-- 已选规格展示 -->
class="sku" <view class="sku" @tap="showSku">
@tap="showSku" <view class="sku-tit">已选</view>
> <view class="sku-con">{{ selectedProp.length > 0 ? selectedProp + '' : '' }}{{ prodNum }}</view> <!-- 展示已选择的规格和数量 -->
<view class="sku-tit"> <view class="more">...</view> <!-- 更多选项提示 -->
已选
</view>
<view class="sku-con">
{{ selectedProp.length > 0 ? selectedProp + '' : '' }}{{ prodNum }}
</view>
<view class="more">
...
</view>
</view> </view>
<!-- 评价 -->
<!-- 评价区域 -->
<view class="cmt-wrap"> <view class="cmt-wrap">
<view <!-- 评价标题 -->
class="cmt-tit" <view class="cmt-tit" @tap="showComment">
@tap="showComment"
>
<view class="cmt-t"> <view class="cmt-t">
评价 评价
<text class="cmt-good"> <text class="cmt-good">好评{{ prodCommData.positiveRating }}%</text> <!-- 好评率 -->
好评{{ prodCommData.positiveRating }}%
</text>
</view>
<view class="cmt-count">
{{ prodCommData.number }}
<text class="cmt-more" />
</view> </view>
<view class="cmt-count">{{ prodCommData.number }}<text class="cmt-more"></text></view> <!-- 评价总数 -->
</view> </view>
<!-- 评价标签和列表 -->
<view class="cmt-cont"> <view class="cmt-cont">
<view <view class="cmt-tag" @tap="showComment">
class="cmt-tag"
@tap="showComment"
>
<text>全部({{ prodCommData.number }})</text> <text>全部({{ prodCommData.number }})</text>
<text>好评({{ prodCommData.praiseNumber }})</text> <text>好评({{ prodCommData.praiseNumber }})</text>
<text>中评({{ prodCommData.secondaryNumber }})</text> <text>中评({{ prodCommData.secondaryNumber }})</text>
<text>差评({{ prodCommData.negativeNumber }})</text> <text>差评({{ prodCommData.negativeNumber }})</text>
<text>有图({{ prodCommData.picNumber }})</text> <text>有图({{ prodCommData.picNumber }})</text>
</view> </view>
<!-- 评价内容列表 -->
<view class="cmt-items"> <view class="cmt-items">
<view <view v-for="(item, index) in littleCommPage" :key="index" class="cmt-item">
v-for="(item, index) in littleCommPage"
:key="index"
class="cmt-item"
>
<view class="cmt-user"> <view class="cmt-user">
<text class="date"> <text class="date">{{ item.recTime }}</text> <!-- 评价时间 -->
{{ item.recTime }}
</text>
<view class="cmt-user-info"> <view class="cmt-user-info">
<image <image class="user-img" :src="item.pic" /> <!-- 用户头像 -->
class="user-img" <view class="nickname">{{ item.nickName }}</view> <!-- 用户昵称 -->
:src="item.pic"
/>
<view class="nickname">
{{ item.nickName }}
</view>
</view> </view>
</view> </view>
<view class="cmt-cnt"> <view class="cmt-cnt">{{ item.content }}</view> <!-- 评价内容 -->
{{ item.content }} <!-- 如果有图片则显示图片滚动视图 -->
</view> <scroll-view v-if="item.pics.length" class="cmt-attr" scroll-x="true">
<scroll-view <image v-for="(commPic, index2) in item.pics" :key="index2" :src="commPic" />
v-if="item.pics.length"
class="cmt-attr"
scroll-x="true"
>
<image
v-for="(commPic, index2) in item.pics"
:key="index2"
:src="commPic"
/>
</scroll-view> </scroll-view>
</view> </view>
</view> </view>
<view <!-- 如果评价超过2条显示查看更多 -->
v-if="prodCommPage.records.length > 2" <view v-if="prodCommPage.records.length > 2" class="cmt-more-v">
class="cmt-more-v" <text @tap="showComment"></text>
>
<text @tap="showComment">
查看全部评价
</text>
</view> </view>
</view> </view>
</view> </view>
<!-- 商品详情 -->
<!-- 商品详情内容 -->
<view class="prod-detail"> <view class="prod-detail">
<view> <view>
<rich-text :nodes="content" /> <rich-text :nodes="content"></rich-text> <!-- 使 -->
</view> </view>
</view> </view>
<!-- end 商品详情 --> <!-- end 商品详情 -->
<!-- 底部操作栏 -->
<!-- 底部按钮 -->
<view class="cart-footer"> <view class="cart-footer">
<view <!-- 首页按钮 -->
class="btn icon" <view class="btn icon" @tap="toHomePage">
@tap="toHomePage" <image src="@/static/images/tabbar/homepage.png" />首页
>
<image src="@/static/images/tabbar/homepage.png" />
首页
</view>
<view
class="btn icon"
@tap="toCartPage"
>
<image src="@/static/images/tabbar/basket.png" />
购物车
<view
v-if="totalCartNum>0"
class="badge badge-1"
>
{{ totalCartNum }}
</view>
</view> </view>
<view <!-- 购物车按钮 -->
class="btn cart" <view class="btn icon" @tap="toCartPage">
@tap="showSku" <image src="@/static/images/tabbar/basket.png" />购物车
> <view v-if="totalCartNum>0" class="badge badge-1">{{ totalCartNum }}</view> <!-- -->
<text>加入购物车</text>
</view>
<view
class="btn buy"
@tap="showSku"
>
<text>立即购买</text>
</view> </view>
<!-- 加入购物车按钮 -->
<view class="btn cart" @tap="showSku"><text>加入购物车</text></view>
<!-- 立即购买按钮 -->
<view class="btn buy" @tap="showSku"><text>立即购买</text></view>
</view> </view>
<!-- end 底部按钮 --> <!-- end 底部按钮 -->
<!-- 规格弹窗 --> <!-- 规格弹窗 -->
<view <view v-if="skuShow" class="pup-sku">
v-if="skuShow"
class="pup-sku"
>
<view class="pup-sku-main"> <view class="pup-sku-main">
<!-- 弹窗头部 -->
<view class="pup-sku-header"> <view class="pup-sku-header">
<image <image class="pup-sku-img" :src="defaultSku.pic?defaultSku.pic:pic" /> <!-- 商品图片 -->
class="pup-sku-img"
:src="defaultSku.pic?defaultSku.pic:pic"
/>
<view class="pup-sku-price"> <view class="pup-sku-price">
<!-- 商品价格 -->
<text <text v-if="defaultSku && defaultSku.price" class="pup-sku-price-int">{{ wxs.parsePrice(defaultSku.price)[0] }}</text>
v-if="defaultSku && defaultSku.price"
class="pup-sku-price-int"
>
{{ wxs.parsePrice(defaultSku.price)[0] }}
</text>
.{{ wxs.parsePrice(defaultSku.price)[1] }} .{{ wxs.parsePrice(defaultSku.price)[1] }}
</view> </view>
<view class="pup-sku-prop"> <view class="pup-sku-prop">
<text>已选</text> <!-- 已选规格 -->
{{ selectedProp.length > 0 ? selectedProp + '' : '' }}{{ prodNum }} <text>已选</text>{{ selectedProp.length > 0 ? selectedProp + '' : '' }}{{ prodNum }}
</view> </view>
<view <view class="close" @tap="closePopup"></view> <!-- -->
class="close"
@tap="closePopup"
/>
</view> </view>
<!-- 弹窗主体 -->
<view class="pup-sku-body"> <view class="pup-sku-body">
<!-- 规格选择区 -->
<view class="pup-sku-area"> <view class="pup-sku-area">
<view <view v-if="skuList.length" class="sku-box">
v-if="skuList.length" <block v-for="(skuGroupItem, skuGroupItemIndex) in skuGroupList" :key="skuGroupItemIndex">
class="sku-box" <view v-for="(skuLine, key) in skuGroupItem" :key="key" class="items sku-text">
> <text class="sku-kind">{{ key }}</text> <!-- 规格类型 -->
<block
v-for="(skuGroupItem, skuGroupItemIndex) in skuGroupList"
:key="skuGroupItemIndex"
>
<view
v-for="(skuLine, key) in skuGroupItem"
:key="key"
class="items sku-text"
>
<text class="sku-kind">
{{ key }}
</text>
<view class="con"> <view class="con">
<text <!-- 循环展示每一个规格选项 -->
v-for="skuLineItem in skuLine" <text v-for="skuLineItem in skuLine" :key="skuLineItem" class="sku-choose-item"
:key="skuLineItem"
class="sku-choose-item"
:class="[selectedPropList.indexOf(key + ':' + skuLineItem) !== -1?'active':'', :class="[selectedPropList.indexOf(key + ':' + skuLineItem) !== -1?'active':'',
isSkuLineItemNotOptional(allProperties,selectedPropObj,key,skuLineItem,propKeys)? 'dashed' : '']" isSkuLineItemNotOptional(allProperties,selectedPropObj,key,skuLineItem,propKeys)? 'dashed' : '']"
@click="toChooseItem(skuGroupItemIndex, skuLineItem, key)" @click="toChooseItem(skuGroupItemIndex, skuLineItem, key)">
>
{{ skuLineItem }} {{ skuLineItem }}
</text> </text>
</view> </view>
@ -262,167 +159,148 @@
</block> </block>
</view> </view>
</view> </view>
<!-- 数量选择 -->
<view class="pup-sku-count"> <view class="pup-sku-count">
<view class="num-wrap"> <view class="num-wrap">
<view <view class="minus" @tap="onCountMinus"><text class="row"></text></view> <!-- 减少数量 -->
class="minus" <view class="text-wrap"><input type="number" :value="prodNum" disabled></view> <!-- 显示数量 -->
@tap="onCountMinus" <view class="plus" @tap="onCountPlus"><text class="row"></text><text class="col"></text></view> <!-- 增加数量 -->
>
<text class="row" />
</view> </view>
<view class="text-wrap"> <view class="count-name">数量</view>
<input
type="number"
:value="prodNum"
disabled
>
</view> </view>
<view
class="plus"
@tap="onCountPlus"
>
<text class="row" />
<text class="col" />
</view> </view>
<!-- 弹窗底部 -->
<view class="pup-sku-footer">
<view class="btn cart" @tap="addToCart"></view> <!-- -->
<view class="btn buy" @tap="buyNow"></view> <!-- -->
</view> </view>
<view class="count-name">
数量
</view> </view>
</view> </view>
<!-- 评价弹窗 -->
<view v-if="commentShow" class="cmt-popup">
<view class="cmt-tit">
<view class="cmt-t">
商品评价
<text class="cmt-good">好评度{{ prodCommData.positiveRating }}%</text> <!-- 好评率 -->
</view> </view>
<view class="pup-sku-footer"> <text class="close" @tap="closePopup"></text> <!-- -->
<view
class="btn cart"
@tap="addToCart"
>
加入购物车
</view> </view>
<view <view class="cmt-cont">
class="btn buy" <!-- 评价筛选标签 -->
@tap="buyNow" <view class="cmt-tag">
> <text data-evaluate="-1" :class="evaluate==-1?'selected':''" @tap="getProdCommPage">({{ prodCommData.number }})</text>
立即购买 <text data-evaluate="0" :class="evaluate==0?'selected':''" @tap="getProdCommPage">({{ prodCommData.praiseNumber }})</text>
<text data-evaluate="1" :class="evaluate==1?'selected':''" @tap="getProdCommPage">({{ prodCommData.secondaryNumber }})</text>
<text data-evaluate="2" :class="evaluate==2?'selected':''" @tap="getProdCommPage">({{ prodCommData.negativeNumber }})</text>
<text data-evaluate="3" :class="evaluate==3?'selected':''" @tap="getProdCommPage">({{ prodCommData.picNumber }})</text>
</view>
<!-- 评价内容列表 -->
<view class="cmt-items">
<block v-if="prodCommPage.records.length">
<view v-for="(item, index) in prodCommPage.records" :key="index" class="cmt-item">
<view class="cmt-user">
<text class="date">{{ item.recTime }}</text> <!-- 评价时间 -->
<view class="cmt-user-info">
<image class="user-img" :src="item.pic" /> <!-- 用户头像 -->
<view class="nickname">{{ item.nickName }}</view> <!-- 用户昵称 -->
</view> </view>
</view> </view>
<view class="cmt-cnt">{{ item.content }}</view> <!-- 评价内容 -->
<!-- 如果有图片则显示图片滚动视图 -->
<scroll-view v-if="item.pics.length" class="cmt-attr" scroll-x="true">
<image v-for="(commPic, index2) in item.pics" :key="index2" :src="commPic" />
</scroll-view>
</view> </view>
</block>
</view> </view>
</view>
<!-- 评价弹窗 --> </view>
<view </view>
v-if="commentShow" <!-- 评价弹窗组件当commentShow为true时显示 -->
class="cmt-popup" <view v-if="commentShow" class="cmt-popup">
> <!-- 弹窗标题栏 -->
<view class="cmt-tit"> <view class="cmt-tit">
<view class="cmt-t"> <view class="cmt-t">
商品评价 商品评价 <!-- 标题文本 -->
<text class="cmt-good"> <text class="cmt-good">好评度{{ prodCommData.positiveRating }}%</text> <!-- 显示商品的好评率 -->
好评度{{ prodCommData.positiveRating }}%
</text>
</view> </view>
<text <text class="close" @tap="closePopup" /> <!-- 关闭按钮点击时调用closePopup方法关闭弹窗 -->
class="close"
@tap="closePopup"
/>
</view> </view>
<!-- 弹窗内容区 -->
<view class="cmt-cont"> <view class="cmt-cont">
<!-- 评价筛选标签 -->
<view class="cmt-tag"> <view class="cmt-tag">
<text <!-- 动态生成评价筛选选项 -->
data-evaluate="-1" <text data-evaluate="-1"
:class="evaluate == -1 ? 'selected' : ''" :class="evaluate == -1 ? 'selected' : ''"
@tap="getProdCommPage" @tap="getProdCommPage">
>
全部({{ prodCommData.number }}) 全部({{ prodCommData.number }})
</text> </text>
<text <text data-evaluate="0"
data-evaluate="0"
:class="evaluate == 0 ? 'selected' : ''" :class="evaluate == 0 ? 'selected' : ''"
@tap="getProdCommPage" @tap="getProdCommPage">
>
好评({{ prodCommData.praiseNumber }}) 好评({{ prodCommData.praiseNumber }})
</text> </text>
<text <text data-evaluate="1"
data-evaluate="1"
:class="evaluate == 1 ? 'selected' : ''" :class="evaluate == 1 ? 'selected' : ''"
@tap="getProdCommPage" @tap="getProdCommPage">
>
中评({{ prodCommData.secondaryNumber }}) 中评({{ prodCommData.secondaryNumber }})
</text> </text>
<text <text data-evaluate="2"
data-evaluate="2"
:class="evaluate == 2 ? 'selected' : ''" :class="evaluate == 2 ? 'selected' : ''"
@tap="getProdCommPage" @tap="getProdCommPage">
>
差评({{ prodCommData.negativeNumber }}) 差评({{ prodCommData.negativeNumber }})
</text> </text>
<text <text data-evaluate="3"
data-evaluate="3"
:class="evaluate == 3 ? 'selected' : ''" :class="evaluate == 3 ? 'selected' : ''"
@tap="getProdCommPage" @tap="getProdCommPage">
>
有图({{ prodCommData.picNumber }}) 有图({{ prodCommData.picNumber }})
</text> </text>
<!-- 每个文本元素都有一个data-evaluate属性用于标识评价类型并根据evaluate值来决定是否添加'selected'类名以高亮当前选中的筛选条件 -->
<!-- 点击任一文本元素时会触发getProdCommPage方法加载对应的评价数据 -->
</view> </view>
<!-- 评价列表 -->
<view class="cmt-items"> <view class="cmt-items">
<!-- 如果存在评价记录则循环渲染每个评价项 -->
<block v-if="prodCommPage.records.length"> <block v-if="prodCommPage.records.length">
<view <view v-for="(item, index) in prodCommPage.records"
v-for="(item, index) in prodCommPage.records"
:key="index" :key="index"
class="cmt-item" class="cmt-item">
> <!-- 用户信息 -->
<view class="cmt-user"> <view class="cmt-user">
<text class="date"> <text class="date">{{ item.recTime }}</text> <!-- 评价时间 -->
{{ item.recTime }}
</text>
<view class="cmt-user-info"> <view class="cmt-user-info">
<image <image class="user-img" :src="item.pic" /> <!-- 用户头像 -->
class="user-img" <view class="nickname">{{ item.nickName }}</view> <!-- 用户昵称 -->
:src="item.pic"
/>
<view class="nickname">
{{ item.nickName }}
</view>
</view> </view>
</view> </view>
<view class="cmt-cnt"> <!-- 评价内容 -->
{{ item.content }} <view class="cmt-cnt">{{ item.content }}</view>
</view> <!-- 如果评价中有图片则展示图片滚动视图 -->
<scroll-view <scroll-view v-if="item.pics.length" class="cmt-attr" scroll-x="true">
v-if="item.pics.length" <image v-for="(commPic, index2) in item.pics"
class="cmt-attr"
scroll-x="true"
>
<image
v-for="(commPic, index2) in item.pics"
:key="index2" :key="index2"
:src="commPic" :src="commPic" />
/>
</scroll-view> </scroll-view>
<view <!-- 店铺回复如果有的话 -->
v-if="item.replyContent" <view v-if="item.replyContent" class="cmt-reply">
class="cmt-reply" <text class="reply-tit">店铺回复</text>
>
<text class="reply-tit">
店铺回复
</text>
{{ item.replyContent }} {{ item.replyContent }}
</view> </view>
</view> </view>
</block> </block>
<view <!-- 如果没有评价记录则显示提示信息 -->
v-if="!prodCommPage.records.length" <view v-if="!prodCommPage.records.length" class="empty">
class="empty"
>
暂无评价 暂无评价
</view> </view>
</view> </view>
<view
v-if="prodCommPage.pages > prodCommPage.current" <!-- 加载更多按钮当还有未加载的评价页时显示 -->
class="load-more" <view v-if="prodCommPage.pages > prodCommPage.current" class="load-more">
> <text @tap="getMoreCommPage"></text> <!-- getMoreCommPage -->
<text @tap="getMoreCommPage">
点击加载更多
</text>
</view>
</view> </view>
</view> </view>
</view> </view>

@ -1,34 +1,40 @@
.recent-news { .recent-news {
background: #fff; background: #fff; /* 设置最近新闻容器的背景颜色为白色 */
.news-item { .news-item {
padding: 20rpx 20rpx 0 20rpx; padding: 20rpx 20rpx 0 20rpx; /* 内边距上20rpx左右各20rpx下0rpx */
position: relative; position: relative; /* 使子元素可以相对于此元素进行绝对定位 */
&::after { &::after {
content: " "; content: " "; /* 生成一个伪元素 */
width: 100%; width: 100%; /* 伪元素宽度为100% */
height: 2rpx; height: 2rpx; /* 伪元素高度为2rpx作为分隔线 */
background-color: #e1e1e1; background-color: #e1e1e1; /* 分隔线的颜色为浅灰色 */
left: 20rpx; left: 20rpx; /* 从左边开始20rpx与父元素内边距对齐 */
display: block; display: block; /* 伪元素作为块级元素显示 */
position: absolute; position: absolute; /* 伪元素绝对定位,相对于父元素 */
bottom: 0; /* 伪元素位于父元素底部 */
} }
.news-item-title { .news-item-title {
font-size: 28rpx; font-size: 28rpx; /* 新闻标题字体大小为28rpx */
text-align: left; text-align: left; /* 文字左对齐 */
} }
.news-item-date { .news-item-date {
font-size: 24rpx; font-size: 24rpx; /* 日期字体大小为24rpx */
color: #999; color: #999; /* 日期颜色为浅灰色 */
text-align: right; text-align: right; /* 文字右对齐 */
margin-top: 10rpx; margin-top: 10rpx; /* 上边距为10rpx */
margin-bottom: 20rpx; margin-bottom: 20rpx; /* 下边距为20rpx */
} }
} }
.empty { .empty {
display: block; display: block; /* 空状态提示作为块级元素显示 */
padding-top: 200rpx; padding-top: 200rpx; /* 上内边距为200rpx用于居中显示空状态提示 */
color: #999; color: #999; /* 文字颜色为浅灰色 */
font-size: 26rpx; font-size: 26rpx; /* 字体大小为26rpx */
text-align: center; text-align: center; /* 文字水平居中 */
} }
} }

@ -1,60 +1,62 @@
<template> <template>
<view class="container"> <view class="container">
<!-- 最近新闻容器 -->
<view class="recent-news"> <view class="recent-news">
<block <!-- 使用 v-for 指令循环渲染 news 数组中的每一个项目 -->
v-for="(item, index) in news" <block v-for="(item, index) in news" :key="index">
:key="index" <!-- 新闻项点击时触发 toNewsDetail 方法 -->
> <view class="news-item" :data-id="item.id" @tap="toNewsDetail">
<view <!-- 新闻标题 -->
class="news-item" <view class="news-item-title">{{ item.title }}</view>
:data-id="item.id" <!-- 新闻发布时间 -->
@tap="toNewsDetail" <view class="news-item-date">{{ item.publishTime }}</view>
>
<view class="news-item-title">
{{ item.title }}
</view>
<view class="news-item-date">
{{ item.publishTime }}
</view>
</view> </view>
</block> </block>
<view <!-- news 数组为空或不存在时显示的空状态提示 -->
v-if="!news || !news.length" <view v-if="!news || !news.length" class="empty"></view>
class="empty"
>
暂无数据
</view>
</view> </view>
</view> </view>
</template> </template>
<script setup> <script setup>
const news = ref([]) import { ref, onShow } from 'vue'; // Vue
import http from '@/utils/http'; // HTTP
//
const news = ref([]);
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
* 当页面显示时调用此函数通常用于加载初始数据
*/ */
onShow(() => { onShow(() => {
// // HTTP GET
http.request({ http.request({
url: '/shop/notice/noticeList', url: '/shop/notice/noticeList', // API
method: 'GET' method: 'GET' //
}) })
.then(({ data }) => { .then(({ data }) => {
news.value = data.records // news
}) news.value = data.records;
}) })
.catch((error) => {
console.error('Failed to fetch news:', error); //
});
});
/** /**
* 跳转公告详情页 * 跳转公告详情页
* @param e * @param e - 触发事件对象包含当前元素的数据集dataset
*/ */
const toNewsDetail = (e) => { const toNewsDetail = (e) => {
// 使 uni.navigateTo ID
uni.navigateTo({ uni.navigateTo({
url: '/pages/news-detail/news-detail?id=' + e.currentTarget.dataset.id url: `/pages/news-detail/news-detail?id=${e.currentTarget.dataset.id}`
}) });
} };
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
/* 引入外部样式文件,这里的样式将仅应用于本组件 */
@use './recent-news.scss'; @use './recent-news.scss';
</style> </style>

Loading…
Cancel
Save