对接小区、故障报修接口,更换图片地址
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
v-for="item in categoryList"
|
||||
:key="item.id"
|
||||
>
|
||||
{{ item.name }}
|
||||
{{ item.projectName }}
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
v-for="item in currentProjectList"
|
||||
:key="item.id"
|
||||
>
|
||||
{{ item.name }}
|
||||
{{ item.projectName }}
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
@@ -38,20 +38,21 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
// import { uniNavigateTo } from '@dcloudio/uni-app'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import {getRepairOrder} from '../../api/api.js'
|
||||
|
||||
// 分类列表
|
||||
const categoryList = ref([
|
||||
{ id: 1, name: '基础设施' },
|
||||
{ id: 2, name: '电子设施' }
|
||||
// { id: 1, name: '基础设施' },
|
||||
// { id: 2, name: '电子设施' }
|
||||
])
|
||||
|
||||
// 所有项目数据
|
||||
const projectList = ref([
|
||||
{ id: 101, categoryId: 1, name: '路灯' },
|
||||
{ id: 102, categoryId: 1, name: '楼层指示灯' },
|
||||
{ id: 103, categoryId: 2, name: '应急出口灯' },
|
||||
{ id: 104, categoryId: 1, name: '草坪灯' }
|
||||
// { id: 101, categoryId: 1, name: '路灯' },
|
||||
// { id: 102, categoryId: 1, name: '楼层指示灯' },
|
||||
// { id: 103, categoryId: 2, name: '应急出口灯' },
|
||||
// { id: 104, categoryId: 1, name: '草坪灯' }
|
||||
])
|
||||
|
||||
// 选中的分类
|
||||
@@ -72,14 +73,39 @@ const currentProjectList = computed(() => {
|
||||
const selectCategory = (item) => {
|
||||
activeCategory.value = item.id
|
||||
}
|
||||
// 获取维修项目
|
||||
const fetchProjectList = async () => {
|
||||
try {
|
||||
const res = await getRepairOrder()
|
||||
if (res.code === 200) {
|
||||
const data = res.data || []
|
||||
// 兼容后端嵌套格式 [{id, name, children: [{id, name}]}]
|
||||
categoryList.value = data.map(item => ({ id: item.id, projectName: item.projectName }))
|
||||
projectList.value = data.flatMap(item =>
|
||||
(item.children || []).map(child => ({
|
||||
id: child.id,
|
||||
categoryId: item.id,
|
||||
projectName: child.projectName
|
||||
}))
|
||||
)
|
||||
activeCategory.value = categoryList.value[0]?.id || 1
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '获取项目列表失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
onLoad(() =>{
|
||||
fetchProjectList()
|
||||
})
|
||||
|
||||
// 选择项目并跳转到维修项目填写页
|
||||
const selectProject = (item) => {
|
||||
// 获取分类名称
|
||||
const categoryName = categoryList.value.find(c => c.id === item.categoryId)?.name
|
||||
const categoryName = categoryList.value.find(c => c.id === item.categoryId)?.projectName
|
||||
// 跳转并传参
|
||||
uni.navigateTo({
|
||||
url: `/pageSubPack/fault-reporting/fault-reporting?category=${categoryName}&project=${item.name}`
|
||||
url: `/pageSubPack/fault-reporting/fault-reporting?category=${categoryName}&project=${item.projectName}&projectId=${item.id}`
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user