<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>
|
|
<template v-if="mode !== 'verify'">
|
<up-form-item label="问题描述" :required="mode === 'add'">
|
<up-textarea v-model="form.problemDesc" :disabled="isReadOnlyProblem" placeholder="请输入" auto-height />
|
</up-form-item>
|
<up-form-item label="问题等级" :required="mode === 'add'">
|
<up-input
|
:model-value="form.problemLevel"
|
placeholder="请选择"
|
readonly
|
:disabled="isReadOnlyProblem"
|
@click="openLevelSheet"
|
/>
|
<template #right>
|
<up-icon name="arrow-right" @click="openLevelSheet"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="计划整改时间" :required="mode === 'add'">
|
<up-input
|
:model-value="form.planTime"
|
placeholder="请选择"
|
readonly
|
:disabled="isReadOnlyProblem"
|
@click="openPlanPicker"
|
/>
|
<template #right>
|
<up-icon name="arrow-right" @click="openPlanPicker"></up-icon>
|
</template>
|
</up-form-item>
|
</template>
|
|
<up-form-item v-if="mode === 'do'" label="整改说明" required>
|
<up-textarea v-model="form.rectifyDesc" placeholder="请输入" auto-height />
|
</up-form-item>
|
|
<up-form-item v-if="mode === 'verify'" label="验收说明" required>
|
<up-textarea v-model="form.verifyDesc" placeholder="请输入" auto-height />
|
</up-form-item>
|
|
<template v-if="mode === 'view'">
|
<up-form-item label="整改说明">
|
<up-textarea :model-value="form.rectifyDesc" disabled auto-height />
|
</up-form-item>
|
<up-form-item label="验收说明">
|
<up-textarea :model-value="form.verifyDesc" disabled auto-height />
|
</up-form-item>
|
</template>
|
</up-form>
|
|
<FooterButtons :loading="loading" :confirmText="confirmText" @cancel="goBack" @confirm="handleSubmit" />
|
|
<up-action-sheet
|
:show="showLevelSheet"
|
title="选择问题等级"
|
:actions="levelActions"
|
@select="onSelectLevel"
|
@close="showLevelSheet = 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 {
|
addFacilityRectification,
|
updateFacilityRectification,
|
} from "@/api/safeProduction/safetyFacility";
|
|
const loading = ref(false);
|
const mode = ref("add");
|
const facilityName = ref("");
|
|
const form = ref({
|
id: null,
|
inspectionId: null,
|
facilityId: null,
|
problemDesc: "",
|
problemLevel: "",
|
planTime: "",
|
rectifyDesc: "",
|
verifyDesc: "",
|
status: "",
|
actualTime: "",
|
verifyTime: "",
|
});
|
|
const showLevelSheet = ref(false);
|
const showPlanPicker = ref(false);
|
|
const levelActions = [
|
{ name: "一般", value: "一般" },
|
{ name: "重大", value: "重大" },
|
];
|
|
const isReadOnlyProblem = computed(() => mode.value !== "add");
|
|
const pageTitle = computed(() => {
|
if (mode.value === "add") return "新增整改";
|
if (mode.value === "do") return "整改";
|
if (mode.value === "verify") return "验收";
|
return "查看整改";
|
});
|
|
const confirmText = computed(() => {
|
if (mode.value === "view") 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 openLevelSheet = () => {
|
if (mode.value !== "add") return;
|
showLevelSheet.value = true;
|
};
|
|
const openPlanPicker = () => {
|
if (mode.value !== "add") return;
|
showPlanPicker.value = true;
|
};
|
|
const onSelectLevel = action => {
|
if (mode.value !== "add") return;
|
form.value.problemLevel = action.value;
|
showLevelSheet.value = false;
|
};
|
|
const onPlanConfirm = e => {
|
if (mode.value !== "add") return;
|
form.value.planTime = dayjs(e?.value).format("YYYY-MM-DD HH:mm:ss");
|
showPlanPicker.value = false;
|
};
|
|
const handleSubmit = () => {
|
if (mode.value === "view") {
|
goBack();
|
return;
|
}
|
|
if (mode.value === "add") {
|
if (!form.value.inspectionId || !form.value.facilityId) {
|
uni.showToast({ title: "缺少巡检信息", icon: "none" });
|
return;
|
}
|
const problemDesc = String(form.value.problemDesc || "").trim();
|
if (!problemDesc) {
|
uni.showToast({ title: "请输入问题描述", icon: "none" });
|
return;
|
}
|
const problemLevel = String(form.value.problemLevel || "").trim();
|
if (!problemLevel) {
|
uni.showToast({ title: "请选择问题等级", icon: "none" });
|
return;
|
}
|
if (!form.value.planTime) {
|
uni.showToast({ title: "请选择计划整改时间", icon: "none" });
|
return;
|
}
|
const payload = { ...form.value, problemDesc, problemLevel };
|
loading.value = true;
|
addFacilityRectification(payload)
|
.then(() => {
|
uni.showToast({ title: "操作成功", icon: "success" });
|
uni.$emit("safetyFacility:refresh");
|
goBack();
|
})
|
.catch(() => {
|
uni.showToast({ title: "操作失败", icon: "none" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
return;
|
}
|
|
if (mode.value === "do") {
|
if (!form.value.id) return;
|
const rectifyDesc = String(form.value.rectifyDesc || "").trim();
|
if (!rectifyDesc) {
|
uni.showToast({ title: "请输入整改说明", icon: "none" });
|
return;
|
}
|
const payload = {
|
...form.value,
|
rectifyDesc,
|
status: "已整改",
|
actualTime: dayjs(Date.now()).format("YYYY-MM-DD HH:mm:ss"),
|
};
|
loading.value = true;
|
updateFacilityRectification(payload)
|
.then(() => {
|
uni.showToast({ title: "操作成功", icon: "success" });
|
uni.$emit("safetyFacility:refresh");
|
goBack();
|
})
|
.catch(() => {
|
uni.showToast({ title: "操作失败", icon: "none" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
return;
|
}
|
|
if (mode.value === "verify") {
|
if (!form.value.id) return;
|
const verifyDesc = String(form.value.verifyDesc || "").trim();
|
if (!verifyDesc) {
|
uni.showToast({ title: "请输入验收说明", icon: "none" });
|
return;
|
}
|
const payload = {
|
...form.value,
|
verifyDesc,
|
status: "已验收",
|
verifyTime: dayjs(Date.now()).format("YYYY-MM-DD HH:mm:ss"),
|
};
|
loading.value = true;
|
updateFacilityRectification(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.inspection) {
|
const ins = obj.inspection;
|
form.value.inspectionId = ins.id;
|
form.value.facilityId = ins.facilityId;
|
facilityName.value = ins.facilityName || "";
|
}
|
if (obj.row) {
|
form.value = { ...form.value, ...(obj.row || {}) };
|
facilityName.value = obj.row.facilityName || facilityName.value;
|
}
|
} catch (e) {}
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
</style>
|