mrr.sj.front/pages/evaluate/components/evaluationDetail.vue

335 lines
7.5 KiB
Vue
Raw Normal View History

2026-03-24 11:45:13 +08:00
<template>
<view class="evaluation-detail" @click="goDetail">
<!-- 用户信息区域 -->
<view class="user-section">
<view class="user-info">
<image class="avatar" :src="evaluatorPhoto" />
<text class="username">{{ evaluatorName }}</text>
</view>
<text class="time">{{formattedCreateTime}}</text>
</view>
<view class="user-contant">
<!-- 评分标题 -->
<view class="rating-header">
<image :src="getComposite" class="tag" mode="heightFix"></image>
<view class="stars">
<image v-for="n in 5" :key="n" :src="getStar(n)" class="star-icon" />
</view>
<text class="score">{{evaluateObj.composite}}</text>
</view>
<!-- 评论内容 -->
<view class="comment">
<!-- <text>
{{ evaluateObj.describe }}
</text> -->
<view class="comment-main-content">
{{evaluateObj.describe.length > 60 ? evaluateObj.describe.slice(0, 59) : evaluateObj.describe}}
<span v-if="evaluateObj.describe.length > 60">
{{hasShowMore ? evaluateObj.describe.slice(59) : '...'}}
<span class="foot-btn" @click.stop="showMore">
{{hasShowMore ? '收起' : '全文'}}
<image src="/static/images/evaluate/open.png" mode="widthFix" :class="{btnImg2:hasShowMore}" class="foot-btn-img"></image>
</span>
</span>
</view>
</view>
<!-- 图片展示 -->
<view class="photos" v-if="isAllImg">
<image v-for="(photo, index) in photos" :key="index" :src="photo" class="photo" mode="aspectFill"
@tap.stop="imgPreview(index)" />
</view>
<view class="photos" v-else>
<image v-for="(photo, index) in photos.slice(0, 3)" :key="index" :src="photo" class="photo"
mode="aspectFill" @tap.stop="imgPreview(index)" />
<view class="more" v-if="photos.length>3">
<image src="/static/images/evaluate/more.png" class="more-img" />
{{photos.length}}
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
hasShowMore:false,
compositeStraList: []
};
},
computed: {
evaluatorPhoto() {
if (!this.evaluateObj.evaluator_head_photo) {
return ""
}
return this.evaluateObj.anonymity == 1 ? "/static/images/evaluate/photo.jpg" : this.evaluateObj
.evaluator_head_photo
},
evaluatorName() {
if (!this.evaluateObj.evaluator_name) {
return ""
}
return this.evaluateObj.anonymity == 1 ? "匿名用户" : this.evaluateObj.evaluator_name
},
photos() {
if (!this.evaluateObj.images) {
return []
}
return this.evaluateObj.images.split(",")
},
// 计算属性:仅返回日期部分
// 计算属性返回带汉字的日期格式如2025年9月12日
formattedCreateTime() {
if (!this.evaluateObj?.create_time) return '';
// 1. 提取日期部分(如从"2025-10-15 10:30:45"中获取"2025-10-15",
const datePart = this.evaluateObj.create_time.split(' ')[0];
if (!datePart) return '';
// 2. 处理旧版iOS兼容性将"-"替换为"/"
const compatibleDateStr = datePart.replace(/-/g, '/');
const date = new Date(compatibleDateStr);
// 3. 验证日期有效性
if (isNaN(date.getTime())) return '';
// 4. 提取年月日并拼接汉字格式
const year = date.getFullYear();
const month = date.getMonth() + 1; // 月份从0开始需+1
const day = date.getDate();
return `${year}${month}${day}`;
},
getComposite() {
if (!this.evaluateObj.composite) {
return ""
}
console.log(1111,`/static/images/evaluate/score${Math.floor(this.evaluateObj.composite)}.png`)
return `/static/images/evaluate/score${Math.floor(this.evaluateObj.composite)}.png`
}
},
props: {
evaluateObj: {
type: Object,
default: () => ({}),
},
isAllImg: {
type: Boolean,
default: false
}
},
methods: {
showMore(){
this.hasShowMore = !this.hasShowMore
},
imgPreview(index) {
uni.previewImage({
current: index,
urls: this.photos,
});
},
getStar(value) {
if (!this.evaluateObj.composite) {
return ""
}
let composite = this.evaluateObj.composite
if (composite >= value) {
return "/static/images/evaluate/star_red.png"
} else if (composite < value && composite > value - 1) {
return "/static/images/evaluate/star2.png"
} else {
return "/static/images/evaluate/star_ash2.png"
}
},
// 处理函数:保留整数部分,小数部分>0.5则取0.5否则取0
handleDecimal(num) {
// 提取整数部分正数用Math.floor负数特殊处理
const integerPart = Math.sign(num) === -1 ? Math.ceil(num) : Math.floor(num);
// 提取小数部分
const decimalPart = num - integerPart;
// 判断小数部分并返回结果
if (decimalPart > 0.5) {
return integerPart + 0.5;
} else {
return integerPart + 0; // 可简化为 integerPart
}
},
goDetail() {
this.$emit("goDetail", this.evaluateObj)
}
}
};
</script>
<style scoped lang="less">
.evaluation-detail {
padding: 30rpx 20rpx;
border-radius: 16rpx;
background-color: #fff;
border-bottom: 2rpx solid #FAFAFA;
flex: 1;
}
/* 用户信息区域 */
.user-section {
display: flex;
align-items: center;
justify-content: space-between;
.user-info {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
.avatar {
width: 62rpx;
height: 62rpx;
border-radius: 50%;
margin-right: 6rpx;
}
.username {
font-weight: 500;
font-size: 24rpx;
color: #333333;
line-height: 33rpx;
text-align: left;
font-style: normal;
}
}
.time {
font-size: 24rpx;
color: #999;
margin-top: 4rpx;
}
}
.user-contant {
padding-left: 70rpx;
/* 评分头部 */
.rating-header {
display: flex;
align-items: center;
margin-top: 20rpx;
.tag {
height: 40rpx;
margin-right: 10rpx;
}
.stars {
display: flex;
align-items: center;
margin-right: 10rpx;
.star-icon {
width: 24rpx;
height: 24rpx;
margin-right: 2rpx;
}
}
.score {
font-weight: 400;
font-size: 26rpx;
2026-06-02 11:39:23 +08:00
color: #FF4767;
2026-03-24 11:45:13 +08:00
line-height: 37rpx;
text-align: left;
font-style: normal;
}
}
/* 评论内容 */
.comment {
font-weight: 400;
font-size: 26rpx;
color: #333333;
line-height: 46rpx;
text-align: left;
font-style: normal;
margin-top: 12rpx;
}
/* 图片区域 */
.photos {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
margin-top: 20rpx;
column-gap: 1.1%;
row-gap: 6rpx;
position: relative;
.photo {
width: 32.6%;
height: 194rpx;
border-radius: 6rpx;
object-fit: cover;
/* background-color: #f5f5f5; */
}
.more {
width: 59rpx;
height: 28rpx;
background: rgba(51, 51, 51, 0.4);
border-radius: 14rpx;
font-weight: 400;
font-size: 22rpx;
color: #FFFFFF;
line-height: 30rpx;
text-align: left;
font-style: normal;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
bottom: 10rpx;
right: 10rpx;
.more-img {
width: 23rpx;
height: 17rpx;
margin-right: 5rpx;
}
}
}
}
.comment-main-content{
.foot-btn{
font-weight: 500;
font-size: 24rpx;
color: #0751ff;
line-height: 33rpx;
text-align: left;
font-style: normal;
.foot-btn-img{
width: 18rpx;
height: 18rpx;
margin-left: 10rpx;
}
.btnImg2{
transform: rotate(180deg);
}
}
}
</style>