disinfectantsFormModal.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="modals">
  3. <BasicModal
  4. v-bind="$attrs"
  5. destroyOnClose
  6. @register="registerModal"
  7. :title="getTitle"
  8. @ok="handleSubmit"
  9. :width="800"
  10. @cancel="handleCancel"
  11. >
  12. <div class="!pl-8 !pt-4">
  13. <BasicForm @register="registerForm">
  14. <template #uniqueCode>
  15. <span>{{ deviceInfo?.uniqueCode }}</span>
  16. </template>
  17. <template #manufacturer>
  18. <span>{{ deviceInfo?.manufacturer }}</span>
  19. </template>
  20. <template #model>
  21. <span>{{ deviceInfo?.model }}</span>
  22. </template>
  23. </BasicForm>
  24. </div>
  25. </BasicModal>
  26. </div>
  27. </template>
  28. <script lang="ts" setup>
  29. import { ref, computed, unref } from 'vue';
  30. import { BasicModal, useModalInner } from '/@/components/Modal';
  31. import { BasicForm, useForm } from '/@/components/Form';
  32. import { useMessage } from '/@/hooks/web/useMessage';
  33. import { upkeepDataFormSchema } from './data';
  34. import {
  35. upkeepAdd,
  36. upkeepDetail,
  37. upkeepEdit,
  38. engineerDialysisDeviceDetail,
  39. } from '/@/api/biz/engineer/dialysisDeviceApi';
  40. const emit = defineEmits(['success', 'cancel', 'register']);
  41. const getTitle = computed(() => (!unref(isUpdate) ? '保养设备' : '保养设备'));
  42. const isUpdate = ref(false);
  43. const deviceInfo = ref();
  44. const rowId = ref();
  45. const { createMessage } = useMessage();
  46. const [registerForm, { resetFields, validate, setFieldsValue }] = useForm({
  47. layout: 'vertical',
  48. showResetButton: true,
  49. labelWidth: 100,
  50. schemas: upkeepDataFormSchema,
  51. showActionButtonGroup: false,
  52. actionColOptions: {
  53. span: 12,
  54. },
  55. baseColProps: {
  56. span: 12,
  57. },
  58. wrapperCol: {
  59. span: 22,
  60. },
  61. });
  62. const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => {
  63. await resetFields();
  64. setModalProps({ confirmLoading: false });
  65. isUpdate.value = !!data?.isUpdate;
  66. if (!data.record.name) {
  67. deviceInfo.value = await engineerDialysisDeviceDetail(data.record?.id);
  68. } else {
  69. deviceInfo.value = data.record;
  70. }
  71. if (unref(isUpdate)) {
  72. rowId.value = data.upkeepRecord.id;
  73. const resData = await upkeepDetail(data.upkeepRecord.id);
  74. console.log('resData::::', resData);
  75. await setFieldsValue({
  76. ...resData,
  77. });
  78. }
  79. });
  80. // 提交按钮事件
  81. async function handleSubmit() {
  82. try {
  83. const values = await validate();
  84. setModalProps({ confirmLoading: true });
  85. values.picture = values.files && values.files.map(ele => ele.id);
  86. if (!isUpdate.value) {
  87. values.deviceIds = [deviceInfo.value.id];
  88. } else {
  89. values.deviceId = deviceInfo.value.id;
  90. }
  91. !unref(isUpdate)
  92. ? await upkeepAdd({ ...values })
  93. : await upkeepEdit({ ...values, id: rowId.value });
  94. !unref(isUpdate) ? createMessage.success('新增成功!') : createMessage.success('编辑成功!');
  95. closeModal();
  96. emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } });
  97. } finally {
  98. setModalProps({ confirmLoading: false, canFullscreen: false });
  99. }
  100. }
  101. async function handleCancel() {
  102. closeModal();
  103. emit('cancel');
  104. }
  105. </script>
  106. <style lang="less" scoped>
  107. ::v-deep(.ant-modal) {
  108. background-color: #000;
  109. }
  110. </style>