<template>
|
<view class="page-wrapper">
|
<div class="bg-top"></div>
|
|
<div class="content-wrapper">
|
|
<view class="text-2xl font-bold mb-4 text-center">投诉和建议</view>
|
|
<!-- 投诉建议 -->
|
<!-- 投诉内容 -->
|
<view>
|
<label class="text-sm font-semibold font-medium mb-1 block">问题描述</label>
|
<textarea v-model="form.question" placeholder="请输入您的投诉或建议(5-500字)"
|
class="w-95-percent h-40 p-2 border border-gray-300 rounded-lg resize-none"
|
maxlength="500"></textarea>
|
<view class="text-right text-xs text-gray-500">{{ form.question.length }}/500</view>
|
</view>
|
|
<!-- 上传图片 -->
|
<view class="mb-4">
|
<view class="text-sm font-semibold mb-1">上传图片</view>
|
<view class="flex justify-start space-x-2">
|
<view v-for="(img, index) in form.images" :key="index" class="relative">
|
<image :src="img" class="w-20 h-20 rounded-md object-cover" />
|
<view
|
class="absolute top-0 right-0 bg-black bg-opacity-50 text-white text-xs px-1 cursor-pointer"
|
@click="removeImage(index)">
|
×
|
</view>
|
</view>
|
<view v-if="form.images.length < 3"
|
class="w-20 h-20 border border-dashed border-gray-400 rounded-md text-gray-400 flex justify-center items-center cursor-pointer"
|
@click="chooseImage">
|
+
|
</view>
|
<!--
|
<button v-if="form.images.length < 3"
|
class="w-20 h-20 border border-dashed border-gray-400 rounded-md text-gray-400"
|
@click="chooseImage">
|
+
|
</button>
|
-->
|
</view>
|
<view class="text-xs text-gray-500 mt-1">最多选择3张,每张不超过5MB</view>
|
</view>
|
|
<!-- 联系人 -->
|
<view>
|
<label class="text-sm font-semibold font-medium mb-1 block">联系人:</label>
|
<input v-model="form.contactperson" type="text" placeholder="请输入联系人(最多10个字)"
|
class="w-95-percent border border-gray-300 rounded p-2 h-12" />
|
</view>
|
|
<!-- 联系电话 -->
|
<view class="mt-10">
|
<label class="text-sm font-semibold font-medium mb-1 block">联系电话:</label>
|
<input v-model="form.contactphone" type="text" placeholder="请输入联系电话"
|
class="w-95-percent border border-gray-300 rounded p-2 h-12" />
|
</view>
|
|
<!-- 提交按钮 -->
|
<button class="w-full bg-blue-500 text-white py-3 rounded mt-10" @click="submitForm">
|
提交
|
</button>
|
</div>
|
<div class="bg-bottom"></div>
|
|
</view>
|
</template>
|
|
<script>
|
import {
|
useUserStore
|
} from '@/stores/user'
|
import {
|
apiService
|
} from '@/apiservice/apiService'
|
|
const userStore = useUserStore()
|
|
export default {
|
data() {
|
return {
|
form: {
|
question: '',
|
images: [],
|
contactperson: userStore.username,
|
contactphone: userStore.phone
|
}
|
}
|
},
|
methods: {
|
chooseImage() {
|
uni.chooseImage({
|
count: 3 - this.form.images.length,
|
sizeType: ['original', 'compressed'],
|
success: (res) => {
|
const files = res.tempFilePaths.filter((f, i) => i + this.form.images.length < 3)
|
|
const maxSize = 5 * 1024 * 1024 // 5MB,单位字节
|
const oversized = files.filter(f => f.size > maxSize)
|
if (oversized.length > 0) {
|
uni.showToast({
|
title: '图片不能大于 5MB,请重新选择',
|
icon: 'none'
|
})
|
return
|
}
|
this.form.images.push(...files)
|
|
}
|
})
|
},
|
removeImage(index) {
|
this.form.images.splice(index, 1)
|
},
|
async uploadAllImages() {
|
if (this.form.images.length === 0) return [];
|
|
const uploadPromises = this.form.images.map(img => {
|
return new Promise((resolve, reject) => {
|
uni.uploadFile({
|
url: apiService.baseURL + '/advices/upload', // 后端上传接口
|
filePath: img,
|
name: 'file',
|
success: (res) => {
|
try {
|
const data = JSON.parse(res.data);
|
if (data.code === 1000 && data.data) {
|
resolve(data.data);
|
} else {
|
reject(new Error('上传失败'));
|
}
|
} catch (err) {
|
reject(err);
|
}
|
},
|
fail: reject
|
});
|
});
|
});
|
|
return Promise.all(uploadPromises);
|
},
|
async submitForm() {
|
// 内容校验
|
if (this.form.question.length < 5) {
|
uni.showToast({
|
title: '投诉内容至少5个字',
|
icon: 'none'
|
})
|
return
|
}
|
if (this.form.question.length > 200) {
|
uni.showToast({
|
title: '投诉内容最多200字',
|
icon: 'none'
|
})
|
return
|
}
|
|
// 联系人校验
|
const contact = this.form.contactperson.trim()
|
if (!contact) {
|
uni.showToast({
|
title: '联系人不能为空',
|
icon: 'none'
|
})
|
return
|
}
|
if (contact.length > 10) {
|
uni.showToast({
|
title: '联系人最多10个字符',
|
icon: 'none'
|
})
|
return
|
}
|
|
// 电话校验
|
const phone = this.form.contactphone.trim()
|
const phoneRegex = /^(1\d{10}|([0-9\uFF10-\uFF19\--\s,,]{5,20}))$/
|
if (!phoneRegex.test(phone)) {
|
uni.showToast({
|
title: '联系电话格式不正确',
|
icon: 'none'
|
})
|
return
|
}
|
try {
|
uni.showLoading({
|
title: '提交中...'
|
});
|
|
// 1️⃣ 并发上传图片
|
const imageUrls = await this.uploadAllImages();
|
const [img1, img2, img3] = imageUrls || [];
|
|
// 2️⃣ 组合提交数据
|
const payload = {
|
uuid: userStore.uuid,
|
question: this.form.question,
|
img1: img1,
|
img2: img2,
|
img3: img3,
|
contactperson: this.form.contactperson,
|
contactphone: this.form.contactphone
|
};
|
|
apiService.advicesAdd(payload).then((res) => {
|
if (res.code === 1000) {
|
uni.showToast({
|
title: '提交成功,我们将在24小时内回复,请在“我的”菜单查看。',
|
icon: 'success'
|
})
|
// 重置表单
|
this.form.question = ''
|
this.form.images = []
|
uni.navigateTo({
|
url: '/pages/ucenter/my-advice'
|
})
|
} else {
|
console.warn('游客更新失败:', res.message)
|
uni.showToast({
|
title: res.message || '提交失败',
|
icon: 'none'
|
})
|
}
|
}).catch((err) => {
|
console.error('游客更新错误:', err)
|
uni.showToast({
|
title: '发生错误,请联系管理员',
|
icon: 'none'
|
})
|
})
|
} catch (err) {
|
console.error("提交错误:", err);
|
uni.showToast({
|
title: "网络错误",
|
icon: "none"
|
});
|
} finally {
|
uni.hideLoading();
|
}
|
}
|
},
|
}
|
</script>
|
<style>
|
/* 布局与容器 */
|
.p-4 {
|
padding: 1rem;
|
}
|
|
.bg-gray-100 {
|
background-color: #f3f4f6;
|
}
|
|
.min-h-screen {
|
min-height: 100vh;
|
}
|
|
/* 字体与文本 */
|
.text-2xl {
|
font-size: 1.5rem;
|
line-height: 2rem;
|
}
|
|
.font-bold {
|
font-weight: 700;
|
}
|
|
.font-medium {
|
font-weight: 500;
|
}
|
|
.font-semibold {
|
font-weight: 600;
|
}
|
|
.text-center {
|
text-align: center;
|
}
|
|
.text-sm {
|
font-size: 0.875rem;
|
line-height: 1.25rem;
|
}
|
|
.mt-10 {
|
margin-top: 50rpx;
|
}
|
|
.justify-start {
|
justify-content: flex-start;
|
}
|
|
.text-xs {
|
font-size: 0.75rem;
|
line-height: 1rem;
|
}
|
|
.text-gray-400 {
|
color: #9ca3af;
|
}
|
|
.text-gray-500 {
|
color: #6b7280;
|
}
|
|
.text-white {
|
color: #ffffff;
|
}
|
|
/* 边距 */
|
.mb-1 {
|
margin-bottom: 0.25rem;
|
}
|
|
.mb-4 {
|
margin-bottom: 1rem;
|
}
|
|
.mt-1 {
|
margin-top: 0.25rem;
|
}
|
|
/* 尺寸与边框 */
|
.w-full {
|
width: 100%;
|
}
|
|
.w-95-percent {
|
width: 95%;
|
}
|
|
.h-40 {
|
height: 8rem;
|
}
|
|
.h-12 {
|
height: 2.5rem;
|
}
|
|
.w-20 {
|
width: 5rem;
|
}
|
|
.h-20 {
|
height: 5rem;
|
}
|
|
.border {
|
border-width: 1px;
|
border-style: solid;
|
border-color: #d1d5db;
|
}
|
|
.border-gray-300 {
|
border-color: #d1d5db;
|
}
|
|
.border-gray-400 {
|
border-color: #9ca3af;
|
}
|
|
.border-dashed {
|
border-style: dashed;
|
}
|
|
.rounded {
|
border-radius: 0.25rem;
|
}
|
|
.rounded-md {
|
border-radius: 0.375rem;
|
}
|
|
.rounded-lg {
|
border-radius: 0.5rem;
|
}
|
|
/* 背景色与透明度 */
|
.bg-black {
|
background-color: #000000;
|
}
|
|
.bg-opacity-50 {
|
opacity: 0.5;
|
}
|
|
.bg-blue-500 {
|
background-color: #3b82f6;
|
}
|
|
/* 位置 */
|
.relative {
|
position: relative;
|
}
|
|
.absolute {
|
position: absolute;
|
}
|
|
.top-0 {
|
top: 0;
|
}
|
|
.right-0 {
|
right: 0;
|
}
|
|
.justify-center {
|
justify-content: center;
|
}
|
|
.items-center {
|
align-items: center;
|
}
|
|
/* 布局与对齐 */
|
.flex {
|
display: flex;
|
}
|
|
.space-x-2 {
|
margin-left: 0.5rem;
|
}
|
|
.text-right {
|
text-align: right;
|
}
|
|
.block {
|
display: block;
|
}
|
|
.cursor-pointer {
|
cursor: pointer;
|
}
|
|
/* 填充 */
|
.p-2 {
|
padding: 0.5rem;
|
}
|
|
.py-3 {
|
padding-top: 0.75rem;
|
padding-bottom: 0.75rem;
|
}
|
|
.px-1 {
|
padding-left: 0.25rem;
|
padding-right: 0.25rem;
|
}
|
|
/* 图片与视频 */
|
.object-cover {
|
object-fit: cover;
|
}
|
|
/* 其他 */
|
.resize-none {
|
resize: none;
|
}
|
|
.page-wrapper {
|
position: relative;
|
min-height: 100vh;
|
/* 确保小内容时填满视口 */
|
overflow: hidden;
|
}
|
|
/* 顶部背景 */
|
.bg-top {
|
position: absolute;
|
top: 0;
|
left: 0;
|
width: 100%;
|
height: 500rpx;
|
/* 可用固定像素或图片高度 */
|
background: url('https://farm.evcc.top/Uploads/yuanboyuan/background/bg_top.jpg') no-repeat top center;
|
background-size: cover;
|
z-index: 0;
|
}
|
|
/* 底部背景 */
|
.bg-bottom {
|
position: absolute;
|
bottom: 0;
|
left: 0;
|
width: 100%;
|
height: 500rpx;
|
/* 可用固定像素或图片高度 */
|
background: url('https://farm.evcc.top/Uploads/yuanboyuan/background/bg_bottom.jpg') no-repeat bottom center;
|
background-size: cover;
|
z-index: 0;
|
}
|
|
/* 内容层 */
|
.content-wrapper {
|
position: relative;
|
z-index: 1;
|
padding: 2rem 1rem;
|
}
|
</style>
|