<template>
|
<el-dialog v-model="visible" :title="modalOptions.title" @close="close">
|
<RepairForm ref="repairFormRef" />
|
<template #footer>
|
<el-button @click="closeModal">{{ modalOptions.cancelText }}</el-button>
|
<el-button type="primary" @click="sendForm" :loading="loading">
|
{{ modalOptions.confirmText }}
|
</el-button>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script setup>
|
import { useModal } from "@/hooks/useModal";
|
import RepairForm from "../Form/RepairForm.vue";
|
import {
|
addRepair,
|
editRepair,
|
getRepairById,
|
} from "@/api/equipmentManagement/repair";
|
import { ElMessage } from "element-plus";
|
|
defineOptions({
|
name: "设备报修弹窗",
|
});
|
|
const emits = defineEmits(["ok"]);
|
|
const repairFormRef = ref();
|
const {
|
id,
|
visible,
|
loading,
|
openModal,
|
modalOptions,
|
handleConfirm,
|
closeModal,
|
} = useModal({ title: "设备报修" });
|
|
const sendForm = async () => {
|
loading.value = true;
|
const form = await repairFormRef.value.getForm();
|
const { code } = id.value
|
? await editRepair({ id: unref(id), ...form })
|
: await addRepair(form);
|
if (code == 200) {
|
ElMessage.success(`${id ? "编辑" : "新增"}报修成功`);
|
closeModal();
|
emits("ok");
|
}
|
loading.value = false;
|
};
|
|
const openEdit = async (id) => {
|
const { data } = await getRepairById(id);
|
openModal(id);
|
await nextTick();
|
await repairFormRef.value.setForm(data);
|
};
|
|
const close = () => {
|
repairFormRef.value.resetForm();
|
closeModal();
|
};
|
|
defineExpose({
|
openModal,
|
openEdit,
|
});
|
</script>
|