<!-- 标识打印 --> <script lang="ts" setup name="BusinessTaskMeasurePrintList"> 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 './print-interface' import { exportFile } from '@/utils/exportUtils' import type { dictType } from '@/global' import selectEquipmentEqptDialog from '@/views/business/manager/order/dialog/selectEquipment.vue' import { getDictByCode } from '@/api/system/dict' import type { TableColumn } from '@/components/NormalTable/table_interface' import { delPrintList, exportPrintList, getPrintList } from '@/api/business/taskMeasure/print' const $router = useRouter() const loadingTable = ref(false) // 查询条件 const listQuery: Ref<IListQuery> = ref({ checkDateEnd: '', // 测试、校准或检定日期结束(设备台账溯源日期) checkDateStart: '', // 测试、校准或检定日期开始(设备台账溯源日期) deptName: '', // 使用部门 deviceName: '', // 设备名称 deviceNo: '', // 统一编号 identifyType: '', // 标志类型 limitInstruction: '', // 限用说明(设备台账无该字段) manufactureNo: '', // 出厂编号 manufacturer: '', // 生产厂家 measurePerson: '', // 检定员 measureValidDateEnd: '', // 检定有效期结束 measureValidDateStart: '', // 检定有效期开始 model: '', // 规格型号 traceCompany: '', // 委托单位(设备台账的溯源单位) updateTimeEnd: '', // 打印结束时间 updateTimeStart: '', // 打印开始时间 limit: 20, offset: 1, }) // 表头 const columns = ref<TableColumn[]>([ { text: '记录编号', value: 'recordNo', align: 'center', width: '160' }, { text: '计量标识', value: 'meterIdentifyName', align: 'center' }, { text: '设备名称', value: 'deviceName', align: 'center' }, { text: '规格型号', value: 'model', align: 'center' }, { text: '出厂编号', value: 'manufactureNo', align: 'center' }, { text: '生产厂家', value: 'manufacturer', align: 'center' }, { text: '委托单位', value: 'traceCompany', align: 'center' }, { text: '使用部门', value: 'deptName', align: 'center' }, { text: '检定结论', value: 'conclusion', align: 'center' }, { text: '限用说明', value: 'limitInstruction', align: 'center' }, { text: '检定有效期', value: 'measureValidDate', align: 'center' }, { text: '检定员', value: 'measurePerson', align: 'center' }, { text: '测试、校准或检定日期', value: 'checkDate', align: 'center' }, { text: '打印时间', value: 'updateTime', align: 'center', width: '180' }, ]) const list = ref<IList[]>([]) // 列表 const total = ref(0) // 数据总条数 // 选中的内容 const checkoutList = ref<IList[]>([]) const timeRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据--检定有效期 const traceDateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据--检定日期 // --------------------------------------------字典-------------------------------------- const meterIdentifyList = ref() // 计量标识 const meterIdentifyDict = ref({}) as any // 计量标识 const conclusionList = ref({}) as any // 检定结论 async function getDict() { // 计量标识 const responseEqptMeterIdentify = await getDictByCode('eqptMeterIdentify') responseEqptMeterIdentify.data.forEach((item: { name: string; value: string }) => { meterIdentifyDict.value[item.value] = item.name }) meterIdentifyList.value = responseEqptMeterIdentify.data // 结论 getDictByCode('bizConclusion').then((response) => { conclusionList.value = response.data }) } // ------------------------------------------------------------------------------------------------- // 多选发生改变时 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 } getPrintList(listQuery.value).then((response) => { list.value = response.data.rows.map((item: { limitInstruction: string; identifyType: string; measureValidDate: string; checkDate: string }) => { return { ...item, meterIdentifyName: `${item.identifyType}` ? meterIdentifyDict.value[`${item.identifyType}`] : `${item.identifyType}`, // 计量标识 measureValidDate: item.measureValidDate ? dayjs(item.measureValidDate).format('YYYY-MM-DD') : item.measureValidDate, checkDate: item.checkDate ? dayjs(item.checkDate).format('YYYY-MM-DD') : item.checkDate, limitInstruction: item.limitInstruction ? item.limitInstruction : '/', // 限用说明 } }) total.value = parseInt(response.data.total) loadingTable.value = false }) } // 清除条件 const clearList = () => { listQuery.value = { checkDateEnd: '', // 测试、校准或检定日期结束(设备台账溯源日期) checkDateStart: '', // 测试、校准或检定日期开始(设备台账溯源日期) deptName: '', // 使用部门 deviceName: '', // 设备名称 deviceNo: '', // 统一编号 identifyType: '', // 标志类型 limitInstruction: '', // 限用说明(设备台账无该字段) manufactureNo: '', // 出厂编号 manufacturer: '', // 生产厂家 measurePerson: '', // 检定员 measureValidDateEnd: '', // 检定有效期结束 measureValidDateStart: '', // 检定有效期开始 model: '', // 规格型号 traceCompany: '', // 委托单位(设备台账的溯源单位) updateTimeEnd: '', // 打印结束时间 updateTimeStart: '', // 打印开始时间 limit: 20, offset: 1, } timeRange.value = ['', ''] // 清空打印时间 dateRange.value = ['', ''] // 清空检定有效期的时间 traceDateRange.value = ['', ''] // 清空检定日期 fetchData() } // 搜索 const searchList = () => { fetchData(true) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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, type: 'edit' | 'detail' | 'del') => { if (type === 'detail' || type === 'edit') { const params = [{ ...row, equipmentId: row.deviceId, id: row.deviceId, equipmentName: row.deviceName, // 设备名称 model: row.model, // 型号 manufactureNo: row.manufactureNo, // 出厂编号 meterIdentify: row.identifyType, // 计量标识 meterIdentifyName: meterIdentifyDict.value[row.identifyType], // 计量标识名称 limitInstruction: row.limitInstruction, // 限用说明 }] $router.push({ path: `print/${type}/${row.id}`, query: { equipmentList: JSON.stringify(params), }, }) } else if (type === 'del') { ElMessageBox.confirm( '确认删除吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { delPrintList({ id: row.id }).then((res) => { ElMessage({ type: 'success', message: '删除成功', }) fetchData(true) }) }) } } // 导出 const exportAll = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.6)', }) if (list.value.length > 0) { const params = { checkDateEnd: listQuery.value.checkDateEnd, // 测试、校准或检定日期结束(设备台账溯源日期) checkDateStart: listQuery.value.checkDateStart, // 测试、校准或检定日期开始(设备台账溯源日期) deptName: listQuery.value.deptName, // 使用部门 deviceName: listQuery.value.deviceName, // 设备名称 deviceNo: listQuery.value.deviceNo, // 统一编号 identifyType: listQuery.value.identifyType, // 标志类型 limitInstruction: listQuery.value.limitInstruction, // 限用说明(设备台账无该字段) manufactureNo: listQuery.value.manufactureNo, // 出厂编号 manufacturer: listQuery.value.manufacturer, // 生产厂家 measurePerson: listQuery.value.measurePerson, // 检定员 measureValidDateEnd: listQuery.value.measureValidDateEnd, // 检定有效期结束 measureValidDateStart: listQuery.value.measureValidDateStart, // 检定有效期开始 model: listQuery.value.model, // 规格型号 traceCompany: listQuery.value.traceCompany, // 委托单位(设备台账的溯源单位) updateTimeEnd: listQuery.value.updateTimeEnd, // 打印结束时间 updateTimeStart: listQuery.value.updateTimeStart, // 打印开始时间 offset: 1, limit: 20, ids: checkoutList.value.map(item => item.id), } exportPrintList(params).then((res) => { const blob = new Blob([res.data]) loading.close() exportFile(blob, '标识打印.xlsx') }) } else { loading.close() ElMessage.warning('无数据可导出数据') } } // ---------------------------------------选择受检设备------------------------------------------ const selectEquipmentEqptRef = ref() // 新建 const add = () => { selectEquipmentEqptRef.value.initDialog() } // 选完设备 const confirmSelectEquipmentEqpt = (equipmentList: any) => { console.log('equipmentList', equipmentList) let params: any = [] if (Array.isArray(equipmentList) && equipmentList.length) { params = equipmentList.map((item) => { return { ...item, equipmentId: item.id, id: item.id, equipmentName: item.equipmentName, // 设备名称 model: item.model, // 型号 manufactureNo: item.manufactureNo, // 出厂编号 meterIdentify: item.meterIdentify, // 计量标识 meterIdentifyName: item.meterIdentifyName, // 计量标识名称 limitInstruction: item.limitInstruction, // 限用说明 // meterIdentifyName: '限用', // 计量标识名称 // limitInstruction: '我是限用说明我是限用说明我是限用说明我是限用说明我是限用说明我是限用说明我是限用说明我是限用说明我是限用说明我是限用说明我是限用说明我是限用说明', // 限用说明 } }) } $router.push({ path: 'print/add', query: { equipmentList: JSON.stringify(params), }, }) } // ---------------------------------------钩子----------------------------------------------- watch(timeRange, (val) => { if (val) { listQuery.value.updateTimeStart = `${val[0]}` listQuery.value.updateTimeEnd = `${val[1]}` } else { listQuery.value.updateTimeStart = '' listQuery.value.updateTimeEnd = '' } }) watch(dateRange, (val) => { if (val) { listQuery.value.measureValidDateStart = `${val[0]}` listQuery.value.measureValidDateEnd = `${val[1]}` } else { listQuery.value.measureValidDateStart = '' listQuery.value.measureValidDateEnd = '' } }) // 测试、校准检定日期 watch(traceDateRange, (val) => { if (val) { listQuery.value.checkDateStart = `${val[0]}` listQuery.value.checkDateEnd = `${val[1]}` } else { listQuery.value.checkDateStart = '' listQuery.value.checkDateEnd = '' } }) onMounted(async () => { await getDict() fetchData(false) }) </script> <template> <div> <!-- 布局 --> <app-container> <search-area :need-clear="true" @search="searchList" @clear="clearList"> <search-item> <el-select v-model="listQuery.identifyType" 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.deviceName" placeholder="设备名称" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.model" placeholder="规格型号" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.manufacturer" placeholder="生产厂家" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.traceCompany" placeholder="委托单位" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.deptName" placeholder="使用部门" class="short-input" clearable /> </search-item> <search-item> <el-select v-model="listQuery.conclusion" class="short-input" placeholder="检定结论" clearable > <el-option v-for="item of conclusionList" :key="item.value" :label="item.name" :value="item.name" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.limitInstruction" placeholder="限用说明" class="short-input" clearable /> </search-item> <search-item> <el-date-picker v-model="dateRange" 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.measurePerson" placeholder="检定员" class="short-input" clearable /> </search-item> <search-item> <el-date-picker v-model="traceDateRange" type="daterange" range-separator="至" format="YYYY-MM-DD" value-format="YYYY-MM-DD" start-placeholder="测试、校准或检定日期(开始)" end-placeholder="测试、校准或检定日期(结束)" style="width: 480px;" /> </search-item> <search-item> <el-date-picker v-model="timeRange" type="datetimerange" range-separator="至" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="打印时间(开始)" end-placeholder="打印时间(结束)" /> </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="120" > <template #default="{ row }"> <el-button size="small" link type="primary" @click="handleEdit(row, 'edit')" > 编辑 </el-button> <!-- <el-button size="small" type="primary" link @click="handleEdit(row, 'detail')" > 详情 </el-button> --> <el-button size="small" type="danger" link @click="handleEdit(row, 'del')" > 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </div> <!-- 选择受检设备组件 --> <select-equipment-eqpt-dialog ref="selectEquipmentEqptRef" @confirm="confirmSelectEquipmentEqpt" /> </template>