<!-- 任务单管理表格 --> <script lang="ts" setup name="TaskList"> import dayjs from 'dayjs' import { reactive, ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import { StringValueToken } from 'html2canvas/dist/types/css/syntax/tokenizer' import ApprovalDialog from './ApprovalDialog.vue' import { cancelTask, cancelTask1, delTask, exportTask, getListPage, submitTask } from '@/api/eqpt/measurementPlan/task' import { getUserDept, getUserDeptSon } from '@/api/system/user' import { getPostList } from '@/api/system/post' import { getDictByCode } from '@/api/system/dict' import { getDeptTree, getDeptTreeList } from '@/api/system/dept' import { exportFile } from '@/utils/exportUtils' import { SCHEDULE } from '@/utils/scheduleDict' import { keepSearchParams } from '@/utils/keepQuery' const $props = defineProps({ statusName: { type: String, default: '', }, }) const { proxy } = getCurrentInstance() as any const listQuery = reactive({ orderNo: '', deliverer: '', customerName: '', createUserName: '', createStartTime: '', createEndTime: '', deptId: '', usePositionId: '', measureCompany: '', manufactureNo: '', orderStatus: '', offset: 1, limit: 20, sort: 'desc', orderBy: 'create_time', formId: SCHEDULE.METERING_TASK_APPROVAL, approvalStatus: '', }) onBeforeRouteLeave((to: any) => { keepSearchParams(to.path, 'TaskPage') }) const applyDict = ref<{ [key: string]: string }>({ 审批: '', 草稿箱: '1', 审批中: '3', 已通过: '4', 未通过: '5', 已取消: '6', }) // 开始结束时间 const datetimerange = ref() watch(() => datetimerange.value, (newVal) => { listQuery.createStartTime = '' listQuery.createEndTime = '' if (Array.isArray(newVal)) { if (newVal.length) { listQuery.createStartTime = `${newVal[0]} 00:00:00` listQuery.createEndTime = `${newVal[1]} 23:59:59` } } }) const columns = ref([ { text: '任务单编号', value: 'orderNo', align: 'center', }, { text: '委托方', value: 'customerName', align: 'center', }, { text: '使用部门', value: 'deptName', align: 'center', }, // { // text: '使用岗位', // value: 'usePosition', // align: 'center', // }, { text: '检定单位', value: 'measureCompany', align: 'center', }, // { // text: '溯源单位', // value: 'measureCompany', // align: 'center', // }, { text: '创建人', value: 'createUserName', align: 'center', }, { text: '创建时间', value: 'createTime', align: 'center', }, // { // text: '送检人', // value: 'deliverer', // align: 'center', // }, { text: '计划送检时间', value: 'planDeliverTime', align: 'center', }, // { // text: '接收状态', // value: 'receiveStatusName', // align: 'center', // }, ]) const list = ref([]) const total = ref(0) const listLoading = ref(true) // 获取数据 const fetchData = (isNowPage = true) => { listLoading.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.offset = 1 } getListPage(listQuery, $props.statusName).then((response) => { list.value = response.data.rows.map((item: any) => ({ ...item, requireOverTime: dayjs(item.requireOverTime).format('YYYY-MM-DD') })) total.value = parseInt(response.data.total) listLoading.value = false }) } // 查询数据 const search = () => { fetchData(false) } // 审批状态发生变化 watch(() => $props.statusName, (newVal) => { if (newVal) { listQuery.approvalStatus = applyDict.value[newVal] as string listQuery.orderStatus = $props.statusName === '全部' ? '' : listQuery.orderStatus fetchData() } }, { deep: true, immediate: true, }) // 重置 const reset = () => { datetimerange.value = [] listQuery.orderNo = '' listQuery.deliverer = '' listQuery.customerName = '' listQuery.createUserName = '' listQuery.createStartTime = '' listQuery.createEndTime = '' listQuery.deptId = '' listQuery.usePositionId = '' listQuery.measureCompany = '' listQuery.manufactureNo = '' listQuery.orderStatus = '' listQuery.offset = 1 listQuery.limit = 20 listQuery.sort = 'desc' listQuery.orderBy = 'create_time' 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 $router = useRouter() // 新建编辑操作 const handler = (row: any, type: string) => { if ($props.statusName === '草稿箱' || $props.statusName === '已取消') { $router.push({ path: '/meteringtask/update', query: { row: JSON.stringify(row), id: row.id, statusName: $props.statusName, }, }) } else { $router.push({ path: `/meteringtask/${type}`, query: { row: JSON.stringify(row), id: row.id, statusName: $props.statusName, }, }) } } // 取消 const cancelHandler = (row: any) => { ElMessageBox.confirm( '确认取消此任务单信息吗?', '确认', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { cancelTask({ id: row.id }).then((res) => { ElMessage.success('操作成功') // close() search() }) }) } // 表格被选中的行 const selectList = ref<any[]>([]) // 表格多选 const multiSelect = (row: any[]) => { selectList.value = row } // 导出列表 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), } exportTask(data).then((res) => { exportFile(res.data, '任务单列表') loading.close() }) .catch((_) => { loading.close() }) } else { ElMessage.warning('无可导出内容') } } // 使用岗位 const usePositionList = ref<any[]>([]) // 部门 const deptList = ref<{ id: string; value: string; name: string }[]>([]) // 接收状态 const receiveStatusList = ref<{ id: string; value: string; name: string }[]>([]) // 获取字典 const fetchDict = () => { // 使用岗位 getPostList({}).then((res) => { usePositionList.value = res.data }) // 获取当前用户所在单位 // getUserDept().then((res) => { // getDeptTree({ pid: '0' }).then((res1) => { // deptList.value = res1.data.filter((item: any) => item.pids.split(',').length === 3).map((item: any) => ({ id: item.id, value: item.id, name: item.fullName })) // }) getUserDeptSon({ }).then((res) => { deptList.value = res.data.map((item: any) => ({ id: item.id, value: item.id, name: item.fullName })) }) // }) // 接收状态 getDictByCode('eqptTaskStatus').then((res) => { receiveStatusList.value = res.data }) } fetchDict() const permUrl = ref({ edit: '/tested/pmetering/task/edit', cancel: '/tested/pmetering/task/cancel', add: '/tested/pmetering/task/add', }) // 同意拒绝 const approvalDialogRef = ref() const approveHandler = (row: any, type: string) => { approvalDialogRef.value.initDialog(type, row.taskId, row.processId, row.id) } // 提交 const submit = (row: any) => { ElMessageBox.confirm( '确认提交吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then((res) => { submitTask({ id: row.id, formId: SCHEDULE.METERING_TASK_APPROVAL }).then((res) => { ElMessage.success('已提交') search() }) }) } // 取消审批 const canHandler = (row: any) => { ElMessageBox.confirm( '确认取消此申请吗?', '确认', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { cancelTask1({ id: row.id, processInstanceId: row.processId, comments: '' }).then((res) => { ElMessage.success('操作成功') // close() search() }) }) } // 删除 const delHandler = (row: any) => { ElMessageBox.confirm( '确认删除此记录吗?', '确认', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { delTask(row.id).then((res) => { ElMessage.success('操作成功') // close() search() }) }) } const TextColor = computed(() => { return (name: string) => { let color = '' switch (name) { case '未接收': color = '#888' break case '已接收': color = '#000' break case '已取消': color = '#EAA341' break case '已退回': color = '#F68787' break case '待取回': color = '#82CD5E' break case '已取回': color = '#89D961' break default: color = '#000' break } return color } }) onActivated(() => { // 从编辑或者新增页面回来需要重新获取列表数据 // $router.options.history.state.forward 上一次路由地址 if (!($router.options.history.state.forward as string || '').includes('detail')) { console.log('需要重新获取列表') fetchData(false) } }) </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.orderNo" placeholder="任务单编号" clearable /> </search-item> --> <search-item> <el-input v-model.trim="listQuery.customerName" placeholder="委托方" clearable /> </search-item> <search-item> <!-- <dept-select v-model="listQuery.deptIds" placeholder="使用部门" /> --> <el-select v-model="listQuery.deptId" filterable placeholder="使用部门" style="width: 100%;"> <el-option v-for="item in deptList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </search-item> <search-item> <!-- <el-input v-model.trim="listQuery.usePosition" placeholder="使用岗位" clearable /> --> <el-select v-model="listQuery.usePositionId" filterable placeholder="使用岗位" clearable style="width: 100%;"> <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.createUserName" placeholder="创建人" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.measureCompany" placeholder="检定单位" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.manufactureNo" placeholder="智能模型出厂编号" clearable /> </search-item> <search-item v-if="$props.statusName === '全部'"> <el-select v-model="listQuery.orderStatus" placeholder="任务单状态" clearable> <el-option v-for="item in receiveStatusList" :key="item.value" :label="item.name" :value="item.value" /> </el-select> </search-item> <!-- <search-item> <el-input v-model.trim="listQuery.deliverer" 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="创建结束时间" /> </search-item> --> </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-showmulti-select="true" @change="changePage" @multi-select="multiSelect" > <template #columns> <el-table-column v-if="$props.statusName === '全部'" label="检定进度" align="center"> <template #default="scope"> {{ scope.row.verificationProgress }} </template> </el-table-column> <el-table-column v-if="$props.statusName === '全部'" label="任务单状态" align="center"> <template #default="scope"> <span :style="{ color: TextColor(scope.row.orderStatusName) }"> {{ scope.row.orderStatusName }} </span> </template> </el-table-column> <el-table-column label="操作" width="140" align="center"> <template #default="scope"> <!-- <el-button link type="primary" size="small" @click="handler(scope.row, 'detail')"> 查看 </el-button> --> <el-button link type="primary" size="small" @click="handler(scope.row, 'detail')"> 查看 </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.edit)" link type="primary" size="small" @click="approveHandler(scope.row, 'agree')" > 同意 </el-button> <el-button v-if="proxy.buttonPerm.reject.if({ approvalStatusName: $props.statusName }, permUrl.edit)" link type="primary" size="small" @click="approveHandler(scope.row, 'refuse')" > 拒绝 </el-button> <el-button v-if="proxy.buttonPerm.submit.if({ approvalStatusName: $props.statusName }, permUrl.edit)" link type="primary" size="small" @click="submit(scope.row)" > 提交 </el-button> <el-button v-if="proxy.buttonPerm.cancel.if({ approvalStatusName: $props.statusName }, permUrl.edit)" link type="primary" size="small" @click="canHandler(scope.row)" > 取消 </el-button> <el-button v-if="proxy.buttonPerm.delete.if({ approvalStatusName: $props.statusName }, permUrl.edit) && $props.statusName !== '全部'" link type="danger" size="small" @click="delHandler(scope.row)" > 删除 </el-button> <!-- <el-button v-if="proxy.hasPerm(permUrl.edit) && $props.statusName === '全部'" link type="primary" :disabled="scope.row.receiveStatusName !== '未接收'" size="small" @click="handler(scope.row, 'update')"> 编辑 </el-button> --> <el-button v-if="proxy.hasPerm(permUrl.cancel) && $props.statusName === '全部'" :disabled="scope.row.orderStatusName !== '未接收'" link type="danger" size="small" @click="cancelHandler(scope.row)"> 取消 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>