<!-- 现行测试校准检定方法列表 --> <script name="MethodList" lang="ts" setup> import { ElMessage, ElLoading, ElMessageBox, dayjs } from 'element-plus' import type { DateModelType } from 'element-plus' import type { IListQuery, IMethodFileInfo } from './method-interface' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import { delFileMethod, getFileMethodList, exportList } from '@/api/resource/fileTechnology' import type { IDictType } from '@/commonInterface/resource-interface' import FilePreviewDialog from '@/components/filePreview/filePreviewDialog.vue' import ImagePreviewDialog from '@/components/ImagePreview/imagePreviewDialog.vue' import { exportFile } from '@/utils/exportUtils' const { proxy } = getCurrentInstance() as any const router = useRouter() const labCodeDict = ref<Array<IDictType>>([]) const groupCodeDict = ref<Array<IDictType>>([]) const noveltyStatusDict = ref<Array<IDictType>>([]) const refFilePreviewDlg = ref() const refImagePreviewDlg = ref() // 查询条件 const searchQuery = ref<IListQuery>({ labCode: '', groupCode: '', fileNo: '', // 文件编号 fileName: '', // 文件名 fileDistributeNo: '', // 文件发放号 activeDateStart: '', // activeDateEnd: '', noveltyStatus: '', offset: 1, limit: 20, }) const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading // 表头 const columns = ref<TableColumn[]>([ { text: '实验室', value: 'labCodeName', align: 'center', width: '100' }, { text: '部门', value: 'groupCodeName', align: 'center', width: '150' }, { text: '文件发放号', value: 'fileDistributeNo', align: 'center', width: '180' }, { text: '文件编号', value: 'fileNo', align: 'center', width: '180' }, { text: '文件名称', value: 'fileName', align: 'center' }, { text: '启用时间', value: 'activeDateStr', align: 'center', width: '120' }, { text: '查新状态', value: 'noveltyStatusName', align: 'center', width: '160' }, { text: '最新查新时间', value: 'latestNoveltyDate', align: 'center', width: '120' }, ]) const methodFileList = ref<Array<IMethodFileInfo>>([]) // 表格数据 // 逻辑 // 跳转到新建的页面 const addMethodFile = () => { router.push({ query: { type: 'create', }, path: 'method/detail', }) } // 详情 const detail = (row: IMethodFileInfo) => { // sessionStorage.setItem('fileInfo', JSON.stringify(row)) sessionStorage.setItem('methodFileInfo', JSON.stringify(row)) router.push({ query: { title: '测试校准检定方法', id: row.id, type: 'detail', }, // path: 'method/stream', path: 'method/detail', }) } // 编辑 const updateById = (row: IMethodFileInfo) => { sessionStorage.setItem('methodFileInfo', JSON.stringify(row)) router.push({ query: { type: 'update', id: row.id, }, path: 'method/detail', }) } // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } getFileMethodList(searchQuery.value).then((response) => { if (response.code === 200) { methodFileList.value = response.data.rows.map((item: { activeDate: string }) => { return { ...item, activeDateStr: dayjs(item.activeDate).format('YYYY-MM-DD') !== 'Invalid Date' ? dayjs(item.activeDate).format('YYYY-MM-DD') : '', } }) total.value = parseInt(response.data.total) } loadingTable.value = false }).catch(() => { loadingTable.value = false }) } const searchList = () => { 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 reset = () => { searchQuery.value = { labCode: '', groupCode: '', fileNo: '', // 文件编号 fileName: '', // 文件名 fileDistributeNo: '', // 文件发放号 activeDateStart: '', // activeDateEnd: '', noveltyStatus: '', offset: 1, limit: 20, } dateRange.value = ['', ''] fetchData(true) } // 删除 const deleteById = (row: IMethodFileInfo) => { ElMessageBox.confirm(`是否删除文件 ${row.fileName}`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }).then(() => { delFileMethod({ id: row.id }).then((res) => { if (res.code === 200) { ElMessage.success(`文件 ${row.fileName} 删除成功`) searchList() } else { ElMessage.error(`文件 ${row.fileName} 删除失败: ${res.message}`) } }) }) } const openFilePreviewDialog = (row: IMethodFileInfo) => { // 手动新增的 if (row.file.lastIndexOf('.pdf') > 0) { refFilePreviewDlg.value.initDialog(row.file) } else { refImagePreviewDlg.value.initDialog(row.file) } } // 获取字典值 const getLabCodeDict = () => { getDictByCode('bizLabCode').then((res) => { if (res.code === 200) { labCodeDict.value = res.data sessionStorage.setItem('bizLabCode', JSON.stringify(labCodeDict.value)) } }) } const getGroupCodeDict = () => { getDictByCode('bizGroupCode').then((res) => { if (res.code === 200) { groupCodeDict.value = res.data sessionStorage.setItem('bizGroupCode', JSON.stringify(groupCodeDict.value)) } }) } const getNoveltyStatusDict = () => { getDictByCode('bizNoveltyStatus').then((res) => { if (res.code === 200) { noveltyStatusDict.value = res.data sessionStorage.setItem('bizNoveltyStatus', JSON.stringify(noveltyStatusDict.value)) } }) } // 导出列表 const exportMethodFile = () => { if (!methodFileList.value.length) { ElMessage.warning('暂无可导出数据') return } const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.6)', }) exportList(searchQuery.value).then((res) => { const blob = new Blob([res.data]) loading.close() exportFile(blob, '现行测试校准检定方法.xlsx') }).catch(() => { loading.close() }) } const getDict = async () => { getLabCodeDict() getGroupCodeDict() getNoveltyStatusDict() } watch(dateRange, (val) => { if (val) { searchQuery.value.activeDateStart = dayjs(val[0]).format('YYYY-MM-DD HH:mm:ss') === 'Invalid Date' ? '' : dayjs(val[0]).format('YYYY-MM-DD HH:mm:ss') searchQuery.value.activeDateEnd = dayjs(val[1]).format('YYYY-MM-DD HH:mm:ss') === 'Invalid Date' ? '' : dayjs(val[1]).format('YYYY-MM-DD HH:mm:ss') } else { searchQuery.value.activeDateStart = '' searchQuery.value.activeDateEnd = '' } }) onMounted(async () => { await getDict() searchList() }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item width="162px"> <el-select v-model="searchQuery.labCode" placeholder="实验室" clearable> <el-option v-for="item in labCodeDict" :key="item.id" :value="item.value" :label="item.name" /> </el-select> </search-item> <search-item width="162px"> <el-select v-model="searchQuery.groupCode" placeholder="部门" clearable> <el-option v-for="item in groupCodeDict" :key="item.id" :value="item.value" :label="item.name" /> </el-select> </search-item> <search-item width="162px"> <el-input v-model="searchQuery.fileDistributeNo" placeholder="文件发放号" clearable /> </search-item> <search-item width="162px"> <el-input v-model="searchQuery.fileNo" placeholder="文件编号" clearable /> </search-item> <search-item width="162px"> <el-input v-model="searchQuery.fileName" placeholder="文件名称" clearable /> </search-item> <search-item> <el-date-picker v-model="dateRange" type="daterange" start-placeholder="启用时间(开始)" end-placeholder="启用时间(结束)" /> </search-item> <search-item width="162px"> <el-select v-model="searchQuery.noveltyStatus" placeholder="查新状态" clearable> <el-option v-for="item in noveltyStatusDict" :key="item.id" :value="item.value" :label="item.name" /> </el-select> </search-item> </search-area> <!-- 表格数据展示 --> <table-container title="方法文件列表"> <!-- 表头区域 --> <template #btns-right> <icon-button v-if="proxy.hasPerm(`/resource/technology/method/add`)" icon="icon-add" title="新建" @click="addMethodFile" /> <icon-button icon="icon-export" title="导出" @click="exportMethodFile" /> </template> <!-- 表格区域 --> <normal-table :data="methodFileList" :total="total" :columns="columns" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" @change="changePage"> <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column label="附件" align="center" width="300"> <template #default="scope"> <el-link type="primary" @click="openFilePreviewDialog(scope.row)"> {{ scope.row.file }} </el-link> </template> </el-table-column> <el-table-column fixed="right" label="操作" align="center" width="130"> <template #default="{ row }"> <el-button size="small" type="primary" link @click="detail(row)"> 查看 </el-button> <el-button v-if="proxy.hasPerm(`/resource/technology/method/edit`)" size="small" type="primary" link @click="updateById(row)"> 编辑 </el-button> <el-button v-if="proxy.hasPerm(`/resource/technology/method/del`)" size="small" type="danger" link @click="deleteById(row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> <file-preview-dialog ref="refFilePreviewDlg" /> <image-preview-dialog ref="refImagePreviewDlg" /> </app-container> </template>