<!-- 提前/延迟送检申请列表 --> <script lang="ts" setup name="InspectionList"> import { reactive, ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import approvalDialog from './ApprovalDialog.vue' import { cancelApply, delApply, exportApply, getListPage, submitApply, valiatePlan } from '@/api/eqpt/measurementPlan/early' import { SCHEDULE } from '@/utils/scheduleDict' import { exportFile } from '@/utils/exportUtils' import { getDictByCode } from '@/api/system/dict' import { getAdminDept, getUserDept } from '@/api/system/user' import { getDeptTreeList } from '@/api/system/dept' import { toTreeList } from '@/utils/structure' import { getPostList } from '@/api/system/post' import { keepSearchParams } from '@/utils/keepQuery' import useUserStore from '@/store/modules/user' const $props = defineProps({ // 申请类型(字典值,提前/延迟) approvalType: { type: String, required: true, }, // 审批状态名字(全部/审批等) statusName: { type: String, required: true, }, }) const userStore = useUserStore() onBeforeRouteLeave((to: any) => { keepSearchParams(to.path, $props.approvalType === '0' ? 'EarlyApplication' : 'DelayApplication') }) const applyDict = ref<{ [key: string]: string }>({ 审批: '', 草稿箱: '1', 审批中: '3', 已通过: '4', 未通过: '5', 已取消: '6', }) const { proxy } = getCurrentInstance() as any const listQuery = reactive({ approvalName: '', // 申请名称 approvalNo: '', // 申请编号 createDeptName: '', // 创建单位 createUserName: '', // 创建人 createTimeEnd: '', // 结束时间 createTimeStart: '', // 开始时间 approvalType: $props.approvalType, // 申请类型(字典值,提前/延迟) approvalStatus: '', offset: 1, limit: 20, formId: '', customerId: '', // 单位 deptId: '', // 部门 usePositionId: '', // 使用岗位 measureCompany: '', // 检定(校准)单位 manufactureNo: '', // 出厂编号 equipmentRemark: '', // 设备备注 }) // 是否折叠查询条件 const searchMore = ref(true) const expandSearch = () => { searchMore.value = !searchMore.value } // 设置formid const setFormID = () => { if ($props.approvalType === '0') { listQuery.formId = SCHEDULE.METERING_PLAN_EARLY } else { listQuery.formId = SCHEDULE.METERING_PLAN_DEALY } } setFormID() // 开始结束时间 const datetimerange = ref() watch(() => datetimerange.value, (newVal) => { listQuery.createTimeStart = '' listQuery.createTimeEnd = '' if (Array.isArray(newVal)) { if (newVal.length) { listQuery.createTimeStart = `${newVal[0]} 00:00:00` listQuery.createTimeEnd = `${newVal[1]} 23:59:59` } } }) const columns = ref([ { text: '文件编号', value: 'approvalNo', align: 'center', }, // { // text: '申请名称', // value: 'approvalName', // align: 'center', // }, // { // text: '创建单位', // value: 'createDeptName', // align: 'center', // }, { text: '单位', value: 'customerName', align: 'center', }, { text: '部门', value: 'createDeptName', align: 'center', }, { text: '检定(校准)单位', value: 'measureCompany', align: 'center', }, { text: '创建人', value: 'createUserName', align: 'center', }, { text: '创建时间', value: 'createTime', align: 'center', }, { text: '计划送检时间', value: 'planDeliverTime', 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 } getListPage(listQuery, $props.statusName).then((response) => { console.log(123) list.value = response.data.rows total.value = parseInt(response.data.total) listLoading.value = false }).catch((_) => { listLoading.value = false }) } // fetchData() // 查询数据 const search = () => { fetchData(false) } // 重置搜索条件 const reset = () => { datetimerange.value = [] listQuery.approvalName = '' listQuery.approvalNo = '' listQuery.createDeptName = '' listQuery.createUserName = '' listQuery.createTimeEnd = '' listQuery.createTimeStart = '' listQuery.limit = 20 listQuery.offset = 1 listQuery.customerId = '' listQuery.deptId = '' listQuery.usePositionId = '' listQuery.measureCompany = '' listQuery.manufactureNo = '' listQuery.equipmentRemark = '' search() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 selectList = ref<any[]>([]) // 表格多选 const multiSelect = (row: any[]) => { selectList.value = row } const $router = useRouter() // 新建编辑操作 const handler = (row: any, type: string) => { // 根据申请类型不同去往不同的路由 // 申请类型(字典值,提前/延迟) const params = $props.approvalType === '0' ? 'ealy' : 'delay' $router.push({ path: `/${params}/${type}`, query: { row: JSON.stringify(row), id: row.id, approvalType: $props.approvalType, // 申请类型(字典值,提前/延迟) statusName: $props.statusName, // statusName }, }) } // 删除 const delHandler = (row: any) => { ElMessageBox.confirm( '确认删除该申请吗?', '确认', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { delApply({ id: row.id }).then((res) => { ElMessage.success('操作成功') search() }) }) } // 详情 const detail = (row: any) => { if ($props.statusName === '草稿箱' || $props.statusName === '未通过' || $props.statusName === '已取消') { handler(row, 'update') } else { const params = $props.approvalType === '0' ? 'ealy' : 'delay' $router.push({ path: `${params}/detail`, query: { row: JSON.stringify(row), id: row.id, approvalType: $props.approvalType, // 申请类型(字典值,提前/延迟) statusName: $props.statusName, // statusName }, }) } } // 取消 const canHandler = (row: any) => { ElMessageBox.confirm( '确认取消此申请吗?', '确认', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { cancelApply({ 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) => { const submitFun = (id: string) => { submitApply({ id, formId: $props.approvalType === '0' ? SCHEDULE.METERING_PLAN_EARLY : SCHEDULE.METERING_PLAN_DEALY }).then((res) => { ElMessage.success('已提交') search() }) } // valiatePlan(row).then((res1) => { // if (res1.data) { // ElMessageBox.confirm( // `${res1.data}`, // '提示', // { // confirmButtonText: '确认', // cancelButtonText: '取消', // type: 'warning', // }, // ).then(() => { // submitFun(row.id) // }) // } // else { submitFun(row.id) // } // }) }) } // 同意拒绝 const approvalDialogRef = ref() const approveHandler = (row: any, type: string) => { approvalDialogRef.value.initDialog(type, row.taskId, row.processId, row.id) } // 导出列表 const exportList = () => { if (list.value.length) { const loading = ElLoading.service({ lock: true, text: 'Loading', background: 'rgba(255, 255, 255, 0.8)', }) const data = { ...listQuery, offset: undefined, limit: undefined, ids: selectList.value.map(item => item.id), } exportApply(data).then((res) => { exportFile(res.data, $props.approvalType === '0' ? '提前送检申请' : '延迟送检申请') loading.close() }) .catch((_) => { loading.close() }) } else { ElMessage.warning('无可导出内容') } } // 审批状态发生变化 watch(() => $props.statusName, (newVal) => { if (newVal) { listQuery.approvalStatus = applyDict.value[newVal] as string fetchData() } }, { deep: true, immediate: true, }) const permUrl = ref({ edit: `/tested/pmetering/${$props.approvalType === '0' ? 'ealy' : 'delay'}/edit`, del: `/tested/pmetering/${$props.approvalType === '0' ? 'ealy' : 'delay'}/delete`, submit: `/tested/pmetering/${$props.approvalType === '0' ? 'ealy' : 'delay'}/submit`, cancel: `/tested/pmetering/${$props.approvalType === '0' ? 'ealy' : 'delay'}/cancel`, agree: `/tested/pmetering/${$props.approvalType === '0' ? 'ealy' : 'delay'}/agree`, reject: `/tested/pmetering/${$props.approvalType === '0' ? 'ealy' : 'delay'}/reject`, add: `/tested/pmetering/${$props.approvalType === '0' ? 'ealy' : 'delay'}/add`, }) // 创建单位 const companyList = ref<{ id: string; value: string; name: string }[]>([]) const deptList = ref<any>([]) // 使用岗位 const usePositionList = ref<any[]>([]) // 检定单位 const measureCompanyList = ref<{ id: string; value: string; name: string }[]>() const fetchCommpany = () => { // 获取单位 getUserDept().then((res) => { if ((res.data.fullName === '顶级' || res.data.version === '1' || res.data.version === 1) && userStore.dataSopeType === '1') { getAdminDept({}).then((res) => { companyList.value = res.data.map((item: any) => ({ id: item.id, value: item.id, name: item.fullName })) }) } else { companyList.value = [ { name: res.data.fullName, value: res.data.id, id: res.data.id, }, ] listQuery.customerId = '' } }) // 使用岗位 getPostList({}).then((res) => { usePositionList.value = res.data }) getDictByCode('eqptmeasureCompany').then((res) => { measureCompanyList.value = res.data }) } fetchCommpany() watch(() => listQuery.customerId, (newVal) => { listQuery.deptId = '' if (newVal) { getDeptTreeList({ pid: newVal }).then((res) => { deptList.value = toTreeList(res.data.map((item: any) => ({ ...item, label: item.name, value: item.id }))) }) } else { deptList.value = [] } }) onActivated(() => { // 从编辑或者新增页面回来需要重新获取列表数据 // $router.options.history.state.forward 上一次路由地址 if (!($router.options.history.state.forward as string || '').includes('detail')) { console.log('需要重新获取列表') fetchData(false) } }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="reset"> <!-- 审批弹窗 --> <approval-dialog ref="approvalDialogRef" @on-success="search" /> <search-item> <el-input v-model.trim="listQuery.approvalNo" placeholder="文件编号" clearable /> </search-item> <search-item> <el-select v-model="listQuery.customerId" clearable filterable placeholder="单位" style="width: 100%;"> <el-option v-for="item in companyList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </search-item> <search-item> <el-tree-select v-model="listQuery.deptId" style="width: 100%;" :data="deptList" :render-after-expand="false" check-strictly placeholder="部门" /> </search-item> <search-item> <el-select v-model="listQuery.usePositionId" filterable clearable placeholder="使用岗位"> <el-option v-for="item in usePositionList" :key="item.id" :label="item.positionName" :value="item.id" /> </el-select> </search-item> <search-item> <!-- <el-input v-model.trim="listQuery.checkOrganization" placeholder="检定(校准)单位" clearable /> --> <el-select v-model="listQuery.measureCompany" filterable placeholder="检定(校准)单位" style="width: 100%;"> <el-option v-for="item in measureCompanyList" :key="item.id" :label="item.name" :value="item.name" /> </el-select> </search-item> <!-- <search-item> <el-input v-model.trim="listQuery.approvalName" placeholder="申请名称" clearable /> </search-item> --> <!-- <search-item> <el-input v-model.trim="listQuery.createDeptName" placeholder="创建单位" clearable /> </search-item> --> <search-item> <el-input v-model.trim="listQuery.createUserName" placeholder="创建人" clearable /> </search-item> <search-item> <el-date-picker v-model="datetimerange" type="daterange" value-format="YYYY-MM-DD" format="YYYY-MM-DD" range-separator="至" start-placeholder="创建开始时间" end-placeholder="创建结束时间" clearable /> </search-item> <!-- 折叠查询条件 --> <template #searchMore> <icon-button v-show="searchMore" icon="icon-zhankai" title="展开查询条件" style="margin-bottom: 10px;" @click="expandSearch" /> <icon-button v-show="!searchMore" icon="icon-zhankai" title="折叠查询条件" style="margin-bottom: 10px;transform: rotate(180deg);" @click="expandSearch" /> </template> <span v-show="!searchMore"> <search-item> <el-input v-model.trim="listQuery.manufactureNo" placeholder="设备出厂编号" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.equipmentRemark" placeholder="设备备注" clearable /> </search-item> </span> </search-area> <table-container> <template v-if="$props.statusName === '全部'" #btns-right> <icon-button v-if="proxy.hasPerm(permUrl.add)" icon="icon-add" title="新增" @click="handler({}, 'create')" /> <icon-button icon="icon-export" title="导出" @click="exportList" /> </template> <!-- 普通表格 --> <normal-table :data="list" :total="total" :columns="columns as any" :query="listQuery" :list-loading="listLoading" :is-multi="true" :is-showmulti-select="true" @change="changePage" @multi-select="multiSelect" > <template #columns> <el-table-column v-if="$props.statusName !== '全部'" label="审批状况" align="center"> <template #default="scope"> <span> {{ scope.row.approvalStatusName }}</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) && $props.statusName !== '全部'" 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.delete.if({ approvalStatusName: $props.statusName }, permUrl.del)" link type="danger" size="small" @click="delHandler(scope.row)" > 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>