CustomerModal.vue
2.11 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
<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 } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form';
import { customerForm } from '../../config/detail.config';
import { dispatchCustomer as dispatchCustomerApi } from '/@/api/device/deviceManager';
import { DeviceModel } from '/@/api/device/model/deviceModel';
import { isArray } from '/@/utils/is';
export default defineComponent({
name: 'AlarmDetailModal',
components: {
BasicModal,
BasicForm,
},
emits: ['reload', 'register'],
setup(_, { emit }) {
let record: DeviceModel[] = [];
const [registerModal, { closeModal }] = useModalInner((data: DeviceModel | DeviceModel[]) => {
data = isArray(data) ? data : [data as DeviceModel];
const { organizationId } = data.at(0) || {};
record = data;
updateSchema([
{
field: 'customerId',
componentProps: {
params: { organizationId },
},
},
]);
});
const [registerForm, { validate, getFieldsValue, updateSchema, resetFields }] = useForm({
labelWidth: 100,
showActionButtonGroup: false,
schemas: customerForm,
});
// 分配客户
const dispatchCustomer = async () => {
await validate();
const { customerId } = getFieldsValue();
const task: Promise<any>[] = [];
for (const item of record) {
task.push(dispatchCustomerApi({ ...item, customerId }));
}
await Promise.all(task);
closeModal();
resetFields();
emit('reload');
};
return {
registerModal,
registerForm,
dispatchCustomer,
resetFields,
};
},
});
</script>