<!-- 故障维修列表页 --> <script lang="ts" setup name="DeviceMainList"> import { ElMessage, ElMessageBox } from 'element-plus' import { deleteMaintain, getMaintainListPage } from '@/api/eqpt/status/maintain' import { getDeviceNameList, getModelAllList } from '@/api/eqpt/device/model' import { getPostList } from '@/api/system/post' import { getAdminDept, getUserDept } from '@/api/system/user' import { toTreeList } from '@/utils/structure' import { getDeptTreeList } from '@/api/system/dept' import { keepSearchParams } from '@/utils/keepQuery' const { proxy } = getCurrentInstance() as any const $router = useRouter() // 查询条件 const listQuery = reactive({ manufactureNo: '', usePositionId: '', createUserName: '', createTimeStart: '', createTimeEnd: '', deptId: '', companyId: '', equipmentName: '', model: '', offset: 1, limit: 20, }) onBeforeRouteLeave((to: any) => { keepSearchParams(to.path, 'DeviceMainList') }) // 申请开始结束时间 const datetimerange = ref() watch(() => datetimerange.value, (newVal) => { listQuery.createTimeStart = '' listQuery.createTimeEnd = '' if (Array.isArray(newVal)) { if (newVal.length) { listQuery.createTimeStart = `${newVal[0]} 00:00:00` listQuery.createTimeEnd = `${newVal[1]} 23:59:59` } } }) const columns = ref([ { text: '设备名称', value: 'equipmentName', align: 'center', }, { text: '规格型号', value: 'model', align: 'center', }, { text: '出厂编号', value: 'manufactureNo', align: 'center', }, { text: '生产厂家', value: 'manufacturer', align: 'center', }, { text: '所在单位', value: 'companyName', align: 'center', }, { text: '使用部门', value: 'deptName', align: 'center', }, { text: '使用岗位', value: 'usePosition', align: 'center', }, { text: '维修内容', value: 'maintainContent', align: 'center', }, { text: '申请人', value: 'createUserName', align: 'center', }, { text: '申请时间', value: 'createTime', align: 'center', }, ]) const list = ref([]) const total = ref(0) const listLoading = ref(true) // 获取列表数据 const fetchData = (isNowPage = true) => { listLoading.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.offset = 1 } getMaintainListPage(listQuery).then((response) => { list.value = response.data.rows total.value = parseInt(response.data.total) listLoading.value = false }).catch(() => { listLoading.value = false }) } // 查询数据 const search = () => { fetchData(false) } search() // 重置 const reset = () => { datetimerange.value = '' listQuery.manufactureNo = '' listQuery.createTimeEnd = '' listQuery.createTimeStart = '' listQuery.usePositionId = '' listQuery.equipmentName = '' listQuery.createUserName = '' listQuery.companyId = '' listQuery.deptId = '' listQuery.model = '' listQuery.offset = 1 listQuery.limit = 20 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 handler = (row: any, type: string) => { $router.push({ path: `/maintainpage/${type}`, query: { row: JSON.stringify(row), id: row.id, }, }) } // 删除 const del = (row: any) => { ElMessageBox.confirm( '确认删除此申请吗?', '确认', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { deleteMaintain(row.id).then((res) => { ElMessage.success('操作成功') search() }) }) } // 获取字典 // 设备名称 const deviceNameList = ref<string[]>([]) // 规格型号 const modelList = ref<any[]>([]) const modelListAll = ref<any[]>([]) // 所在单位 const companyList = ref<{ id: string; value: string; name: string }[]>([]) // 使用部门 const deptList = ref<{ id: string; value: string; name: string }[]>([]) // 使用岗位 const usePositionList = ref<any[]>([]) const fetchDict = () => { // 设备名称 getDeviceNameList({ equipmentType: '1' }).then((res) => { deviceNameList.value = res.data }) // 规格型号及辅助字段 getModelAllList({ equipmentType: '1' }).then((res) => { modelList.value = Array.from(new Set(res.data.filter((item: any) => item.model).map((item: any) => item.model))).sort() modelListAll.value = res.data }) // 单位 getUserDept().then((res) => { if (res.data.fullName === '顶级' || res.data.version === '1' || res.data.version === 1) { getAdminDept({}).then((res) => { companyList.value = res.data.map((item: any) => ({ id: item.id, value: item.id, name: item.fullName })) }) } else { companyList.value = [ { name: res.data.fullName, value: res.data.id, id: res.data.id, }, ] } }) // 使用岗位 getPostList({}).then((res) => { usePositionList.value = res.data }) } fetchDict() watch(() => listQuery.equipmentName, (newVal) => { listQuery.model = '' if (newVal) { modelList.value = Array.from(new Set(modelListAll.value.filter((item: any) => item.equipmentName === newVal && item.model).map((item: any) => item.model))).sort() } else { modelList.value = Array.from(new Set(modelListAll.value.filter((item: any) => item.model).map((item: any) => item.model))).sort() } }) // 监听单位,修改部门 watch(() => listQuery.companyId, (newVal) => { listQuery.deptId = '' if (newVal) { getDeptTreeList({ pid: newVal }).then((res) => { deptList.value = toTreeList(res.data.map((item: any) => ({ ...item, label: item.name, value: item.id }))) as any[] }) } else { deptList.value = [] } }, { deep: true, }) </script> <template> <app-container> <search-area :need-clear="true" @search="search" @clear="reset"> <search-item> <el-select v-model.trim="listQuery.equipmentName" filterable placeholder="设备名称" clearable> <el-option v-for="item in deviceNameList" :key="item" :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-select v-model="listQuery.companyId" clearable filterable placeholder="所在单位"> <el-option v-for="item in companyList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </search-item> <search-item> <el-tree-select v-model="listQuery.deptId" style="width: 100%;" :data="deptList" :render-after-expand="false" check-strictly placeholder="部门" /> </search-item> <search-item> <el-select v-model="listQuery.usePositionId" filterable clearable placeholder="使用岗位"> <el-option v-for="item in usePositionList" :key="item.id" :label="item.positionName" :value="item.id" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.createUserName" placeholder="申请人" clearable /> </search-item> <search-item> <el-date-picker v-model="datetimerange" type="daterange" value-format="YYYY-MM-DD" format="YYYY-MM-DD" range-separator="至" start-placeholder="申请开始时间" end-placeholder="申请结束时间" /> </search-item> </search-area> <table-container> <template #btns-right> <!-- v-if="proxy.hasPerm(permUrl.add)" --> <icon-button icon="icon-add" title="新增" @click="handler({}, 'create')" /> </template> <normal-table :data="list" :total="total" :columns="columns as any" :query="listQuery" :list-loading="listLoading" :is-showmulti-select="true" @change="changePage" > <template #columns> <el-table-column label="操作" width="160" align="center"> <template #default=" scope "> <el-button link type="primary" size="small" @click="handler(scope.row, 'detail')"> 查看 </el-button> <el-button link type="primary" size="small" @click="handler(scope.row, 'update')"> 编辑 </el-button> <el-button link type="danger" size="small" @click="del(scope.row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>