<script lang="ts" setup name="ListPlan"> import type { Ref } from 'vue' import { reactive, ref } from 'vue' import { Delete } from '@element-plus/icons-vue' import { ElLoading, ElMessage } from 'element-plus' import type { IlistQuery, IlistType } from './plan_interface' import PlanAdd from './planAdd.vue' import { exportExcel } from '@/utils/exportXlsx' import { getDeptTree, getListDelete, getPlanList } from '@/api/system/plan' const listQuery: Ref<IlistQuery> = ref({ trainTime: '', createTime: '', deptId: '', effectiveCompany: '', director: '', offset: 1, limit: 10, }) const checkoutList = ref([]) const list = ref([]) // 删除id const deleteId = ref('') const isPopconfirmShow = ref(false) const total = ref(0) const show = ref(true) const infoId = ref('') const buttonType = ref('') const fetchData = (isNowPage: boolean) => { if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } getPlanList(listQuery.value).then((response) => { list.value = response.data.rows total.value = parseInt(response.data.total) }) } fetchData(true) // 主管部门下拉框 const options = ref([]) // 表头 const columns = ref([ { text: '计划编号', value: 'planNo', width: '160', }, { text: '培训名称', value: 'planName', width: '120', }, { text: '培训对象', value: 'trainPerson', }, { text: '培训人数', value: 'trainNumber', }, { text: '培训学时', value: 'trainHour', }, { text: '培训时间', value: 'trainTime', width: '180', }, { text: '主管部门', value: 'deptName', width: '120', }, { text: '实施单位', value: 'effectiveCompany', }, { text: '培训内容', value: 'trainContent', }, { text: '创建时间', value: 'createTime', width: '180', }, { text: '备注', value: 'remark', }, ]) // 搜索 const searchList = () => { fetchData(true) } // 重置 const clearList = () => { listQuery.value = { trainTime: '', createTime: '', deptId: '', effectiveCompany: '', director: '', offset: 1, limit: 10, } } // 导出 const exportExcelBtn = () => { const loading = ElLoading.service({ lock: true, text: 'Loading', background: 'rgba(255, 255, 255, 0.8)', }) if (checkoutList.value.length <= 0) { exportExcel({ json: list.value.map((item: IlistType, index: number) => ({ index: index + 1, planNo: item.planNo, planName: item.planName, trainPerson: item.trainPerson, trainNumber: item.trainNumber, trainHour: item.trainHour, trainTime: item.trainTime, deptName: item.deptName, effectiveCompany: item.effectiveCompany, director: item.director, trainContent: item.trainContent, createTime: item.createTime, remark: item.remark })), name: '培训计划', titleArr: ['序号', '培训计划编号', '培训名称', '培训对象', '培训人数', '培训学时', '培训时间', '主管部门', '实施单位', '负责人', '培训内容', '创建时间', '备注'], sheetName: 'sheet1', }) } else { exportExcel({ json: checkoutList.value.map((item: IlistType, index: number) => ({ index: index + 1, planNo: item.planNo, planName: item.planName, trainPerson: item.trainPerson, trainNumber: item.trainNumber, trainHour: item.trainHour, trainTime: item.trainTime, deptName: item.deptName, effectiveCompany: item.effectiveCompany, director: item.director, trainContent: item.trainContent, createTime: item.createTime, remark: item.remark })), name: '培训计划', titleArr: ['序号', '培训计划编号', '培训名称', '培训对象', '培训人数', '培训学时', '培训时间', '主管部门', '实施单位', '负责人', '培训内容', '创建时间', '备注'], sheetName: 'sheet1', }) } loading.close() } // 关闭编辑 const close = () => { show.value = true fetchData(true) } const handleEdit = (index: string, row: object, type: string) => { infoId.value = row.id buttonType.value = type show.value = false } // 点击删除 const handleDelete = (index: string, row: object) => { isPopconfirmShow.value = true deleteId.value = row.id } const handelClick = (text: string) => {} const handleSelectionChange = (e: any) => { checkoutList.value = e } // 分页 const handleSizeChange = (val: number) => { listQuery.value.limit = val fetchData(true) } // 分页 const handleCurrentChange = (val: number) => { listQuery.value.offset = val fetchData(true) } const add = () => { infoId.value = '' buttonType.value = '新建' show.value = false } const exportAll = () => { exportExcelBtn() } // 获取到组织信息 const getDept = () => { const params = { roleId: '', deptType: '', tips: '', } getDeptTree(params).then((response) => { options.value = response.data }) } getDept() const confirmEvent = () => { getListDelete({ id: deleteId.value }).then((res) => { if (res.code === 200) { isPopconfirmShow.value = false fetchData(true) } }) } // 打印 const printObj = ref({ id: 'print', // 需要打印元素的id popTitle: '证书报告模板', // 打印配置页上方的标题 extraHead: '', // 最上方的头部文字,附加在head标签上的额外标签,使用逗号分割 preview: false, // 是否启动预览模式,默认是false previewBeforeOpenCallback() { console.log('正在加载预览窗口!') }, // 预览窗口打开之前的callback previewOpenCallback() { console.log('已经加载完预览窗口,预览打开了!') }, // 预览窗口打开时的callback beforeOpenCallback() { console.log('开始打印之前!') }, // 开始打印之前的callback openCallback() { console.log('执行打印了!') }, // 调用打印时的callback closeCallback() { console.log('关闭了打印工具!') }, // 关闭打印的callback(无法区分确认or取消) clickMounted() { console.log('点击v-print绑定的按钮了!') }, standard: '', extarCss: '', }) </script> <template> <div v-if="show"> <app-container> <search-area @search="searchList"> <search-item> <el-date-picker v-model="listQuery.trainTime" type="datetime" placeholder="培训时间" format="YYYY/MM/DD HH:mm:ss" value-format="YYYY-MM-DD h:m:s" /> </search-item> <search-item> <el-date-picker v-model="listQuery.createTime" type="datetime" placeholder="创建时间" format="YYYY/MM/DD HH:mm:ss" value-format="YYYY-MM-DD h:m:s" /> </search-item> <search-item> <el-select v-model="listQuery.deptId" clearable placeholder="主管部门" size="default" > <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.effectiveCompany" placeholder="实施单位" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.director" placeholder="负责人" clearable /> </search-item> <template #btns> <el-button class="filter-item" type="info" :icon="Delete" :style="{ marginTop: '-10px' }" @click="clearList" > 重置 </el-button> </template> </search-area> <table-container> <template #btns-right> <el-button type="primary" @click="add"> 新建 </el-button> <el-button type="primary" @click="exportAll"> 导出 </el-button> <el-button v-print="printObj" type="primary"> 打印 </el-button> </template> <el-table id="print" :data="list" style="width: 100%;" @selection-change="handleSelectionChange" > <el-table-column type="selection" width="55" /> <el-table-column align="center" label="序号" width="80" type="index" /> <el-table-column v-for="(column, index) in columns" :key="index" :label="column.text" :prop="column.value" :width="column.width" align="center" /> <el-table-column align="center" label="操作" width="240"> <template #default="scope"> <el-button size="small" type="primary" link @click="handleEdit(scope.$index, scope.row, '编辑')" > 编辑 </el-button> <el-button size="small" link type="primary" @click="handleEdit(scope.$index, scope.row, '详情')" > 详情 </el-button> <el-button size="small" link type="danger" @click="handleDelete(scope.$index, scope.row)" > 删除 </el-button> <el-button size="small" link type="primary" > 二维码 </el-button> </template> </el-table-column> </el-table> </table-container> </app-container> <div class="pagination"> <el-pagination v-model:current-page="listQuery.offset" v-model:page-size="listQuery.limit" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" /> </div> </div> <plan-add v-else :info-id="infoId" :button-type="buttonType" @close="close" /> <el-dialog v-model="isPopconfirmShow" title="确认框" width="30%" > <span>确定删除吗?</span> <template #footer> <span class="dialog-footer"> <el-button @click="isPopconfirmShow = false">取消</el-button> <el-button type="primary" @click="confirmEvent"> 确定 </el-button> </span> </template> </el-dialog> </template> <style lang="scss" scoped> .pagination { position: fixed; bottom: 0; } </style>