1.18整合

This commit is contained in:
2026-01-18 16:06:37 +08:00
parent 10c3fbb0d7
commit a11d3cc2f8
138 changed files with 7241 additions and 856 deletions

View File

@@ -1,13 +1,18 @@
<template>
<view class=" page padding">
<view class="padding radius bg-white list-list margin-bottom" v-for="item in hiddenDangerList" :key="item.hazardId">
<view class="padding radius bg-white list-list margin-bottom" v-for="item in hiddenDangerList"
:key="item.hazardId">
<view class="flex justify-between margin-bottom">
<view class="text-bold text-black">{{item.title}}</view>
<view class="text-blue">{{item.statusName}}</view>
</view>
<view class="flex margin-bottom">
<view class="text-gray">隐患等级</view>
<view>{{item.levelName}}</view>
<view class="level-tag" :class="{
'level-minor': item.levelName === '轻微隐患',
'level-normal': item.levelName === '一般隐患',
'level-major': item.levelName === '重大隐患'
}">{{item.levelName}}</view>
</view>
<view class="flex margin-bottom">
<view class="text-gray" style="white-space: nowrap;">隐患位置</view>
@@ -17,10 +22,18 @@
<view class="text-gray">创建时间</view>
<view class="text-black">{{item.createdAt}}</view>
</view>
<view class="flex col-3" style="gap: 10rpx;">
<view class="flex justify-end" style="gap: 10rpx;">
<!-- 所有状态都显示查看详情 -->
<button class="round cu-btn lg light bg-blue" @click="details(item)">查看详情</button>
<button class="round cu-btn lg light bg-blue" @click="Rectification(item)">立即整改</button>
<button class="round cu-btn lg bg-blue" @click="acceptance()">立即验收</button>
<!-- 待整改待验收显示立即整改 -->
<button v-if="item.statusName === '待整改' || item.statusName === '待验收'"
class="round cu-btn lg light bg-blue" @click="Rectification(item)">立即整改</button>
<!-- 待验收显示立即验收 -->
<button v-if="item.statusName === '待验收'"
class="round cu-btn lg bg-blue" @click="acceptance(item)">立即验收</button>
<!-- 待交办显示隐患交办 -->
<button v-if="item.statusName === '待交办'"
class="round cu-btn lg bg-blue" @click="assignHazard(item)">隐患交办</button>
</view>
</view>
<button class="cuIcon-add round bg-blue margin-top-xl" @click="showAddPopup = true">新增</button>
@@ -50,53 +63,35 @@
<view class="text-gray">隐患等级</view>
<view class="text-red">*</view>
</view>
<up-choose v-model="formData.level" :options="levelOptions" :wrap="false" item-width="183rpx" item-height="72rpx"></up-choose>
<up-choose v-model="formData.level" :options="levelOptions" :wrap="false" item-width="183rpx"
item-height="72rpx"></up-choose>
<view class="flex margin-bottom margin-top">
<view class="text-gray">隐患来源</view>
<view class="text-red">*</view>
</view>
<up-choose v-model="formData.source" :options="sourceOptions" :wrap="false" item-width="183rpx"
item-height="72rpx"></up-choose>
<view class="flex margin-bottom margin-top">
<view class="text-gray">隐患位置</view>
<view class="text-red">*</view>
</view>
<view class="address-box">
<view class="address-input" @click="showAddressPopup = true">
<view class="address-input" @tap.stop="chooseLocation">
<text :class="selectedAddress ? '' : 'text-gray'">{{ selectedAddress || '请选择地址' }}</text>
</view>
<button class="btn-address bg-blue" @click="showAddressPopup = true">选择地址</button>
<button class="btn-address bg-blue" @tap.stop="chooseLocation">选择地址</button>
</view>
<!-- 地址选择弹窗 -->
<u-popup :show="showAddressPopup" mode="center" round="20" @close="showAddressPopup = false">
<view class="address-popup">
<view class="popup-header">
<view class="popup-title text-bold">选择地址</view>
<view class="popup-close" @click="showAddressPopup = false">×</view>
</view>
<view class="address-popup-body">
<view class="search-box">
<input class="search-input" v-model="addressKeyword" placeholder="请输入关键词搜索" />
</view>
<view class="address-list">
<view class="address-item" v-for="(item, index) in filteredAddressList" :key="index"
@click="tempSelectedAddress = item" :class="{'address-item-active': tempSelectedAddress === item}">
<text>{{ item }}</text>
</view>
</view>
</view>
<view class="popup-footer">
<button class="btn-cancel" @click="showAddressPopup = false">取消</button>
<button class="btn-confirm bg-blue" @click="confirmAddress">定位</button>
</view>
</view>
</u-popup>
<view class="text-gray text-sm margin-top-xs">办公楼3层东侧消防通道生产车间A区设备旁等或点击"选择地址"按钮在地图上选择</view>
<view class="flex margin-bottom margin-top">
<view class="text-gray">隐患描述</view>
<view class="text-red">*</view>
</view>
<up-textarea v-model="formData.description" placeholder="请输入内容" ></up-textarea>
<up-textarea v-model="formData.description" placeholder="请输入内容"></up-textarea>
<view class="text-gray text-sm margin-top-xs">请详细说明隐患现状潜在风险及影响范围</view>
<view class="text-gray margin-bottom margin-top">隐患标签</view>
<up-choose v-model="formData.tagIndex" :options="tagOptions"></up-choose>
<view class="text-gray text-sm">可选择多个相关标签对隐患进行分类</view>
<up-choose v-model="formData.tagIndex" :options="tagOptions"></up-choose>
<view class="text-gray text-sm">可选择多个相关标签对隐患进行分类</view>
</view>
<view class="popup-footer">
<button class="btn-cancel" @click="showAddPopup = false">取消</button>
@@ -108,18 +103,35 @@
</template>
<script setup>
import { ref, computed, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { addHiddenDanger, enterCheckPlan, getCheckTaskDetail,getMyHiddenDangerList,getHiddenDangerLabelList} from '@/request/api.js'
import { baseUrl,AUTH_TOKEN } from '@/request/request.js'
import {
ref,
computed,
reactive,
watch
} from 'vue'
import {
onLoad,
onShow
} from '@dcloudio/uni-app'
import {
addHiddenDanger,
enterCheckPlan,
getCheckTaskDetail,
getMyHiddenDangerList,
getHiddenDangerLabelList
} from '@/request/api.js'
import {
baseUrl,
getToken
} from '@/request/request.js'
// 弹窗控制
const showAddPopup = ref(false);
// 任务相关ID从接口获取
const taskId = ref('');
const checkPointId = ref('');
// 获取任务详情
const fetchTaskInfo = async (oneTableId) => {
try {
@@ -127,7 +139,7 @@
const startRes = await enterCheckPlan(oneTableId);
if (startRes.code === 0 && startRes.data) {
const tid = startRes.data.taskId;
// 第二步:用 taskId 获取任务详情
const detailRes = await getCheckTaskDetail(tid);
if (detailRes.code === 0 && detailRes.data) {
@@ -139,59 +151,79 @@
console.error('获取任务信息失败:', error);
}
};
onLoad((options) => {
if (options.id) {
fetchTaskInfo(options.id);
}
});
// 表单数据
const formData = reactive({
title: '', // 隐患标题
level: 0, // 隐患等级索引
description: '', // 隐患描述
tagIndex: 0, // 隐患标签索引
title: '', // 隐患标题
level: 0, // 隐患等级索引
description: '', // 隐患描述
tagIndex: 0, // 隐患标签索引
source: '', // 隐患来源
});
// 经纬度
const lng = ref(0);
const lat = ref(0);
// 地址选择
const showAddressPopup = ref(false);
const addressKeyword = ref('');
// 地址选择 - 调用腾讯地图
const selectedAddress = ref('');
const tempSelectedAddress = ref('');
const addressList = ref([
'湖南省湘西土家族苗族自治州吉首市人民北路105号',
'湖南省湘西土家族苗族自治州吉首市人民南路100号',
'湖南省湘西土家族苗族自治州吉首市团结广场',
'湖南省湘西土家族苗族自治州吉首市火车站'
]);
const filteredAddressList = computed(() => {
if (!addressKeyword.value) return addressList.value;
return addressList.value.filter(item => item.includes(addressKeyword.value));
});
const confirmAddress = () => {
if (tempSelectedAddress.value) {
selectedAddress.value = tempSelectedAddress.value;
}
showAddressPopup.value = false;
const chooseLocation = () => {
console.log('chooseLocation called');
// 先关闭弹窗,避免在弹窗中调用地图选择出现问题
showAddPopup.value = false;
setTimeout(() => {
uni.chooseLocation({
success: (res) => {
console.log('选择位置成功:', res);
// 获取选择的位置信息
selectedAddress.value = res.address + (res.name ? `(${res.name})` : '');
lng.value = res.longitude;
lat.value = res.latitude;
// 重新打开弹窗
showAddPopup.value = true;
},
fail: (err) => {
console.error('选择位置失败:', err);
// 重新打开弹窗
showAddPopup.value = true;
// 用户取消选择不提示
if (err.errMsg && err.errMsg.indexOf('cancel') === -1) {
uni.showToast({
title: '选择位置失败',
icon: 'none'
});
}
}
});
}, 300);
};
// 确定新增
const handleAdd = async () => {
// 表单验证
if (!formData.title) {
uni.showToast({ title: '请输入隐患标题', icon: 'none' });
uni.showToast({
title: '请输入隐患标题',
icon: 'none'
});
return;
}
if (fileList1.value.length === 0) {
uni.showToast({ title: '请上传隐患图片/视频', icon: 'none' });
uni.showToast({
title: '请上传隐患图片/视频',
icon: 'none'
});
return;
}
// 构建附件列表 - 从上传返回的url中提取文件名
const attachments = fileList1.value.map(file => {
// 确保 url 是字符串
@@ -210,24 +242,25 @@
fileSize: file.size || 0
};
});
// 获取隐患标签ID
const selectedTag = tagOptions.value[formData.tagIndex];
const tagId = selectedTag ? selectedTag.id : null;
console.log("innnn",sourceOptions);
// 构建请求参数
const params = {
title: formData.title,//标题
level: formData.level + 1, // 1.轻微隐患 2.一般隐患 3.重大隐患
lng: lng.value || 0,//经度
lat: lat.value || 0,//纬度
address: selectedAddress.value || '',//详细地址
description: formData.description || '',//隐患描述
tagId: tagId,//隐患标签ID
title: formData.title, //标题
level: formData.level + 1, // 1.轻微隐患 2.一般隐患 3.重大隐患
lng: lng.value || 0, //经度
lat: lat.value || 0, //纬度
address: selectedAddress.value || '', //详细地址
description: formData.description || '', //隐患描述
tagId: tagId, //隐患标签ID
taskId: taskId.value, //关联任务ID
checkPointId: checkPointId.value,//关联检查点ID
source:'cillum labore veniam',//隐患来源
checkPointId: checkPointId.value, //关联检查点ID
source: sourceOptions.value[formData.source]?.title || '', //隐患来源(随手拍、企业自查、行业互查、专家诊查)
};
//
@@ -246,12 +279,20 @@
formData.tagIndex = 0;
selectedAddress.value = '';
fileList1.value = [];
// 刷新隐患列表
fetchHiddenDangerList();
} else {
uni.showToast({ title: res.msg || '新增失败', icon: 'none' });
uni.showToast({
title: res.msg || '新增失败',
icon: 'none'
});
}
} catch (error) {
console.error(error);
uni.showToast({ title: '请求失败', icon: 'none' });
uni.showToast({
title: '请求失败',
icon: 'none'
});
}
};
//获取隐患列表
@@ -260,16 +301,26 @@
try {
const res = await getMyHiddenDangerList();
if (res.code === 0) {
hiddenDangerList.value = res.data;
hiddenDangerList.value = res.data.records;
} else {
uni.showToast({ title: res.msg || '获取隐患列表失败', icon: 'none' });
uni.showToast({
title: res.msg || '获取隐患列表失败',
icon: 'none'
});
}
} catch (error) {
console.error(error);
uni.showToast({ title: '请求失败', icon: 'none' });
uni.showToast({
title: '请求失败',
icon: 'none'
});
}
};
// 页面显示时刷新列表(从交办、验收页面返回时自动刷新)
onShow(() => {
fetchHiddenDangerList();
});
const details = (item) => {
uni.navigateTo({
@@ -281,9 +332,15 @@
url: `/pages/hiddendanger/rectification?hazardId=${item.hazardId}&assignId=${item.assignId}`
})
}
const acceptance = () => {
const acceptance = (item) => {
uni.navigateTo({
url: '/pages/hiddendanger/acceptance'
url: `/pages/hiddendanger/acceptance?hazardId=${item.hazardId}&assignId=${item.assignId}&rectifyId=${item.rectifyId}`
})
}
// 隐患交办
const assignHazard = (item) => {
uni.navigateTo({
url: `/pages/hiddendanger/assignment?hazardId=${item.hazardId}&assignId=${item.assignId}`
})
}
const fileList1 = ref([]);
@@ -325,7 +382,7 @@
filePath: filePath,
name: 'file',
header: {
'Authorization': AUTH_TOKEN
'Authorization': getToken()
},
success: (res) => {
const data = JSON.parse(res.data);
@@ -342,15 +399,6 @@
});
});
};
// 隐患标签选项
// const tagOptions = ref([
// {id: 1, title: '安全'},
// {id: 2, title: '人机工程'},
// {id: 3, title: '其他'},
// {id: 4, title: '职业健康'},
// {id: 5, title: '电气隐患'},
// {id: 6, title: '环保'}
// ])
const tagOptions = ref([]);
const fetchTagOptions = async () => {
try {
@@ -362,22 +410,66 @@
title: item.name
}));
} else {
uni.showToast({ title: res.msg || '获取标签列表失败', icon: 'none' });
uni.showToast({
title: res.msg || '获取标签列表失败',
icon: 'none'
});
}
} catch (error) {
console.error(error);
uni.showToast({ title: '请求失败', icon: 'none' });
uni.showToast({
title: '请求失败',
icon: 'none'
});
}
};
fetchTagOptions();
//
// 隐患等级选项
const levelOptions = ref([
{id: 1, title: '轻微隐患'},
{id: 2, title: '一般隐患'},
{id: 3, title: '重大隐患'}
const levelOptions = ref([{
id: 1,
title: '轻微隐患'
},
{
id: 2,
title: '一般隐患'
},
{
id: 3,
title: '重大隐患'
}
])
//隐患来源
const sourceOptions = ref([{
id: 1,
title: '随手拍'
},
{
id: 2,
title: '企业自查'
},
{
id: 3,
title: '行业互查'
},
{
id: 4,
title: '专家诊查'
}
])
// 监听隐患来源选择变化
watch(() => formData.source, (newVal) => {
const selected = sourceOptions.value[newVal];
console.log('隐患来源选择结果:', {
索引: newVal,
选中项: selected,
id: selected?.id,
title: selected?.title
});
});
</script>
<style lang="scss" scoped>
@@ -393,6 +485,33 @@
border-radius: 20rpx;
padding: 20rpx;
}
// 隐患等级标签样式
.level-tag {
padding: 4rpx 16rpx;
border-radius: 8rpx;
}
// 轻微隐患
.level-minor {
background: #F6FFED;
border: 2rpx solid #B7EB8F;
color: #52C41A;
}
// 一般隐患
.level-normal {
background: #FFF7E6;
border: 2rpx solid #FFD591;
color: #FA8C16;
}
// 重大隐患
.level-major {
background: #FFF1F0;
border: 2rpx solid #FFA39E;
color: #F5222D;
}
.popup-content {
width: 600rpx;
@@ -451,16 +570,17 @@
color: #fff;
}
}
.address-box {
display: flex;
align-items: center;
gap: 20rpx;
.address-input {
flex: 1;
background: #fff;
border: 1rpx solid #F6F6F6;;
border: 1rpx solid #F6F6F6;
;
border-radius: 8rpx;
padding: 20rpx;
font-size: 26rpx;
@@ -469,7 +589,7 @@
text-overflow: ellipsis;
white-space: nowrap;
}
.btn-address {
flex-shrink: 0;
height: 70rpx;
@@ -478,27 +598,27 @@
font-size: 26rpx;
border-radius: 8rpx;
color: #fff;
&::after {
border: none;
}
}
}
.address-popup {
width: 600rpx;
background: #fff;
border-radius: 20rpx;
overflow: hidden;
}
.address-popup-body {
padding: 30rpx;
max-height: 500rpx;
.search-box {
margin-bottom: 20rpx;
.search-input {
width: 100%;
background: #f5f5f5;
@@ -507,29 +627,28 @@
font-size: 28rpx;
}
}
.address-list {
max-height: 350rpx;
overflow-y: auto;
}
.address-item {
padding: 24rpx 20rpx;
border-bottom: 1rpx solid #eee;
font-size: 26rpx;
color: #333;
&:last-child {
border-bottom: none;
}
&.address-item-active {
background: #EBF2FC;
color: #2667E9;
}
}
}
</style>
<style lang="scss">

View File

@@ -2,27 +2,204 @@
<view class="page padding">
<view class="padding bg-white radius">
<view class="text-gray margin-bottom">整改记录</view>
<up-textarea v-model="value1" placeholder="请输入内容"></up-textarea>
<view class="padding solid radius">
<view class="flex">
<view>整改方案</view>
<view>{{ rectifyData.rectifyPlan || '暂无' }}</view>
</view>
<view class="flex margin-top-sm">
<view>完成情况</view>
<view>{{ rectifyData.rectifyResult || '暂无' }}</view>
</view>
<view class="margin-top-sm">
<view>整改附件</view>
<view class="flex margin-top-xs" style="flex-wrap: wrap; gap: 10rpx;" v-if="rectifyAttachments.length > 0">
<image v-for="(img, idx) in rectifyAttachments" :key="idx" :src="getFullPath(img.filePath)" style="width: 136rpx;height: 136rpx;border-radius: 16rpx;" mode="aspectFill" @click="previewImage(idx)"></image>
</view>
<view v-else class="text-gray text-sm margin-top-xs">暂无附件</view>
</view>
</view>
<view class="flex margin-bottom margin-top">
<view class="text-gray">验收内容</view>
<view class="text-gray">验收结果</view>
<view class="text-red">*</view>
</view>
<up-textarea v-model="value1" placeholder="请输入内容"></up-textarea>
<view class="flex" style="gap: 20rpx;">
<button :class="['result-btn', formData.result === 1 ? 'active' : '']" @click="formData.result = 1">通过</button>
<button :class="['result-btn', formData.result === 2 ? 'active' : '']" @click="formData.result = 2">不通过</button>
</view>
<view class="flex margin-bottom margin-top">
<view class="text-gray">验收备注</view>
</view>
<up-textarea v-model="formData.verifyRemark" placeholder="请输入验收备注"></up-textarea>
<view class="flex margin-bottom margin-top">
<view class="text-gray">验收图片/视频</view>
<view class="text-red">*</view>
</view>
<up-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="10"></up-upload>
<button class="bg-blue round margin-top-xl"> 提交验收</button>
<view class="flex margin-top-xl" style="gap: 20rpx;">
<button class="round flex-sub" @click="handleCancel">取消</button>
<button class="bg-blue round flex-sub" @click="handleSubmit">提交验收</button>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue';
import { ref, reactive } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { acceptanceRectification, getHiddenDangerDetail } from '@/request/api.js';
import { baseUrl,getToken } from '@/request/request.js';
// 页面参数
const rectifyId = ref('');
const hazardId = ref('');
const assignId = ref('');
// 整改记录数据
const rectifyData = reactive({
rectifyPlan: '',
rectifyResult: ''
});
// 整改附件
const rectifyAttachments = ref([]);
// 表单数据
const formData = reactive({
result: 1, // 验收结果 1.通过 2.不通过
verifyRemark: '' // 验收备注
});
const fileList1 = ref([]);
// 获取完整图片路径
const getFullPath = (filePath) => {
if (!filePath) return '';
if (filePath.startsWith('http://') || filePath.startsWith('https://')) {
return filePath;
}
return baseUrl + filePath;
};
// 图片预览
const previewImage = (index) => {
const urls = rectifyAttachments.value.map(item => getFullPath(item.filePath));
uni.previewImage({
current: index,
urls: urls
});
};
// 获取隐患详情
const fetchDetail = async () => {
if (!hazardId.value || !assignId.value) return;
try {
const res = await getHiddenDangerDetail({ hazardId: hazardId.value, assignId: assignId.value });
if (res.code === 0 && res.data) {
// 提取整改信息assigns[0].rectify
if (res.data.assigns && res.data.assigns.length > 0) {
const assign = res.data.assigns[0];
if (assign.rectify) {
rectifyData.rectifyPlan = assign.rectify.rectifyPlan || '';
rectifyData.rectifyResult = assign.rectify.rectifyResult || '';
if (assign.rectify.attachments) {
rectifyAttachments.value = assign.rectify.attachments;
}
console.log('整改记录:', rectifyData);
console.log('整改附件:', rectifyAttachments.value);
}
}
} else {
uni.showToast({ title: res.msg || '获取详情失败', icon: 'none' });
}
} catch (error) {
console.error('获取隐患详情失败:', error);
uni.showToast({ title: '请求失败', icon: 'none' });
}
};
onLoad((options) => {
if (options.rectifyId) {
rectifyId.value = options.rectifyId;
}
if (options.hazardId) {
hazardId.value = options.hazardId;
}
if (options.assignId) {
assignId.value = options.assignId;
}
console.log('验收页面参数:', { rectifyId: rectifyId.value, hazardId: hazardId.value, assignId: assignId.value });
// 获取隐患详情
fetchDetail();
});
// 取消
const handleCancel = () => {
uni.navigateBack();
};
// 提交验收
const handleSubmit = async () => {
if (!rectifyId.value) {
uni.showToast({
title: '缺少整改ID',
icon: 'none'
});
return;
}
// 构建附件列表
const attachments = fileList1.value.map(file => {
let url = '';
if (typeof file.url === 'string') {
url = file.url;
} else if (file.url && typeof file.url === 'object') {
url = file.url.url || file.url.path || '';
}
const fileName = (typeof url === 'string' && url) ? url.split('/').pop() : (file.name || '');
return {
fileName: fileName || '',
filePath: url || '',
fileType: file.type || 'image/png',
fileSize: file.size || 0
};
});
const params = {
rectifyId: Number(rectifyId.value),
result: formData.result,
verifyRemark: formData.verifyRemark || '',
attachments: attachments
};
console.log('提交验收参数:', params);
try {
const res = await acceptanceRectification(params);
if (res.code === 0) {
uni.showToast({
title: '验收成功',
icon: 'success'
});
setTimeout(() => {
uni.navigateBack();
}, 1500);
} else {
uni.showToast({
title: res.msg || '验收失败',
icon: 'none'
});
}
} catch (error) {
console.error('验收失败:', error);
uni.showToast({
title: '请求失败',
icon: 'none'
});
}
};
// 删除图片
const deletePic = (event) => {
fileList1.value.splice(event.index, 1);
@@ -30,7 +207,6 @@
// 新增图片
const afterRead = async (event) => {
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file);
let fileListLen = fileList1.value.length;
lists.map((item) => {
@@ -53,20 +229,27 @@
}
};
const uploadFilePromise = (url) => {
const uploadFilePromise = (filePath) => {
return new Promise((resolve, reject) => {
let a = uni.uploadFile({
url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
filePath: url,
uni.uploadFile({
url: baseUrl + '/frontend/attachment/upload',
filePath: filePath,
name: 'file',
formData: {
user: 'test',
header: {
'Authorization': getToken()
},
success: (res) => {
setTimeout(() => {
resolve(res.data.data);
}, 1000);
},
const data = JSON.parse(res.data);
if (data.code === 0) {
resolve(data.data);
} else {
reject(data.msg || '上传失败');
}
},
fail: (err) => {
console.error('上传失败:', err);
reject(err);
}
});
});
};
@@ -77,4 +260,23 @@
min-height: 100vh;
background: #EBF2FC;
}
</style>
.result-btn {
flex: 1;
height: 80rpx;
line-height: 80rpx;
border-radius: 8rpx;
background: #f5f5f5;
color: #666;
font-size: 28rpx;
&::after {
border: none;
}
&.active {
background: #2667E9;
color: #fff;
}
}
</style>

View File

@@ -0,0 +1,210 @@
<template>
<view class="padding page">
<view class="padding radius bg-white">
<view class="flex margin-bottom">
<view class="text-gray">整改人员</view>
<view class="text-red">*</view>
</view>
<view class="picker-input" @click="showUserPicker = true">
<text :class="selectedUser ? '' : 'text-gray'">{{ selectedUser || '请选择整改人员' }}</text>
</view>
<up-picker
:show="showUserPicker"
:columns="userColumns"
@confirm="onUserConfirm"
@cancel="showUserPicker = false"
@close="showUserPicker = false"
></up-picker>
<view class="flex margin-bottom margin-top">
<view class="text-gray">整改期限</view>
<view class="text-red">*</view>
</view>
<view class="picker-input" @click="showDatePicker = true">
<text :class="selectedDate ? '' : 'text-gray'">{{ selectedDate || '请选择整改期限' }}</text>
</view>
<up-datetime-picker
:show="showDatePicker"
v-model="dateValue"
mode="datetime"
@confirm="onDateConfirm"
@cancel="showDatePicker = false"
@close="showDatePicker = false"
></up-datetime-picker>
<view class="btn-group margin-top-xl">
<button class="btn-cancel" @click="handleCancel">取消</button>
<button class="btn-confirm bg-blue" @click="handleSubmit">确认</button>
</view>
</view>
</view>
</template>
<script setup>
import { ref, reactive } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { getDepartmentPersonUsers,assignHiddenDanger } from '@/request/api.js';
// 页面参数
const hazardId = ref('');
const assignId = ref('');
// 整改人员选择
const showUserPicker = ref(false);
const selectedUser = ref('');
const selectedUserId = ref('');
const userColumns = ref([['暂无数据']]);
const userList = ref([]); // 存储完整用户数据
// 整改期限选择
const showDatePicker = ref(false);
const dateValue = ref(Date.now());
const selectedDate = ref('');
// 获取部门人员列表
const fetchDeptUsers = async () => {
try {
const res = await getDepartmentPersonUsers();
if (res.code === 0 && res.data) {
const users = [];
res.data.forEach(dept => {
if (dept.users && dept.users.length > 0) {
dept.users.forEach(user => {
users.push({
id: String(user.userId),
name: `${user.nickName}${dept.deptName}`
});
});
}
});
userList.value = users;
// 转换为 picker 需要的格式
userColumns.value = [users.map(u => u.name)];
console.log('整改人员列表:', users);
}
} catch (error) {
console.error('获取部门人员失败:', error);
}
};
// 人员选择确认
const onUserConfirm = (e) => {
console.log('选择的人员:', e);
if (e.value && e.value.length > 0) {
selectedUser.value = e.value[0];
// 找到对应的用户ID
const user = userList.value.find(u => u.name === e.value[0]);
if (user) {
selectedUserId.value = user.id;
}
}
showUserPicker.value = false;
};
// 日期时间选择确认
const onDateConfirm = (e) => {
console.log('选择的日期时间:', e);
const date = new Date(e.value);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
selectedDate.value = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
showDatePicker.value = false;
};
// 取消
const handleCancel = () => {
uni.navigateBack();
};
// 确认提交
const handleSubmit = async () => {
if (!selectedUserId.value) {
uni.showToast({ title: '请选择整改人员', icon: 'none' });
return;
}
if (!selectedDate.value) {
uni.showToast({ title: '请选择整改期限', icon: 'none' });
return;
}
// 构建请求参数
const params = {
hazardId: Number(hazardId.value), // 隐患ID
assigneeId: Number(selectedUserId.value), // 被指派人ID
deadline: selectedDate.value, // 处理期限
assignRemark: '' // 交办备注(可选)
};
console.log('提交数据:', params);
try {
const res = await assignHiddenDanger(params);
if (res.code === 0) {
uni.showToast({ title: '交办成功', icon: 'success' });
setTimeout(() => {
uni.navigateBack();
}, 1500);
} else {
uni.showToast({ title: res.msg || '交办失败', icon: 'none' });
}
} catch (error) {
console.error('交办失败:', error);
uni.showToast({ title: '请求失败', icon: 'none' });
}
};
onLoad((options) => {
if (options.hazardId) hazardId.value = options.hazardId;
if (options.assignId) assignId.value = options.assignId;
fetchDeptUsers();
});
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
background: #EBF2FC;
}
.picker-input {
background: #fff;
border-radius: 8rpx;
padding: 24rpx 20rpx;
margin-bottom: 20rpx;
border: 1rpx solid #F6F6F6;
text {
font-size: 28rpx;
color: #333;
}
}
.btn-group {
display: flex;
gap: 30rpx;
}
.btn-cancel {
flex: 1;
height: 80rpx;
line-height: 80rpx;
border: 2rpx solid #2667E9;
border-radius: 40rpx;
background: #fff;
color: #2667E9;
font-size: 30rpx;
}
.btn-confirm {
flex: 1;
height: 80rpx;
line-height: 80rpx;
border-radius: 40rpx;
color: #fff;
font-size: 30rpx;
}
</style>

View File

@@ -28,141 +28,154 @@
<view class="date-input" @click="show = true">
<text :class="selectedDate ? '' : 'text-gray'">{{ selectedDate || '请选择日期' }}</text>
</view>
<up-calendar :show="show" :mode="mode" @confirm="confirmDate" @close="show = false"></up-calendar>
<view class="flex margin-bottom">
<view class="text-gray">整改人员</view>
<view class="text-red">*</view>
<up-datetime-picker hasInput :show="show" v-model="value1" mode="date"></up-datetime-picker>
<view class=" margin-bottom margin-top">
<!-- <view class="text-gray">整改人员</view>
<view class="text-red">*</view> -->
<up-select v-model:current="cateId" label="整改人员" :options="cateList" @select="selectItem"></up-select>
</view>
<up-radio-group v-model="radiovalue1" placement="column" @change="groupChange">
<up-radio shape="square" :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist1"
:key="index" :label="item.name" :name="item.name" @change="radioChange"></up-radio>
</up-radio-group>
<view class="flex margin-bottom">
<view class="text-gray">整改图片/视频</view>
<view class="text-red">*</view>
</view>
<up-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="10"></up-upload>
<up-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
:maxCount="10"></up-upload>
<button class="bg-blue round margin-top-xl" @click="handleSubmit">提交整改</button>
</view>
</view>
</template>
<script setup>
import {ref,reactive} from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {submitRectification} from '@/request/api.js'
import { baseUrl, AUTH_TOKEN } from '@/request/request.js'
import {ref,reactive,onMounted} from 'vue'
import {onLoad} from '@dcloudio/uni-app'
import {submitRectification,getDepartmentPersonUsers} from '@/request/api.js'
import {baseUrl,getToken} from '@/request/request.js'
// 从页面参数获取的ID
const hazardId = ref('');
const assignId = ref('');
// 表单数据
const formData = reactive({
rectifyPlan: '', // 整改方案
rectifyResult: '', // 整改完成情况
planCost: '', // 投资资金(计划)
actualCost: '' // 投资资金(实际)
rectifyPlan: '', // 整改方案
rectifyResult: '', // 整改完成情况
planCost: '', // 投资资金(计划)
actualCost: '' // 投资资金(实际)
});
const show = ref(false);
const mode = ref('single');
const value1 = ref(Date.now());
const selectedDate = ref('');
const radiovalue1 = ref('');
// 整改人员
const cateId = ref('')
const cateList = ref([])
// 基本案列数据
const radiolist1 = reactive([{
name: '孙致远',
disabled: false,
},
{
name: '符友成',
disabled: false,
},
{
name: '向彪',
disabled: false,
},
{
name: '向纪荣',
disabled: false,
},
]);
// 获取部门人员列表
const fetchDeptUsers = async () => {
try {
const res = await getDepartmentPersonUsers();
if (res.code === 0 && res.data) {
// 将部门下的用户数据扁平化为 up-select 需要的格式
const userList = [];
res.data.forEach(dept => {
if (dept.users && dept.users.length > 0) {
dept.users.forEach(user => {
userList.push({
id: String(user.userId),
name: `${user.nickName}${dept.deptName}`
});
});
}
});
cateList.value = userList;
console.log('整改人员列表:', cateList.value);
}
} catch (error) {
console.error('获取部门人员失败:', error);
}
};
// 页面加载时获取人员列表
fetchDeptUsers();
// 上传图片
const fileList1 = ref([]);
// 删除图片
const deletePic = (event) => {
fileList1.value.splice(event.index, 1);
fileList1.value.splice(event.index, 1);
};
// 新增图片
// 新增图
const afterRead = async (event) => {
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file);
let fileListLen = fileList1.value.length;
lists.map((item) => {
fileList1.value.push({
...item,
status: 'uploading',
message: '上传中',
});
});
for (let i = 0; i < lists.length; i++) {
const result = await uploadFilePromise(lists[i].url);
let item = fileList1.value[fileListLen];
fileList1.value.splice(fileListLen, 1, {
...item,
status: 'success',
message: '',
url: result,
});
fileListLen++;
}
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file);
let fileListLen = fileList1.value.length;
lists.map((item) => {
fileList1.value.push({
...item,
status: 'uploading',
message: '上传中',
});
});
for (let i = 0; i < lists.length; i++) {
const result = await uploadFilePromise(lists[i].url);
let item = fileList1.value[fileListLen];
fileList1.value.splice(fileListLen, 1, {
...item,
status: 'success',
message: '',
url: result,
});
fileListLen++;
}
};
// 日期选择确认
const confirmDate = (e) => {
selectedDate.value = e[0];
show.value = false;
};
const uploadFilePromise = (filePath) => {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: baseUrl + '/frontend/attachment/upload',
filePath: filePath,
name: 'file',
header: {
'Authorization': AUTH_TOKEN
},
success: (res) => {
const data = JSON.parse(res.data);
if (data.code === 0) {
resolve(data.data);
} else {
reject(data.msg || '上传失败');
}
},
fail: (err) => {
console.error('上传失败:', err);
reject(err);
}
});
});
return new Promise((resolve, reject) => {
uni.uploadFile({
url: baseUrl + '/frontend/attachment/upload',
filePath: filePath,
name: 'file',
header: {
'Authorization': getToken()
},
success: (res) => {
const data = JSON.parse(res.data);
if (data.code === 0) {
resolve(data.data);
} else {
reject(data.msg || '上传失败');
}
},
fail: (err) => {
console.error('上传失败:', err);
reject(err);
}
});
});
};
// 提交整改
const handleSubmit = async () => {
if (!formData.rectifyPlan) {
uni.showToast({ title: '请输入整改方案', icon: 'none' });
uni.showToast({
title: '请输入整改方案',
icon: 'none'
});
return;
}
if (!formData.rectifyResult) {
uni.showToast({ title: '请输入整改完成情况', icon: 'none' });
uni.showToast({
title: '请输入整改完成情况',
icon: 'none'
});
return;
}
// 构建附件列表
const attachments = fileList1.value.map(file => {
let url = '';
@@ -179,7 +192,7 @@
fileSize: file.size || 0
};
});
const params = {
hazardId: hazardId.value,
assignId: assignId.value,
@@ -189,23 +202,32 @@
actualCost: Number(formData.actualCost) || 0,
attachments: attachments
};
try {
const res = await submitRectification(params);
if (res.code === 0) {
uni.showToast({ title: '提交成功', icon: 'success' });
uni.showToast({
title: '提交成功',
icon: 'success'
});
setTimeout(() => {
uni.navigateBack();
}, 1500);
} else {
uni.showToast({ title: res.msg || '提交失败', icon: 'none' });
uni.showToast({
title: res.msg || '提交失败',
icon: 'none'
});
}
} catch (error) {
console.error('提交整改失败:', error);
uni.showToast({ title: '请求失败', icon: 'none' });
uni.showToast({
title: '请求失败',
icon: 'none'
});
}
};
onLoad((options) => {
if (options.hazardId) {
hazardId.value = options.hazardId;
@@ -214,6 +236,11 @@
assignId.value = options.assignId;
}
});
// 选择整改人员
const selectItem = (item) => {
console.log('选择的整改人员:', item);
cateId.value = item.id;
};
</script>
<style lang="scss" scoped>
@@ -221,14 +248,14 @@
min-height: 100vh;
background: #EBF2FC;
}
.date-input {
background: #fff;
border-radius: 8rpx;
padding: 24rpx 20rpx;
margin-bottom: 20rpx;
border: 1rpx solid #F6F6F6 ;
border: 1rpx solid #F6F6F6;
text {
font-size: 28rpx;
color: #333;

View File

@@ -6,8 +6,10 @@
<view class="text-red">*</view>
</view>
<view class="margin-bottom">
<view class="flex" style="flex-wrap: wrap; gap: 10rpx;" v-if="detailData?.attachments && detailData.attachments.length > 0">
<image v-for="(img, idx) in detailData.attachments" :key="idx" :src="img.filePath" style="width: 136rpx;height: 136rpx;border-radius: 16rpx;" mode="aspectFill"></image>
<view v-if="rectifyAttachments.length > 0" class="margin-top">
<view class="flex" style="flex-wrap: wrap; gap: 10rpx;">
<image v-for="(img, idx) in rectifyAttachments" :key="idx" :src="getFullPath(img.filePath)" style="width: 136rpx;height: 136rpx;border-radius: 16rpx;" mode="aspectFill" @click="previewRectifyImage(idx)"></image>
</view>
</view>
<view v-else class="text-gray text-sm">暂无图片</view>
<view class="text-gray text-sm margin-top-xs">必填请上传现场照片或者视频作为隐患证据</view>
@@ -60,6 +62,7 @@
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getHiddenDangerDetail } from '@/request/api.js'
import { baseUrl } from '@/request/request.js'
// 详情数据
const detailData = reactive({
@@ -75,12 +78,53 @@
attachments: []
});
// 整改附件(单独存储)
const rectifyAttachments = ref([]);
// 获取完整图片路径
const getFullPath = (filePath) => {
if (!filePath) return '';
// 如果已经是完整路径则直接返回
if (filePath.startsWith('http://') || filePath.startsWith('https://')) {
return filePath;
}
// 拼接 baseUrl
return baseUrl + filePath;
};
// 图片预览 - 隐患图片
const previewImage = (attachments, index) => {
const urls = attachments.map(item => getFullPath(item.filePath));
uni.previewImage({
current: index,
urls: urls
});
};
// 图片预览 - 整改图片
const previewRectifyImage = (index) => {
const urls = rectifyAttachments.value.map(item => getFullPath(item.filePath));
uni.previewImage({
current: index,
urls: urls
});
};
// 获取隐患详情
const fetchDetail = async (hazardId, assignId) => {
try {
const res = await getHiddenDangerDetail({ hazardId, assignId });
if (res.code === 0 && res.data) {
Object.assign(detailData, res.data);
// 提取整改附件assigns[0].rectify.attachments
if (res.data.assigns && res.data.assigns.length > 0) {
const assign = res.data.assigns[0];
if (assign.rectify && assign.rectify.attachments) {
rectifyAttachments.value = assign.rectify.attachments;
console.log('整改附件:', rectifyAttachments.value);
}
}
} else {
uni.showToast({ title: res.msg || '获取详情失败', icon: 'none' });
}
@@ -128,4 +172,4 @@
font-size: 28rpx;
color: #fff;
}
</style>
</style>