<!-- 选择设备(设备台账) --> <script lang="ts" setup name="SelectEquipmentDialog"> import { ElMessage } from 'element-plus' import type { Ref } from 'vue' import { ref } from 'vue' import dayjs from 'dayjs' import type { DateModelType } from 'element-plus' import { disableCache } from '@iconify/vue' import { getEquipmentList } from '@/api/equipment/info/book' import type { TableColumn } from '@/components/NormalTable/table_interface' import { SCHEDULE } from '@/utils/scheduleDict' import { getDeptTreeList } from '@/api/system/dept' import { getDictByCode } from '@/api/system/dict' import { getStaffList } from '@/api/resource/register' import { toTreeList } from '@/utils/structure' import type { deptType } from '@/global' const props = defineProps({ isMulti: { // 是否多选 type: Boolean, default: false, }, equipmentName: { type: String, // 设备名称 default: '', }, }) const emits = defineEmits(['confirm']) const dialogFormVisible = ref(false) const labCode = ref('') // 实验室 const groupCode = ref('') // 部门 const changeType = ref('') // 允许筛选条件改变类型 const selectByUseStatus = ref('') // 固定筛选使用状态 // 查询条件 const listQuery = ref({ approvalStatus: '0', // 审批状态类型code,导出接口不用传 groupCode: '', // 部门--后台定义用此字段筛选部门(刘翔) directorId: '', // 负责人id equipmentName: props.equipmentName, // 设备名称 equipmentNo: '', // 设备编号 formId: SCHEDULE.EQUIPMENT_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传 labCode: '', // 实验室 labName: '', // 实验室名称 manufactureNo: '', // 出厂编号 measureValidDateStart: '', // 检定有效期开始 measureValidDateEnd: '', // 检定有效期结束 meterStandardName: '', // 所属标准装置名称 model: '', // 规格型号 manufacturer: '', // 生产厂家 // partType: '', // 参照标准、工作标准和关键测量设备表功能该参数传1(同时approvalStatus参数传0),其余情况不用传该参数 standardType: '', // 标准类型(字典code) traceCompany: '', // 溯源单位 offset: 1, limit: props.isMulti ? 20 : 5, usageStatus: '', // 使用状态 }) // 多选选中的内容 const checkoutList = ref([]) const loadingTable = ref(false) const list = ref([]) // 表格数据 const total = ref(0) 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: 'labCodeName', align: 'center' }, { text: '部门', value: 'groupCodeName', align: 'center' }, { text: '设备单价(万元)', value: 'unitPrice', align: 'center' }, { text: '负责人', value: 'directorName', align: 'center', width: '120' }, { text: '使用状态', value: 'usageStatusName', align: 'center', width: '90' }, { text: '溯源单位', value: 'traceCompany', align: 'center' }, { text: '检定有效期', value: 'measureValidDate', align: 'center', width: '120' }, { text: '所属标准装置', value: 'meterStandardName', align: 'center', width: '220' }, ]) const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 // -----------------------------------------字典-------------------------------------------------------------- const useDeptList = ref<deptType[]>([]) // 所属部门列表 const userList = ref<{ [key: string]: string }[]>([]) // 用户列表 const labDeptList = ref<deptType[]>([]) // 实验室 const usageStatusList = ref<deptType[]>([]) // 使用状态 const standardList = ref<deptType[]>([]) // 标准装置 // 查询字典 const getDict = async () => { // 实验室 getDictByCode('bizGroupCodeEquipment').then((response) => { labDeptList.value = response.data }) // 部门 getDictByCode('bizGroupCode').then((response) => { useDeptList.value = response.data }) // 获取用户列表 getStaffList({ offset: 1, limit: 999999 }).then((res: any) => { userList.value = res.data.rows }) // 使用状态 getDictByCode('bizUsageStatus').then((response) => { usageStatusList.value = response.data }) // 检校标准装置 getDictByCode('bizStandardEquipmentType').then((response) => { standardList.value = response.data.map((item: { name: string }) => { return { value: item.name, } }) }) } // -------------------------------------------------------------------------------------------- // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } if (changeType.value === 'noChange') { listQuery.value.labCode = labCode.value listQuery.value.groupCode = groupCode.value } if (selectByUseStatus.value !== '') { listQuery.value.usageStatus = selectByUseStatus.value } getEquipmentList(listQuery.value).then((response) => { list.value = response.data.rows.map((item: { estimateSignDate: string; agreementAmount: number; measureValidDate: string; labCodeName: string }) => { return { ...item, measureValidDate: item.measureValidDate ? dayjs(item.measureValidDate).format('YYYY-MM-DD') : item.measureValidDate, labCodeName: item.labCodeName === '海口' ? '海口实验室' : item.labCodeName === '西昌' ? '西昌实验室' : item.labCodeName, // 实验室 } }) total.value = parseInt(response.data.total) loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 重置 const clearList = () => { listQuery.value = { approvalStatus: '0', // 审批状态类型code,导出接口不用传 groupCode: '', // 部门--后台定义用此字段筛选部门(刘翔) directorId: '', // 负责人id equipmentName: '', // 设备名称 equipmentNo: '', // 设备编号 formId: SCHEDULE.EQUIPMENT_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传 labCode: '', // 实验室 labName: '', // 实验室名称 manufactureNo: '', // 出厂编号 measureValidDateStart: '', // 检定有效期开始 measureValidDateEnd: '', // 检定有效期结束 meterStandardName: '', // 所属标准装置名称 model: '', // 规格型号 manufacturer: '', // 生产厂家 // partType: '', // 参照标准、工作标准和关键测量设备表功能该参数传1(同时approvalStatus参数传0),其余情况不用传该参数 standardType: '', // 标准类型(字典code) traceCompany: '', // 溯源单位 usageStatus: '', // 使用状态 offset: 1, limit: props.isMulti ? 20 : 5, } dateRange.value = ['', ''] if (changeType.value === 'noChange') { listQuery.value.labCode = labCode.value listQuery.value.groupCode = groupCode.value } fetchData() } // 搜索 const search = () => { fetchData(true) } // 多选选中 const handleSelectionChange = (val: any) => { checkoutList.value = val } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 confirmSelect = () => { if (!checkoutList.value.length) { ElMessage.warning('请选择设备') } else { emits('confirm', checkoutList.value) dialogFormVisible.value = false } } // 取消 const resetForm = () => { dialogFormVisible.value = false clearList() } /** * 弹窗初始化 * @param labCode 实验室 * @param groupCode 部门 * @param noChange 是否实验室和部门固定,不允许改变 * @param selectByUseStatusType 固定筛选使用状态的类型 */ const initDialog = async (labCodeParam = '', groupCodeParam = '', changeTypeParam = '', selectByUseStatusType = '') => { await getDict() listQuery.value.labCode = labCodeParam listQuery.value.groupCode = groupCodeParam labCode.value = labCodeParam// 实验室 groupCode.value = groupCodeParam// 部门 changeType.value = changeTypeParam// 允许筛选条件改变类型 selectByUseStatus.value = selectByUseStatusType dialogFormVisible.value = true fetchData() } // 匹配标准装置输入建议 const querySearchStandard = (queryString: string, cb: any) => { const results = queryString ? standardList.value.filter((item: any) => item.value.includes(queryString)) : standardList.value // 调用 callback 返回建议列表的数据 cb(results) } watch(dateRange, (val) => { if (val) { listQuery.value.measureValidDateStart = `${val[0]}` listQuery.value.measureValidDateEnd = `${val[1]}` } else { listQuery.value.measureValidDateStart = '' listQuery.value.measureValidDateEnd = '' } }) defineExpose({ initDialog }) </script> <template> <el-dialog v-if="dialogFormVisible" v-model="dialogFormVisible" title="选择设备" width="65%"> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="clearList"> <search-item> <el-input v-model.trim="listQuery.equipmentName" 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-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.manufacturer" placeholder="生产厂家" class="short-input" clearable /> </search-item> <search-item> <el-select v-model="listQuery.labCode" placeholder="实验室" class="short-input" filterable clearable :disabled="changeType === 'noChange'" > <el-option v-for="item in labDeptList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.groupCode" placeholder="部门" class="short-input" filterable clearable :disabled="changeType === 'noChange'" > <el-option v-for="item in useDeptList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.directorId" placeholder="负责人" class="short-input" filterable clearable > <el-option v-for="item in userList" :key="item.id" :label="item.staffName" :value="item.id" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.usageStatus" placeholder="使用状态" class="short-input" :disabled="selectByUseStatus !== ''" filterable clearable > <el-option v-for="item in usageStatusList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.traceCompany" 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-item> <el-autocomplete v-model="listQuery.meterStandardName" :fetch-suggestions="querySearchStandard" placeholder="所属标准装置" clearable style="width: 260px;" /> </search-item> <search-item /> </search-area> <!-- 查询结果Table显示 --> <div style="padding: 12px;"> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" is-showmulti-select :list-loading="loadingTable" :is-multi="props.isMulti" :height="520" @change="changePage" @multi-select="handleSelectionChange" > <!-- 序号 --> <template #preColumns> <el-table-column label="#" width="55" align="center" fixed> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> </normal-table> </div> <template #footer> <span class="dialog-footer"> <el-button type="primary" @click="confirmSelect">确认</el-button> <el-button @click="resetForm"> 取消 </el-button> </span> </template> </el-dialog> </template> <style lang="scss" scoped> :deep(.el-radio__label) { display: none; } </style>