185 lines
6.6 KiB
Vue
185 lines
6.6 KiB
Vue
<template>
|
||
<view class="container">
|
||
<!-- 点位选择下拉菜单 -->
|
||
<view class="select-container">
|
||
<label class="select-label">选择点位</label>
|
||
<input type="text" class="search-input" v-model="searchKeyword" @focus="showOptions = true"
|
||
placeholder="请输入点位名称搜索" readonly />
|
||
|
||
<!-- 下拉选项 -->
|
||
<view class="options-container" v-if="showOptions">
|
||
<!-- 为空时显示提示 -->
|
||
<view v-if="pointsList.length === 0" class="no-options">
|
||
暂无数据
|
||
</view>
|
||
<!-- 有选项时显示选项列表 -->
|
||
<view v-else>
|
||
<view v-for="option in pointsList"
|
||
:key="option.point_id"
|
||
class="option-item"
|
||
@click="selectPointHandler(option)">
|
||
{{ option.point_info.point_name }}
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 拍照功能和图片预览 -->
|
||
<view class="camera-section">
|
||
<!-- 拍照按钮,当图片数量达到12张时隐藏 -->
|
||
<view class="camera-container" v-if="images.length < 12">
|
||
<image class="camera-icon" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/zhaoxiangji.png"
|
||
mode="aspectFit" @click="takePhoto"></image>
|
||
<view class="camera-text">点击拍照上传</view>
|
||
</view>
|
||
|
||
<!-- 照片列表 -->
|
||
<view class="photos-container">
|
||
<view v-for="(image, index) in images" :key="index" class="photo-item">
|
||
<image class="photo-preview" :src="image" mode="aspectFit"></image>
|
||
<!-- 删除图标 -->
|
||
<view class="delete-icon" @click="deleteImage(index)">×</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 底部提交按钮 -->
|
||
<view class="footer">
|
||
<button class="submit-button" @click="submitForm">确认提交</button>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import {
|
||
request,
|
||
picUrl,
|
||
uniqueByField,
|
||
menuButtonInfo,
|
||
NavgateTo,
|
||
} from "../../../utils";
|
||
|
||
import { apiArr } from "../../../api/routingInspection";
|
||
export default {
|
||
data() {
|
||
return {
|
||
searchKeyword: '',
|
||
showOptions: false,
|
||
selectedPoint: '',
|
||
selectedPointInfo: null, // 存储完整的点位信息
|
||
pointsList: [],
|
||
images: [], // 存储多张图片路径
|
||
taskId: '',
|
||
}
|
||
},
|
||
onLoad(options) {
|
||
if (options.item) {
|
||
const item = JSON.parse(options.item)
|
||
this.taskId = item.id
|
||
this.getInfo(this.taskId)
|
||
}
|
||
},
|
||
methods: {
|
||
async getInfo(id) {
|
||
const res = await request(apiArr.routingInspectionInfo, "POST", {
|
||
task_id: id,
|
||
});
|
||
this.pointsList = res.task_point_info
|
||
},
|
||
selectPointHandler(option) {
|
||
console.log("🚀 ~ selectPointHandler ~ option:", option)
|
||
// 安全检查,确保必要的属性存在
|
||
if (option && option.point_info && option.point_info.point_name) {
|
||
// 根据实际数据结构选择正确的id属性
|
||
this.selectedPoint = option.location_info && option.point_id
|
||
? option.point_id
|
||
: option.id || option.point_info.point_name
|
||
this.selectedPointInfo = option // 保存完整的点位信息
|
||
this.searchKeyword = option.point_info.point_name
|
||
this.showOptions = false
|
||
} else {
|
||
console.warn('选择的点位信息不完整', option)
|
||
}
|
||
},
|
||
takePhoto() {
|
||
// 调起手机拍照功能,不允许从相册选择
|
||
const that = this
|
||
// 计算还可以拍摄的图片数量
|
||
const remainingCount = 12 - that.images.length
|
||
|
||
uni.chooseImage({
|
||
count: remainingCount > 0 ? remainingCount : 1, // 最多选择的图片数量
|
||
sizeType: ['original', 'compressed'],
|
||
sourceType: ['camera'], // 只允许拍照
|
||
success: function (res) {
|
||
const tempFilePaths = res.tempFilePaths
|
||
// 将新拍摄的图片添加到列表中
|
||
that.images = [...that.images, ...tempFilePaths]
|
||
console.log('拍照成功,当前图片数量:', that.images.length)
|
||
},
|
||
fail: function (err) {
|
||
console.error('拍照失败', err)
|
||
uni.showToast({
|
||
title: '拍照失败',
|
||
icon: 'none'
|
||
})
|
||
}
|
||
})
|
||
},
|
||
deleteImage(index) {
|
||
// 删除指定索引的图片
|
||
this.images.splice(index, 1)
|
||
},
|
||
async submitForm() {
|
||
// 验证是否选择了点位
|
||
if (!this.selectedPoint) {
|
||
uni.showToast({
|
||
title: '请选择点位',
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
|
||
// 验证是否上传了图片
|
||
if (this.images.length === 0) {
|
||
uni.showToast({
|
||
title: '请至少上传一张照片',
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
|
||
try {
|
||
// 准备提交数据,使用正确的参数格式
|
||
const params = {
|
||
task_id: parseInt(this.taskId), // 巡检任务ID
|
||
task_point_id: parseInt(this.selectedPoint), // 巡检点ID
|
||
image: this.images // 巡检图片,格式为字符串数组
|
||
}
|
||
|
||
// 调用正确的接口
|
||
const res = await request(apiArr.routingInspectionSubmit, "POST", params);
|
||
|
||
// 输出提交的数据
|
||
console.log('提交数据:', params)
|
||
|
||
// 显示提交成功提示
|
||
uni.showToast({
|
||
title: '提交成功',
|
||
icon: 'success'
|
||
})
|
||
} catch (error) {
|
||
console.error('提交失败', error)
|
||
uni.showToast({
|
||
title: '提交失败',
|
||
icon: 'none'
|
||
})
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
@import url("./index.css");
|
||
</style> |