<!-- 内部审核工作管理列表 --> <script name="QualityInternalWork" lang="ts" setup> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import { getDictByCode } from '@/api/system/dict' import type { TableColumn } from '@/components/NormalTable/table_interface' import { exportFile } from '@/utils/exportUtils' import { deleteWork, exportInternalWorkZip, getWorkList } from '@/api/quality/internal/workManage' // 查询条件 const listQuery = ref({ yearTime: '', bizLabCode: '', offset: 1, limit: 20, }) // 列表数据 const tableList = ref([]) const total = ref(0) const loadingTable = ref(true) const checkoutList = ref<string[]>([])// 选中的内容 // 列 const columns = ref<TableColumn[]>([ { text: '年度', value: 'yearTime', align: 'center' }, { text: '实验室', value: 'bizLabCodeName', align: 'center' }, { text: '工作名称', value: 'workName', align: 'center' }, { text: '当前阶段', value: 'currentStageName', align: 'center' }, { text: '创建人', value: 'commanderName', align: 'center' }, { text: '创建时间', value: 'createTime', align: 'center' }, ]) // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } getWorkList(listQuery.value).then((response) => { tableList.value = response.data.rows total.value = parseInt(response.data.total) loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 搜索 const searchList = () => { fetchData(true) } // 重置查询条件 const clearList = () => { listQuery.value = { yearTime: '', bizLabCode: '', offset: 1, limit: 20, } searchList() } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 } fetchData(true) } // 新建 const $router = useRouter() const handler = (type: string, row: any) => { $router.push({ path: `/internalwork/${type}`, query: { id: row.id, }, }) } // 下载 const downRow = (row: any) => { const params = { ...listQuery.value, ids: [row.id], } const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) exportInternalWorkZip(params).then((res) => { if (res.data.type.includes('zip') && res.data.size) { const blob = new Blob([res.data]) loading.close() exportFile(blob, `${row.workName}.zip`) } else { ElMessage.warning('导出失败') loading.close() } }) } // 删除 const deleteRow = (row: any) => { ElMessageBox.confirm( '确认删除该数据吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then((res) => { deleteWork({ id: row.id }).then((res) => { ElMessage.success('删除成功') searchList() }) }) } onMounted(async () => { searchList() }) const labelList = ref<{ id: string; value: string; name: string }[]>()// 实验室代码 const yearList = ref<{ id: string; value: string; name: string }[]>([])// 年度 // 获取字典 const fetchDict = () => { // 获取实验室代码字典 getDictByCode('bizLabCode').then((res) => { labelList.value = res.data }) // 循环出最近十年的year // 获取当前年份 const year = new Date().getFullYear() + 5 for (let i = year; i > year - 10; i--) { yearList.value?.push({ name: String(i), value: String(i), id: String(i), }) } yearList.value?.reverse() } fetchDict() const { proxy } = getCurrentInstance() as any </script> <template> <app-container> <search-area :need-clear="true" @search="searchList" @clear="clearList"> <search-item> <el-select v-model="listQuery.yearTime" placeholder="年度" class="short-input" filterable clearable > <el-option v-for="item in yearList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.bizLabCode" placeholder="实验室" class="short-input" filterable clearable > <el-option v-for="item in labelList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> </search-area> <table-container> <template #btns-right> <icon-button v-if="proxy.hasPerm('/quality/internal/work/add')" icon="icon-add" title="新建" type="primary" @click="handler('create', {})" /> </template> <normal-table :data="tableList" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange" > <template #preColumns> <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" fixed="right" width="140" > <template #default="{ row }"> <el-button v-if="proxy.hasPerm('/quality/internal/work/download')" size="small" type="primary" link @click="downRow(row)" > 下载 </el-button> <el-button size="small" type="primary" link @click="handler('detail', row)" > 查看 </el-button> <el-button v-if="proxy.hasPerm('/quality/internal/work/delete')" size="small" type="danger" link @click="deleteRow(row)" > 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>