gaoluyang
3 天以前 b92ea6fb8b4a75a0d7c561bd045f1a8b1720ddd1
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
  <el-dialog
    v-model="visible"
    :title="modalOptions.title"
    width="30%"
    @close="close"
  >
    <PlanForm ref="planFormRef"></PlanForm>
    <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 PlanForm from "../Form/PlanForm";
import {
  addUpkeep,
  editUpkeep,
  getUpkeepById,
} from "@/api/equipmentManagement/upkeep";
import { ElMessage } from "element-plus";
 
defineOptions({
  name: "设备保养新增计划",
});
 
const emits = defineEmits(["ok"]);
const planFormRef = ref();
const {
  id,
  visible,
  loading,
  openModal,
  modalOptions,
  handleConfirm,
  closeModal,
} = useModal({ title: "设备保养计划" });
 
const openEdit = async (id) => {
  const { data } = await getUpkeepById(id);
  openModal(id);
  await nextTick();
  await planFormRef.value.setForm(data);
};
 
const sendForm = async () => {
  loading.value = true;
  const form = await planFormRef.value.getForm();
  const { code } = id.value
    ? await editUpkeep({ id: unref(id), ...form })
    : await addUpkeep(form);
  if (code == 200) {
    ElMessage.success(`${id ? "编辑" : "新增"}计划成功`);
    closeModal();
    emits("ok");
  }
  loading.value = false;
};
 
const close = () => {
  planFormRef.value.resetForm();
  closeModal();
};
 
defineExpose({
  openModal,
  openEdit,
});
</script>
 
<style lang="scss" scoped></style>