<template>
|
<view class="accident-detail">
|
<PageHeader :title="isEdit ? '编辑事故报告' : '新增事故报告'"
|
@back="goBack" />
|
<u-form @submit="handleSubmit"
|
ref="formRef"
|
label-width="110">
|
<!-- 事故信息 -->
|
<u-cell-group title="基本信息">
|
<u-form-item label="事故名称"
|
prop="accidentName"
|
required
|
border-bottom>
|
<u-input v-model="form.accidentName"
|
placeholder="请输入事故名称" />
|
</u-form-item>
|
<u-form-item label="事故编码"
|
prop="accidentCode"
|
required
|
border-bottom>
|
<u-input v-model="form.accidentCode"
|
placeholder="请输入事故编码" />
|
</u-form-item>
|
<u-form-item label="事故类型"
|
prop="accidentType"
|
required
|
border-bottom>
|
<u-input v-model="accidentTypeName"
|
placeholder="请选择事故类型"
|
@click="showTypeSheet"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showTypeSheet"></up-icon>
|
</template>
|
</u-form-item>
|
<u-form-item label="事故等级"
|
prop="accidentGrade"
|
required
|
border-bottom>
|
<u-input v-model="accidentGradeName"
|
placeholder="请选择事故等级"
|
@click="showGradeSheet"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showGradeSheet"></up-icon>
|
</template>
|
</u-form-item>
|
</u-cell-group>
|
<u-cell-group title="详细信息">
|
<u-form-item label="发生时间"
|
prop="happenTime"
|
required
|
border-bottom>
|
<u-input v-model="form.happenTime"
|
placeholder="请选择发生时间"
|
@click="showTimePicker"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showTimePicker"></up-icon>
|
</template>
|
</u-form-item>
|
<u-form-item label="事故地点"
|
prop="happenLocation"
|
required
|
border-bottom>
|
<u-input v-model="form.happenLocation"
|
placeholder="请输入事故地点" />
|
</u-form-item>
|
<u-form-item label="直接财产损失"
|
prop="assetLoss"
|
border-bottom>
|
<u-input v-model="form.assetLoss"
|
placeholder="请输入直接财产损失"
|
type="number" />
|
<template #right>
|
<view class="unit">元</view>
|
</template>
|
</u-form-item>
|
<u-form-item label="事故直接原因"
|
prop="accidentCause"
|
border-bottom>
|
<u-textarea v-model="form.accidentCause"
|
placeholder="请输入事故直接原因"
|
:maxlength="200"
|
count
|
:autoHeight="true" />
|
</u-form-item>
|
<u-form-item label="事故根本原因"
|
prop="rootCause"
|
border-bottom>
|
<u-textarea v-model="form.rootCause"
|
placeholder="请输入事故根本原因"
|
:maxlength="200"
|
count
|
:autoHeight="true" />
|
</u-form-item>
|
<u-form-item label="生产影响情况"
|
prop="productionLoss"
|
border-bottom>
|
<u-textarea v-model="form.productionLoss"
|
placeholder="请输入生产影响情况"
|
:maxlength="200"
|
count
|
:autoHeight="true" />
|
</u-form-item>
|
<u-form-item label="现场应急处置措施"
|
prop="handleMeasures"
|
border-bottom>
|
<u-textarea v-model="form.handleMeasures"
|
placeholder="请输入现场应急处置措施"
|
:maxlength="200"
|
count
|
:autoHeight="true" />
|
</u-form-item>
|
<u-form-item label="备注"
|
prop="remark"
|
border-bottom>
|
<u-textarea v-model="form.remark"
|
placeholder="请输入备注"
|
:maxlength="200"
|
count
|
:autoHeight="true" />
|
</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-action-sheet :show="typeSheetVisible"
|
:actions="typeOptions"
|
@select="handleTypeSelect"
|
@close="typeSheetVisible = false"
|
title="选择事故类型" />
|
<!-- 事故等级选择器 -->
|
<up-action-sheet :show="gradeSheetVisible"
|
:actions="gradeOptions"
|
@select="handleGradeSelect"
|
@close="gradeSheetVisible = false"
|
title="选择事故等级" />
|
<!-- 时间选择器 -->
|
<up-datetime-picker :show="timePickerVisible"
|
mode="datetime"
|
v-model="currentTime"
|
@confirm="handleTimeConfirm"
|
@cancel="timePickerVisible = false"
|
title="选择发生时间" />
|
</view>
|
</template>
|
|
<script setup>
|
// 替换 toast 方法
|
defineOptions({ name: "accident-detail" });
|
const showToast = message => {
|
uni.showToast({ title: message, icon: "none" });
|
};
|
|
import { ref, onMounted } from "vue";
|
import PageHeader from "@/components/PageHeader.vue";
|
import {
|
safeAccidentAdd,
|
safeAccidentUpdate,
|
} from "@/api/safeProduction/accidentReportingRecord";
|
import { onLoad } from "@dcloudio/uni-app";
|
import { useDict } from "@/utils/dict";
|
import dayjs from "dayjs";
|
|
// 获取字典数据
|
const { accident_type } = useDict("accident_type");
|
|
// 表单数据
|
const form = ref({
|
accidentName: "",
|
accidentCode: "",
|
accidentType: "",
|
accidentGrade: "",
|
happenTime: "",
|
happenLocation: "",
|
createUserName: "",
|
createTime: "",
|
assetLoss: "",
|
accidentCause: "",
|
rootCause: "",
|
productionLoss: "",
|
handleMeasures: "",
|
remark: "",
|
});
|
|
// 页面状态
|
const loading = ref(false);
|
const formRef = ref(null);
|
const isEdit = ref(false);
|
const currentTime = ref(new Date());
|
|
// 事故类型选择器
|
const typeSheetVisible = ref(false);
|
const accidentTypeName = ref("");
|
const typeOptions = ref([]);
|
|
const showTypeSheet = () => {
|
typeSheetVisible.value = true;
|
};
|
|
const handleTypeSelect = item => {
|
form.value.accidentType = item.value;
|
accidentTypeName.value = item.name;
|
typeSheetVisible.value = false;
|
};
|
|
// 事故等级选择器
|
const gradeSheetVisible = ref(false);
|
const accidentGradeName = ref("");
|
const gradeOptions = ref([
|
{ value: "轻微事故", name: "轻微事故" },
|
{ value: "一般事故", name: "一般事故" },
|
{ value: "较大事故", name: "较大事故" },
|
{ value: "重大事故", name: "重大事故" },
|
]);
|
|
const showGradeSheet = () => {
|
gradeSheetVisible.value = true;
|
};
|
|
const handleGradeSelect = item => {
|
form.value.accidentGrade = item.value;
|
accidentGradeName.value = item.name;
|
gradeSheetVisible.value = false;
|
};
|
|
// 时间选择器
|
const timePickerVisible = ref(false);
|
|
const showTimePicker = () => {
|
timePickerVisible.value = true;
|
};
|
|
const handleTimeConfirm = e => {
|
form.value.happenTime = dayjs(e.value).format("YYYY-MM-DD HH:mm:ss");
|
currentTime.value = e.value;
|
timePickerVisible.value = false;
|
};
|
|
// 返回上一页
|
const goBack = () => {
|
uni.removeStorageSync("accidentReport");
|
uni.navigateBack();
|
};
|
|
// 提交表单
|
const handleSubmit = async () => {
|
if (!form.value.accidentName) {
|
showToast("请输入事故名称");
|
return;
|
}
|
|
if (!form.value.accidentCode) {
|
showToast("请输入事故编码");
|
return;
|
}
|
|
if (!form.value.accidentType) {
|
showToast("请选择事故类型");
|
return;
|
}
|
|
if (!form.value.accidentGrade) {
|
showToast("请选择事故等级");
|
return;
|
}
|
|
if (!form.value.happenTime) {
|
showToast("请选择发生时间");
|
return;
|
}
|
|
if (!form.value.happenLocation) {
|
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];
|
});
|
|
if (isEdit.value) {
|
const { code } = await safeAccidentUpdate(submitData);
|
if (code === 200) {
|
showToast("修改成功");
|
setTimeout(() => {
|
goBack();
|
}, 500);
|
} else {
|
loading.value = false;
|
showToast("修改失败,请重试");
|
}
|
} else {
|
const { code } = await safeAccidentAdd(submitData);
|
if (code === 200) {
|
showToast("新增成功");
|
setTimeout(() => {
|
goBack();
|
}, 500);
|
} else {
|
loading.value = false;
|
showToast("新增失败,请重试");
|
}
|
}
|
} catch (e) {
|
loading.value = false;
|
console.error("提交失败:", e);
|
showToast("提交失败,请重试");
|
}
|
};
|
|
onLoad(() => {
|
// 编辑事故时,从本地存储获取数据
|
const accidentReport = uni.getStorageSync("accidentReport");
|
if (accidentReport.id) {
|
form.value = accidentReport;
|
currentTime.value = dayjs(accidentReport.happenTime).toDate();
|
isEdit.value = true;
|
} else {
|
isEdit.value = false;
|
}
|
});
|
|
onMounted(() => {
|
// 初始化事故类型选项
|
typeOptions.value =
|
accident_type?.value.map(item => ({
|
value: item.value,
|
name: item.label,
|
})) || [];
|
|
// 设置已选值的显示文本
|
if (form.value.accidentType) {
|
const typeItem = typeOptions.value.find(
|
item => String(item.value) === String(form.value.accidentType)
|
);
|
accidentTypeName.value = typeItem ? typeItem.name : "";
|
}
|
if (form.value.accidentGrade) {
|
const gradeItem = gradeOptions.value.find(
|
item => item.value === form.value.accidentGrade
|
);
|
accidentGradeName.value = gradeItem ? gradeItem.name : "";
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
|
.accident-detail {
|
min-height: 100vh;
|
background: #f8f9fa;
|
padding-bottom: 5rem;
|
}
|
|
.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;
|
}
|
|
.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;
|
}
|
</style>
|