<!-- 参照标准、工作标准和关键测量设备表列表页 --> <script name="EquipmentInfoTableList" lang="ts" setup> 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 './table-interface' import type { deptType, dictType } from '@/global' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import { getDeptTreeList } from '@/api/system/dept' import { getUserList } from '@/api/system/user' import { toTreeList } from '@/utils/structure' import type { IMenu } from '@/components/buttonBox/buttonBox' const $router = useRouter() const { proxy } = getCurrentInstance() as any const active = ref('') const operateWidth = ref('90') // 操作栏的宽度 const buttonBoxActive = 'equipmentInfoBook' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态 const approvalDialog = ref() // 审批对话ref // 查询条件 const listQuery: Ref<IListQuery> = ref({ equipmentNo: '', // 统一编号 equipmentName: '', // 设备名称 manufactureNo: '', // 出厂编号 standardType: '', // 标准类型 deptId: '', // 所属部门id deptName: '', // 所属部门 directorId: '', // 负责人id directorName: '', // 负责人 traceCompany: '', // 溯源单位 startTime: '', // 检定有效期(开始) endTime: '', // 检定有效期(结束) 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', width: '140' }, { text: '设备名称', value: 'equipmentName', align: 'center' }, { text: '型号规格', value: 'model', align: 'center' }, { text: '标准类型', value: 'standardType', align: 'center' }, { text: '生产厂家', value: 'manufacturer', align: 'center' }, { text: '出厂编号', value: 'manufactureNo', align: 'center' }, { text: '所属部门', value: 'deptName', align: 'center' }, { text: '负责人', value: 'directorName', align: 'center' }, { text: '使用状态', value: 'usageStatus', align: 'center', width: '90' }, { text: '检定有效期', value: 'measureValidDate', align: 'center', width: '120' }, { text: '溯源单位', value: 'traceCompany', align: 'center' }, ]) const list = ref<IList[]>([]) // 表格数据 const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const checkoutList = ref<string[]>([])// 选中的内容 // -----------------------------------------字典-------------------------------------------------------------- const useDeptList = ref<deptType[]>([]) // 所属部门列表 const userList = ref<{ [key: string]: string }[]>([]) // 用户列表 const standardTypeList = ref<dictType[]>([]) // 标准类型 // 查询字典 const getDict = async () => { // 获取部门列表 getDeptTreeList().then((res) => { // 转成树结构 useDeptList.value = toTreeList(res.data, '0', true) }) // 获取用户列表 getUserList({ offset: 1, limit: 999999 }).then((res: any) => { userList.value = res.data.rows }) // 标准类型 getDictByCode('').then((response) => { standardTypeList.value = response.data }) } // ------------------------------------------------------------------------------------------------------- // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } // getContractList(listQuery.value).then((response) => { // list.value = response.data.rows.map((item: { estimateSignDate: string; agreementAmount: number }) => { // return { // ...item, // estimateSignDate: item.estimateSignDate ? dayjs(item.estimateSignDate).format('YYYY-MM-DD') : item.estimateSignDate, // agreementAmount: calc(Number(item.agreementAmount), 100, '/'), // } // }) // total.value = parseInt(response.data.total) // loadingTable.value = false // }).catch(() => { loadingTable.value = false // }) list.value = [ { id: 'test', // 主键 equipmentNo: 'test', // 统一编号 equipmentName: 'test', // 设备名称 model: 'test', // 型号规格 unitPrice: 'test', // 设备单价(万元) manufacturer: 'test', // 生产厂家 manufactureNo: 'test', // 出厂编号 deptName: 'test', // 所属部门 directorName: 'test', // 负责人 usageStatus: 'test', // 使用状态 measureValidDate: 'test', // 检定有效期 traceCompany: 'test', // 溯源单位 standardType: 'test', }, ] } // 搜索 const searchList = () => { fetchData(true) } // 重置 const clearList = () => { listQuery.value = { equipmentNo: '', // 统一编号 equipmentName: '', // 设备名称 manufactureNo: '', // 出厂编号 standardType: '', // 标准类型 deptId: '', // 所属部门id deptName: '', // 所属部门 directorId: '', // 负责人id directorName: '', // 负责人 traceCompany: '', // 溯源单位 startTime: '', // 检定有效期(开始) endTime: '', // 检定有效期(结束) 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) } // -------------------------------------表格上方工具栏----------------------------------- // 导出word const exportWord = () => {} // 导出excel const exportExcel = () => {} // ----------------------------------------------操作--------------------------------------------------- const handleEdit = (row: IList, type: string) => { if (type === 'detail') { $router.push({ path: `/equipmentInfo/${type}/${row.id}`, query: { // id: row.id, }, }) } } // ----------------------------------------------钩子------------------------------------------------------ watch(dateRange, (val) => { if (val) { listQuery.value.startTime = `${val[0]}` listQuery.value.endTime = `${val[1]}` } else { listQuery.value.startTime = '' listQuery.value.endTime = '' } }) onMounted(async () => { // await getDict() fetchData(true) }) </script> <template> <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-select v-model="listQuery.standardType" placeholder="标准类型" class="short-input" filterable > <el-option v-for="item in standardTypeList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" class="short-input" clearable /> </search-item> <search-item> <el-select v-model="listQuery.deptId" placeholder="所属部门" class="short-input" filterable > <el-option v-for="item in useDeptList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.directorId" placeholder="负责人" class="short-input" filterable > <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.traceCompany" placeholder="溯源单位" class="short-input" clearable /> </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 icon="icon-word" title="导出word" type="primary" @click="exportWord" /> <icon-button icon="icon-excel" title="导出excel" type="primary" @click="exportExcel" /> </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="operateWidth" > <template #default="{ row }"> <el-button size="small" type="primary" link @click="handleEdit(row, 'detail')" > 详情 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template> <style lang="ts" scoped> </style>