<!-- 设备台账管理列表页 --> <script name="EquipmentInfoBookList" setup lang="ts"> import type { Ref } from 'vue' import { getCurrentInstance, onMounted, ref, watch } from 'vue' import type { DateModelType } from 'element-plus' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import dayjs from 'dayjs' import type { IList, IListQuery } from './testEquipment-interface' import { batchImport, deleteTestEquipment, getTestEquipmentList } from '@/api/resource/testEquipment' import type { deptType } from '@/global' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import type { IMenu } from '@/components/buttonBox/buttonBox' import useTemplateDownload from '@/utils/useTemplateDownload' import useUserStore from '@/store/modules/user' const { proxy } = getCurrentInstance() as any const user = useUserStore() const $router = useRouter() // 查询条件 const listQuery: Ref<IListQuery> = ref({ certificateValidEnd: '', // 证书有效期结束时间 certificateValidStart: '', // 证书有效期开始时间 customerId: '', // 委托方id equipmentName: '', // 设备名称 equipmentNo: '', // 统一编号 equipmentType: '', // 设备类型(1受检设备;2特种设备) manufactureNo: '', // 出厂编号 model: '', // 规格型号 customerName: '', // 委托方名称 offset: 1, limit: 20, }) const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading const menu = ref<IMenu[]>([]) // 审批状态按钮组合 // 表头 const columns = ref<TableColumn[]>([ // { text: '统一编号', value: 'equipmentNo', align: 'center' }, { text: '设备名称', value: 'equipmentName', align: 'center' }, { text: '委托方名称', value: 'customerName', align: 'center' }, { text: '设备型号', value: 'model', align: 'center' }, { text: '出厂编号', value: 'manufacturer', align: 'center' }, // { text: '专业分类', value: 'equipmentType', align: 'center' }, // { text: '业务类型', value: 'category', align: 'center', width: '120' }, { text: '检定校准时间', value: 'certificateValid', align: 'center', width: '120' }, { text: '备注', value: 'remark', align: 'center' }, ]) const list = ref<IList[]>([]) // 表格数据 const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const checkoutList = ref<string[]>([])// 选中的内容 // -----------------------------------------字典-------------------------------------------------------------- const majorTypeList = ref<deptType[]>([]) // 专业分类 const businessTypeList = ref<deptType[]>([]) // 业务类型 // 查询字典 const getDict = async () => { // 专业分类 getDictByCode('bizGroupCodeEquipment').then((response) => { majorTypeList.value = response.data }) // 业务类型 getDictByCode('businessType').then((response) => { businessTypeList.value = response.data }) } // ------------------------------------------------------------------------------------------------------- // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } getTestEquipmentList({ ...listQuery.value }).then((response) => { list.value = response.data.rows.map((item: { estimateSignDate: string; agreementAmount: number; certificateValid: string }) => { return { ...item, certificateValid: item.certificateValid ? dayjs(item.certificateValid).format('YYYY-MM-DD') : item.certificateValid, } }) total.value = parseInt(response.data.total) loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 搜索 const searchList = () => { fetchData(true) } // 重置 const clearList = () => { listQuery.value = { certificateValidEnd: '', // 证书有效期结束时间 certificateValidStart: '', // 证书有效期开始时间 customerId: '', // 委托方id equipmentName: '', // 设备名称 equipmentNo: '', // 统一编号 equipmentType: '', // 设备类型(1受检设备;2特种设备) manufactureNo: '', // 出厂编号 model: '', // 规格型号 customerName: '', // 委托方名称 offset: 1, limit: 20, } dateRange.value = ['', ''] 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) // } // 改变页容量 function handleSizeChange(val: number) { listQuery.value.limit = val fetchData() } // 改变当前页 function handleCurrentChange(val: number) { listQuery.value.offset = val fetchData(true) } // -------------------------------------表格上方工具栏----------------------------------- const fileRef = ref() // 文件上传input const onFileChange = (event: any) => { // 原生上传 if (event.target.files?.length !== 0) { // 创建formdata对象 const fd = new FormData() fd.append('file', event.target.files[0]) const loading = ElLoading.service({ lock: true, background: 'rgba(255, 255, 255, 0.8)', }) // 调批量导入接口 batchImport(fd).then((res) => { ElMessage.success('上传成功') event.target.value = null loading.close() fetchData(true) loading.close() }).catch(() => { event.target.value = null loading.close() }) } } // 批量导入 const handleBatchImport = () => { fileRef.value.click() } // 新建 const add = () => { $router.push({ path: 'testEquipment/add' }) } // ----------------------------------------------操作--------------------------------------------------- const handleEdit = (row: IList, type: string) => { if (type === 'edit' || type === 'detail') { // 编辑、详情 $router.push({ path: `testEquipment/${type}/${row.id}`, query: { }, }) } else { ElMessageBox.confirm( `确认${type}吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { deleteTestEquipment({ id: row.id }).then(() => { ElMessage.success(`已${type}`) fetchData() }) }) } } // ----------------------------------------------钩子------------------------------------------------------ watch(dateRange, (val) => { if (val) { listQuery.value.certificateValidStart = `${val[0]}` listQuery.value.certificateValidEnd = `${val[1]}` } else { listQuery.value.certificateValidStart = '' listQuery.value.certificateValidEnd = '' } }) onMounted(async () => { getDict() fetchData() }) </script> <template> <div class="equipment-info-book"> <app-container> <search-area :need-clear="true" @search="searchList" @clear="clearList"> <!-- <search-item> <el-input v-model.trim="listQuery.equipmentNo" placeholder="统一编号" class="short-input" clearable /> </search-item> --> <search-item> <el-input v-model.trim="listQuery.equipmentName" 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.customerName" placeholder="委托方名称" class="short-input" clearable /> </search-item> <!-- <search-item> <el-select v-model="listQuery.equipmentType" placeholder="专业分类" class="short-input" filterable clearable > <el-option v-for="item in majorTypeList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> --> <!-- <search-item> <el-select v-model="listQuery.ywlx" placeholder="业务类型" class="short-input" filterable clearable > <el-option v-for="item in businessTypeList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </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-area> <table-container> <template #btns-right> <icon-button v-if="proxy.hasPerm('/resource/testEquipment/add')" icon="icon-add" title="新建" type="primary" @click="add" /> <icon-button v-if="proxy.hasPerm('/resource/testEquipment/import')" icon="icon-import" title="批量导入" type="primary" @click="handleBatchImport" /> <icon-button v-if="proxy.hasPerm('/resource/testEquipment/import')" icon="icon-template" title="模板下载" type="primary" @click="useTemplateDownload('设备台账管理')" /> </template> <input v-show="false" id="fileInput" ref="fileRef" type="file" accept="*" @change="onFileChange"> <el-table v-loading="loadingTable" :data="list" border style="width: 100%;" :row-key="(row: any) => { return row.id || row.index }" @selection-change="handleSelectionChange" > <el-table-column :reserve-selection="true" type="selection" width="38" fixed="left" /> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> <el-table-column v-for="item in columns" :key="item.value" :prop="item.value" :label="item.text" :width="item.width" :show-overflow-tooltip="true" align="center" /> <el-table-column fixed="right" label="操作" width="150" align="center" > <template #default="{ row }"> <el-button size="small" type="primary" link @click="handleEdit(row, 'detail')" > 查看 </el-button> <el-button v-if="proxy.hasPerm('/resource/testEquipment/edit')" size="small" link type="primary" @click="handleEdit(row, 'edit')" > 编辑 </el-button> <el-button v-if="proxy.hasPerm('/resource/testEquipment/delete')" size="small" link type="danger" @click="handleEdit(row, '删除')" > 删除 </el-button> </template> </el-table-column> </el-table> <!-- 页码 --> <el-pagination style="width: 100%;margin-top: 10px;" :current-page="listQuery.offset" :page-sizes="[5, 10, 20, 30, 50, 100, 150, 200]" :page-size="listQuery.limit" :total="total" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange" @current-change="handleCurrentChange" /> </table-container> </app-container> </div> </template>