<!-- 到期提醒 --> <script lang="ts" setup name="RemindList"> import { reactive, ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import dayjs from 'dayjs' import trendChart from './components/trend.vue' import { exportRemind, getRemindList, remindRow } from '@/api/eqpt/device/remind' import { getDictByCode } from '@/api/system/dict' import { exportFile } from '@/utils/exportUtils' import { getDeviceNameList, getModelAllList, getModelList } from '@/api/eqpt/device/model' import { getTaskList } from '@/api/eqpt/device/task' import { getUserDept, getUserDeptSon } from '@/api/system/user' import { toTreeList } from '@/utils/structure' import { getPostList } from '@/api/system/post' import { getDeptTree, getDeptTreeList } from '@/api/system/dept' import useUserStore from '@/store/modules/user' import { keepSearchParams } from '@/utils/keepQuery' const { proxy } = getCurrentInstance() as any onBeforeRouteLeave((to: any) => { keepSearchParams(to.path, 'RemindList') }) const userStore = useUserStore() const listQuery = reactive({ certificateValidEnd: '', certificateValidStart: '', equipmentName: '', equipmentNo: '', usePositionId: '', usageStatus: '', manufactureNo: '', tastEndTime: '', taskStartTime: '', checkDestination: '', // 鉴定去向 deptIds: '', taskId: '', model: '', useSign: '', checkStatus: '', sort: 'desc', orderBy: 'certificate_valid', offset: 1, limit: 20, }) const columns = ref([ // { // text: '统一编号', // value: 'equipmentNo', // align: 'center', // }, { text: '设备名称', value: 'equipmentName', align: 'center', }, { text: '规格型号', value: 'model', align: 'center', }, { text: '出厂编号', value: 'manufactureNo', align: 'center', }, { text: '使用岗位', value: 'usePosition', align: 'center', }, { text: '使用部门', value: 'deptName', align: 'center', }, { text: '计量标识', value: 'meterIdentifyName', align: 'center', width: '90', }, { text: '检定周期', value: 'checkCycle', align: 'center', width: '90', }, ]) const otherColumns = ref([ { text: '使用状态', value: 'usageStatusName', align: 'center', width: '90', }, // { // text: '备注', // value: 'remark', // align: 'center', // }, { text: '参试任务', value: 'taskNames', align: 'center', width: '250', }, { text: '参试任务时间', value: 'taskTimes', align: 'center', }, { text: '检定去向', value: 'checkDestinationName', align: 'center', width: '90', }, { text: '检定状态', value: 'checkStatusName', align: 'center', width: '90', }, ]) const list = ref([]) const total = ref(0) const listLoading = ref(true) // 获取数据 const fetchData = (isNowPage = true) => { listLoading.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.offset = 1 } getRemindList(listQuery).then((response) => { list.value = response.data.rows total.value = parseInt(response.data.total) listLoading.value = false }) } fetchData() // 查询数据 const search = () => { fetchData(false) } // const range = ref() // watch(() => range.value, (newVal) => { // listQuery.certificateValidStart = '' // listQuery.certificateValidEnd = '' // if (Array.isArray(newVal)) { // if (newVal.length) { // listQuery.certificateValidStart = `${newVal[0]} 00:00:00` // listQuery.certificateValidEnd = `${newVal[1]} 23:59:59` // } // } // }, { // deep: true, // }) const datetimerange1 = ref() watch(() => datetimerange1.value, (newVal) => { listQuery.taskStartTime = '' listQuery.tastEndTime = '' if (Array.isArray(newVal)) { if (newVal.length) { listQuery.taskStartTime = `${newVal[0]} 00:00:00` listQuery.tastEndTime = `${newVal[1]} 23:59:59` } } }, { deep: true, }) const reset = () => { // range.value = [] datetimerange1.value = [] listQuery.tastEndTime = '' listQuery.taskStartTime = '' listQuery.certificateValidEnd = '' listQuery.certificateValidStart = '' listQuery.equipmentName = '' listQuery.manufactureNo = '' listQuery.equipmentNo = '' listQuery.usePositionId = '' listQuery.usageStatus = '' listQuery.model = '' listQuery.taskId = '' listQuery.deptIds = '' listQuery.checkStatus = '' listQuery.checkDestination = '' listQuery.useSign = '' listQuery.limit = 20 listQuery.offset = 1 listQuery.sort = 'desc' listQuery.orderBy = 'certificate_valid' search() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size: number; page: number }) => { if (val && val.size) { listQuery.limit = val.size } if (val && val.page) { listQuery.offset = val.page } fetchData() } // 表格被选中的行 const selectList = ref<any[]>([]) // 表格多选 const multiSelect = (row: any[]) => { selectList.value = row } const $router = useRouter() const detail = (row: any) => { $router.push({ path: '/dremindlist/detail', query: { row: JSON.stringify(row), id: row.id, statusName: '全部', equipmentType: '1', }, }) } // 提醒 const remind = (row: any) => { ElMessageBox.confirm( '确认提醒吗?', '确认', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then((res) => { remindRow({ equipmentId: row.id }).then(() => { ElMessage.success('操作成功') search() }) }) } // 导出列表 const exportList = () => { if (list.value.length) { const loading = ElLoading.service({ lock: true, text: 'Loading', background: 'rgba(255, 255, 255, 0.8)', }) const data = { ...listQuery, offset: undefined, limit: undefined, ids: selectList.value.map(item => item.id), } exportRemind(data).then((res) => { exportFile(res.data, '到期提醒') loading.close() }) .catch((_) => { loading.close() }) } else { ElMessage.warning('无可导出内容') } } // 设备使用状态 const useStatusList = ref<{ id: string; value: string; name: string }[]>() // 使用状态 const checkDirectionList = ref<{ id: string; value: string; name: string }[]>() // 检定去向 const remindList = ref<{ id: string; value: string; name: string }[]>() // 状态 // 任务列表 const taskList = ref<{ id: string; value: string; name: string }[]>([]) // 设备名称 const deviceNameList = ref<string[]>([]) // 规格型号 const modelList = ref<any[]>([]) const allList = ref<any[]>([]) // 使用岗位 const usePositionList = ref<any[]>([]) // 部门 const deptList = ref<{ id: string; value: string; name: string }[]>([]) // 设备在用信息 const inUseList = ref<{ id: string; value: string; name: string }[]>() const fetchStatusList = () => { getDictByCode('eqptDeviceUseStatus').then((res) => { const arr = ['在用', '禁用', '延用'] useStatusList.value = res.data.filter((item: any) => arr.includes(item.name)) }) // 设备名称 getDeviceNameList({ equipmentType: '1' }).then((res) => { deviceNameList.value = res.data }) // 规格型号 getModelAllList({ equipmentType: '1' }).then((res) => { allList.value = res.data modelList.value = res.data.map((item: any) => item.model).sort() }) // 参试任务 getTaskList({ limit: 9999, offset: 1 }).then((res) => { taskList.value = res.data.rows.map((item: any) => ({ name: item.taskName, value: item.id, id: item.id })) }) // 检定去向 getDictByCode('eqptCheckDirection').then((res) => { checkDirectionList.value = res.data }) // 状态 getDictByCode('eqptRemindStatus').then((res) => { remindList.value = res.data }) // 获取当前用户所在单位 getDeptTreeList({ pid: '0' }).then((res1) => { deptList.value = toTreeList(res1.data.map((item: any) => ({ ...item, label: item.name, value: item.id }))) as any[] }) // getUserDept().then((res) => { // // getDeptTree({ pid: '0' }).then((res1) => { // // deptList.value = res1.data.filter((item: any) => item.pids.split(',').length === 3 && item.pid !== '0').map((item: any) => ({ id: item.id, value: item.id, name: item.fullName })) // // }) // // getUserDeptSon({ }).then((res) => { // // deptList.value = res.data.map((item: any) => ({ id: item.id, value: item.id, name: item.fullName })) // // console.log(deptList.value, 'deptList.value') // // getDeptTreeList({ pid: res.data.id }).then((res) => { // // deptList.value = toTreeList(res.data.map((item: any) => ({ ...item, label: item.name, value: item.id }))) as any // // }) // }) // }) // 使用岗位 getPostList({}).then((res) => { usePositionList.value = res.data }) // 在用信息 getDictByCode('eqptDeviceInUse').then((res) => { inUseList.value = res.data }) } fetchStatusList() // 列表图表切换 const showTable = ref(true) const changeTable = () => { showTable.value = !showTable.value } // 时间在一个之内标红 const rowClassName = (data: any) => { const diff = dayjs(data).diff(new Date().getTime(), 'day') if (diff < 30) { return 'danger-class' } else { return '' } } // 监听设备名称下拉框,修改规格型号 watch(() => listQuery.equipmentName, (newVal) => { if (newVal) { listQuery.model = '' // 修改规格型号和辅助字段列表 const data = allList.value.filter(item => item.equipmentName === newVal) modelList.value = Array.from(new Set(data.filter(item => item.model).map(item => item.model))).sort() } else { listQuery.model = '' modelList.value = Array.from(new Set(allList.value.filter(item => item.model).map(item => item.model))).sort() } }) onActivated(() => { // 从编辑或者新增页面回来需要重新获取列表数据 // $router.options.history.state.forward 上一次路由地址 if (!($router.options.history.state.forward as string || '').includes('detail')) { console.log('需要重新获取列表') fetchData(false) } }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="reset"> <!-- <search-item> <el-input v-model.trim="listQuery.equipmentNo" placeholder="统一编号" clearable /> </search-item> --> <search-item> <el-select v-model.trim="listQuery.equipmentName" filterable placeholder="设备名称" clearable> <el-option v-for="(item, index) in deviceNameList" :key="index" :label="item" :value="item" /> </el-select> </search-item> <search-item> <el-select v-model.trim="listQuery.model" filterable placeholder="规格型号" clearable> <el-option v-for="item in modelList" :key="item" :label="item" :value="item" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" clearable /> </search-item> <!-- <search-item> <el-input v-model.trim="listQuery.equipmentName" placeholder="设备名称" clearable /> </search-item> --> <search-item> <!-- <dept-select v-model="listQuery.deptIds" placeholder="使用部门" /> --> <!-- <el-select v-model="listQuery.deptId" filterable placeholder="使用部门" style="width: 100%;" clearable> <el-option v-for="item in deptList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> --> <el-tree-select v-model="listQuery.deptIds" :data="deptList" :render-after-expand="false" check-strictly placeholder="使用部门" /> </search-item> <search-item> <!-- <el-input v-model.trim="listQuery.usePosition" placeholder="使用岗位" clearable /> --> <el-select v-model="listQuery.usePositionId" placeholder="使用岗位" clearable style="width: 100%;"> <el-option v-for="item in usePositionList" :key="item.id" :label="item.positionName" :value="item.id" /> </el-select> </search-item> <!-- <search-item> <el-date-picker v-model="range" type="daterange" value-format="YYYY-MM-DD" format="YYYY-MM-DD" range-separator="至" start-placeholder="证书有效期开始时间" end-placeholder="证书有效期结束时间" /> </search-item> --> <search-item> <el-date-picker v-model="listQuery.certificateValidStart" type="date" placeholder="证书有效期开始时间" value-format="YYYY-MM-DD 00:00:00" format="YYYY-MM-DD" clearable /> </search-item> <search-item> <el-date-picker v-model="listQuery.certificateValidEnd" type="date" placeholder="证书有效期结束时间" value-format="YYYY-MM-DD 23:59:59" format="YYYY-MM-DD" clearable /> </search-item> <search-item> <el-select v-model="listQuery.checkDestination" placeholder="检定去向" clearable style="width: 100%;"> <el-option v-for="item in checkDirectionList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.checkStatus" placeholder="状态" clearable style="width: 100%;"> <el-option v-for="item in remindList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.usageStatus" placeholder="使用状态" clearable style="width: 100%;"> <el-option v-for="item in useStatusList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.useSign" placeholder="在用信息" clearable> <el-option v-for="item in inUseList" :key="item.value" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.taskId" placeholder="参试任务" clearable> <el-option v-for="item in taskList" :key="item.value" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-date-picker v-model="datetimerange1" type="daterange" value-format="YYYY-MM-DD" format="YYYY-MM-DD" range-separator="至" start-placeholder="参试任务开始时间" end-placeholder="参试任务结束时间" clearable /> </search-item> </search-area> <table-container> <template #btns-right> <icon-button icon="icon-change" title="切换" @click="changeTable" /> <icon-button v-if="showTable" icon="icon-export" title="导出" @click="exportList" /> </template> <!-- 普通表格 --> <normal-table v-if="showTable" :data="list" :total="total" :columns="columns as any" :query="listQuery" :list-loading="listLoading" :is-showmulti-select="true" :is-multi="true" @change="changePage" @multi-select="multiSelect" > <template #columns> <el-table-column label="证书有效期" align="center"> <template #default="scope"> <span :class="rowClassName(scope.row.certificateValid)">{{ scope.row.certificateValid }}</span> </template> </el-table-column> <el-table-column v-for="item in otherColumns" :key="item.text" :width="item.width" :label="item.text" :prop="item.value" align="center" /> <el-table-column label="操作" width="140" align="center"> <template #default="scope"> <el-button link type="primary" size="small" @click="detail(scope.row)"> 查看 </el-button> <el-button v-if="proxy.hasPerm('/tested/device/remind/remind')" link type="primary" size="small" @click="remind(scope.row)" > 提醒 </el-button> </template> </el-table-column> </template> </normal-table> <trend-chart v-else /> </table-container> </app-container> </template> <style scoped lang="scss"> .el-table .danger-class { --el-table-tr-bg-color: red; } .danger-class { color: red; } </style>