<template>
|
<view class="account-detail">
|
<PageHeader :title="pageTitle"
|
@back="goBack" />
|
<up-form :model="form"
|
label-width="110">
|
<up-form-item label="设施名称">
|
<up-input :model-value="facilityName"
|
disabled
|
placeholder="自动带出" />
|
</up-form-item>
|
<up-form-item label="设施编号">
|
<up-input :model-value="facilityCode"
|
disabled
|
placeholder="自动带出" />
|
</up-form-item>
|
<up-form-item label="巡检编号"
|
required>
|
<up-input v-model="form.inspectionCode"
|
:disabled="isView"
|
placeholder="请输入"
|
clearable />
|
</up-form-item>
|
<up-form-item label="巡检类型">
|
<up-input :model-value="form.inspectionType"
|
placeholder="请选择"
|
readonly
|
:disabled="isView"
|
@click="openTypeSheet" />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="openTypeSheet"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="计划巡检时间">
|
<up-input :model-value="form.planTime"
|
placeholder="请选择"
|
readonly
|
:disabled="isView"
|
@click="openPlanPicker" />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="openPlanPicker"></up-icon>
|
</template>
|
</up-form-item>
|
<template v-if="mode === 'do' || mode === 'view'">
|
<up-form-item label="实际巡检时间">
|
<up-input :model-value="form.actualTime"
|
disabled
|
placeholder="自动填充" />
|
</up-form-item>
|
<up-form-item label="检查结果"
|
:required="mode === 'do'">
|
<up-input :model-value="form.checkResult"
|
placeholder="请选择"
|
readonly
|
:disabled="isView"
|
@click="openResultSheet" />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="openResultSheet"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="检查说明">
|
<up-textarea v-model="form.checkDesc"
|
:disabled="isView"
|
placeholder="请输入"
|
auto-height />
|
</up-form-item>
|
</template>
|
</up-form>
|
<FooterButtons :loading="loading"
|
:confirmText="isView ? '返回' : '保存'"
|
@cancel="goBack"
|
@confirm="handleSubmit" />
|
<up-action-sheet :show="showTypeSheet"
|
title="选择巡检类型"
|
:actions="typeActions"
|
@select="onSelectType"
|
@close="showTypeSheet = false" />
|
<up-action-sheet :show="showResultSheet"
|
title="选择检查结果"
|
:actions="resultActions"
|
@select="onSelectResult"
|
@close="showResultSheet = false" />
|
<up-datetime-picker :show="showPlanPicker"
|
mode="datetime"
|
:value="planValue"
|
@confirm="onPlanConfirm"
|
@cancel="showPlanPicker = false" />
|
</view>
|
</template>
|
|
<script setup>
|
import { computed, ref } from "vue";
|
import { onLoad } from "@dcloudio/uni-app";
|
import dayjs from "dayjs";
|
import PageHeader from "@/components/PageHeader.vue";
|
import FooterButtons from "@/components/FooterButtons.vue";
|
import {
|
addFacilityInspection,
|
updateFacilityInspection,
|
} from "@/api/safeProduction/safetyFacility";
|
|
const loading = ref(false);
|
const mode = ref("add");
|
|
const facilityName = ref("");
|
const facilityCode = ref("");
|
|
const form = ref({
|
id: null,
|
facilityId: null,
|
inspectionCode: "",
|
inspectionType: "定期巡检",
|
planTime: "",
|
checkResult: "",
|
checkDesc: "",
|
actualTime: "",
|
status: "",
|
});
|
|
const showTypeSheet = ref(false);
|
const showResultSheet = ref(false);
|
const showPlanPicker = ref(false);
|
|
const typeActions = [
|
{ name: "定期巡检", value: "定期巡检" },
|
{ name: "临时巡检", value: "临时巡检" },
|
];
|
const resultActions = [
|
{ name: "正常", value: "正常" },
|
{ name: "异常", value: "异常" },
|
];
|
|
const isView = computed(() => mode.value === "view");
|
|
const pageTitle = computed(() => {
|
if (mode.value === "add") return "发起巡检";
|
if (mode.value === "do") return "巡检";
|
return "查看巡检";
|
});
|
|
const planValue = computed(() => {
|
if (!form.value.planTime) return Date.now();
|
const ts = dayjs(form.value.planTime).valueOf();
|
return Number.isFinite(ts) ? ts : Date.now();
|
});
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const openTypeSheet = () => {
|
if (isView.value) return;
|
showTypeSheet.value = true;
|
};
|
|
const openPlanPicker = () => {
|
if (isView.value) return;
|
showPlanPicker.value = true;
|
};
|
|
const openResultSheet = () => {
|
if (isView.value) return;
|
showResultSheet.value = true;
|
};
|
|
const onSelectType = action => {
|
if (isView.value) return;
|
form.value.inspectionType = action.value;
|
showTypeSheet.value = false;
|
};
|
|
const onSelectResult = action => {
|
if (isView.value) return;
|
form.value.checkResult = action.value;
|
showResultSheet.value = false;
|
};
|
|
const onPlanConfirm = e => {
|
if (isView.value) return;
|
form.value.planTime = dayjs(e?.value).format("YYYY-MM-DD HH:mm:ss");
|
showPlanPicker.value = false;
|
};
|
|
const handleSubmit = () => {
|
if (isView.value) {
|
goBack();
|
return;
|
}
|
|
const inspectionCode = String(form.value.inspectionCode || "").trim();
|
if (!inspectionCode) {
|
uni.showToast({ title: "请输入巡检编号", icon: "none" });
|
return;
|
}
|
if (!form.value.facilityId) {
|
uni.showToast({ title: "缺少设施信息", icon: "none" });
|
return;
|
}
|
if (!form.value.planTime) {
|
uni.showToast({ title: "请选择计划巡检时间", icon: "none" });
|
return;
|
}
|
if (mode.value === "do") {
|
const checkResult = String(form.value.checkResult || "").trim();
|
if (!checkResult) {
|
uni.showToast({ title: "请选择检查结果", icon: "none" });
|
return;
|
}
|
form.value.status = "已巡检";
|
form.value.actualTime = dayjs(Date.now()).format("YYYY-MM-DD HH:mm:ss");
|
}
|
|
const payload = {
|
...form.value,
|
inspectionCode,
|
checkDesc: String(form.value.checkDesc || "").trim(),
|
};
|
|
loading.value = true;
|
const api = payload.id ? updateFacilityInspection : addFacilityInspection;
|
api(payload)
|
.then(() => {
|
uni.showToast({ title: "操作成功", icon: "success" });
|
uni.$emit("safetyFacility:refresh");
|
goBack();
|
})
|
.catch(() => {
|
uni.showToast({ title: "操作失败", icon: "none" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
};
|
|
onLoad(options => {
|
if (options?.data) {
|
try {
|
const obj = JSON.parse(decodeURIComponent(options.data));
|
mode.value = obj.mode || "add";
|
if (obj.facility) {
|
const f = obj.facility;
|
form.value.facilityId = f.id;
|
facilityName.value = f.facilityName || "";
|
facilityCode.value = f.facilityCode || "";
|
}
|
if (obj.row) {
|
const r = obj.row;
|
form.value = { ...form.value, ...(r || {}) };
|
facilityName.value = r.facilityName || facilityName.value;
|
facilityCode.value = r.facilityCode || facilityCode.value;
|
}
|
} catch (e) {}
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
</style>
|