<!-- 查询所用设备(测量设备) --> <script setup lang="ts" name="SelectMeasureDevice"> import { ref } from 'vue' import type { Ref } from 'vue' import { ElMessage } from 'element-plus' import dayjs from 'dayjs' import { toTreeList } from '@/utils/structure' import type { TableColumn } from '@/components/NormalTable/table_interface' import type { fixedAssetsParams, fixedAssetsType } from '@/views/device/standingBook/standingBook-interface' import { listPageApi } from '@/api/device/standingBook' import { getDeptTreeList } from '@/api/system/dept' const props = defineProps({ visible: { type: Boolean, default: false, }, isMulti: { type: Boolean, default: false, }, }) const emits = defineEmits(['changeVisible', 'confirmCheckout']) // 查询条件 const searchQuery = ref({ equipmentNo: '', // 设备编号 equipmentName: '', // 名称 mesureType: '', // 检定方式 managerState: '1', // 管理状态 1表示在用(启封) useDept: '', // 使用部门 assetType: '1', // 资产类型 1表示测量设备 equipmentCategory: '', // 设备类别 isCalibrationTestEquipment: '', // 校准/检定设备 isMeasureAccount: '', // 测量工装 isStandardSupportEquipment: '', // 标准配套设备 isFixedAssets: '', // 固定资产 validStartDate: '', // 有效开始日期 validEndDate: '', // 有效结束日期 abc: '', limit: 5, offset: 1, modelNo: '', // 型号 // ids: [] as string[], }) // 表头 const columns = ref<TableColumn[]>([ // { text: '设备编号', value: 'equipmentNo', align: 'center', width: 160 }, { text: '名称', value: 'equipmentName', align: 'center' }, { text: '型号', value: 'modelNo', align: 'center' }, { text: 'ABC', value: 'abc', align: 'center', width: 58 }, // { text: '检定方式', value: 'mesureTypeName', align: 'center', width: 90 }, { text: '出厂编号', value: 'manufacturingNo', align: 'center' }, // { text: '强制检定', value: 'compulsoryVerification', align: 'center', width: 65 }, { text: '测量范围', value: 'mesureRange', align: 'center' }, { text: '管理状态', value: 'managerStateName', align: 'center', width: 100 }, { text: '使用部门', value: 'useDeptName', align: 'center' }, // { text: '使用人', value: 'usePersonName', align: 'center' }, { text: '溯源机构', value: 'mesureDeptName', align: 'center' }, { text: '有效日期', value: 'validDate', align: 'center', width: 120 }, // { text: '备注', value: 'remark', align: 'center' }, ]) // 表格数据 const list = ref<fixedAssetsType[]>([]) // 总数 const total = ref(0) // 表格加载状态 const loadingTable = ref(false) // 选中的内容 const checkoutList = ref<string[]>([]) // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } listPageApi(searchQuery.value).then((res) => { if (res.code === 200) { list.value = res.data.rows.map((item: fixedAssetsType) => { return { ...item, validDate: item.validDate ? dayjs(item.validDate).format('YYYY-MM-DD') : '', } }) total.value = res.data.total } loadingTable.value = false }).catch((_) => { loadingTable.value = false }) } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: any) => { return { ...item, isEdit: false, } }) } // 点击搜索 const searchList = () => { fetchData(true) } // 点击重置 const clearList = () => { searchQuery.value = { equipmentNo: '', // 设备编号 equipmentName: '', // 名称 mesureType: '', // 检定方式 managerState: '', // 管理状态 useDept: '', // 使用部门 assetType: '1', // 资产类型 1表示测量设备 equipmentCategory: '', // 设备类别 isCalibrationTestEquipment: '', // 校准/检定设备 isMeasureAccount: '', // 测量工装 isStandardSupportEquipment: '', // 标准配套设备 isFixedAssets: '', // 固定资产 validStartDate: '', // 有效开始日期 validEndDate: '', // 有效结束日期 abc: '', limit: 5, offset: 1, modelNo: '', // 型号 // ids: [] as string[], } fetchData(true) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.value.limit = val.size } if (val && val.page) { searchQuery.value.offset = val.page } fetchData(true) } // 点击取消 const cancle = () => { emits('changeVisible', false) } // 点击确定 const clickConfirmSample = () => { if (!checkoutList.value.length) { ElMessage({ message: '请选中', type: 'warning', }) } // 将选择好的样品传给父组件 emits('confirmCheckout', checkoutList.value) cancle() } watch(() => props.visible, (newValue) => { if (newValue) { fetchData(true) } }) const useDeptList = ref([]) // 获取使用部门 getDeptTreeList().then((res) => { if (res.data) { // 将列表转树结构 useDeptList.value = toTreeList(res.data, '0', true) } }) </script> <template> <div class="select-kehu-dialog"> <el-dialog :model-value="visible" title="选择设备" width="65%" @close="cancle"> <search-area :need-clear="true" @search="searchList" @clear="clearList" > <!-- <search-item> <el-input v-model="searchQuery.equipmentNo" placeholder="设备编号" clearable class="w-50 m-2" style="width: 185px;" /> </search-item> --> <search-item> <el-input v-model="searchQuery.equipmentName" placeholder="名称" clearable class="w-50 m-2" style="width: 185px;" /> </search-item> <search-item> <el-input v-model="searchQuery.modelNo" placeholder="型号" clearable class="w-50 m-2" style="width: 185px;" /> </search-item> <search-item> <dept-select v-model="searchQuery.useDept" :data="useDeptList" placeholder="使用部门" style="width: 185px;" /> </search-item> </search-area> <normal-table :data="list" :total="total" :columns="columns" :query="searchQuery" :list-loading="loadingTable" is-showmulti-select :is-multi="props.isMulti" :page-sizes="[5]" @change="changePage" @multi-select="handleSelectionChange" > <!-- 序号 --> <template #preColumns> <el-table-column label="#" width="55" align="center" fixed> <template #default="scope"> {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> </normal-table> <template #footer> <el-button type="primary" @click="clickConfirmSample"> 确定 </el-button> <el-button @click="cancle"> 取消 </el-button> </template> </el-dialog> </div> </template>