<!-- 分包验收列表 --> <script lang="ts" setup name="check"> import type { Ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { DateModelType } from 'element-plus' import type { IApplyList, IListQuery } from '../subpackage-interface' import type { IList } from './check-interface' import { printJSON } from '@/utils/printUtils' import { exportFile } from '@/utils/exportUtils' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import type { dictType } from '@/views/device/receive/receive' import type { IMenu } from '@/components/buttonBox/buttonBox' import { SCHEDULE } from '@/utils/scheduleDict' import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue' import ButtonBox from '@/components/buttonBox/buttonBox.vue' import { deleteListItem, getListPage, submit } from '@/api/business/subpackage/check' import { cancelApproval } from '@/api/approval' import { getUserList } from '@/api/system/user' import type { userType } from '@/views/system/user/user-interface' import { keepSearchParams, renewSearchParams } from '@/utils/keepQuery' const approvalDialog = ref() // 审批对话ref const $route = useRoute() const $router = useRouter() const { proxy } = getCurrentInstance() as any const usePersonList = ref<userType[]>([]) // 申请人列表(用户) const usePersonOptions = ref<userType[]>([]) // 申请人列表(用户)--模糊搜索数据 const applyPersonLoading = ref(false) // 申请人模糊搜索框loading const TabActiveButton = 'SubpackageCheckActive' const loadingTable = ref(false) const timeRange = ref<[DateModelType, DateModelType]>(['', '']) const menu = ref<IMenu[]>([]) // 审批状态按钮组合 const active = ref('') // 查询条件 const listQuery: Ref<IListQuery> = ref({ checkStartTime: '', // 开始时间 checkEndTime: '', // 结束时间 applicantName: '', // 申请人名称 approvalStatus: active.value, // 申请状态 formId: SCHEDULE.BUSINESS_SUBPACKAGE_CHECK, // 表单id outsourcerName: '', // 分包方名称 projectName: '', // 分包项目名称 projectNo: '', // 分包项目编号 createUserId: '', // 验收人id offset: 1, limit: 20, }) // 页面跳转之前保存参数 onBeforeRouteLeave((to: any) => { keepSearchParams(to.path, 'subpackage-check', listQuery.value) }) // 重新赋值 listQuery.value = renewSearchParams('subpackage-check') || { checkStartTime: '', // 开始时间 checkEndTime: '', // 结束时间 applicantName: '', // 申请人名称 approvalStatus: active.value, // 申请状态 formId: SCHEDULE.BUSINESS_SUBPACKAGE_CHECK, // 表单id outsourcerName: '', // 分包方名称 projectName: '', // 分包项目名称 projectNo: '', // 分包项目编号 createUserId: '', // 验收人id offset: 1, limit: 20, } // 表头 const columns = ref<TableColumn[]>([ { text: '分包项目编号', value: 'projectNo', align: 'center', width: '160px' }, { text: '分包项目名称', value: 'projectName', align: 'center' }, { text: '验收人', value: 'checkerName', align: 'center' }, { text: '分包方名称', value: 'outsourcerName', align: 'center' }, { text: '验收结论', value: 'checkConclusion', align: 'center' }, { text: '验收时间', value: 'checkTime', align: 'center', width: '180px' }, { text: '审批状态', value: 'approvalStatusName', align: 'center', width: '110px' }, ]) const list = ref<IList[]>([]) // 表格数据 const total = ref(0) // 表格总数 // 选中的内容 const checkoutList = ref<string[]>([]) // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true // if (!isNowPage) { // // 是否显示当前页,否则跳转第一页 // listQuery.value.offset = 1 // } // 模拟数据 getListPage(listQuery.value).then((response) => { list.value = response.data.rows.map((item: IList) => { return { ...item, approvalStatusName: item.checkApprovalStatusName, } }) total.value = parseInt(response.data.total) loadingTable.value = false }) } // 搜索 const searchList = () => { fetchData(true) } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } // 重置 const reset = () => { listQuery.value = { checkEndTime: '', // 开始时间 applicantName: '', // 申请人名称 checkStartTime: '', // 结束时间 approvalStatus: active.value, // 申请状态 formId: SCHEDULE.BUSINESS_SUBPACKAGE_CHECK, // 表单id outsourcerName: '', // 分包方名称 projectName: '', // 分包项目名称 projectNo: '', // 分包项目编号 offset: 1, limit: 20, } timeRange.value = ['', ''] fetchData() } // 时间变更 watch(timeRange, (val) => { if (val) { listQuery.value.checkStartTime = `${val[0]}` listQuery.value.checkEndTime = `${val[1]}` } else { listQuery.value.checkStartTime = '' listQuery.value.checkEndTime = '' } }) // 打印 const 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: IList) => checkoutList.value.includes(item.id)) printJSON(printList, properties, '分包项目验收列表') } else { ElMessage.warning('无可打印内容') } } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 add = () => { $router.push({ path: 'subpackage/check/add', query: { formId: listQuery.value.formId, }, }) } // 操作 const handleEdit = (row: IList, val: string, title = '') => { if (val === '取消') { const params = { processInstanceId: row.checkProcessId!, comments: '', } ElMessageBox.confirm( '确认取消该审批吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { cancelApproval(params).then((res) => { ElMessage({ type: 'success', message: '取消成功', }) fetchData(true) }) }) } else if (val === '删除') { ElMessageBox.confirm( '确认删除吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { deleteListItem({ id: row.id }).then((res) => { ElMessage({ type: 'success', message: '删除成功', }) fetchData(true) }) }) } else if (val === '提交') { ElMessageBox.confirm( '确认提交该审批吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { submit({ id: row.id, formId: SCHEDULE.BUSINESS_SUBPACKAGE_CHECK, processId: row.checkApprovalStatusName === '已取消' ? row.checkProcessId : '' }).then((res: any) => { ElMessage({ type: 'success', message: '已提交', }) fetchData(true) }) }) } else if (val === '同意') { approvalDialog.value.initDialog('agree', row.taskId, row.decisionItem) } else if (val === '驳回') { approvalDialog.value.initDialog('reject', row.taskId, row.decisionItem) } else if (val === '拒绝') { approvalDialog.value.initDialog('refuse', row.taskId, row.decisionItem) } else if (val === 'detail' || val === 'edit') { // 详情和编辑 $router.push({ path: `subpackage/check/${val}/${row.id}`, query: { formId: listQuery.value.formId, approvalStatusName: row.approvalStatusName, // 审批状态名称 checkProcessId: row.checkProcessId, // 流程实例 taskId: row.taskId, decisionItem: `${row.decisionItem}`, }, }) } } // 审批结束回调 const approvalSuccess = () => { fetchData(true) } // 获取字典值 const getDict = async () => { // 审批状态 const res = await getDictByCode('approvalStatus') // 制作右上角的菜单 res.data.forEach((item: dictType) => { if (item.name === '全部' || item.name === '草稿箱' || item.name === '待审批' || item.name === '审批中' || item.name === '已通过' || item.name === '未通过' || item.name === '已取消') { menu.value.push({ name: item.name, id: `${item.value}`, }) } }) } // 切换tab状态 const changeCurrentButton = (val: string) => { active.value = val window.sessionStorage.setItem(TabActiveButton, val) // reset() listQuery.value.approvalStatus = active.value fetchData(true) } // 选择器模糊查询 const remoteMethod = (query: string) => { if (query) { applyPersonLoading.value = true setTimeout(() => { applyPersonLoading.value = false usePersonOptions.value = usePersonList.value.filter((item) => { return item.name.toLowerCase().includes(query.toLowerCase()) }) }, 200) } else { usePersonOptions.value = usePersonList.value } } // 获取用户列表(增加模糊查询) const fetchUserList = () => { getUserList({ offset: 1, limit: 999999 }).then((res: any) => { usePersonList.value = res.data.rows usePersonOptions.value = res.data.rows }) } onMounted(async () => { await getDict() // 获取字典值 fetchUserList() // 获取人员列表 if (window.sessionStorage.getItem(TabActiveButton)) { active.value = window.sessionStorage.getItem(TabActiveButton)! } else { active.value = menu.value.find(item => item.name === '全部')!.id as string // 全部 } }) </script> <template> <div> <!-- 布局 --> <app-container> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item> <el-input v-model.trim="listQuery.projectNo" placeholder="分包项目编号" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.projectName" placeholder="分包项目名称" class="short-input" clearable /> </search-item> <search-item> <!-- <el-input v-model.trim="listQuery.applicantName" placeholder="验收人" class="short-input" clearable /> --> <el-select v-model="listQuery.createUserId" placeholder="请选择验收人" class="short-input" filterable remote remote-show-suffix :remote-method="remoteMethod" :loading="applyPersonLoading" > <el-option v-for="item in usePersonOptions" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.outsourcerName" placeholder="分包方名称" class="short-input" clearable /> </search-item> <search-item> <el-date-picker v-model="timeRange" clearable type="datetimerange" range-separator="到" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="验收开始时间" end-placeholder="验收结束时间" /> </search-item> </search-area> <table-container> <template #btns-right> <icon-button icon="icon-add" title="新建" type="primary" @click="add" /> <icon-button 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="(active === '0') ? 200 : (active === '1' || active === '6' || active === '3') ? 150 : (active === '4' || active === '5') ? 100 : 200" > <template #default="{ row }"> <el-button size="small" type="primary" link @click="handleEdit(row, 'detail')" > 查看 </el-button> <el-button v-if=" row.approvalStatusName === '待审批'" size="small" link type="primary" :disabled="row.approvalStatusName !== '待审批' && row.approvalStatusName !== '审批中'" @click="handleEdit(row, '同意')" > 同意 </el-button> <el-button v-if=" row.approvalStatusName === '待审批' && row.decisionItem !== 3" size="small" link type="primary" :disabled="row.approvalStatusName !== '待审批' && row.approvalStatusName !== '审批中'" @click="handleEdit(row, '驳回')" > 驳回 </el-button> <el-button v-if=" row.approvalStatusName === '待审批' && row.decisionItem !== 2" size="small" link type="danger" :disabled="row.approvalStatusName !== '待审批' && row.approvalStatusName !== '审批中'" @click="handleEdit(row, '拒绝')" > 拒绝 </el-button> <el-button v-if="(row.approvalStatusName === '未通过-驳回') || row.approvalStatusName === '草稿箱' || row.approvalStatusName === '已取消'" size="small" link type="primary" @click="handleEdit(row, 'edit')" > 编辑 </el-button> <el-button v-if="row.approvalStatusName === '草稿箱' || row.approvalStatusName === '已取消'" size="small" link type="primary" @click="handleEdit(row, '提交')" > 提交 </el-button> <!-- <el-button v-if="row.approvalStatusName === '草稿箱'" size="small" link type="primary" @click="handleEdit(row, '提交')" > 提交 </el-button> --> <!-- 是发起者且审批中可以取消 --> <el-button v-if="row.approvalStatusName === '审批中'" size="small" link type="info" :disabled="row.approvalStatusName !== '审批中'" @click="handleEdit(row, '取消')" > 取消 </el-button> <!-- 发起者和有删除权限的可以删除,已通过未通过状态不可以删除 --> <!-- <el-button v-if="row.approvalStatusName !== '未通过' && row.approvalStatusName !== '已通过' && row.approvalStatusName !== '未通过-驳回'" size="small" link type="danger" :disabled="row.approvalStatusName === '未通过' || row.approvalStatusName === '已通过'" @click="handleEdit(row, '删除')" > 删除 </el-button> --> <!-- ---------------------------审批中的删除按钮暂时去掉------------------------ --> <el-button v-if="row.approvalStatusName !== '未通过' && row.approvalStatusName !== '已通过' && row.approvalStatusName !== '未通过-驳回' && row.approvalStatusName !== '审批中' && row.approvalStatusName !== '待审批'" size="small" link type="danger" :disabled="row.approvalStatusName === '未通过' || row.approvalStatusName === '已通过'" @click="handleEdit(row, '删除')" > 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" /> <button-box :active="active" :menu="menu" @changeCurrentButton="changeCurrentButton" /> </app-container> </div> </template>