TenantDefaultPackList.vue
3.6 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<template>
<div>
<BasicTable @register="registerTable" :rowSelection="rowSelection">
<template #tableTitle>
<a-button preIcon="ant-design:user-add-outlined" type="primary" @click="handleAdd">新增</a-button>
<a-button
v-if="selectedRowKeys.length > 0"
preIcon="ant-design:delete-outlined"
type="primary"
@click="handlePackBatch"
style="margin-right: 5px"
>批量删除
</a-button>
</template>
<template #action="{ record }">
<TableAction :actions="getActions(record)" />
</template>
</BasicTable>
<!-- 套餐包 -->
<TenantPackMenuModal @register="registerPackMenuModal" @success="handleSuccess"/>
</div>
</template>
<script lang="ts" name="tenant-default-pack" setup>
import { ref, unref } from 'vue';
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { deleteTenantPack, packList } from '../tenant.api';
import { packColumns, packFormSchema } from '../tenant.data';
import TenantPackMenuModal from './TenantPackMenuModal.vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { useListPage } from '/@/hooks/system/useListPage';
import { useUserStore } from '/@/store/modules/user';
import {Modal} from "ant-design-vue";
const { createMessage } = useMessage();
const [registerModal, { openModal }] = useModal();
const [registerPackMenuModal, { openModal: packModal }] = useModal();
const userStore = useUserStore();
// 列表页面公共参数、方法
const { prefixCls, tableContext } = useListPage({
designScope: 'tenant-template',
tableProps: {
api: packList,
columns: packColumns,
formConfig: {
schemas: packFormSchema,
},
beforeFetch: (params) => {
return Object.assign(params, { packType: 'default' });
},
},
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys, selectedRows }] = tableContext;
/**
* 操作列定义
* @param record
*/
function getActions(record) {
return [
{
label: '编辑',
onClick: handleEdit.bind(null, record),
},
{
label: '删除',
popConfirm: {
title: '是否确认删除租户套餐包',
confirm: handleDelete.bind(null, record.id),
},
},
];
}
/**
* 编辑套餐包
*/
function handleAdd() {
packModal(true, {
isUpdate: false,
packType:'default',
showFooter: true
});
}
/**
* 删除默认套餐包
*/
async function handleDelete(id) {
await deleteTenantPack({ ids: id }, handleSuccess);
}
/**
* 编辑
*/
function handleEdit(record) {
packModal(true, {
isUpdate: true,
record: record,
packType:'default',
showFooter: true
});
}
/**
* 新增套餐包
*/
async function handlePack() {
if (unref(selectedRowKeys).length > 1) {
createMessage.warn('请选择一个');
return;
}
packModal(true, {
tenantId: unref(selectedRowKeys.value.join(',')),
});
}
/**
* 删除成功之后回调事件
*/
function handleSuccess() {
(selectedRowKeys.value = []) && reload();
}
/**
* 批量删除套餐包
*/
async function handlePackBatch() {
Modal.confirm({
title: '删除租户套餐包',
content: '是否删除租户套餐包',
okText: '确认',
cancelText: '取消',
onOk: async () => {
await deleteTenantPack({ ids: selectedRowKeys.value.join(',')}, handleSuccess);
}
})
}
</script>