<!-- 内部审核计划 --> <script name="QualityInternalPlan" lang="ts" setup> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import { Message } from '@element-plus/icons-vue' import { getDictByCode } from '@/api/system/dict' import type { TableColumn } from '@/components/NormalTable/table_interface' import { deleteInternalPlan, exportInternalPlanZip, getInternalPlanList } from '@/api/quality/internal/internalPlan' import useUserStore from '@/store/modules/user' import { exportFile } from '@/utils/exportUtils' const userStore = useUserStore() // 查询条件 const listQuery = ref({ fileName: '', fileCode: '', bizLabCode: '', commanderName: '', createTimeStart: '', createTimeEnd: '', offset: 1, limit: 20, }) // 开始结束时间 const datetimerange = ref() watch(() => datetimerange.value, (newVal) => { listQuery.value.createTimeStart = '' listQuery.value.createTimeEnd = '' if (Array.isArray(newVal)) { if (newVal.length) { listQuery.value.createTimeStart = `${newVal[0]} 00:00:00` listQuery.value.createTimeEnd = `${newVal[1]} 23:59:59` } } }) // 列表数据 const tableList = ref([]) const total = ref(0) const loadingTable = ref(true) const checkoutList = ref<string[]>([])// 选中的内容 // 列 const columns = ref<TableColumn[]>([ { text: '文件编号', value: 'fileCode', align: 'center' }, { text: '文件名称', value: 'fileName', align: 'center' }, { text: '实验室', value: 'bizLabCodeName', align: 'center' }, { text: '质量负责人', value: 'commanderName', align: 'center' }, { text: '创建时间', value: 'updateTime', align: 'center' }, ]) // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } getInternalPlanList(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 = () => { datetimerange.value = [] listQuery.value = { fileName: '', fileCode: '', bizLabCode: '', commanderName: '', createTimeStart: '', createTimeEnd: '', 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: `/internalplan/${type}`, query: { id: row.id, data: JSON.stringify(row), }, }) } // 删除 const deleteRow = (row: any) => { ElMessageBox.confirm( '确认删除该数据吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then((res) => { deleteInternalPlan({ id: row.id }).then((res) => { ElMessage.success('删除成功') searchList() }) }) } onMounted(async () => { searchList() }) const { proxy } = getCurrentInstance() as any // 导出 const exportList = () => { if (!tableList.value.length) { ElMessage.warning('暂无导出数据') return } const params = { ...listQuery.value, ids: checkoutList.value, } const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) exportInternalPlanZip(params).then((res) => { if (res.data.type.includes('zip') && res.data.size) { const blob = new Blob([res.data]) loading.close() exportFile(blob, '内部审核计划.zip') } else { ElMessage.warning('导出失败') loading.close() } }) } </script> <template> <app-container> <search-area :need-clear="true" @search="searchList" @clear="clearList"> <search-item> <el-input v-model="listQuery.fileCode" placeholder="文件编号" clearable /> </search-item> <search-item> <el-input v-model="listQuery.fileName" placeholder="文件名称" clearable /> </search-item> <search-item> <el-input v-model="listQuery.commanderName" placeholder="质量负责人" clearable /> </search-item> <search-item> <el-date-picker v-model="datetimerange" type="daterange" value-format="YYYY-MM-DD" format="YYYY-MM-DD" range-separator="至" start-placeholder="创建开始时间" end-placeholder="创建结束时间" clearable /> </search-item> </search-area> <table-container> <template #btns-right> <icon-button v-if="proxy.hasPerm('/quality/internal/plan/add')" icon="icon-add" title="新建" type="primary" @click="handler('create', {})" /> <icon-button v-if="proxy.hasPerm('/quality/internal/plan/export')" icon="icon-export" title="导出" type="primary" @click="exportList" /> </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 size="small" type="primary" link @click="handler('detail', row)" > 详情 </el-button> <el-button v-if="proxy.hasPerm('/quality/internal/plan/update')" size="small" type="primary" link :disabled="row.commanderId !== userStore.id" @click="handler('update', row)" > 编辑 </el-button> <el-button v-if="proxy.hasPerm('/quality/internal/plan/delete')" size="small" type="danger" link @click="deleteRow(row)" > 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>