<template>
|
<el-dialog :title="modalOptions.title" v-model="visible">
|
<Form ref="formRef"></Form>
|
<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 { addLedger, editLedger } from "@/api/equipmentManagement/ledger";
|
import Form from "./Form.vue";
|
import { ElMessage } from "element-plus";
|
|
defineOptions({
|
name: "设备台账新增编辑",
|
});
|
|
const emits = defineEmits(["success"]);
|
|
const formRef = ref();
|
const {
|
id,
|
visible,
|
loading,
|
openModal,
|
modalOptions,
|
handleConfirm,
|
closeModal,
|
} = useModal();
|
|
const sendForm = async () => {
|
loading.value = true;
|
const { code } = id.value
|
? await editLedger({ id: id.value, ...formRef.value.form })
|
: await addLedger(formRef.value.form);
|
if (code == 200) {
|
emits("success");
|
ElMessage({ message: "操作成功", type: "success" });
|
closeModal();
|
} else {
|
loading.value = false;
|
}
|
};
|
|
const loadForm = async (id) => {
|
openModal(id);
|
await nextTick();
|
formRef.value.loadForm(id);
|
};
|
|
defineExpose({
|
openModal,
|
loadForm,
|
});
|
</script>
|