<!-- UPS内阻测试记录 列表 --> <script name="EnvironmentUpsResistanceList" lang="ts" setup> import type { DateModelType } from 'element-plus' import { ElLoading, ElMessage, ElMessageBox, dayjs } from 'element-plus' import type { IListQuery, IUpsResistanceRecord } from './ups-interface' import ApprovalDialog from '@/views/resource/common/approvalDialog.vue' import { SCHEDULE } from '@/utils/scheduleDict' import type { IMenu } from '@/components/buttonBox/buttonBox' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import { canceledApprDeleteUpsResistance, draftDeleteUpsResistance, getStreamUpsResistance, getUpsResistanceRecordList, refuseApprovalUpsResistance, rejectApprovalUPS, revokeApprovalUpsResistance } from '@/api/resource/environmentTest' import type { IDictType } from '@/commonInterface/resource-interface' import upsLocation from '/public/config/ups.json' import { findDictNameByCode } from '@/commonMethods/useDictCheck' import type { deptType } from '@/global' import { printPdf } from '@/utils/printUtils' import { exportFile } from '@/utils/exportUtils' import useBridgeCount from '@/components/buttonBox/useBridgeCount' // 定义常量 const buttonBoxActive = 'labUpsResistanceRecordApproval' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态 const { proxy } = getCurrentInstance() as any const router = useRouter() // 选中的审批状态按钮 const active = ref('') const menu = ref<IMenu[]>([]) // 审批状态按钮组合 const approvalStatusList = ref<String[]>([ '全部', '已审批', '待审批', '审批', '草稿箱', '审批中', '已通过', '未通过', '已取消', ]) // 弹窗子组件 const apprDial = ref() // 查询条件 const searchQuery = ref<IListQuery>({ testLocation: '', // 测试地点 testTimeStart: '', // 测试时间-起始 testTimeEnd: '', // 测试时间-结束 testUseEquipment: '', batteryBrand: '', batteryCapacity: '', conclusion: '', approvalStatus: active.value, // 审批状态 formId: SCHEDULE.UPS_RESISTANCE_RECORD_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值 offset: 1, limit: 20, }) const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const total = ref(0) // 数据条数 const totalToApproval = ref(0) // 待审批数据条数 const totalApproval = ref(0) // 审批中数据条数 const totalRefuse = ref(0) // 未通过数据条数 const loadingTable = ref(false) // 表格loading // 表头 const columns = ref<TableColumn[]>([ // { text: '文件编号', value: 'recordNo', align: 'center', width: '180' }, { text: '测试时间', value: 'testTime', align: 'center', width: '160' }, { text: '测试地点', value: 'testLocationName', align: 'center', width: '240' }, { text: '测试人员', value: 'createUserName', align: 'center', width: '120' }, { text: '测试仪表', value: 'testUseEquipment', align: 'center', width: '200' }, { text: '蓄电池品牌型号', value: 'batteryBrand', align: 'center' }, { text: '蓄电池容量', value: 'batteryCapacity', align: 'center', width: '140' }, { text: '测试结论', value: 'conclusionName', align: 'center', width: '160' }, { text: '审批状态', value: 'approvalStatusName', align: 'center', width: '100' }, ]) const list = ref<Array<IUpsResistanceRecord>>([]) // 表格数据 const checkoutList = ref<Array<IUpsResistanceRecord>>([]) // 多选表格数据 // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } const conclusionDict = ref<Array<IDictType>>([]) // 逻辑 // 跳转到新建的页面 const addTestRecord = () => { router.push({ query: { type: 'create', }, path: 'ups/detail', }) } // 点击编辑按钮 const updateInfo = (row: IUpsResistanceRecord) => { sessionStorage.setItem('upsResistanceRecordTaskId', row.taskId!) router.push({ query: { type: 'update', id: row.id, status: row.approvalStatus, processId: row.processId, taskId: row.taskId, decisionItem: row.decisionItem, }, path: 'ups/detail', }) } // 点击查看(或编辑)按钮 const detail = (row: IUpsResistanceRecord) => { if (searchQuery.value.approvalStatus === '1') { // 全部或草稿箱 状态的 查看 是可以编辑的组件 updateInfo(row) } else if (active.value === '0') { router.push({ query: { type: 'ups', id: row.id, status: row.approvalStatus, processId: row.processId, taskId: row.taskId, decisionItem: row.decisionItem, }, path: `ups/approved/detail/${row.id}`, }) } else { // 将行数据存入缓存 用来在路由之间传递数据 sessionStorage.setItem('upsResistanceRecordTaskId', row.taskId!) router.push({ query: { type: 'detail', id: row.id, status: row.approvalStatus, processId: row.processId, taskId: row.taskId, decisionItem: row.decisionItem, }, path: 'ups/detail', }) } } // 删除UPS蓄电池内阻测试记录 或 删除草稿箱中的审批单 const deleteById = (row: any) => { ElMessageBox.confirm('是否删除UPS蓄电池内阻测试记录', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }).then(() => { if (active.value === '1') { // 草稿箱中的删除记录 draftDeleteUpsResistance({ id: row.id }).then((res) => { if (res.code === 200) { ElMessage.success('UPS蓄电池内阻测试记录删除成功') fetchData() } else { ElMessage.error(`UPS蓄电池内阻测试记录删除失败: ${res.message}`) } }) } else if (active.value === '6') { // 已取消中的删除记录 canceledApprDeleteUpsResistance({ id: row.id, taskId: row.taskId }).then((res) => { if (res.code === 200) { ElMessage.success('UPS蓄电池内阻测试记录删除成功') fetchData() } else { ElMessage.error(`UPS蓄电池内阻测试记录删除失败: ${res.message}`) } }) } }) } // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } if (searchQuery.value.approvalStatus === '10') { searchQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传'' getUpsResistanceRecordList(searchQuery.value).then((response) => { if (response.code === 200) { list.value = response.data.rows.map((item: IUpsResistanceRecord) => { return { ...item, testTime: item.createTime!.length > 16 ? item.createTime!.substring(0, 10) : '', conclusionName: findDictNameByCode(item.conclusion, conclusionDict.value), testLocationName: findDictNameByCode(item.testLocation, upsLocation), } }) total.value = parseInt(response.data.total) } loadingTable.value = false }).catch(() => { loadingTable.value = false }) // 获取待审批,审批中,未通过数据数量 useBridgeCount(searchQuery.value).then((res: any) => { totalToApproval.value = res.totalToApproval // 待审批数据条数 totalApproval.value = res.totalApproval // 审批中数据条数 totalRefuse.value = res.totalRefuse // 未通过数据条数 }) } const searchList = () => { fetchData(true) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.value.limit = val.size } if (val && val.page) { searchQuery.value.offset = val.page } fetchData(true) } // 重置 const reset = () => { searchQuery.value = { testLocation: '', // 测试地点 testTimeStart: '', // 测试时间-起始 testTimeEnd: '', // 测试时间-结束 testUseEquipment: '', batteryBrand: '', batteryCapacity: '', conclusion: '', approvalStatus: active.value, // 审批状态 formId: SCHEDULE.UPS_RESISTANCE_RECORD_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值 offset: 1, limit: 20, } dateRange.value = ['', ''] fetchData(true) } // 审批按钮点击切换事件 const changeCurrentButton = (val: string) => { active.value = val // 此时的tab window.sessionStorage.setItem(buttonBoxActive, val) // 记录tab状态 reset() // 刷新 } // ----------------------------------------------审批------------------------------------------------ // 流程审批-同意 const approvalAgreeHandler = (row: IUpsResistanceRecord) => { apprDial.value.initDialog('agree', row.id, row.taskId, '') } // 流程审批-驳回 const approvalRejectHandler = (row: IUpsResistanceRecord) => { apprDial.value.initDialog('reject', row.id, row.taskId, '') } // 流程审批-拒绝 const approvalRefuseHandler = (row: IUpsResistanceRecord) => { apprDial.value.initDialog('refuse', row.id, row.taskId, '') } // 取消(撤回审批单) const revokeApprById = (row: IUpsResistanceRecord) => { const params = { processInstanceId: row.processId!, comments: '', id: row.id, } ElMessageBox.confirm( '确认取消该审批吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { const loading = ElLoading.service({ lock: true, text: '正在取消中,请耐心等待...', background: 'rgba(255, 255, 255, 0.6)', }) revokeApprovalUpsResistance(params).then((res) => { loading.close() ElMessage({ type: 'success', message: '已取消', }) fetchData(true) }) }) } // 流程操作之后刷新 const afterApprovalHandler = () => { fetchData(true) } // 拒绝 const refuseHandler = (param: any) => { refuseApprovalUpsResistance(param).then((res) => { if (res.code === 200) { ElMessage.success('拒绝审批完成') } else { ElMessage.error(`拒绝审批失败:${res.message}`) } // 关闭弹窗 apprDial.value.handleClose() fetchData(true) }) } // 驳回 const reject = (comments: string, taskId: string, id: string) => { const param = { id, taskId, // 任务id comments, // 拒绝原因 } rejectApprovalUPS(param).then((res) => { if (res.code === 200) { ElMessage.success('已驳回') } else { ElMessage.error(`驳回失败:${res.message}`) } // 关闭弹窗 apprDial.value.handleClose() fetchData(true) }) } // 初始化流程审批状态按钮 const getApprovalStatusDict = () => { getDictByCode('approvalStatus').then((res) => { if (res.code === 200) { approvalStatusList.value.forEach((item) => { const tempFindData = res.data.find((e: { name: string; value: string }) => e.name === item) if (tempFindData) { menu.value.push({ name: tempFindData.name, id: `${tempFindData.value}`, }) } }) } }) } // --------------------------------------打印\导出word----------------------------------------------- const stream = ref() as any // 流 // 获取流 const fetchStream = async (isPdf = true) => { const loading = ElLoading.service({ lock: true, text: '加载中...', background: 'rgba(255, 255, 255, 0.6)', }) const res = await getStreamUpsResistance({ id: checkoutList.value[0], pdf: isPdf }) stream.value = res.data loading.close() } // 点击导出word const exportWord = () => { if (!checkoutList.value.length) { ElMessage.warning('请至少选择一项') return false } if (checkoutList.value.length > 0 && checkoutList.value.length !== 1) { ElMessage.warning('只允许选中一项') return false } fetchStream(false).then((res) => { exportFile(stream.value, '工作间供电电压记录.doc') }) } // 点击打印 const handlePrint = () => { if (!checkoutList.value.length) { ElMessage.warning('请至少选择一项') return false } if (checkoutList.value.length > 0 && checkoutList.value.length !== 1) { ElMessage.warning('只允许选中一项') return false } fetchStream().then(() => { const blobUrl = URL.createObjectURL(stream.value) printPdf(blobUrl) }) } // --------------------------------------字典----------------------------------------------- const useDeptList = ref<deptType[]>([]) // 部门 const labDeptList = ref<deptType[]>([]) // 实验室 // 查询字典 const getDictFun = () => { // 实验室 getDictByCode('bizLabCode').then((response) => { labDeptList.value = response.data }) // 部门 getDictByCode('bizGroupCode').then((response) => { useDeptList.value = response.data }) // 结论 getDictByCode('bizUpsConclusion').then((res) => { if (res.code === 200) { conclusionDict.value = res.data sessionStorage.setItem('bizUpsConclusion', JSON.stringify(res.data)) } }) } const getDict = async () => { getApprovalStatusDict() getDictFun() } watch(dateRange, (val) => { if (val) { searchQuery.value.testTimeStart = dayjs(val[0]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[0]).format('YYYY-MM-DD') searchQuery.value.testTimeEnd = dayjs(val[1]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[1]).format('YYYY-MM-DD') } else { searchQuery.value.testTimeStart = '' searchQuery.value.testTimeEnd = '' } }) watch(() => active.value, (val) => { if (val === '10') { // 审批把审批状态加上 if (columns.value[columns.value.length - 1].value !== 'approvalStatusName') { columns.value.push({ text: '审批状态', value: 'approvalStatusName', align: 'center' }) } } else { // 其他不显示审批状态 if (columns.value[columns.value.length - 1].value === 'approvalStatusName') { columns.value.pop() } } }, { immediate: true }) onMounted(async () => { await getDict() if (sessionStorage.getItem(buttonBoxActive) !== 'undefined' && sessionStorage.getItem(buttonBoxActive) !== null) { active.value = sessionStorage.getItem(buttonBoxActive)! } else { active.value = '0' // 全部 } }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item> <el-select v-model="searchQuery.testLocation" placeholder="测试地点" clearable> <el-option v-for="loc in upsLocation" :key="loc.value" :value="loc.value" :label="loc.name" /> </el-select> </search-item> <search-item> <el-date-picker v-model="dateRange" type="daterange" start-placeholder="测试时间(开始)" end-placeholder="测试时间(结束)" /> </search-item> <search-item> <el-input v-model="searchQuery.testUseEquipment" placeholder="测试仪表" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.batteryBrand" placeholder="蓄电池品牌型号" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.batteryCapacity" placeholder="蓄电池容量" clearable /> </search-item> <search-item> <el-select v-model="searchQuery.conclusion" placeholder="测试结论" clearable> <el-option v-for="dict in conclusionDict" :key="dict.id" :label="dict.name" :value="dict.value" /> </el-select> </search-item> </search-area> <!-- 表格数据展示 --> <table-container> <!-- 表头区域 --> <template v-if="active === '0' && proxy.hasPerm(`/resource/environment/ups/add`)" #btns-right> <icon-button icon="icon-add" title="新建" @click="addTestRecord" /> <icon-button icon="icon-word" title="导出word" @click="exportWord" /> <icon-button icon="icon-print" title="打印" @click="handlePrint" /> </template> <normal-table id="recordTableRef" :data="list" :total="total" :columns="columns" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange" > <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column fixed="right" label="操作" align="center" width="180"> <template #default="{ row }"> <el-button size="small" type="primary" link @click="detail(row)"> 查看 </el-button> <el-button v-if="(row.approvalStatus === '1' || row.approvalStatus === '6') && proxy.hasPerm(`/resource/environment/ups/del`)" size="small" type="danger" link @click="deleteById(row)"> 删除 </el-button> <template v-if="row.approvalStatus === '2'"> <el-button size="small" type="primary" link @click="approvalAgreeHandler(row)"> 同意 </el-button> <el-button v-if="`${row.decisionItem}` === '1' || `${row.decisionItem}` === '2'" size="small" link type="warning" @click="approvalRejectHandler(row)" > 驳回 </el-button> <el-button v-if="`${row.decisionItem}` === '1' || `${row.decisionItem}` === '3'" size="small" type="danger" link @click="approvalRefuseHandler(row)"> 拒绝 </el-button> </template> <template v-if="row.approvalStatus === '3'"> <el-button size="small" type="info" link @click="revokeApprById(row)"> 取消 </el-button> </template> </template> </el-table-column> </template> </normal-table> </table-container> <!-- 审批单弹窗 --> <approval-dialog ref="apprDial" @on-success="afterApprovalHandler" @on-refuse="refuseHandler" @reject="reject" /> <!-- 右上角按钮集合 --> <button-box :active="active" :total-refuse="totalRefuse" :total-approval="totalApproval" :total-to-approval="totalToApproval" :menu="menu" @change-current-button="changeCurrentButton" /> </app-container> </template>