<template>
|
<view class="account-detail">
|
<PageHeader :title="pageTitle" @back="goBack" />
|
<up-form :model="form" label-width="110">
|
<up-form-item label="隐患描述" required>
|
<up-textarea v-model="form.hazardDesc" placeholder="请输入" auto-height />
|
</up-form-item>
|
<up-form-item label="隐患等级" required>
|
<up-input :model-value="form.hazardLevel" placeholder="请选择" readonly @click="showLevelSheet = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showLevelSheet = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="隐患位置" required>
|
<up-input v-model="form.hazardLocation" placeholder="请输入" clearable />
|
</up-form-item>
|
</up-form>
|
|
<FooterButtons :loading="loading" confirmText="保存" @cancel="goBack" @confirm="handleSubmit" />
|
|
<up-action-sheet
|
:show="showLevelSheet"
|
title="选择隐患等级"
|
:actions="levelActions"
|
@select="onSelectLevel"
|
@close="showLevelSheet = false"
|
/>
|
</view>
|
</template>
|
|
<script setup>
|
import { computed, ref } from "vue";
|
import { onLoad } from "@dcloudio/uni-app";
|
import PageHeader from "@/components/PageHeader.vue";
|
import FooterButtons from "@/components/FooterButtons.vue";
|
import { addInspectionHazard, updateInspectionHazard } from "@/api/safeProduction/lineInspection";
|
|
const loading = ref(false);
|
const inspectionId = ref(null);
|
|
const form = ref({
|
id: null,
|
inspectionId: null,
|
hazardDesc: "",
|
hazardLevel: "",
|
hazardLocation: "",
|
});
|
|
const showLevelSheet = ref(false);
|
const levelActions = [
|
{ name: "一般", value: "一般" },
|
{ name: "重大", value: "重大" },
|
];
|
|
const pageTitle = computed(() => (form.value.id ? "编辑隐患" : "上报隐患"));
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const onSelectLevel = action => {
|
form.value.hazardLevel = action.value;
|
showLevelSheet.value = false;
|
};
|
|
const handleSubmit = () => {
|
const hazardDesc = String(form.value.hazardDesc || "").trim();
|
if (!hazardDesc) {
|
uni.showToast({ title: "请输入隐患描述", icon: "none" });
|
return;
|
}
|
const hazardLevel = String(form.value.hazardLevel || "").trim();
|
if (!hazardLevel) {
|
uni.showToast({ title: "请选择隐患等级", icon: "none" });
|
return;
|
}
|
const hazardLocation = String(form.value.hazardLocation || "").trim();
|
if (!hazardLocation) {
|
uni.showToast({ title: "请输入隐患位置", icon: "none" });
|
return;
|
}
|
|
const payload = {
|
...form.value,
|
inspectionId: inspectionId.value,
|
hazardDesc,
|
hazardLevel,
|
hazardLocation,
|
};
|
|
loading.value = true;
|
const api = payload.id ? updateInspectionHazard : addInspectionHazard;
|
api(payload)
|
.then(() => {
|
uni.showToast({ title: "保存成功", icon: "success" });
|
uni.$emit("lineInspection:hazardsRefresh");
|
goBack();
|
})
|
.catch(() => {
|
uni.showToast({ title: "保存失败", icon: "none" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
};
|
|
onLoad(options => {
|
if (options?.data) {
|
try {
|
const obj = JSON.parse(decodeURIComponent(options.data));
|
inspectionId.value = obj.inspectionId;
|
if (obj?.row) {
|
form.value = { ...form.value, ...(obj.row || {}) };
|
}
|
} catch (e) {}
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
</style>
|