1
|
1
|
<template>
|
2
|
2
|
<PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
|
3
|
3
|
<OrganizationIdTree class="w-1/4 xl:w-1/5" @select="handleSelect" />
|
4
|
|
- <BasicTable
|
5
|
|
- @register="registerTable"
|
6
|
|
- :searchInfo="searchInfo"
|
7
|
|
- class="w-3/4 xl:w-4/5"
|
8
|
|
- :rowSelection="{
|
9
|
|
- onChange: onSelectChange,
|
10
|
|
- type: 'checkbox',
|
11
|
|
- }"
|
12
|
|
- rowKey="id"
|
13
|
|
- >
|
|
4
|
+ <BasicTable @register="registerTable" :searchInfo="searchInfo" class="w-3/4 xl:w-4/5">
|
14
|
5
|
<template #toolbar>
|
15
|
|
- <a-button type="primary" @click="handleCreate"> 新增联系人 </a-button>
|
|
6
|
+ <a-button type="primary" @click="handleCreateOrEdit"> 新增联系人 </a-button>
|
16
|
7
|
<a-button
|
17
|
8
|
type="primary"
|
18
|
9
|
color="error"
|
19
|
|
- @click="handleBatchDelete"
|
|
10
|
+ @click="handleDeleteOrBatchDelete"
|
20
|
11
|
:disabled="hasBatchDelete"
|
21
|
12
|
>
|
22
|
13
|
批量删除
|
...
|
...
|
@@ -28,7 +19,7 @@ |
28
|
19
|
{
|
29
|
20
|
label: '编辑',
|
30
|
21
|
icon: 'clarity:note-edit-line',
|
31
|
|
- onClick: handleEdit.bind(null, record),
|
|
22
|
+ onClick: handleCreateOrEdit.bind(null, record),
|
32
|
23
|
},
|
33
|
24
|
{
|
34
|
25
|
label: '删除',
|
...
|
...
|
@@ -36,7 +27,7 @@ |
36
|
27
|
color: 'error',
|
37
|
28
|
popConfirm: {
|
38
|
29
|
title: '是否确认删除',
|
39
|
|
- confirm: handleDelete.bind(null, record),
|
|
30
|
+ confirm: handleDeleteOrBatchDelete.bind(null, record),
|
40
|
31
|
},
|
41
|
32
|
},
|
42
|
33
|
]"
|
...
|
...
|
@@ -55,6 +46,7 @@ |
55
|
46
|
import { useDrawer } from '/@/components/Drawer';
|
56
|
47
|
import ContactDrawer from './ContactDrawer.vue';
|
57
|
48
|
import OrganizationIdTree from '../../common/OrganizationIdTree.vue';
|
|
49
|
+ import { Modal } from 'ant-design-vue';
|
58
|
50
|
import { getAlarmContact, deleteAlarmContact } from '/@/api/alarm/contact/alarmContact';
|
59
|
51
|
import { searchFormSchema, columns } from './config.data';
|
60
|
52
|
export default defineComponent({
|
...
|
...
|
@@ -68,6 +60,11 @@ |
68
|
60
|
setup() {
|
69
|
61
|
let selectedRowIds = ref<string[]>([]);
|
70
|
62
|
const hasBatchDelete = computed(() => selectedRowIds.value.length <= 0);
|
|
63
|
+ // 复选框事件
|
|
64
|
+ const onSelectRowChange = (selectedRowKeys: string[]) => {
|
|
65
|
+ selectedRowIds.value = selectedRowKeys;
|
|
66
|
+ };
|
|
67
|
+ // 表格hooks
|
71
|
68
|
const [registerTable, { reload }] = useTable({
|
72
|
69
|
api: getAlarmContact,
|
73
|
70
|
columns,
|
...
|
...
|
@@ -78,7 +75,11 @@ |
78
|
75
|
useSearchForm: true,
|
79
|
76
|
showTableSetting: true,
|
80
|
77
|
bordered: true,
|
81
|
|
- showIndexColumn: false,
|
|
78
|
+ rowSelection: {
|
|
79
|
+ onChange: onSelectRowChange,
|
|
80
|
+ type: 'checkbox',
|
|
81
|
+ },
|
|
82
|
+ rowKey: 'id',
|
82
|
83
|
actionColumn: {
|
83
|
84
|
width: 180,
|
84
|
85
|
title: '操作',
|
...
|
...
|
@@ -87,69 +88,66 @@ |
87
|
88
|
fixed: 'right',
|
88
|
89
|
},
|
89
|
90
|
});
|
|
91
|
+ // 弹框
|
90
|
92
|
const [registerDrawer, { openDrawer }] = useDrawer();
|
91
|
93
|
const { createMessage } = useMessage();
|
92
|
94
|
const searchInfo = reactive<Recordable>({});
|
93
|
|
- // 新增
|
94
|
|
- const handleCreate = () => {
|
95
|
|
- openDrawer(true, {
|
96
|
|
- isUpdate: false,
|
97
|
|
- });
|
98
|
|
- };
|
99
|
|
- // 编辑
|
100
|
|
- const handleEdit = (record: Recordable) => {
|
101
|
|
- openDrawer(true, {
|
102
|
|
- isUpdate: true,
|
103
|
|
- record,
|
104
|
|
- });
|
105
|
|
- };
|
106
|
|
- // 删除
|
107
|
|
- const handleDelete = async (record: Recordable) => {
|
108
|
|
- let ids: string[] = [record.id];
|
109
|
|
- try {
|
110
|
|
- await deleteAlarmContact(ids);
|
111
|
|
- createMessage.success('删除联系人成功');
|
112
|
|
- handleSuccess();
|
113
|
|
- } catch (e) {
|
114
|
|
- createMessage.error('删除失败');
|
115
|
|
- }
|
116
|
|
- };
|
117
|
|
- // 批量删除
|
118
|
|
- const handleBatchDelete = async () => {
|
119
|
|
- try {
|
120
|
|
- await deleteAlarmContact(selectedRowIds.value);
|
121
|
|
- createMessage.success('批量删除联系人成功');
|
122
|
|
- handleSuccess();
|
123
|
|
- } catch (e) {
|
124
|
|
- createMessage.error('删除失败');
|
125
|
|
- }
|
126
|
|
- };
|
127
|
95
|
// 刷新
|
128
|
96
|
const handleSuccess = () => {
|
129
|
97
|
reload();
|
130
|
98
|
};
|
131
|
|
- // 复选框事件
|
132
|
|
- const onSelectChange = (selectedRowKeys: string[]) => {
|
133
|
|
- selectedRowIds.value = selectedRowKeys;
|
|
99
|
+ // 新增或编辑
|
|
100
|
+ const handleCreateOrEdit = (record: Recordable) => {
|
|
101
|
+ if (record) {
|
|
102
|
+ openDrawer(true, {
|
|
103
|
+ isUpdate: true,
|
|
104
|
+ record,
|
|
105
|
+ });
|
|
106
|
+ } else {
|
|
107
|
+ openDrawer(true, {
|
|
108
|
+ isUpdate: false,
|
|
109
|
+ });
|
|
110
|
+ }
|
134
|
111
|
};
|
135
|
|
- const handleSelect = (organizationId = '') => {
|
|
112
|
+ // 删除或批量删除
|
|
113
|
+ const handleDeleteOrBatchDelete = async (record?: Recordable) => {
|
|
114
|
+ if (record) {
|
|
115
|
+ try {
|
|
116
|
+ await deleteAlarmContact([record.id]);
|
|
117
|
+ createMessage.success('删除联系人成功');
|
|
118
|
+ handleSuccess();
|
|
119
|
+ } catch (e) {
|
|
120
|
+ createMessage.error('删除失败');
|
|
121
|
+ }
|
|
122
|
+ } else {
|
|
123
|
+ try {
|
|
124
|
+ await Modal.confirm({
|
|
125
|
+ title: '警告',
|
|
126
|
+ content: '是否删除勾选的信息?',
|
|
127
|
+ });
|
|
128
|
+ await deleteAlarmContact(selectedRowIds.value);
|
|
129
|
+ createMessage.success('批量删除联系人成功');
|
|
130
|
+ handleSuccess();
|
|
131
|
+ } catch (e) {
|
|
132
|
+ createMessage.info('取消删除');
|
|
133
|
+ }
|
|
134
|
+ }
|
|
135
|
+ };
|
|
136
|
+
|
|
137
|
+ // 树形选择器
|
|
138
|
+ const handleSelect = (organizationId: string) => {
|
136
|
139
|
searchInfo.organizationId = organizationId;
|
137
|
|
- console.log(organizationId);
|
138
|
|
- reload();
|
|
140
|
+ handleSuccess();
|
139
|
141
|
};
|
140
|
142
|
return {
|
141
|
143
|
searchInfo,
|
142
|
144
|
hasBatchDelete,
|
143
|
|
- onSelectChange,
|
144
|
|
- handleBatchDelete,
|
145
|
|
- handleEdit,
|
146
|
|
- handleCreate,
|
147
|
|
- handleDelete,
|
|
145
|
+ handleCreateOrEdit,
|
|
146
|
+ handleDeleteOrBatchDelete,
|
148
|
147
|
handleSelect,
|
149
|
148
|
handleSuccess,
|
150
|
149
|
registerTable,
|
151
|
150
|
registerDrawer,
|
152
|
|
- reload,
|
153
|
151
|
};
|
154
|
152
|
},
|
155
|
153
|
});
|
...
|
...
|
|