<!-- 设备列表弹窗-单选 --> <script lang="ts" setup name="SelectDeviceSinge"> import { ElMessage } from 'element-plus' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import useUserStore from '@/store/modules/user' import { getInfoListPage } from '@/api/eqpt/device/info' import { getDeptTreeList } from '@/api/system/dept' import { toTreeList } from '@/utils/structure' import { getDeviceNameList, getModelAllList, getModelList } from '@/api/eqpt/device/model' import { getAdminDept, getUserDept, getUserDeptSon, getUserList } from '@/api/system/user' import { getPostList } from '@/api/system/post' const $props = defineProps({ // 使用状态列表 // 主要用于 状态管理时 过滤不同的设备使用状态 needStatus: { type: Boolean, default: false, }, // 不同设备状态 // 主要用于 状态管理时 过滤不同的设备使用状态 statusType: { type: String, default: '', }, }) const emits = defineEmits(['add']) const userStore = useUserStore() const dialogFormVisible = ref(false) // 查询条件 const listQuery = ref({ usageStatus: '', equipmentName: '', // 设备名称 model: '', // 规格型号 manufactureNo: '', // 出厂编号 equipmentType: '1', manufacturer: '', // 生产厂家 deptIds: '', // 部门 usePositionId: '', // 使用岗位 certificateValidStart: '', certificateValidEnd: '', checkDestination: '', // 检定去向 limit: 5, offset: 1, }) const loadingTable = ref<boolean>(false) const list = ref([]) // 表格数据 const total = ref(0) const select = ref(-1) // 证书有效期开始结束时间 const datetimerange = ref() watch(() => datetimerange.value, (newVal) => { listQuery.value.certificateValidStart = '' listQuery.value.certificateValidEnd = '' if (Array.isArray(newVal)) { if (newVal.length) { listQuery.value.certificateValidStart = `${newVal[0]} 00:00:00` listQuery.value.certificateValidEnd = `${newVal[1]} 23:59:59` } } }) // 表头 const columns = ref<TableColumn[]>([ { 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: 'directorName', align: 'center', }, { text: '计量标识', value: 'meterIdentifyName', align: 'center', }, { text: '检定(校准)单位', value: 'checkOrganization', align: 'center', }, { text: '证书有效期', value: 'certificateValid', align: 'center', }, ]) const statusDict = ref<{ [key: string]: string[] }>({ 1: ['在用', '禁用', '延用'], // 封存 2: ['禁用', '封存'], // 启封 3: ['在用', '延用'], // 禁用 4: ['在用', '禁用', '封存', '延用'], // 报废 5: ['在用', '禁用'], // 沿用 }) // 获取使用状态列表 const useStatusList = ref() const fetchUseStatus = () => { getDictByCode('eqptDeviceUseStatus').then((res) => { if ($props.needStatus) { useStatusList.value = res.data.filter((item: any) => statusDict.value[$props.statusType].includes(item.name)) } else { useStatusList.value = res.data } }) } // 获取数据列表 const fetchData = () => { fetchUseStatus() select.value = -1 loadingTable.value = true // 判断是否需要加入设备使用状态查询条件 const data = { ...listQuery.value, usageStatusList: [] as string[], } if ($props.needStatus) { switch ($props.statusType) { case '1': data.usageStatusList = ['0', '1', '4'] break case '2': data.usageStatusList = ['1', '3'] break case '3': data.usageStatusList = ['0', '4'] break case '4': data.usageStatusList = ['0', '1', '3', '4'] break case '5': data.usageStatusList = ['0', '1'] break } } getInfoListPage(data, '全部').then((response) => { list.value = response.data.rows total.value = parseInt(response.data.total) loadingTable.value = false }) } // 搜索 const search = () => { fetchData() } // 重置 const reset = () => { datetimerange.value = [] listQuery.value = { usageStatus: '', equipmentName: '', // 设备名称 model: '', // 规格型号 manufactureNo: '', // 出厂编号 equipmentType: '1', manufacturer: '', // 生产厂家 deptIds: '', // 部门 usePositionId: '', // 使用岗位 certificateValidStart: '', certificateValidEnd: '', checkDestination: '', // 检定去向 limit: 5, offset: 1, } search() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 } search() } // 点击保存 const submitForm = () => { if (select.value >= 0) { const device = list.value.filter((item, index) => index == select.value)[0] emits('add', device) dialogFormVisible.value = false reset() } else { ElMessage.warning('请先选择设备') } } // 取消 const resetForm = () => { dialogFormVisible.value = false reset() } // 初始化 const initDialog = () => { // reset() dialogFormVisible.value = true fetchData() // 获取人员列表 } defineExpose({ initDialog }) // 加载组织机构树形下拉 const deptTreeList = ref() // 设备名称 const deviceNameList = ref<string[]>([]) // 设备在用信息 const inUseList = ref<{ id: string; value: string; name: string }[]>() // 规格型号 const modelList = ref<any[]>([]) const allList = ref<any[]>([]) // 部门 const deptList = ref<any[]>([]) // 使用岗位 const usePositionList = ref<any[]>([]) const fetchDeptTree = () => { getDeptTreeList().then((res) => { if (res.data) { // 将列表转树结构 deptTreeList.value = toTreeList(res.data, '0', true) } }) // 在用信息 getDictByCode('eqptDeviceInUse').then((res) => { inUseList.value = res.data }) // 设备名称 getDeviceNameList({ equipmentType: '1' }).then((res) => { deviceNameList.value = res.data }) // 规格型号 getModelAllList({ equipmentType: '1' }).then((res) => { allList.value = res.data modelList.value = Array.from(new Set(res.data.filter((item: any) => item.model).map((item: any) => item.model))).sort() }) // 部门 getUserDept().then((res) => { getDeptTreeList({ pid: res.data.id }).then((res) => { deptList.value = toTreeList(res.data.map((item: any) => ({ ...item, label: item.name, value: item.id }))) }) }) // 使用岗位 getPostList({}).then((res) => { usePositionList.value = res.data }) } fetchDeptTree() watch(() => listQuery.value.equipmentName, (newVal) => { if (newVal) { listQuery.value.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.value.model = '' modelList.value = Array.from(new Set(allList.value.filter(item => item.model).map(item => item.model))).sort() } }) </script> <template> <el-dialog v-model="dialogFormVisible" title="选择设备" width="75%"> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="reset"> <el-select v-model.trim="listQuery.equipmentName" clearable filterable placeholder="设备名称"> <el-option v-for="(item, index) in deviceNameList" :key="index" :label="item" :value="item" /> </el-select> <search-item> <el-select v-model.trim="listQuery.model" clearable filterable placeholder="规格型号"> <el-option v-for="item in modelList" :key="item" :label="item" :value="item" /> </el-select> </search-item> <search-item v-if="$props.needStatus"> <el-select v-model="listQuery.usageStatus" placeholder="使用状态" clearable> <el-option v-for="item in useStatusList" :key="item.value" :label="item.name" :value="item.value" /> </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.manufacturer" placeholder="生产厂家" clearable /> </search-item> <search-item> <el-tree-select v-model="listQuery.deptIds" style="width: 100%;" :data="deptList" :render-after-expand="false" check-strictly placeholder="部门" /> </search-item> <search-item> <el-select v-model.trim="listQuery.usePositionId" clearable filterable placeholder="使用岗位"> <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="datetimerange" type="daterange" value-format="YYYY-MM-DD" format="YYYY-MM-DD" range-separator="至" start-placeholder="证书有效期开始时间" end-placeholder="证书有效期结束时间" clearable /> </search-item> <search-item> <el-select v-model="listQuery.checkDestination" filterable clearable placeholder="检定去向"> <el-option label="计量室" value="1" /> <el-option label="外送" value="2" /> </el-select> </search-item> </search-area> <!-- 查询结果Table显示 --> <div style="padding: 12px;"> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable" :page-sizes="[5, 10, 20]" @change="changePage" > <template #preColumns> <el-table-column label="" width="55" align="center"> <template #default="scope"> <el-radio v-model="select" :label="scope.$index" :disabled="scope.row.isRadioDisabled" class="radio" /> </template> </el-table-column> <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"> <template #default="scope"> {{ scope.row.checkDestination === '1' ? '计量室' : '外送' }} </template> </el-table-column> </template> </normal-table> </div> <template #footer> <span class="dialog-footer"> <el-button type="primary" @click="submitForm">确认</el-button> <el-button @click="resetForm"> 取消 </el-button> </span> </template> </el-dialog> </template> <style lang="scss" scoped> :deep(.el-radio__label) { display: none; } </style>