<template>
|
<view class="danger-investigation-detail">
|
<PageHeader :title="isEdit ? '编辑隐患' : '新增隐患'"
|
@back="goBack" />
|
<u-form @submit="handleSubmit"
|
ref="formRef"
|
label-width="110">
|
<!-- 隐患信息 -->
|
<u-cell-group title="隐患信息">
|
<u-form-item label="隐患编号"
|
prop="hiddenCode"
|
border-bottom>
|
<u-input v-model="form.hiddenCode"
|
placeholder="系统自动生成"
|
readonly />
|
</u-form-item>
|
<u-form-item label="隐患类型"
|
prop="type"
|
required
|
border-bottom>
|
<u-input v-model="hiddenTypeName"
|
placeholder="请选择隐患类型"
|
@click="showHiddenTypeSheet"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showHiddenTypeSheet"></up-icon>
|
</template>
|
</u-form-item>
|
<u-form-item label="风险等级"
|
prop="riskLevel"
|
required
|
border-bottom>
|
<u-input v-model="riskLevelName"
|
placeholder="请选择风险等级"
|
@click="showRiskLevelSheet"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showRiskLevelSheet"></up-icon>
|
</template>
|
</u-form-item>
|
<u-form-item label="隐患描述"
|
prop="hiddenDesc"
|
required
|
border-bottom>
|
<u-textarea v-model="form.hiddenDesc"
|
placeholder="请输入隐患描述"
|
:maxlength="200"
|
count
|
:autoHeight="true" />
|
</u-form-item>
|
<u-form-item label="隐患具体位置"
|
prop="location"
|
required
|
border-bottom>
|
<u-input v-model="form.location"
|
placeholder="请输入隐患具体位置" />
|
</u-form-item>
|
<u-form-item label="整改完成期限"
|
prop="rectifyTime"
|
required
|
border-bottom>
|
<u-input v-model="form.rectifyTime"
|
placeholder="请选择整改完成期限"
|
@click="showTimePicker" />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showTimePicker"></up-icon>
|
</template>
|
</u-form-item>
|
<u-form-item label="整改责任人"
|
prop="rectifyUserName"
|
required
|
border-bottom>
|
<u-input v-model="form.rectifyUserName"
|
placeholder="请选择整改责任人"
|
@click="showPrincipalSheet"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showPrincipalSheet"></up-icon>
|
</template>
|
</u-form-item>
|
<u-form-item label="上报人"
|
prop="createUserName"
|
border-bottom>
|
<u-input v-model="form.createUserName"
|
disabled
|
placeholder="请输入上报人" />
|
</u-form-item>
|
<u-form-item label="上报时间"
|
prop="createTime"
|
border-bottom>
|
<u-input v-model="form.createTime"
|
disabled
|
placeholder="请输入上报时间" />
|
</u-form-item>
|
</u-cell-group>
|
<!-- 提交按钮 -->
|
<view class="footer-btns">
|
<u-button class="cancel-btn"
|
@click="goBack">取消</u-button>
|
<u-button class="sign-btn"
|
type="primary"
|
@click="handleSubmit"
|
:loading="loading">{{ isEdit ? '保存修改' : '提交' }}</u-button>
|
</view>
|
</u-form>
|
<!-- 时间选择器 -->
|
<up-datetime-picker :show="showTime"
|
v-model="currentTime"
|
@confirm="onTimeConfirm"
|
@cancel="showTime = false"
|
mode="date" />
|
<!-- 隐患类型选择器 -->
|
<up-action-sheet :show="hiddenTypeSheetVisible"
|
:actions="hiddenTypeOptions"
|
@select="handleHiddenTypeSelect"
|
title="选择隐患类型" />
|
<!-- 风险等级选择器 -->
|
<up-action-sheet :show="riskLevelSheetVisible"
|
:actions="riskLevelOptions"
|
@select="handleRiskLevelSelect"
|
title="选择风险等级" />
|
<!-- 整改责任人选择器 -->
|
<up-action-sheet :show="principalSheetVisible"
|
:actions="principalOptions"
|
@select="handlePrincipalSelect"
|
title="选择整改责任人" />
|
</view>
|
</template>
|
|
<script setup>
|
// 替换 toast 方法
|
defineOptions({ name: "danger-investigation-detail" });
|
const showToast = message => {
|
uni.showToast({
|
title: message,
|
icon: "none",
|
});
|
};
|
|
import { ref, onMounted } from "vue";
|
import PageHeader from "@/components/PageHeader.vue";
|
import {
|
safeHiddenAdd,
|
safeHiddenUpdate,
|
} from "@/api/safeProduction/dangerInvestigation";
|
import { userListNoPageByTenantId } from "@/api/system/user";
|
import useUserStore from "@/store/modules/user";
|
import { useDict } from "@/utils/dict";
|
import dayjs from "dayjs";
|
import { onLoad } from "@dcloudio/uni-app";
|
|
// 获取字典数据
|
const { hidden_danger_type } = useDict("hidden_danger_type");
|
|
const userStore = useUserStore();
|
|
// 表单数据
|
const form = ref({
|
hiddenCode: "",
|
type: "",
|
riskLevel: "",
|
hiddenDesc: "",
|
location: "",
|
rectifyTime: "",
|
rectifyUserName: "",
|
rectifyUserMobile: "",
|
rectifyMeasures: "",
|
});
|
|
// 页面状态
|
const loading = ref(false);
|
const formRef = ref(null);
|
const isEdit = ref(false);
|
|
// 时间相关
|
const currentTime = ref(Date.now());
|
const showTime = ref(false);
|
|
// 隐患类型选择器
|
const hiddenTypeSheetVisible = ref(false);
|
const hiddenTypeName = ref("");
|
const hiddenTypeOptions = ref([]);
|
const showHiddenTypeSheet = () => {
|
hiddenTypeSheetVisible.value = true;
|
};
|
const handleHiddenTypeSelect = item => {
|
form.value.type = item.value;
|
hiddenTypeName.value = item.name;
|
hiddenTypeSheetVisible.value = false;
|
};
|
|
// 风险等级选择器
|
const riskLevelSheetVisible = ref(false);
|
const riskLevelName = ref("");
|
const riskLevelOptions = ref([]);
|
const showRiskLevelSheet = () => {
|
riskLevelSheetVisible.value = true;
|
};
|
const handleRiskLevelSelect = item => {
|
form.value.riskLevel = item.value;
|
riskLevelName.value = item.name;
|
riskLevelSheetVisible.value = false;
|
};
|
|
// 整改责任人选择器
|
const principalSheetVisible = ref(false);
|
const userList = ref([]);
|
const principalOptions = ref([]);
|
const showPrincipalSheet = () => {
|
if (principalOptions.value.length === 0) {
|
getUserList();
|
} else {
|
principalSheetVisible.value = true;
|
}
|
};
|
const handlePrincipalSelect = item => {
|
form.value.rectifyUserId = item.value;
|
form.value.rectifyUserName = item.name;
|
form.value.rectifyUserMobile = item.mobile;
|
principalSheetVisible.value = false;
|
};
|
|
// 获取用户列表
|
const getUserList = () => {
|
userListNoPageByTenantId().then(res => {
|
if (res.code === 200) {
|
userList.value = res.data;
|
principalOptions.value = res.data.map(user => ({
|
value: user.userId,
|
name: user.nickName,
|
mobile: user.phonenumber,
|
}));
|
principalSheetVisible.value = true;
|
}
|
});
|
};
|
|
// 返回上一页
|
const goBack = () => {
|
// 返回时清除本地存储的数据
|
uni.removeStorageSync("dangerInvestigation");
|
uni.navigateBack();
|
};
|
|
// 显示时间选择器
|
const showTimePicker = () => {
|
showTime.value = true;
|
};
|
|
// 确认时间选择
|
const onTimeConfirm = e => {
|
form.value.rectifyTime = dayjs(e.value).format("YYYY-MM-DD");
|
currentTime.value = e.value;
|
showTime.value = false;
|
};
|
|
// 提交表单
|
const handleSubmit = async () => {
|
console.log("form.value", form.value);
|
if (!form.value.type) {
|
showToast("请选择隐患类型");
|
return;
|
}
|
|
if (!form.value.riskLevel) {
|
showToast("请选择风险等级");
|
return;
|
}
|
|
if (!form.value.hiddenDesc) {
|
showToast("请输入隐患描述");
|
return;
|
}
|
|
if (!form.value.location) {
|
showToast("请输入隐患具体位置");
|
return;
|
}
|
|
if (!form.value.rectifyTime) {
|
showToast("请选择整改完成期限");
|
return;
|
}
|
|
if (!form.value.rectifyUserName) {
|
showToast("请选择整改责任人");
|
return;
|
}
|
|
if (!form.value.rectifyUserMobile) {
|
showToast("请输入整改责任人联系方式");
|
return;
|
}
|
|
try {
|
loading.value = true;
|
|
// 使用安全浅拷贝,避免对象展开在某些运行时抛错
|
const source =
|
form.value && typeof form.value === "object" ? form.value : {};
|
const submitData = {};
|
Object.keys(source).forEach(k => {
|
submitData[k] = source[k];
|
});
|
console.log("submitData", submitData);
|
if (isEdit.value) {
|
const { code } = await safeHiddenUpdate(submitData);
|
if (code === 200) {
|
showToast("修改成功");
|
setTimeout(() => {
|
goBack();
|
}, 500);
|
} else {
|
loading.value = false;
|
showToast("修改失败,请重试");
|
}
|
} else {
|
const { code } = await safeHiddenAdd(submitData);
|
if (code === 200) {
|
showToast("新增成功");
|
setTimeout(() => {
|
goBack();
|
}, 500);
|
} else {
|
loading.value = false;
|
showToast("新增失败,请重试");
|
}
|
}
|
} catch (e) {
|
loading.value = false;
|
console.error("提交失败:", e);
|
showToast("提交失败,请重试");
|
}
|
};
|
|
onLoad(() => {
|
// 编辑隐患时,从本地存储获取数据
|
const dangerInvestigation = uni.getStorageSync("dangerInvestigation");
|
if (dangerInvestigation && dangerInvestigation.id) {
|
form.value = dangerInvestigation;
|
isEdit.value = true;
|
} else {
|
isEdit.value = false;
|
}
|
userStore.getInfo().then(res => {
|
form.value.createUser = res.user.userId;
|
form.value.createUserName = res.user.nickName;
|
});
|
form.value.createTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
});
|
|
// 初始化页面数据
|
const initPageData = () => {
|
// 设置默认整改完成期限为当前时间
|
if (!isEdit.value) {
|
form.value.rectifyTime = dayjs().format("YYYY-MM-DD");
|
currentTime.value = Date.now();
|
}
|
};
|
|
onMounted(() => {
|
initPageData();
|
// 初始化选项数据
|
hiddenTypeOptions.value = hidden_danger_type.value.map(item => ({
|
value: item.value,
|
name: item.label,
|
}));
|
riskLevelOptions.value = [
|
{
|
value: "重大风险",
|
name: "重大风险",
|
},
|
{
|
value: "较大风险",
|
name: "较大风险",
|
},
|
{
|
value: "一般风险",
|
name: "一般风险",
|
},
|
{
|
value: "低风险",
|
name: "低风险",
|
},
|
];
|
// 设置已选值的显示文本
|
if (form.value.type) {
|
hiddenTypeName.value =
|
hiddenTypeOptions.value.find(item => item.value == form.value.type)
|
?.name || "";
|
}
|
if (form.value.riskLevel) {
|
riskLevelName.value =
|
riskLevelOptions.value.find(item => item.value == form.value.riskLevel)
|
?.name || "";
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
.danger-investigation-detail {
|
min-height: 100vh;
|
background-color: #f8f9fa;
|
}
|
|
.footer-btns {
|
position: fixed;
|
left: 0;
|
right: 0;
|
bottom: 0;
|
background: #fff;
|
display: flex;
|
justify-content: space-around;
|
align-items: center;
|
padding: 0.75rem 0;
|
box-shadow: 0 -0.125rem 0.5rem rgba(0, 0, 0, 0.05);
|
z-index: 1000;
|
}
|
|
.cancel-btn {
|
font-weight: 400;
|
font-size: 1rem;
|
color: #666;
|
background: #f5f5f5;
|
border: 1px solid #ddd;
|
width: 45%;
|
height: 2.5rem;
|
border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
|
}
|
|
.sign-btn {
|
font-weight: 500;
|
font-size: 1rem;
|
color: #fff;
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
border: none;
|
width: 45%;
|
height: 2.5rem;
|
border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
|
}
|
</style>
|