OrgModal.vue
2.48 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
<template>
  <BasicModal
    v-bind="$attrs"
    @register="registerModal"
    title="批量修改设备"
    :canFullscreen="false"
    centered
    @ok="dispatchCustomer"
    @cancel="resetFields"
    :minHeight="300"
    okText="确认"
  >
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, nextTick } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form';
  import { orgForm } from '../../config/detail.config';
  import { doBatchUpdateDevice, getGATEWAY } from '/@/api/device/deviceManager';
  import { useMessage } from '/@/hooks/web/useMessage';
  export default defineComponent({
    name: 'AlarmDetailModal',
    components: {
      BasicModal,
      BasicForm,
    },
    emits: ['reload', 'register'],
    setup(_, { emit }) {
      const { createMessage } = useMessage();
      const record = ref([]);
      const [registerModal, { closeModal, setModalProps }] = useModalInner(async (data) => {
        await nextTick();
        record.value = data;
        // 如果是网关子设备
        const deviceTypeFilterSensor = data
          .filter((filterItem) => filterItem.deviceType === 'SENSOR')
          .map((mapItem) => mapItem.tbDeviceId);
        // 根据gatewayId获取网关所属组织
        for (let item of deviceTypeFilterSensor) {
          await getGATEWAYByTbDeviceId(item);
        }
      });
      const getGATEWAYByTbDeviceId = async (tbDeviceId: string) => {
        const result = await getGATEWAY(tbDeviceId);
        if (!result) return;
        setFieldsValue({
          sensorOrganizationId: result.organizationId,
        });
      };
      const [registerForm, { validate, resetFields, setFieldsValue }] = useForm({
        labelWidth: 100,
        showActionButtonGroup: false,
        schemas: orgForm,
      });
      // 分配组织
      const dispatchCustomer = async () => {
        setModalProps({ loading: true });
        try {
          const value = await validate();
          if (!value) return;
          await doBatchUpdateDevice(value.organizationId, record.value);
          closeModal();
          resetFields();
          emit('reload');
        } finally {
          setModalProps({ loading: false });
          createMessage.success('操作成功');
        }
      };
      return {
        registerModal,
        registerForm,
        dispatchCustomer,
        resetFields,
      };
    },
  });
</script>