<!-- 设备信息表格 --> <script lang="ts" setup name="DeviceInfoList"> import { reactive, ref } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import type { IlistObjType, IlistQueryType } from './interface' import { delTextBtn, editTextBtn } from '@/utils/applyBtns' import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue' import { cancelInfo, deleteInfo, editInfo, getInfoList, getInfoListPage, getInfoListTogether, submitInfo } from '@/api/eqpt/device/info' import { getDictByCode } from '@/api/system/dict' import { SCHEDULE } from '@/utils/scheduleDict' const $props = defineProps({ statusName: { type: String, default: '', }, // 设备类型(1受检设备;2特种设备) equipmentType: { type: String, default: '1', }, }) const applyDict = ref<{ [key: string]: string }>({ 审批: '', 草稿箱: '1', 审批中: '3', 已通过: '4', 未通过: '5', 已取消: '6', }) const { proxy } = getCurrentInstance() as any const listQuery = reactive<IlistQueryType>({ certificateValidStart: '', certificateValidEnd: '', deptIds: '', // 使用部门 usageStatus: '', // 使用状态 usePosition: '', // 使用岗位 equipmentNo: '', // 统一编号 equipmentName: '', // 设备名称 equipmentType: $props.equipmentType, // 设备类型(1受检设备;2特种设备) offset: 1, limit: 20, approvalStatus: '', formId: SCHEDULE.DEVICE_INFO_APPROVAL, }) const columns = ref([ { text: '统一编号', value: 'equipmentNo', align: 'center', }, { text: '设备名称', value: 'equipmentName', align: 'center', }, { text: '型号规格', value: 'model', align: 'center', }, { text: '出厂编号', value: 'manufactureNo', align: 'center', }, { text: '使用岗位', value: 'usePosition', align: 'center', }, { text: '计量标识', value: 'meterIdentify', align: 'center', }, { text: '检定周期', value: 'checkCycle', align: 'center', }, { text: '证书有效期', value: 'certificateValid', align: 'center', }, ]) const allColums = ref([ { text: '使用状态', value: 'usageStatusName', align: 'center', }, { text: '备注', value: 'remark', align: 'center', }, ]) const otherColums = ref([ { text: '审批类型', value: 'approvalTypeName', align: 'center', }, { text: '创建人', value: 'createUserName', align: 'center', }, { text: '创建时间', value: 'createTime', align: 'center', }, { text: '审批状态', value: 'approvalStatusName', align: 'center', }, ]) const list = ref([]) const total = ref(0) const listLoading = ref(true) // 获取列表数据 const fetchData = (isNowPage = true) => { list.value = [] total.value = 0 listLoading.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.offset = 1 } getInfoListPage(listQuery, $props.statusName).then((response) => { list.value = response.data.rows total.value = parseInt(response.data.total) listLoading.value = false }) } // 获取使用状态列表 const useStatusList = ref() const fetchUseStatus = () => { getDictByCode('eqptDeviceUseStatus').then((res) => { useStatusList.value = res.data }) } fetchUseStatus() // 查询数据 const search = () => { fetchData(false) } // 证书有效期开始结束时间 const datetimerange = ref() watch(() => datetimerange.value, (newVal) => { if (newVal.length === 2) { listQuery.certificateValidStart = newVal[0] listQuery.certificateValidEnd = newVal[1] } }) // 重置 const reset = () => { datetimerange.value = [] listQuery.equipmentNo = '' listQuery.equipmentName = '' listQuery.usageStatus = '' listQuery.usePosition = '' listQuery.certificateValidEnd = '' listQuery.certificateValidStart = '' listQuery.deptIds = '' listQuery.offset = 1 listQuery.limit = 20 search() } // 获取聚合表格数据 const togetherLoading = ref(true) const togetherList = ref([]) const fetchTogetherData = () => { togetherLoading.value = true getInfoListTogether(listQuery).then((res) => { togetherList.value = res.data togetherLoading.value = false }) } // 获取展开行内表格数据 const expandLoading = ref(true) const expandList = ref([]) const fetchExpandData = (params: any) => { expandLoading.value = true getInfoList(params).then((res) => { expandList.value = res.data expandLoading.value = false }) } const getRowKeys = (row: any) => { // 获取当前行id return row.equipmentName // 这里看这一行中需要根据哪个属性值是id } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size: number; page: number }) => { if (val && val.size) { listQuery.limit = val.size } if (val && val.page) { listQuery.offset = val.page } fetchData() } // 控制展开行 const expands = ref() const expandChange = (row: any, expandedRows: any) => { if (expandedRows.length) { expands.value = [] if (row) { expands.value.push(row.equipmentName) } } else { expands.value = [] } } watch(() => expands.value, (newVal) => { fetchExpandData({ equipmentName: newVal[0] }) }, { deep: true, }) const $router = useRouter() // 新建编辑操作 const handler = (row: IlistObjType, type: string) => { $router.push({ path: `/${$props.equipmentType === '1' ? 'dinfo' : 'speciallist'}/${type}`, query: { row: JSON.stringify(row), id: row.id, statusName: $props.statusName, equipmentType: $props.equipmentType, }, }) } // 详情 const detail = (row: IlistObjType) => { if ($props.statusName === '草稿箱' || $props.statusName === '未通过' || $props.statusName === '已取消') { handler(row, 'update') } else { $router.push({ path: `/${$props.equipmentType === '1' ? 'info' : 'speciallist'}/detail`, query: { row: JSON.stringify(row), id: row.id, statusName: $props.statusName, equipmentType: $props.equipmentType, }, }) } } // 删除 const valiate = (val: string | any) => { if (val) { return true } else { return false } } // 删除 const delHandler = (row: IlistObjType) => { if ($props.statusName === '全部') { // 删除设备 ElMessageBox.prompt('请填写删除原因', '确认删除', { confirmButtonText: '确认', cancelButtonText: '取消', inputValidator: valiate, inputErrorMessage: '请输入原因', }) .then(({ value }) => { console.log(row, 'row') editInfo({ approvalType: '3', equipmentId: row.id, id: null, }).then((res) => { // ElMessage.success('操作成功') // search() submitInfo({ id: res.data, formId: SCHEDULE.DEVICE_INFO_APPROVAL, reason: value, processId: row.processId }).then((res) => { ElMessage.success('操作成功') search() }) }) // ElMessage({ // type: 'success', // message: `Your email is:${value}`, // }) }) } else { ElMessageBox.confirm( '确认删除此记录吗?', '确认', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { // 分删除设备和删除记录 deleteInfo({ id: row.id }).then((res) => { ElMessage.success('操作成功') // close() search() }) }) } } // 取消 const canHandler = (row: IlistObjType) => { ElMessageBox.confirm( '确认取消此申请吗?', '确认', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { cancelInfo({ id: row.id, processInstanceId: row.processId, comments: '' }).then((res) => { ElMessage.success('操作成功') // close() search() }) }) } // 提交 const submit = (row: any) => { ElMessageBox.confirm( '确认提交吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then((res) => { submitInfo({ id: row.id, formId: SCHEDULE.DEVICE_INFO_APPROVAL }).then((res) => { ElMessage.success('已提交') search() }) }) } // 同意拒绝 const approvalDialogRef = ref() const approveHandler = (row: any, type: string) => { approvalDialogRef.value.initDialog(type, row.taskId, row.processId, row.id) } // 切换表格标识 true:普通表格 false:聚合表格 const tableFlage = ref(true) const changeTable = () => { tableFlage.value = !tableFlage.value if (tableFlage.value) { // 获取普通表格数据 fetchData() } else { // 获取聚合表格数据 fetchTogetherData() } } // 审批状态发生变化 watch(() => $props.statusName, (newVal) => { listQuery.approvalStatus = applyDict.value[newVal] as string fetchData() tableFlage.value = true }, { deep: true, // immediate: true, }) const permUrl = ref({ edit: '/tested/device/info/edit', del: '/tested/device/info/delete', submit: '/tested/device/info/submit', cancel: '/tested/device/info/cancel', agree: '/tested/device/info/agree', reject: '/tested/device/info/reject', }) </script> <template> <app-container> <!-- 审批弹窗 --> <approval-dialog ref="approvalDialogRef" @on-success="search" /> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="reset"> <search-item> <el-input v-model.trim="listQuery.equipmentNo" placeholder="统一编号" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.equipmentName" placeholder="设备名称" clearable /> </search-item> <!-- <search-item> <el-input v-model.trim="listQuery.equipmentName" placeholder="设备名称" clearable /> </search-item> --> <search-item> <el-input v-model.trim="listQuery.usePosition" placeholder="所属岗位" clearable /> </search-item> <search-item> <el-select v-model="listQuery.usageStatus" placeholder="使用状态" clearable> <el-option v-for="item in useStatusList" :key="item.value" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-date-picker v-model="datetimerange" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss" range-separator="至" start-placeholder="证书有效期开始时间" end-placeholder="证书有效期结束时间" /> </search-item> </search-area> <table-container> <template v-if="$props.statusName === '全部'" #btns-right> <icon-button icon="icon-change" title="切换列表状态" @click="changeTable" /> <icon-button icon="icon-sweep" title="扫描" /> <icon-button icon="icon-add" title="新增" @click="handler({}, 'create')" /> <icon-button icon="icon-import" title="批量导入" /> <icon-button icon="icon-template" title="模板下载" /> <icon-button icon="icon-export" title="导出" /> </template> <!-- 普通表格 --> <normal-table v-show=" tableFlage " :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="listLoading" :is-showmulti-select="true" @change="changePage" > <template #columns> <!-- 全部状态 --> <el-table-column v-for=" column of allColums " v-if=" $props.statusName === '全部' " :key=" column.value " :label=" column.text " :prop=" column.value " :width=" column.width " :align=" column.align " :show-overflow-tooltip="true" > <template #default=" scope "> <span> {{ scope.row[column.value] }}</span> </template> </el-table-column> <!-- 其他审批状态 --> <el-table-column v-for=" column of otherColums " v-else :key=" column.value " :label=" column.text " :prop=" column.value " :width=" column.width " :align=" column.align " :show-overflow-tooltip="true" > <template #default=" scope "> <span> {{ scope.row[column.value] }}</span> </template> </el-table-column> <el-table-column label="操作" width="160" align="center"> <template #default=" scope "> <el-button link type="primary" size="small" @click="detail(scope.row)"> 查看 </el-button> <el-button v-if="proxy.buttonPerm.edit.if({ approvalStatusName: $props.statusName }, permUrl.edit)" link type="primary" size="small" @click="handler(scope.row, 'update')" > 编辑 </el-button> <el-button v-if="proxy.buttonPerm.agree.if({ approvalStatusName: $props.statusName }, permUrl.agree)" link type="primary" size="small" @click="approveHandler(scope.row, 'agree')" > 同意 </el-button> <el-button v-if="proxy.buttonPerm.reject.if({ approvalStatusName: $props.statusName }, permUrl.reject)" link type="primary" size="small" @click="approveHandler(scope.row, 'refuse')" > 拒绝 </el-button> <el-button v-if="proxy.buttonPerm.submit.if({ approvalStatusName: $props.statusName }, permUrl.submit)" link type="primary" size="small" @click="submit(scope.row)" > 提交 </el-button> <el-button v-if="proxy.buttonPerm.cancel.if({ approvalStatusName: $props.statusName }, permUrl.cancel)" link type="primary" size="small" @click="canHandler(scope.row)" > 取消 </el-button> <el-button v-if="proxy.buttonPerm.edit.if({ approvalStatusName: $props.statusName }, permUrl.del)" link type="danger" size="small" @click="delHandler(scope.row)" > 删除 </el-button> <!-- <el-button v-if="$props.statusName === '审批中'" link type="danger" size="small" @click="canHandler(scope.row)"> 取消 </el-button> --> </template> </el-table-column> </template> </normal-table> <!-- 展开行表格 --> <normal-table v-show=" !tableFlage " class="nortable-header" :data=" [] " :total=" 0 " :columns=" columns " :options=" { needIndex: false, // 是否需要序号列 border: true, // 是否需要上方边框 } " :pagination=" false " :is-showmulti-select=" true " /> <el-table v-show=" !tableFlage " v-loading=" togetherLoading " :data=" togetherList " border style="width: 100%;" :row-key=" getRowKeys " :expand-row-keys=" expands " :show-header=" false " @expand-change=" expandChange " > <el-table-column type="expand"> <template #default="props"> <normal-table :data=" expandList " :total=" total " :columns=" columns " :list-loading=" expandLoading " :options=" { needIndex: false, // 是否需要序号列 border: true, // 是否需要上方边框 } " :pagination=" false " :is-showmulti-select=" true " :show-header=" false " /> </template> </el-table-column> <el-table-column label="设备名称" prop="equipmentName" align="center" /> <el-table-column label="数量" align="center"> <template #default=" scope "> 共计{{ scope.row.count }}台 </template> </el-table-column> </el-table> </table-container> </app-container> </template> <style lang="scss" scoped> .nortable-header { ::v-deep(.el-table__body-wrapper) { display: none; } } </style>