<template>
|
<view class="account-detail">
|
<PageHeader :title="pageTitle" @back="goBack" />
|
<up-form ref="formRef" :model="form" label-width="110">
|
<up-form-item label="关联设备" required>
|
<up-input v-model="equipmentText" placeholder="请选择" readonly @click="showEquipmentSheet = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showEquipmentSheet = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="记录类型" required>
|
<up-input v-model="recordTypeText" placeholder="请选择" readonly @click="showRecordTypeSheet = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showRecordTypeSheet = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="记录编号" required>
|
<up-input v-model="form.recordNo" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="记录日期" required>
|
<up-input v-model="form.recordDate" placeholder="请选择" readonly @click="showRecordDatePicker = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showRecordDatePicker = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="执行人" required>
|
<up-input v-model="executorText" placeholder="请选择" readonly @click="showExecutorSheet = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showExecutorSheet = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="下次到期日期">
|
<up-input v-model="form.nextDueDate" placeholder="请选择" readonly @click="showNextDueDatePicker = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showNextDueDatePicker = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="执行结果">
|
<up-textarea v-model="form.executeResult" placeholder="请输入" auto-height />
|
</up-form-item>
|
<up-form-item label="问题描述">
|
<up-textarea v-model="form.problemDescription" placeholder="请输入" auto-height />
|
</up-form-item>
|
<up-form-item label="处理措施">
|
<up-textarea v-model="form.disposeMeasure" placeholder="请输入" auto-height />
|
</up-form-item>
|
<up-form-item label="附件说明">
|
<up-textarea v-model="form.attachmentRemark" placeholder="请输入" auto-height />
|
</up-form-item>
|
</up-form>
|
|
<FooterButtons :loading="loading" confirmText="保存" @cancel="goBack" @confirm="handleSubmit" />
|
|
<up-action-sheet
|
:show="showEquipmentSheet"
|
title="选择设备"
|
:actions="equipmentActions"
|
@select="onSelectEquipment"
|
@close="showEquipmentSheet = false"
|
/>
|
<up-action-sheet
|
:show="showRecordTypeSheet"
|
title="选择记录类型"
|
:actions="recordTypeActions"
|
@select="onSelectRecordType"
|
@close="showRecordTypeSheet = false"
|
/>
|
<up-action-sheet
|
:show="showExecutorSheet"
|
title="选择执行人"
|
:actions="executorActions"
|
@select="onSelectExecutor"
|
@close="showExecutorSheet = false"
|
/>
|
|
<up-datetime-picker
|
:show="showRecordDatePicker"
|
v-model="recordDateValue"
|
mode="date"
|
@confirm="onRecordDateConfirm"
|
@cancel="showRecordDatePicker = false"
|
/>
|
<up-datetime-picker
|
:show="showNextDueDatePicker"
|
v-model="nextDueDateValue"
|
mode="date"
|
@confirm="onNextDueDateConfirm"
|
@cancel="showNextDueDatePicker = false"
|
/>
|
</view>
|
</template>
|
|
<script setup>
|
import { computed, onMounted, ref } from "vue";
|
import { onLoad } from "@dcloudio/uni-app";
|
import FooterButtons from "@/components/FooterButtons.vue";
|
import PageHeader from "@/components/PageHeader.vue";
|
import { formatDateToYMD } from "@/utils/ruoyi";
|
import { userListNoPageByTenantId } from "@/api/system/user";
|
import {
|
specialEquipmentLedgerList,
|
specialEquipmentRecordAdd,
|
specialEquipmentRecordUpdate,
|
} from "@/api/safeProduction/specialEquipmentManagement";
|
|
const formRef = ref();
|
const loading = ref(false);
|
|
const showEquipmentSheet = ref(false);
|
const showRecordTypeSheet = ref(false);
|
const showExecutorSheet = ref(false);
|
const equipmentActions = ref([]);
|
const executorActions = ref([]);
|
|
const showRecordDatePicker = ref(false);
|
const showNextDueDatePicker = ref(false);
|
const recordDateValue = ref(Date.now());
|
const nextDueDateValue = ref(Date.now());
|
|
const equipmentText = ref("");
|
const recordTypeText = ref("");
|
const executorText = ref("");
|
|
const recordTypeActions = [
|
{ name: "检验", value: 1 },
|
{ name: "维保", value: 2 },
|
];
|
|
const form = ref({
|
id: "",
|
equipmentId: "",
|
recordType: "",
|
recordNo: "",
|
recordDate: "",
|
executeResult: "",
|
problemDescription: "",
|
disposeMeasure: "",
|
executorId: "",
|
executorName: "",
|
nextDueDate: "",
|
attachmentRemark: "",
|
});
|
|
const pageTitle = computed(() => (form.value.id ? "编辑记录" : "新增记录"));
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const loadEquipmentOptions = () => {
|
specialEquipmentLedgerList({})
|
.then(res => {
|
const rows = Array.isArray(res?.data) ? res.data : [];
|
equipmentActions.value = rows.map(r => ({
|
name: r.equipmentName || "",
|
value: r.id,
|
equipmentNo: r.equipmentNo,
|
}));
|
})
|
.catch(() => {
|
equipmentActions.value = [];
|
});
|
};
|
|
const loadUsers = () => {
|
userListNoPageByTenantId()
|
.then(res => {
|
const rows = Array.isArray(res?.data) ? res.data : [];
|
executorActions.value = rows.map(u => ({
|
name: u.nickName || u.userName || "",
|
value: u.userId,
|
}));
|
})
|
.catch(() => {
|
executorActions.value = [];
|
});
|
};
|
|
const onSelectEquipment = action => {
|
form.value.equipmentId = action.value;
|
equipmentText.value = action.equipmentNo ? `${action.name}(${action.equipmentNo})` : action.name;
|
showEquipmentSheet.value = false;
|
};
|
|
const onSelectRecordType = action => {
|
form.value.recordType = action.value;
|
recordTypeText.value = action.name;
|
showRecordTypeSheet.value = false;
|
};
|
|
const onSelectExecutor = action => {
|
form.value.executorId = action.value;
|
form.value.executorName = action.name;
|
executorText.value = action.name;
|
showExecutorSheet.value = false;
|
};
|
|
const onRecordDateConfirm = e => {
|
const value = e?.value ?? recordDateValue.value;
|
form.value.recordDate = formatDateToYMD(value);
|
showRecordDatePicker.value = false;
|
};
|
|
const onNextDueDateConfirm = e => {
|
const value = e?.value ?? nextDueDateValue.value;
|
form.value.nextDueDate = formatDateToYMD(value);
|
showNextDueDatePicker.value = false;
|
};
|
|
const normalizeTexts = () => {
|
if (form.value.recordType) {
|
recordTypeText.value = String(form.value.recordType) === "1" ? "检验" : "维保";
|
}
|
executorText.value = form.value.executorName || "";
|
};
|
|
const handleSubmit = async () => {
|
if (!form.value.equipmentId) {
|
uni.showToast({ title: "请选择关联设备", icon: "none" });
|
return;
|
}
|
if (!form.value.recordType) {
|
uni.showToast({ title: "请选择记录类型", icon: "none" });
|
return;
|
}
|
const recordNo = String(form.value.recordNo || "").trim();
|
if (!recordNo) {
|
uni.showToast({ title: "请输入记录编号", icon: "none" });
|
return;
|
}
|
if (!form.value.recordDate) {
|
uni.showToast({ title: "请选择记录日期", icon: "none" });
|
return;
|
}
|
if (!form.value.executorId) {
|
uni.showToast({ title: "请选择执行人", icon: "none" });
|
return;
|
}
|
|
loading.value = true;
|
const api = form.value.id ? specialEquipmentRecordUpdate : specialEquipmentRecordAdd;
|
api({ ...form.value, recordNo })
|
.then(() => {
|
uni.showToast({ title: "保存成功", icon: "success" });
|
uni.$emit("specialEquipmentManagement:refresh");
|
goBack();
|
})
|
.catch(() => {
|
uni.showToast({ title: "保存失败", icon: "none" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
};
|
|
onLoad(options => {
|
if (!options?.data) return;
|
try {
|
const row = JSON.parse(decodeURIComponent(options.data));
|
form.value = { ...form.value, ...(row || {}) };
|
normalizeTexts();
|
} catch {
|
uni.showToast({ title: "数据加载失败", icon: "none" });
|
}
|
});
|
|
onMounted(() => {
|
loadEquipmentOptions();
|
loadUsers();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
</style>
|