曹睿
2 天以前 76a985e3d790e506eef36c4df7442a95db0b29a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<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
    ? 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>