<!-- 培训签到表列表 --> <script name="TrainSignList" lang="ts" setup> import type { DateModelType } from 'element-plus' import { ElLoading, ElMessage, ElMessageBox, dayjs } from 'element-plus' import type { IRegistrationForm, ISignListQuery } from './train-interface' import { deleteTrainSignInfo, exportTrainList, getTrainSignList } from '@/api/resource/train' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import { exportFile } from '@/utils/exportUtils' // 定义变量 const { proxy } = getCurrentInstance() as any const router = useRouter() const searchQuery = ref<ISignListQuery>({ fileCode: '', position: '', host: '', beginTime: '', endTime: '', offset: 1, limit: 20, }) const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const loadingTable = ref<boolean>(false) // 表格loading const total = ref<number>(0) // 数据总条数 const columns = ref<Array<TableColumn>>([ { text: '文件编号', value: 'fileCode', align: 'center', width: '200' }, { text: '文件名称', value: 'fileName', align: 'center', width: '150' }, { text: '地点', value: 'position', align: 'center' }, { text: '主持', value: 'host', align: 'center', width: '180' }, { text: '时间', value: 'trainingTimeMin', align: 'center', width: '160' }, { text: '参加人数', value: 'participantCount', align: 'center', width: '100' }, { text: '确认情况', value: 'confirmCount', align: 'center', width: '100' }, { text: '创建时间', value: 'createTime', align: 'center', width: '180' }, ]) // 表头 const list = ref([]) // 表格数据 const checkoutList = ref([]) // 多选表格数据 // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } // 逻辑 // 导出列表 const batchExportList = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.6)', }) if (list.value.length > 0) { const params = { fileCode: searchQuery.value.fileCode, position: searchQuery.value.position, host: searchQuery.value.host, beginTime: searchQuery.value.beginTime, endTime: searchQuery.value.endTime, offset: 1, limit: 20, ids: checkoutList.value, } exportTrainList(params).then((res) => { const blob = new Blob([res.data]) loading.close() exportFile(blob, '培训签到表.xlsx') }) } else { loading.close() ElMessage.warning('无数据可导出数据') } } const addTrain = () => { router.push({ query: { type: 'create', }, path: 'trainSign/detail', }) } // 获取数据列表 const fetchData = (isNowPage = false) => { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } getTrainSignList(searchQuery.value).then((res) => { if (res.code === 200) { list.value = res.data.rows.map((item: IRegistrationForm) => ({ ...item, trainingTimeMin: dayjs(item.trainingTime).format('YYYY-MM-DD HH:mm'), })) total.value = Number(res.data.total) } loadingTable.value = false }).catch((_) => { loadingTable.value = false }) } const search = () => { fetchData() } const clearList = () => { searchQuery.value = { fileCode: '', position: '', host: '', beginTime: '', endTime: '', offset: 1, limit: 20, } dateRange.value = ['', ''] fetchData(true) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.value.limit = val.size } if (val && val.page) { searchQuery.value.offset = val.page } fetchData(true) } // 查看详情信息 const detail = (row: any) => { router.push({ query: { type: 'detail', id: row.id, }, path: 'trainSign/detail', }) } // 编辑信息 const update = (row: any) => { router.push({ query: { type: 'update', id: row.id, }, path: 'trainSign/detail', }) } // 删除信息 const deleteTrainSignById = (id: string, trainNo: string) => { ElMessageBox.confirm(`是否删除培训签到表 ${trainNo}`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }).then(() => { deleteTrainSignInfo({ ids: [id] }).then((res: { code: number; message: any }) => { if (res.code === 200) { ElMessage.success(`培训签到表 ${trainNo} 删除成功`) fetchData() } else { ElMessage.error(`培训签到表 ${trainNo} 删除失败: ${res.message}`) } }) }) } const getGroupCodeDict = async () => { await getDictByCode('bizGroupCode').then((res) => { if (res.code === 200) { sessionStorage.setItem('bizGroupCode', JSON.stringify(res.data)) } }) } const getLabCodeDict = async () => { await getDictByCode('bizLabCode').then((res) => { if (res.code === 200) { sessionStorage.setItem('bizLabCode', JSON.stringify(res.data)) } }) } const getDict = () => { getLabCodeDict() getGroupCodeDict() } watch(dateRange, (val) => { if (val) { searchQuery.value.beginTime = dayjs(val[0]).format('YYYY-MM-DD HH:mm:ss') === 'Invalid Date' ? '' : dayjs(val[0]).format('YYYY-MM-DD HH:mm:ss') searchQuery.value.endTime = dayjs(val[1]).format('YYYY-MM-DD HH:mm:ss') === 'Invalid Date' ? '' : dayjs(val[1]).format('YYYY-MM-DD HH:mm:ss') } else { searchQuery.value.beginTime = '' searchQuery.value.endTime = '' } }) onMounted(async () => { getDict() fetchData() }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="clearList"> <search-item> <el-input v-model="searchQuery.fileCode" placeholder="文件编号" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.position" placeholder="地点" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.host" placeholder="主持" clearable /> </search-item> <search-item> <el-date-picker v-model="dateRange" type="daterange" start-placeholder="培训时间(开始)" end-placeholder="培训时间(结束)" /> </search-item> </search-area> <!-- 表格数据展示 --> <table-container> <!-- 表头区域 --> <template #btns-right> <icon-button icon="icon-export" title="导出" @click="batchExportList" /> <icon-button v-if="proxy.hasPerm('/resource/person/trainning/add')" icon="icon-add" title="新建" @click="addTrain" /> </template> <!-- 表格区域 --> <normal-table id="registerTabel" :data="list" :total="total" :columns="columns" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" :is-showmulti-select="true" @change="changePage" @multi-select="handleSelectionChange" > <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 fixed="right" label="操作" align="center" width="130"> <template #default="{ row }"> <el-button v-if="proxy.hasPerm('/resource/person/trainning/edit')" size="small" type="primary" link @click="update(row)"> 编辑 </el-button> <el-button size="small" type="primary" link @click="detail(row)"> 详情 </el-button> <el-button v-if="proxy.hasPerm('/resource/person/trainning/del')" size="small" type="danger" :disabled="row.confirmCount > 1" link @click="deleteTrainSignById(row.id, row.fileCode)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>