<!-- 参试任务 --> <script lang="ts" setup name="DeviceModelList"> import { reactive, ref, watch } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import { deleteModel, exportModelList, getDeviceNameList, getModelAllList, getModelList } from '@/api/eqpt/device/model' import { exportFile } from '@/utils/exportUtils' import { getDictByCode } from '@/api/system/dict' const emits = defineEmits(['add']) const { proxy } = getCurrentInstance() as any const dialogFormVisible = ref(false) const listQuery = reactive({ category: '', equipmentName: '', helpInstruction: '', model: '', offset: 1, limit: 20, }) const columns = ref([ { text: '型号规格编号', value: 'modelNo', align: 'center', }, { text: '设备名称', value: 'equipmentName', align: 'center', }, { text: '型号规格', value: 'model', align: 'center', }, { text: '辅助字段', value: 'helpInstruction', align: 'center', }, { text: '设备分类', value: 'categoryName', align: 'center', }, { text: '检定周期', value: 'checkCycle', align: 'center', }, { text: '使用说明书', value: 'instructionsFile', align: 'center', }, { text: '备注', value: 'remark', 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 } getModelList(listQuery).then((response) => { list.value = response.data.rows total.value = parseInt(response.data.total) listLoading.value = false }) } fetchData() // 查询数据 const search = () => { fetchData(false) } // 重置 const reset = () => { listQuery.category = '' listQuery.equipmentName = '' listQuery.helpInstruction = '' 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 selectList = ref<any[]>([]) // 表格多选 const multiSelect = (row: any[]) => { selectList.value = row } // 获取下拉列表相关 // 设备名称 const deviceNameList = ref<{ id: string; value: string; name: string }[]>([]) // 设备分类 const deviceTypeList = ref<{ id: string; value: string; name: string }[]>([]) // 规格型号 const modelList = ref<any[]>([]) // 辅助字段 const helpList = ref<any[]>([]) const allList = ref<any[]>([]) const fetchSelect = () => { // 设备分类 getDictByCode('eqptDeviceType').then((res) => { deviceTypeList.value = res.data }) // 设备名称 getDeviceNameList().then((res) => { deviceNameList.value = res.data }) // 规格型号及辅助字段 getModelAllList({}).then((res) => { allList.value = res.data modelList.value = res.data helpList.value = res.data.filter(item => item.helpInstruction) }) } fetchSelect() // 监听设备名称下拉框,修改规格型号和辅助字段 watch(() => listQuery.equipmentName, (newVal) => { if (newVal) { listQuery.helpInstruction = '' listQuery.model = '' // 修改规格型号和辅助字段列表 const data = allList.value.filter(item => item.equipmentName === newVal) modelList.value = data helpList.value = data.filter(item => item.helpInstruction) } }) // 监听规格型号下拉框,修改辅助字段 watch(() => listQuery.model, (newVal) => { if (newVal) { listQuery.helpInstruction = '' // 修改规格型号和辅助字段列表 console.log(helpList.value, 'helpList.value') helpList.value = helpList.value.filter(item => item.model === newVal) } }) // 点击保存 const submitForm = () => { // 多选 if (selectList.value.length) { emits('add', selectList.value) dialogFormVisible.value = false reset() } else { ElMessage.warning('请先选择设备') } } // 取消 const resetForm = () => { dialogFormVisible.value = false reset() } // 初始化 const initDialog = () => { // reset() dialogFormVisible.value = true } fetchData() defineExpose({ initDialog, list }) </script> <template> <el-dialog v-model="dialogFormVisible" title="选择设备" width="65%" style="z-index: 999999;"> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="reset"> <search-item> <el-select v-model.trim="listQuery.equipmentName" 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" placeholder="规格型号" clearable> <el-option v-for="item in modelList" :key="item.id" :label="item.model" :value="item.model" /> </el-select> </search-item> <search-item> <el-select v-model.trim="listQuery.helpInstruction" placeholder="辅助字段" clearable> <el-option v-for="item in helpList" :key="item.id" :label="item.helpInstruction" :value="item.helpInstruction" /> </el-select> </search-item> <search-item> <el-select v-model.trim="listQuery.category" placeholder="设备分类" clearable> <el-option v-for="item in deviceTypeList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> </search-area> <table-container> <!-- 普通表格 --> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="listLoading" :is-showmulti-select="true" :is-multi="true" @change="changePage" @multi-select="multiSelect" /> </table-container> <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>