<!-- 设备管理点检查列表 --> <script lang="ts" setup name="ManageCheckList"> import { getCurrentInstance, ref } from 'vue' import type { Ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import dayjs from 'dayjs' import type { IManageChecklist, IManageChecklistQuery } from './checkList_interface' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDeleteCheckInfo, getExportCheckInfoList, getcheckInfoList } from '@/api/device/checkList' import { printJSON } from '@/utils/printUtils' import { exportFile } from '@/utils/exportUtils' // 查询条件 const listQuery: Ref<IManageChecklistQuery> = ref({ checkStartDate: '', // 检查表开始时间 ids: [], // 导出id集合 checkEndDate: '', // 检查表结束时间 checkName: '', // 检查表名称 checkNo: '', // 检查表编号 offset: 1, // 当前页 limit: 20, // 当前页多少条 }) // 表格数据 const list = ref<IManageChecklist[]>([]) // 获取权限 const { proxy } = getCurrentInstance() as any // 总数 const total = ref(0) // 表头 const columns = ref<TableColumn[]>([ { text: '检查表编号', value: 'checkNo', width: '160', align: 'center', }, { text: '检查表名称', value: 'checkName', width: '120', align: 'center', }, { text: '管理点位置', value: 'managerPoinLocation', align: 'center', }, { text: '检查结果', value: 'checkResultName', align: 'center', }, { text: '检查人', value: 'checkPerson', align: 'center', }, { text: '检查日期', value: 'checkDate', align: 'center', }, ]) // 检查开始时间和结束时间 const checkDate = ref('') // 选中的内容 const checkoutList = ref<IManageChecklist[]>([]) // 文件上传input const fileRef = ref() const loadingTable = ref(false) const fetchData = (isNowPage: boolean) => { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } listQuery.value.checkStartDate = checkDate.value[0] || '' listQuery.value.checkEndDate = checkDate.value[1] || '' getcheckInfoList(listQuery.value).then((response) => { list.value = response.data.rows.map((item: any) => { return { ...item, checkDate: dayjs(item.checkDate).format('YYYY-MM-DD'), } }) total.value = response.data.total loadingTable.value = false }) } fetchData(true) // 多选发生改变时 const handleSelectionChange = (e: any) => { checkoutList.value = e.map((item: { id: string }) => item.id) } // 点击编辑id和删除row类型 interface rowReturn { id: string checkName: string } const $router = useRouter() // 点击编辑/详情 const handleEdit = (row: rowReturn, pageType: 'edit' | 'detail') => { $router.push(`/maintenance/manageCheckList/${pageType}/${row.id}`) } // 点击删除 const handleDelete = (index: string, row: rowReturn) => { ElMessageBox.confirm( `确认删除${row.checkName}吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { getDeleteCheckInfo({ id: row.id as string }).then((res) => { if (res.code === 200) { ElMessage({ type: 'success', message: '删除成功', }) fetchData(true) } }) }) } // 点击搜索 const searchList = () => { fetchData(true) } // 点击重置 const clearList = () => { listQuery.value = { checkStartDate: '', // 检查表开始时间 ids: [], // 导出id集合 checkEndDate: '', // 检查表结束时间 checkName: '', // 检查表名称 checkNo: '', // 检查表编号 offset: 1, // 当前页 limit: 20, // 当前页多少条 } checkDate.value = '' fetchData(true) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { listQuery.value.limit = val.size } if (val && val.page) { listQuery.value.offset = val.page } fetchData(true) } // 添加设备管理点检查 const add = () => { $router.push('/maintenance/manageCheckList/add') } const exportAll = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (list.value.length > 0) { getExportCheckInfoList(listQuery.value).then((res) => { const blob = new Blob([res.data]) exportFile(blob, '设备管理点检查列表.xlsx') }) } else { ElMessage.warning('无数据可导出数据') } loading.close() } // 打印列表 function printList() { // 打印列 const properties = columns.value.map((item) => { return { field: item.value, displayName: item.text, } }) if (checkoutList.value.length <= 0 && list.value.length > 0) { printJSON(list.value, properties, '设备管理点检查列表') } else if (checkoutList.value.length > 0) { const printList = list.value.filter((item: IManageChecklist) => checkoutList.value.includes(item)) printJSON(printList, properties, '设备管理点检查列表') } else { ElMessage.warning('无可打印内容') } } </script> <template> <app-container> <search-area :need-clear="true" @search="searchList" @clear="clearList" > <search-item> <el-input v-model.trim="listQuery.checkNo" placeholder="检查表编号" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.checkName" placeholder="检查表名称" clearable /> </search-item> <search-item> <el-date-picker v-model="checkDate" type="datetimerange" range-separator="到" format="YYYY-MM-DD" value-format="YYYY-MM-DD" start-placeholder="检查开始日期" end-placeholder="检查结束日期" /> </search-item> </search-area> <table-container> <template #btns-right> <icon-button v-if="proxy.hasPerm('/device/manage/check/list/add')" icon="icon-add" title="新建" type="primary" @click="add" /> <icon-button v-if="proxy.hasPerm('/device/manage/check/list/export')" icon="icon-export" title="导出" type="primary" @click="exportAll" /> <icon-button v-if="proxy.hasPerm('/device/manage/check/list/print')" icon="icon-print" title="打印" type="primary" @click="printList" /> </template> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable" is-showmulti-select @change="changePage" @multiSelect="handleSelectionChange" > <template #columns> <el-table-column label="操作" align="center" width="140"> <template #default="{ row }"> <el-button size="small" link type="primary" @click="handleEdit(row, 'detail')" > 详情 </el-button> <el-button v-if="proxy.hasPerm('/device/manage/check/list/delete')" size="small" link type="danger" @click="handleDelete(row.$index, row)" > 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>