Files
SmartParks_uniapp/pages/sys/user/myRepair/repairEvaluate.vue
liyuanchao 400e95c81b
Some checks failed
Uniapp 自动化打包 CI/CD / 打包 Uniapp 项目 (push) Has been cancelled
首页活动,报事报修评价
2025-09-09 17:21:35 +08:00

288 lines
6.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="evaluate-container">
<!-- 评分项 -->
<view class="evaluate-list">
<view class="evaluate-row">
<text class="evaluate-label">服务评价</text>
<view class="evaluate-stars">
<image v-for="i in 5" :key="i"
:src="detailItem.serviceEvalua >= i ? '/static/ic_evaluate_select.png' : '/static/ic_evaluate_disselect.png'"
class="evaluate-star" :class="{'disabled': isViewMode}" @click="!isViewMode && setRating(i)" />
</view>
</view>
</view>
<!-- 输入框 -->
<textarea class="evaluate-textarea" placeholder="说点什么吧..." v-model="detailItem.serviceEvaluaText"
:disabled="isViewMode" />
<!-- 上传照片 -->
<view class="repair-evaluate-section" v-if="!isViewMode">
<view class="add-repair-label">上传照片 <text class="add-repair-optional">(非必填最多三张)</text></view>
<u-upload :fileList="selectedImages" @on-list-change="onListChange" @delete="deletePic" name="upload"
multiple maxCount="3" width="180" height="180" :autoUpload="false"></u-upload>
</view>
<!-- 查看图片 -->
<view class="repair-evaluate-section" v-else>
<view class="add-repair-label">评价图片</view>
<view class="image-preview-container" v-if="imageList.length > 0">
<image v-for="(img, index) in imageList" :key="index" :src="img" class="preview-image"
@click="previewImage(index)"></image>
</view>
<view class="no-image" v-else>暂无图片</view>
</view>
<!-- 提交按钮 -->
<button class="evaluate-btn" @click="submit" v-if="!isViewMode">提交</button>
</view>
</template>
<script>
// 导入MediaSelector和MediaType
import MediaSelector, {
MediaType
} from '@/utils/mediaSelector';
import {
uploadFiles
} from '@/common/upload.js';
export default {
data() {
return {
comment: '',
selectedImages: [], // 存储已选图片
imageList: [], // 查看模式下的图片列表
detailItem: {
serviceEvalua: 0,
serviceEvaluaText: ''
}, // 接收传递的详情项
isViewMode: false // 是否为查看模式
}
},
onLoad(options) {
// 接收传递的参数
if (options.item) {
try {
const item = JSON.parse(decodeURIComponent(options.item));
this.detailItem = {
...this.detailItem,
...item
};
console.log(this.detailItem)
this.isViewMode = this.detailItem.serviceEvalua
if (this.isViewMode) {
this.getImageUrl()
}
} catch (e) {
console.error('解析item参数失败', e);
}
}
},
methods: {
async getImageUrl() {
if (!this.detailItem.imgUrl) return;
const imgIds = this.detailItem.imgUrl.split(',');
const res = await this.$u.api.getImageUrl({}, imgIds.join(','));
if (res.code == 200 && res.data) this.imageList = res.data.map(item => item.url);
},
// 设置评分
setRating(rating) {
this.$set(this.detailItem, 'serviceEvalua', rating);
},
// 删除图片
deletePic(event) {
this.selectedImages.splice(event.index, 1);
},
// 图片列表变化处理
onListChange(list) {
this.selectedImages = list;
},
// 预览图片
previewImage(index) {
uni.previewImage({
current: index,
urls: this.imageList
});
},
async submit() {
console.log(this.selectedImages)
if (this.selectedImages.length <= 0) {
this.realSubmit()
return
}
// 遍历selectedImages数组并处理图片路径
const images = this.selectedImages
.map(item => item?.path?.replace('file://', '') || item?.url || null)
.filter(path => path !== null);
uni.showLoading({
title: '加载中...'
});
const result = await uploadFiles({
files: images,
url: this.vuex_config.baseUrl + '/resource/oss/upload',
name: 'file',
vm: this // 关键:用于注入 token 等
});
const allSuccess = result.every(item => item.code == 200);
if (!allSuccess) {
uni.showToast({
title: '上传失败',
icon: 'none'
});
uni.hideLoading();
return;
}
// 遍历result获取data.url加上,分割
const urls = result.map(item => item.data?.ossId || '').filter(ossId => ossId !== '');
this.detailItem.imgUrl = urls.join(',');
this.realSubmit()
},
async realSubmit() {
let res = await this.$u.api.updateOrder2(this.detailItem);
if (res.code == '200') {
// 关闭页面前发送事件通知前页面刷新
uni.$emit('refreshData', '');
// 返回上一页
uni.navigateBack();
}
}
}
}
</script>
<style scoped>
.evaluate-container {
min-height: 100vh;
background: #fff;
padding-bottom: 40rpx;
/* 防止在iOS等设备上滑动到顶部或底部时出现回弹效果 */
overscroll-behavior-y: contain;
}
.evaluate-list {
margin: 0 53rpx 0 40rpx;
}
.evaluate-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 38rpx;
}
.evaluate-label {
font-size: 30rpx;
color: #222;
width: 160rpx;
text-align: left;
}
.evaluate-stars {
display: flex;
align-items: center;
}
.evaluate-star {
width: 36rpx;
height: 34rpx;
margin-right: 36rpx;
}
.evaluate-star.disabled {
opacity: 1;
}
.evaluate-tag {
flex: 0 0 calc((100% - 60rpx) / 4);
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
height: 64rpx;
border-radius: 32rpx;
font-size: 28rpx;
color: #666666;
background: #F2F2F2;
}
.evaluate-tag.selected {
background: #0090FF;
color: #fff;
}
.evaluate-textarea {
width: 85vw;
min-height: 120rpx;
background: #F5F6F7;
border-radius: 10rpx;
font-size: 26rpx;
color: #222222;
padding: 23rpx 27rpx 23rpx 27rpx;
margin: 49rpx auto 0 auto;
display: block;
}
.evaluate-textarea[disabled] {
background-color: #f0f0f0;
}
.evaluate-btn {
width: 80vw;
height: 88rpx;
background: #0090FF;
color: #fff;
font-size: 36rpx;
border: none;
border-radius: 44rpx;
margin: 137rpx auto 0 auto;
display: block;
font-weight: bold;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.18);
}
.repair-evaluate-section {
background: #fff;
border-radius: 12rpx;
margin: 22rpx 0rpx 0 0rpx;
padding: 24rpx 46rpx 24rpx 44rpx;
}
.add-repair-label {
font-size: 32rpx;
color: #000000;
font-weight: 500;
margin-bottom: 41rpx;
}
.add-repair-optional {
color: #888;
font-size: 24rpx;
font-weight: 400;
}
.image-preview-container {
display: flex;
flex-wrap: wrap;
}
.preview-image {
width: 180rpx;
height: 180rpx;
margin-right: 20rpx;
margin-bottom: 20rpx;
}
.no-image {
color: #888;
font-size: 28rpx;
text-align: center;
padding: 20rpx 0;
}
</style>