houzhongjian
2024-08-08 820397e43a0b64d35c6d31d2a55475061438593b
提交 | 用户 | 时间
820397 1 <template>
H 2   <!-- 搜索 -->
3   <ContentWrap>
4     <el-form
5       class="-mb-15px"
6       :model="queryParams"
7       ref="queryFormRef"
8       :inline="true"
9       label-width="68px"
10     >
11       <el-form-item label="套餐名" prop="name">
12         <el-input
13           v-model="queryParams.name"
14           placeholder="请输入套餐名"
15           clearable
16           @keyup.enter="handleQuery"
17           class="!w-240px"
18         />
19       </el-form-item>
20       <el-form-item label="状态" prop="status">
21         <el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
22           <el-option
23             v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
24             :key="dict.value"
25             :label="dict.label"
26             :value="dict.value"
27           />
28         </el-select>
29       </el-form-item>
30       <el-form-item label="创建时间" prop="createTime">
31         <el-date-picker
32           v-model="queryParams.createTime"
33           type="daterange"
34           value-format="YYYY-MM-DD HH:mm:ss"
35           start-placeholder="开始日期"
36           end-placeholder="结束日期"
37           class="!w-240px"
38         />
39       </el-form-item>
40       <el-form-item>
41         <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
42         <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
43         <el-button
44           type="primary"
45           plain
46           @click="openForm('create')"
47           v-hasPermi="['system:tenant-package:create']"
48         >
49           <Icon icon="ep:plus" class="mr-5px" />
50           新增
51         </el-button>
52       </el-form-item>
53     </el-form>
54   </ContentWrap>
55
56   <!-- 列表 -->
57   <ContentWrap>
58     <el-table v-loading="loading" :data="list">
59       <el-table-column label="套餐编号" align="center" prop="id" width="120" />
60       <el-table-column label="套餐名" align="center" prop="name" />
61       <el-table-column label="状态" align="center" prop="status" width="100">
62         <template #default="scope">
63           <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
64         </template>
65       </el-table-column>
66       <el-table-column label="备注" align="center" prop="remark" />
67       <el-table-column
68         label="创建时间"
69         align="center"
70         prop="createTime"
71         width="180"
72         :formatter="dateFormatter"
73       />
74       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
75         <template #default="scope">
76           <el-button
77             link
78             type="primary"
79             @click="openForm('update', scope.row.id)"
80             v-hasPermi="['system:tenant-package:update']"
81           >
82             修改
83           </el-button>
84           <el-button
85             link
86             type="danger"
87             @click="handleDelete(scope.row.id)"
88             v-hasPermi="['system:tenant-package:delete']"
89           >
90             删除
91           </el-button>
92         </template>
93       </el-table-column>
94     </el-table>
95     <!-- 分页 -->
96     <Pagination
97       :total="total"
98       v-model:page="queryParams.pageNo"
99       v-model:limit="queryParams.pageSize"
100       @pagination="getList"
101     />
102   </ContentWrap>
103
104   <!-- 表单弹窗:添加/修改 -->
105   <TenantPackageForm ref="formRef" @success="getList" />
106 </template>
107 <script lang="ts" setup>
108 import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
109 import { dateFormatter } from '@/utils/formatTime'
110 import * as TenantPackageApi from '@/api/system/tenantPackage'
111 import TenantPackageForm from './TenantPackageForm.vue'
112
113 defineOptions({ name: 'SystemTenantPackage' })
114
115 const message = useMessage() // 消息弹窗
116 const { t } = useI18n() // 国际化
117
118 const loading = ref(true) // 列表的加载中
119 const total = ref(0) // 列表的总页数
120 const list = ref([]) // 列表的数据
121 const queryParams = reactive({
122   pageNo: 1,
123   pageSize: 10,
124   name: undefined,
125   status: undefined,
126   remark: undefined,
127   createTime: []
128 })
129 const queryFormRef = ref() // 搜索的表单
130
131 /** 查询列表 */
132 const getList = async () => {
133   loading.value = true
134   try {
135     const data = await TenantPackageApi.getTenantPackagePage(queryParams)
136     list.value = data.list
137     total.value = data.total
138   } finally {
139     loading.value = false
140   }
141 }
142
143 /** 搜索按钮操作 */
144 const handleQuery = () => {
145   queryParams.pageNo = 1
146   getList()
147 }
148
149 /** 重置按钮操作 */
150 const resetQuery = () => {
151   queryFormRef.value?.resetFields()
152   getList()
153 }
154
155 /** 添加/修改操作 */
156 const formRef = ref()
157 const openForm = (type: string, id?: number) => {
158   formRef.value.open(type, id)
159 }
160
161 /** 删除按钮操作 */
162 const handleDelete = async (id: number) => {
163   try {
164     // 删除的二次确认
165     await message.delConfirm()
166     // 发起删除
167     await TenantPackageApi.deleteTenantPackage(id)
168     message.success(t('common.delSuccess'))
169     // 刷新列表
170     await getList()
171   } catch {}
172 }
173
174 /** 初始化 **/
175 onMounted(() => {
176   getList()
177 })
178 </script>