<!-- 签章管理 --> <script lang="ts" setup> import { Delete } from '@element-plus/icons-vue' import { ElMessage, ElMessageBox } from 'element-plus' import tableHeader from '../../notice/table.header.vue' import type { queryType, signType, typeofSign } from '../tool_interface' import addDDialog from './addDDialog.vue' import { deleteApi, listPageApi } from '@/api/system/tool' import { getDictByCode } from '@/api/system/dict' const searchQuery = reactive<queryType>({ signNo: '', // 编号 signName: '', // 名称 signDirector: '', // 负责人 createTime: '', // 创建时间 limit: 10, offset: 1, signType: '', }) // 查询参数 const loadingTable = ref<boolean>(false) // 表格loading const total = ref<number>(0) // 数据总条数 const columns = ref([ { text: '签章编号', value: 'signNo', align: 'center', width: '180' }, { text: '签章名称', value: 'signName', align: 'center', width: '150' }, { text: '签章负责人', value: 'signDirector', align: 'center', width: '100' }, { text: '创建时间', value: 'createTime', align: 'center', width: '250' }, { text: '描述', value: 'signDesc', align: 'center' }, ]) // 表格 const list = ref([]) // 表格数据 const addRef = ref() // 添加/编辑/详情/组件 // 获取类型 const getType = async () => { const res = await getDictByCode('signType') searchQuery.signType = res.data.filter((item: typeofSign) => item.name === '签章')[0].value } // 获取数据列表 const getList = () => { loadingTable.value = true listPageApi(searchQuery).then((res) => { if (res.code === 200) { list.value = res.data.rows total.value = res.data.total } loadingTable.value = false }).catch((_) => { loadingTable.value = false }) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.limit = val.size } if (val && val.page) { searchQuery.offset = val.page } getList() } // 编辑 const edit = (row: signType) => { addRef.value.initDialog({ ...row, signType: searchQuery.signType, title: '更新', }) } // 详情 const detail = (row: signType) => { addRef.value.initDialog({ ...row, signType: searchQuery.signType, title: '详情', }) } // 删除 const remove = (row: signType) => { ElMessageBox.confirm( `确认删除${row.signName}吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { deleteApi({ id: (row.id as string) }).then((res) => { if (res.code === 200) { ElMessage({ type: 'success', message: '删除成功', }) getList() } }) }) } // 搜索 const search = () => { getList() } // 重置 const reset = () => { searchQuery.createTime = '' searchQuery.signDirector = '' searchQuery.signName = '' searchQuery.signNo = '' getList() } // 新增 const add = () => { addRef.value.initDialog({ signType: searchQuery.signType, title: '新增', }) } // 导出 const exportExcel = () => { } // 打印 const print = () => { } onMounted(() => { getType().then((_) => { getList() }) }) </script> <template> <!-- 布局 --> <app-container> <!-- 筛选条件 --> <search-area @search="search"> <search-item> <el-input v-model="searchQuery.signNo" placeholder="签章编号" clearable class="w-50 m-2 normal-input" /> </search-item> <search-item> <el-input v-model="searchQuery.signName" placeholder="签章名称" clearable class="w-50 m-2 normal-input" /> </search-item> <search-item> <el-input v-model="searchQuery.signDirector" placeholder="负责人" clearable class="w-50 m-2 normal-input" /> </search-item> <search-item> <el-date-picker v-model="searchQuery.createTime" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" placeholder="发布时间" /> </search-item> <template #btns> <el-button class="filter-item" type="info" :icon="Delete" :style="{ marginTop: '-10px' }" @click="reset"> 重置 </el-button> </template> </search-area> <!-- 表头区域 --> <table-header title="数据列表"> <template #btns> <el-button type="primary" @click="add"> 新建 </el-button> <el-button type="primary" @click="exportExcel"> 导出 </el-button> <el-button type="primary" @click="print"> 打印 </el-button> </template> </table-header> <!-- 表格区域 --> <normal-table :data="list" :total="total" :columns="columns as any" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" @change="changePage"> <template #preColumns> <el-table-column label="#" width="55" align="center"> <template #default="scope"> {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column label="操作" align="center" width="250"> <template #default="{ row }"> <el-button @click="edit(row)"> 编辑 </el-button> <el-button @click="detail(row)"> 详情 </el-button> <el-button @click="remove(row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> <add-d-dialog ref="addRef" @resetData="getList" /> </app-container> </template> <style lang="scss" scoped> .normal-input { width: 180px !important; margin-right: 15px !important; } :deep(.el-table__header) { background-color: #bbb; } </style>