| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <template>
- <div class="modals">
- <BasicModal
- v-bind="$attrs"
- destroyOnClose
- @register="registerModal"
- :title="getTitle"
- @ok="handleSubmit"
- :width="800"
- @cancel="handleCancel"
- >
- <div class="!pl-8 !pt-4">
- <BasicForm @register="registerForm">
- <template #uniqueCode>
- <span>{{ deviceInfo?.uniqueCode }}</span>
- </template>
- <template #manufacturer>
- <span>{{ deviceInfo?.manufacturer }}</span>
- </template>
- <template #model>
- <span>{{ deviceInfo?.model }}</span>
- </template>
- </BasicForm>
- </div>
- </BasicModal>
- </div>
- </template>
- <script lang="ts" setup>
- import { ref, computed, unref } from 'vue';
- import { BasicModal, useModalInner } from '/@/components/Modal';
- import { BasicForm, useForm } from '/@/components/Form';
- import { useMessage } from '/@/hooks/web/useMessage';
- import { upkeepDataFormSchema } from './data';
- import {
- upkeepAdd,
- upkeepDetail,
- upkeepEdit,
- engineerDialysisDeviceDetail,
- } from '/@/api/biz/engineer/dialysisDeviceApi';
- const emit = defineEmits(['success', 'cancel', 'register']);
- const getTitle = computed(() => (!unref(isUpdate) ? '保养设备' : '保养设备'));
- const isUpdate = ref(false);
- const deviceInfo = ref();
- const rowId = ref();
- const { createMessage } = useMessage();
- const [registerForm, { resetFields, validate, setFieldsValue }] = useForm({
- layout: 'vertical',
- showResetButton: true,
- labelWidth: 100,
- schemas: upkeepDataFormSchema,
- showActionButtonGroup: false,
- actionColOptions: {
- span: 12,
- },
- baseColProps: {
- span: 12,
- },
- wrapperCol: {
- span: 22,
- },
- });
- const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => {
- await resetFields();
- setModalProps({ confirmLoading: false });
- isUpdate.value = !!data?.isUpdate;
- if (!data.record.name) {
- deviceInfo.value = await engineerDialysisDeviceDetail(data.record?.id);
- } else {
- deviceInfo.value = data.record;
- }
- if (unref(isUpdate)) {
- rowId.value = data.upkeepRecord.id;
- const resData = await upkeepDetail(data.upkeepRecord.id);
- console.log('resData::::', resData);
- await setFieldsValue({
- ...resData,
- });
- }
- });
- // 提交按钮事件
- async function handleSubmit() {
- try {
- const values = await validate();
- setModalProps({ confirmLoading: true });
- values.picture = values.files && values.files.map(ele => ele.id);
- if (!isUpdate.value) {
- values.deviceIds = [deviceInfo.value.id];
- } else {
- values.deviceId = deviceInfo.value.id;
- }
- !unref(isUpdate)
- ? await upkeepAdd({ ...values })
- : await upkeepEdit({ ...values, id: rowId.value });
- !unref(isUpdate) ? createMessage.success('新增成功!') : createMessage.success('编辑成功!');
- closeModal();
- emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } });
- } finally {
- setModalProps({ confirmLoading: false, canFullscreen: false });
- }
- }
- async function handleCancel() {
- closeModal();
- emit('cancel');
- }
- </script>
- <style lang="less" scoped>
- ::v-deep(.ant-modal) {
- background-color: #000;
- }
- </style>
|