对接小区、故障报修接口,更换图片地址

This commit is contained in:
zhouyanli
2026-05-13 17:49:02 +08:00
parent d45bb90c5e
commit 7e5ee9d4e0
28 changed files with 495 additions and 629 deletions

View File

@@ -53,7 +53,7 @@
<view class="upload-item" v-for="(img, index) in form.images" :key="index">
<image :src="img" mode="aspectFill" class="upload-img"></image>
<image
src="/static/imgs/delete.png"
src="http://47.104.199.163:9090/images/imgs/delete.png"
class="upload-delete"
@click="deleteImage(index)"
></image>
@@ -75,10 +75,12 @@
<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
// import { onLoad, uniShowToast, uniNavigateBack, uniChooseImage, uniUploadFile } from '@dcloudio/uni-app'
import {addRepairList,uploadFile} from '../../api/api.js'
// 接收上个页面传的维修项目
const repairProject = ref('')
const repairId = ref('')
// 表单数据
const form = ref({
@@ -88,11 +90,15 @@ const form = ref({
images: [] // 图片列表
})
// ==========方法========
// 页面加载时获取传参
onLoad(options => {
if (options.category && options.project) {
repairProject.value = `${options.category}-${options.project}`
repairId.value = options.projectId
}
console.log('项目id',repairId.value)
})
// 选择项目页
@@ -124,14 +130,35 @@ const chooseImage = () => {
}
})
}
// 上传图片
const uploadImages = async () => {
const uploadedUrls = []
for (const path of form.value.images) {
if (path.startsWith('http')) {
uploadedUrls.push(path)
continue
}
try {
const res = await uploadFile(path)
// 根据后端实际返回结构调整字段名
uploadedUrls.push(res.url || '')
} catch (err) {
uni.showToast({
title:e.msg || '图片上传失败',
icon:'error'
})
}
}
return uploadedUrls
}
// 删除图片
const deleteImage = index => {
form.value.images.splice(index, 1)
}
// 表单提交
const submitForm = () => {
const submitForm = async () => {
// 表单校验
if (!repairProject.value) {
uni.showToast({ title: '请选择维修项目', icon: 'none' })
@@ -149,20 +176,41 @@ const submitForm = () => {
uni.showToast({ title: '请输入正确的手机号', icon: 'none' })
return
}
// 提交数据
uni.showLoading({ title: '提交中...' ,})
try {
// 先上传图片
const imageUrls = await uploadImages()
// 提交数据(替换成你的接口)
uni.showLoading({ title: '提交中...' })
const params = {
maintenanceItemId:repairId.value,
item: form.value.title,
problem: form.value.desc,
phone: form.value.phone,
problemImageUrl: imageUrls.join(','),
// projectType: '0',
problemStatus:'0'
}
// 模拟接口请求
setTimeout(() => {
const res = await addRepairList(params)
if (res.code === 200) {
uni.showToast({ title: '提交成功', icon: 'success' })
form.value = { title: '', desc: '', phone: '', images: [] }
repairProject.value = ''
// uni.navigateBack({ delta: 2 })
setTimeout(() => {
uni.switchTab({ url: '/pages/index/index' })
}, 1500)
} else {
uni.showToast({ title: res.msg || '提交失败', icon: 'none' })
}
} catch (e) {
uni.showToast({ title: e.msg || '网络异常', icon: 'none' })
} finally {
uni.hideLoading()
uni.showToast({ title: '提交成功', icon: 'success' })
}
// 提交成功后重置表单/返回上一页
form.value = { title: '', desc: '', phone: '', images: [] }
// 或返回上一页
uni.navigateBack({ delta: 3 })
}, 1000)
}
</script>