<!-- 设备交接单列表 --> <script lang="ts" setup name="ReceiptList"> import type { DateModelType } from 'element-plus' import type { Ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { IListQuery, IReceiptList } from './receiptList-interface' import { printJSON } from '@/utils/printUtils' import { exportFile } from '@/utils/exportUtils' import type { TableColumn } from '@/components/NormalTable/table_interface' import { delInterchangeReceiptList, deleteReceiptList, exportReceiptList, getReceiptList } from '@/api/business/schedule/interchangeReceipt' import { keepSearchParams, renewSearchParams } from '@/utils/keepQuery' import userStore from '@/store/modules/user' const user = userStore() const $router = useRouter() const { proxy } = getCurrentInstance() as any // 查询条件 const listQuery: Ref<IListQuery> = ref({ customerName: '', // 委托方名称 customerNo: '', // 委托方编号 deliverer: '', // 联系人/送检人 interchangeCode: '', // 交接单编号 reciever: '', // 收发员 startTime: '', // 交接开始时间 endTime: '', // 交接结束时间 orderNo: '', // 任务单编号 offset: 1, limit: 20, }) // 页面跳转之前保存参数 onBeforeRouteLeave((to: any) => { keepSearchParams(to.path, 'schedule-interchangeReceipt', listQuery.value) }) // 重新赋值 listQuery.value = renewSearchParams('schedule-interchangeReceipt') || { customerName: '', // 委托方名称 customerNo: '', // 委托方编号 deliverer: '', // 联系人/送检人 interchangeCode: '', // 交接单编号 reciever: '', // 收发员 startTime: '', // 交接开始时间 endTime: '', // 交接结束时间 orderNo: '', // 任务单编号 offset: 1, limit: 20, } // 表头 const columns = ref<TableColumn[]>([ { text: '委托单编号', value: 'orderNo', align: 'center', width: '160px' }, { text: '委托方名称', value: 'customerName', align: 'center' }, { text: '联系人', value: 'deliverer', align: 'center' }, { text: '电话', value: 'delivererTel', align: 'center' }, { text: '证书单位名称', value: 'certificationCompany', align: 'center' }, { text: '收发员', value: 'reciever', align: 'center', width: '180px' }, { text: '签收人', value: 'signee', align: 'center' }, { text: '交接样品数量', value: 'sampleAmount', align: 'center' }, ]) // 表格数据 const list = ref<IReceiptList[]>([]) // 总数 const total = ref(0) // 表格加载状态 const loadingTable = ref(false) // 选中的内容 const checkoutList = ref<string[]>([]) // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } getReceiptList(listQuery.value).then((response) => { list.value = response.data.rows total.value = parseInt(response.data.total) loadingTable.value = false }) } // 点击编辑/详情 const handleEdit = (row: IReceiptList, pageType: 'edit' | 'detail') => { $router.push({ path: `/schedule/receipt/${pageType}/${row.id}`, query: { createUser: row.createUser, // 创建人 }, }) } // 点击新建 const add = () => { $router.push('/schedule/receipt/add') } // 点击取消 const handleCancle = (id: string) => { deleteReceiptList({ id }).then(() => { ElMessage.success('已取消') fetchData(true) }) } // 点击搜索 const searchList = () => { fetchData(true) } // 点击重置 const clearList = () => { listQuery.value = { customerName: '', // 委托方名称 customerNo: '', // 委托方编号 deliverer: '', // 联系人/送检人 interchangeCode: '', // 交接单编号 reciever: '', // 收发员 startTime: '', // 交接开始时间 endTime: '', // 交接结束时间 orderNo: '', // 任务单编号 offset: 1, limit: 20, } fetchData(true) } // 多选发生改变时 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 exportAll = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (list.value.length > 0) { const params = { customerName: listQuery.value.customerName, // 委托方名称 customerNo: listQuery.value.customerNo, // 委托方编号 deliverer: listQuery.value.deliverer, // 联系人/送检人 interchangeCode: listQuery.value.interchangeCode, // 交接单编号 reciever: listQuery.value.reciever, // 收发员 startTime: listQuery.value.startTime, // 交接开始时间 endTime: listQuery.value.endTime, // 交接结束时间 orderNo: listQuery.value.orderNo, // 任务单编号 offset: 1, limit: 20, ids: checkoutList.value, } exportReceiptList(params).then((res) => { const blob = new Blob([res.data]) exportFile(blob, '设备交接单列表.xlsx') }) } else { ElMessage.warning('无数据可导出数据') } loading.close() } // 打印列表 function printList() { // 打印列 const properties = columns.value.map((item) => { return { field: item.value, displayName: item.text, } }) if (checkoutList.value.length <= 0 && list.value.length > 0) { printJSON(list.value, properties, '设备交接单列表') } else if (checkoutList.value.length > 0) { const printList = list.value.filter((item: IReceiptList) => checkoutList.value.includes(item.id)) printJSON(printList, properties, '设备交接单列表') } else { ElMessage.warning('无可打印内容') } } // 删除 const del = (id: string) => { ElMessageBox.confirm( '确认删除吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { delInterchangeReceiptList({ id }).then((res) => { ElMessage.success('删除成功') fetchData(true) }) }) } onMounted(() => { fetchData(true) }) </script> <template> <app-container> <search-area :need-clear="true" @search="searchList" @clear="clearList" > <search-item> <el-input v-model.trim="listQuery.orderNo" placeholder="委托单编号" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.customerName" placeholder="委托方名称" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.deliverer" placeholder="联系人" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.reciever" placeholder="收发员" class="short-input" clearable /> </search-item> </search-area> <table-container> <template #btns-right> <icon-button v-if="proxy.hasPerm('/schedule/receiptList/add')" icon="icon-add" title="新建" type="primary" @click="add" /> <icon-button v-if="proxy.hasPerm('/schedule/receiptList/export')" icon="icon-export" title="导出" type="primary" @click="exportAll" /> <icon-button v-if="proxy.hasPerm('/schedule/receiptList/print')" icon="icon-print" title="打印" type="primary" @click="printList" /> </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 v-if="proxy.hasPerm('/schedule/receiptList/edit')" size="small" type="primary" link :disabled="row.createUser !== user.id" @click="handleEdit(row, 'edit')" > 编辑 </el-button> <el-button size="small" link type="primary" @click="handleEdit(row, 'detail')" > 详情 </el-button> <!-- <el-button v-if="proxy.hasPerm('/schedule/receiptList/cancle')" size="small" link type="danger" @click="handleCancle(row.id)" > 取消 </el-button> --> <el-button size="small" link type="danger" :disabled="row.createUser !== user.id" @click="del(row.id)" > 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template> <style lang="scss" scoped> // 样式 </style>