<!-- 任务监测列表 -->
<script lang="ts" setup name="EquipmentMonitorTaskList">
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { DateModelType } from 'element-plus'
import type { IList, IListQuery } from './task-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { exportFile } from '@/utils/exportUtils'
import { batchDelete, exportMonitorTaskList, getMonitorTaskList } from '@/api/equipment/monitor/task'
const $router = useRouter()
const loadingTable = ref(false)
// 查询条件
const listQuery: Ref<IListQuery> = ref({
taskDateEnd: '', // 任务时间结束
taskDateStart: '', // 任务时间开始
taskName: '', // 任务名称
taskNo: '', // 任务编号
limit: 20,
offset: 1,
})
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
// 表头
const columns = ref<TableColumn[]>([
{ text: '任务代号', value: 'taskNo', align: 'center', width: '160' },
{ text: '任务名称', value: 'taskName', align: 'center' },
{ text: '任务时间', value: 'taskDate', align: 'center', width: '180' },
{ text: '监测人员', value: 'monitorStaff', align: 'center' },
{ text: '备注', value: 'remark', align: 'center' },
])
const list = ref<IList[]>([]) // 列表
const total = ref(0) // 数据总条数
// 选中的内容
const checkoutList = ref<string[]>([])
// ---------------------------------------------------------------------------------------------------------
// 多选发生改变时
function handleSelectionChange(e: any) {
checkoutList.value = e.map((item: { id: string }) => item.id)
}
// 数据查询
function fetchData(isNowPage = false) {
loadingTable.value = true
if (!isNowPage) {
// 是否显示当前页,否则跳转第一页
listQuery.value.offset = 1
}
getMonitorTaskList(listQuery.value).then((response) => {
list.value = response.data.rows
total.value = parseInt(response.data.total)
loadingTable.value = false
})
}
// 清除条件
const clearList = () => {
listQuery.value = {
taskDateEnd: '', // 任务时间结束
taskDateStart: '', // 任务时间开始
taskName: '', // 任务名称
taskNo: '', // 任务编号
limit: 20,
offset: 1,
}
dateRange.value = ['', '']
fetchData()
}
// 搜索
const searchList = () => {
fetchData(true)
}
// 新建
const add = () => {
$router.push({
path: 'task/add',
})
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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, val: string) => {
switch (val) {
case 'delete':
ElMessageBox.confirm(
'确认删除吗?',
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
},
)
.then(() => {
batchDelete({ ids: [row.id] }).then((res) => {
ElMessage({
type: 'success',
message: '删除成功',
})
fetchData(true)
})
})
break
default:
$router.push({
path: `task/${val}/${row.id}`,
})
break
}
}
// 导出
const exportAll = () => {
const loading = ElLoading.service({
lock: true,
text: '下载中请稍后',
background: 'rgba(255, 255, 255, 0.6)',
})
if (list.value.length > 0) {
const params = {
taskDateEnd: listQuery.value.taskDateEnd, // 任务时间结束
taskDateStart: listQuery.value.taskDateStart, // 任务时间开始
taskName: listQuery.value.taskName, // 任务名称
taskNo: listQuery.value.taskNo, // 任务编号
offset: 1,
limit: 20,
ids: checkoutList.value,
}
exportMonitorTaskList(params).then((res) => {
const blob = new Blob([res.data])
loading.close()
exportFile(blob, '任务监测.xlsx')
})
}
else {
loading.close()
ElMessage.warning('无数据可导出数据')
}
}
// ---------------------------------------钩子----------------------------------------------
watch(dateRange, (val) => {
if (val) {
listQuery.value.taskDateStart = `${val[0]}`
listQuery.value.taskDateEnd = `${val[1]}`
}
else {
listQuery.value.taskDateStart = ''
listQuery.value.taskDateEnd = ''
}
})
onMounted(() => {
fetchData(false)
})
</script>
<template>
<div>
<!-- 布局 -->
<app-container>
<search-area :need-clear="true" @search="searchList" @clear="clearList">
<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-date-picker
v-model="dateRange"
class="short-input"
type="daterange"
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 icon="icon-add" title="新建" type="primary" @click="add" />
<icon-button icon="icon-export" title="导出" type="primary" @click="exportAll" />
</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="150"
>
<template #default="{ row }">
<el-button
size="small"
type="primary"
link
@click="handleEdit(row, 'detail')"
>
查看
</el-button>
<el-button
size="small"
link
type="primary"
@click="handleEdit(row, 'edit')"
>
编辑
</el-button>
<el-button
size="small"
type="danger"
link
@click="handleEdit(row, 'delete')"
>
删除
</el-button>
</template>
</el-table-column>
</template>
</normal-table>
</table-container>
</app-container>
</div>
</template>