| | |
| | | <script setup lang="ts"> |
| | | import { computed, ref } from 'vue'; |
| | | |
| | | import { useVbenDrawer } from '@vben/common-ui'; |
| | | import { useVbenDrawer, useVbenModal } from '@vben/common-ui'; |
| | | import { $t } from '@vben/locales'; |
| | | import { addFullName, cloneDeep, getPopupContainer } from '@vben/utils'; |
| | | |
| | | import { InputSearch } from 'ant-design-vue'; |
| | | |
| | | import { useVbenForm } from '#/adapter/form'; |
| | | import { listEqu } from '#/api/eims/equ'; |
| | | import { addEquStatu, getEquStatu, updateEquStatu } from '#/api/eims/equ-statu'; |
| | | import { getDeptTree, userList } from '#/api/system/user'; |
| | | import equModal from '#/views/eims/components/equ-modal.vue'; |
| | | |
| | | import { drawerSchema } from './data'; |
| | | |
| | |
| | | // 初始化 |
| | | await setupEquSelect(); |
| | | await setupDeptSelect(); |
| | | |
| | | // 设备详情页打开指定设备id |
| | | const { equId } = drawerApi.getData() as { equId?: number | string }; |
| | | if (equId) { |
| | | await formApi.setValues({ equId}); |
| | | } |
| | | // 更新 && 赋值 |
| | | if (isUpdate.value && id) { |
| | | const record = await getEquStatu(id); |
| | | await formApi.setValues(record); |
| | | if(isUpdate.value && record.userDept){ |
| | | if (isUpdate.value && record.userDept) { |
| | | await setupUserOptions(record.userDept); |
| | | } |
| | | } |
| | | // 设备id有值时不允许编辑(1.编辑 2.设备详情页打开) |
| | | const flag = equId !== undefined || isUpdate.value; |
| | | formApi.updateSchema([ |
| | | { |
| | | componentProps: { |
| | | disabled: flag |
| | | }, |
| | | fieldName: 'equId' |
| | | } |
| | | ]); |
| | | |
| | | drawerApi.drawerLoading(false); |
| | | } |
| | | }); |
| | |
| | | async function setupEquSelect() { |
| | | const equPageResult = await listEqu({ |
| | | pageNum: 1, |
| | | pageSize: 1000, |
| | | pageSize: 1000 |
| | | }); |
| | | // 使用map来跟踪已经遇到的equId,使用filter来过滤掉重复的元素。 |
| | | const uniqueItems = equPageResult.rows.filter((item, index, self) => index === self.findIndex((tm) => tm.equId === item.equId)); |
| | |
| | | drawerApi.close(); |
| | | await formApi.resetForm(); |
| | | } |
| | | |
| | | // EQU modal |
| | | const [EquModal, equModalApi] = useVbenModal({ |
| | | connectedComponent: equModal, |
| | | draggable: true, |
| | | title: '选择成员' |
| | | }); |
| | | |
| | | function handleEquModal() { |
| | | equModalApi.setData({}); |
| | | equModalApi.open(); |
| | | } |
| | | |
| | | async function selectEqu(equ: any) { |
| | | await formApi.setValues({ 'equId': equ.equId, 'equName': equ.equName }); |
| | | } |
| | | </script> |
| | | |
| | | <template> |
| | | <BasicDrawer :close-on-click-modal="false" :title="title" class="w-[600px]"> |
| | | <BasicForm /> |
| | | <BasicForm> |
| | | <template #equName="slotProps"> |
| | | <InputSearch :enter-button="true" placeholder="请选择" @search="handleEquModal" v-bind="slotProps" /> |
| | | </template> |
| | | </BasicForm> |
| | | <EquModal :disabled="true" class="w-[1200px]" @update-equ="selectEqu" /> |
| | | </BasicDrawer> |
| | | </template> |