<!-- 巡检任务列表页 --> <script name="TaskList" setup lang="ts"> import { getCurrentInstance, onMounted, ref, watch } from 'vue' import type { Ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { DateModelType } from 'element-plus' import type { dictType } from '../../../global' import type { IList, IListQuery } from './task-interface' import { getDictByCode } from '@/api/system/dict' import { exportFile } from '@/utils/exportUtils' import type { TableColumn } from '@/components/NormalTable/table_interface' const $router = useRouter() const { proxy } = getCurrentInstance() as any // 查询条件 const listQuery: Ref<IListQuery> = ref({ taskNo: '', // 巡检任务编号 taskName: '', // 巡检任务名称 plateNo: '', // 巡检车牌号 model: '', // 车载云台型号 startTime: '', // 巡检开始时间 endTime: '', // 巡检结束时间 km: '', // 巡检公里 status: '', // 巡检状态 offset: 1, limit: 20, }) const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading // 表头 const columns = ref<TableColumn[]>([ { text: '巡检任务编号', value: 'taskNo', align: 'center', width: '160' }, { text: '巡检任务名称', value: 'taskName', align: 'center' }, { text: '巡检车牌号', value: 'plateNo', align: 'center' }, { text: '车载云台型号', value: 'model', align: 'center' }, { text: '巡检开始时间', value: 'startTime', align: 'center', width: '180' }, { text: '巡检结束时间', value: 'endTime', align: 'center', width: '180' }, { text: '巡检公里(km)', value: 'km', align: 'center' }, { text: '巡检状态', value: 'status', align: 'center', width: '90' }, ]) const list = ref<IList[]>([]) // 表格数据 // 筛选时间段数据 const dateRange = ref<[DateModelType, DateModelType]>(['', '']) // 选中的内容 const checkoutList = ref<string[]>([]) // 时间变更 watch(dateRange, (val) => { if (val) { listQuery.value.startTime = `${val[0]}` listQuery.value.endTime = `${val[1]}` } else { listQuery.value.startTime = '' listQuery.value.endTime = '' } }) // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } list.value = [ { id: '1', // 主键 taskNo: '202304120001', // 巡检任务编号 taskName: '永定路巡检任务', // 巡检任务名称 plateNo: '京E 72314', // 巡检车牌号 model: 'czyt20230001', // 车载云台型号 startTime: '2023-04-12 10:00:00', // 巡检开始时间 endTime: '2023-04-12 10:59:00', // 巡检结束时间 km: '10', // 巡检公里 status: '已完成', // 巡检状态 }, ] // total.value = parseInt(response.data.total) loadingTable.value = false } // 搜索 const searchList = () => { fetchData(true) } // 重置 const reset = () => { listQuery.value = { taskNo: '', // 巡检任务编号 taskName: '', // 巡检任务名称 plateNo: '', // 巡检车牌号 model: '', // 车载云台型号 startTime: '', // 巡检开始时间 endTime: '', // 巡检结束时间 km: '', // 巡检公里 status: '', // 巡检状态 offset: 1, limit: 20, } dateRange.value = ['', ''] // 时间清空 fetchData(true) } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } // 导出 const exportList = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (list.value.length > 0) { const params = { taskNo: listQuery.value.taskNo, // 巡检任务编号 taskName: listQuery.value.taskName, // 巡检任务名称 plateNo: listQuery.value.plateNo, // 巡检车牌号 model: listQuery.value.model, // 车载云台型号 startTime: listQuery.value.startTime, // 巡检开始时间 endTime: listQuery.value.endTime, // 巡检结束时间 km: listQuery.value.km, // 巡检公里 status: listQuery.value.status, // 巡检状态 offset: 1, limit: 20, ids: checkoutList.value, } // 调导出接口 // exportBusinessSettlementList(params).then((res) => { // const blob = new Blob([res.data]) // exportFile(blob, '巡检任务列表.xlsx') // }) } else { ElMessage.warning('无数据可导出数据') } loading.close() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 handleEdit = (row: IList, pageType: 'edit' | 'detail') => { // $router.push({ path: `/businessSettlement/${pageType}/${row.id}` }) } // 删除 const deleteList = (id: string) => { ElMessageBox.confirm( '确认删除吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { // 删除逻辑 }) } const inspectionStatusMap = ref<dictType[]>([]) // 合同类型 // 查询字典 const getDict = async () => { // 巡检状态 getDictByCode('inspectionStatus').then((response) => { inspectionStatusMap.value = response.data }) } onMounted(async () => { await getDict() fetchData(true) // 获取数据 }) </script> <template> <!-- 布局 --> <app-container> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item> <el-input v-model.trim="listQuery.taskNo" placeholder="巡检任务编号" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.taskName" placeholder="巡检任务名称" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.plateNo" placeholder="巡检车牌号" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.model" placeholder="车载云台型号" class="short-input" clearable /> </search-item> <search-item> <el-date-picker v-model="dateRange" class="short-input" type="datetimerange" range-separator="至" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="巡检开始时间" end-placeholder="巡检结束时间" /> </search-item> <search-item> <el-select v-model="listQuery.status" class="short-input" placeholder="巡检状态" clearable> <el-option v-for="item in inspectionStatusMap" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> </search-area> <table-container> <template #btns-right> <icon-button icon="icon-delete" title="删除" type="primary" @click="deleteList" /> <icon-button icon="icon-export" title="导出" type="primary" @click="exportList" /> </template> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange" > <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column label="操作" align="center" fixed="right" width="120"> <template #default="{ row }"> <el-button size="small" link type="primary" @click="handleEdit(row, 'detail')"> 巡检详情 </el-button> <el-button size="small" type="primary" link @click="handleEdit(row, 'edit')"> 编辑 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template> <style lang="scss" scoped> // 样式 </style>