<!-- 溯源证书管理 --> <script lang="ts" setup name="EquipmentSourceCertList"> import type { Ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { DateModelType } from 'element-plus' import dayjs from 'dayjs' import type { IList, IListQuery } from './cert-interface' import type { TableColumn } from '@/components/NormalTable/table_interface' import type { IMenu } from '@/components/buttonBox/buttonBox' import { getDictByCode } from '@/api/system/dict' import { exportFile } from '@/utils/exportUtils' import type { deptType } from '@/global' import { delSourceCertList, exportResourceSourceCert, getSourceCertList } from '@/api/equipment/source/cert' const $route = useRoute() const $router = useRouter() const { proxy } = getCurrentInstance() as any const loadingTable = ref(false) // 查询条件 const listQuery: Ref<IListQuery> = ref({ certificateName: '', // 证书名称 certificateNo: '', // 证书编号 equipmentName: '', // 设备名称 equipmentNo: '', // 设备编号 manufactureNo: '', // 出厂编号 manufacturer: '', // 生产厂家 meterIdentify: '', // 计量标识(字典code) model: '', // 规格型号 traceCompany: '', // 溯源单位名 traceDateEnd: '', // 测试、校准或检定日期结束 traceDateStart: '', // 测试、校准或检定日期开始 validDateEnd: '', // 检定有效期结束 validDateStart: '', // 检定有效期开始 limit: 20, offset: 1, }) // 表头 const columns = ref<TableColumn[]>([ { text: '设备名称', value: 'equipmentName', align: 'center' }, { text: '规格型号', value: 'model', align: 'center' }, { text: '出厂编号', value: 'manufactureNo', align: 'center' }, { text: '生产厂家', value: 'manufacturer', align: 'center' }, { text: '检定日期', value: 'traceDate', align: 'center', width: '120' }, { text: '证书有效期', value: 'certificateValid', align: 'center', width: '120' }, { text: '计量标识', value: 'meterIdentifyName', align: 'center', width: '120' }, { text: '溯源单位', value: 'traceCompany', align: 'center' }, { text: '证书编号', value: 'certificateNo', align: 'center', width: '160' }, ]) const list = ref<IList[]>([]) // 列表 const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const traceDateRange = ref<[DateModelType, DateModelType]>(['', ''])// 检定日期筛选时间段数据 const total = ref(0) // 数据总条数 // 选中的内容 const checkoutList = ref<string[]>([]) // -----------------------------------------字典-------------------------------------------------------------- const meterIdentifyList = ref<deptType[]>([]) // 计量标识 const meterIdentifyDict = ref([]) as any // 计量标识 // 查询字典 const getDict = async () => { // 计量标识 const response = await getDictByCode('bizMeterIdentify') meterIdentifyList.value = response.data response.data.forEach((item: { value: string; name: string }) => { meterIdentifyDict.value[`${item.value}`] = item.name }) } // ------------------------------------------------------------------------------------------------------- // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } getSourceCertList(listQuery.value).then((response) => { list.value = response.data.rows.map((item: { traceDate: string; certificateValid: string; meterIdentify: string }) => { return { ...item, traceDate: item.traceDate ? dayjs(item.traceDate).format('YYYY-MM-DD') : item.traceDate, certificateValid: item.certificateValid ? dayjs(item.certificateValid).format('YYYY-MM-DD') : item.certificateValid, meterIdentifyName: `${item.meterIdentify}` ? meterIdentifyDict.value[item.meterIdentify] : item.meterIdentify, // 计量标识 } }) total.value = parseInt(response.data.total) loadingTable.value = false }) } // 清除条件 const clearList = () => { listQuery.value = { certificateName: '', // 证书名称 certificateNo: '', // 证书编号 equipmentName: '', // 设备名称 equipmentNo: '', // 设备编号 manufactureNo: '', // 出厂编号 manufacturer: '', // 生产厂家 meterIdentify: '', // 计量标识(字典code) model: '', // 规格型号 traceCompany: '', // 溯源单位名 traceDateEnd: '', // 测试、校准或检定日期结束 traceDateStart: '', // 测试、校准或检定日期开始 validDateEnd: '', // 检定有效期结束 validDateStart: '', // 检定有效期开始 limit: 20, offset: 1, } dateRange.value = ['', ''] // 证书有效期 traceDateRange.value = ['', ''] // 检定日期 fetchData() } // 搜索 const searchList = () => { fetchData(true) } // 新建 const add = () => { $router.push({ path: 'cert/add', }) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 handleEdit = (row: any, val: string) => { switch (val) { case 'delete': ElMessageBox.confirm( '确认删除吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { delSourceCertList({ ids: [row.id] }).then((res) => { ElMessage({ type: 'success', message: '删除成功', }) fetchData(true) }) }) break case 'detail': $router.push({ path: `cert/detail/${row.id}`, query: { ...row, certificateDetailList: JSON.stringify(row.certificateDetailList), }, }) break case 'edit': $router.push({ path: `cert/${val}/${row.id}`, query: { ...row, certificateDetailList: JSON.stringify(row.certificateDetailList), }, }) break } } // 导出 const exportAll = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (list.value.length > 0) { const params = { certificateName: listQuery.value.certificateName, // 证书名称 certificateNo: listQuery.value.certificateNo, // 证书编号 equipmentName: listQuery.value.equipmentName, // 设备名称 equipmentNo: listQuery.value.equipmentNo, // 设备编号 manufactureNo: listQuery.value.manufactureNo, // 出厂编号 manufacturer: listQuery.value.manufacturer, // 生产厂家 meterIdentify: listQuery.value.meterIdentify, // 计量标识(字典code) model: listQuery.value.model, // 规格型号 traceCompany: listQuery.value.traceCompany, // 溯源单位名 traceDateEnd: listQuery.value.traceDateEnd, // 测试、校准或检定日期结束 traceDateStart: listQuery.value.traceDateStart, // 测试、校准或检定日期开始 validDateEnd: listQuery.value.validDateEnd, // 检定有效期结束 validDateStart: listQuery.value.validDateStart, // 检定有效期开始 offset: 1, limit: 20, ids: checkoutList.value, } exportResourceSourceCert(params).then((res) => { const blob = new Blob([res.data]) exportFile(blob, '溯源证书.xlsx') loading.close() }) } else { loading.close() ElMessage.warning('无数据可导出数据') } } // ------------------------------------------钩子------------------------------------------------ watch(dateRange, (val) => { if (val) { listQuery.value.validDateStart = `${val[0]}` listQuery.value.validDateEnd = `${val[1]}` } else { listQuery.value.validDateStart = '' listQuery.value.validDateEnd = '' } }) watch(traceDateRange, (val) => { if (val) { listQuery.value.traceDateStart = `${val[0]}` listQuery.value.traceDateEnd = `${val[1]}` } else { listQuery.value.traceDateStart = '' listQuery.value.traceDateEnd = '' } }) onMounted(async () => { getDict().then(() => { fetchData(false) }) }) </script> <template> <div> <!-- 布局 --> <app-container> <search-area :need-clear="true" @search="searchList" @clear="clearList"> <search-item> <el-input v-model.trim="listQuery.equipmentName" placeholder="设备名称" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.model" placeholder="规格型号" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.manufacturer" placeholder="生产厂家" clearable /> </search-item> <search-item> <el-date-picker v-model="traceDateRange" class="short-input" type="daterange" range-separator="至" format="YYYY-MM-DD" value-format="YYYY-MM-DD" start-placeholder="检定日期(开始)" end-placeholder="检定日期(结束)" /> </search-item> <search-item> <el-date-picker v-model="dateRange" class="short-input" type="daterange" range-separator="至" format="YYYY-MM-DD" value-format="YYYY-MM-DD" start-placeholder="证书有效期(开始)" end-placeholder="证书有效期(结束)" /> </search-item> <!-- <search-item> <el-input v-model.trim="listQuery.certificateName" placeholder="证书名称" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.equipmentNo" placeholder="统一编号" class="short-input" clearable /> </search-item> --> <search-item> <el-select v-model="listQuery.meterIdentify" class="short-input" placeholder="计量标识" clearable > <el-option v-for="item of meterIdentifyList" :key="item.value" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.traceCompany" placeholder="溯源单位" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.certificateNo" placeholder="证书编号" class="short-input" clearable /> </search-item> </search-area> <table-container> <template #btns-right> <icon-button icon="icon-add" title="新建" type="primary" @click="add" /> <icon-button icon="icon-export" title="导出" type="primary" @click="exportAll" /> </template> <normal-table :data="list" :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="handleEdit(row, 'detail')" > 查看 </el-button> <el-button size="small" link type="primary" @click="handleEdit(row, 'edit')" > 编辑 </el-button> <el-button size="small" type="danger" link @click="handleEdit(row, 'delete')" > 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </div> </template>