liu
2 天以前 f7e06aaee32674791f63d6e5111c0d0a3f4de4a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BpmTaskApi } from '#/api/bpm/task';
 
import { Page } from '@vben/common-ui';
 
import { message } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { reverseApprove } from '#/api/erp/purchase/order';
import { getTaskDonePage, withdrawTask } from '#/api/bpm/task';
import { router } from '#/router';
 
import { useGridColumns, useGridFormSchema } from './data';
 
defineOptions({ name: 'BpmDoneTask' });
 
/** 查看历史 */
function handleHistory(row: BpmTaskApi.Task) {
  router.push({
    name: 'BpmProcessInstanceDetail',
    query: {
      id: row.processInstance.id,
      taskId: row.id,
    },
  });
}
 
/** 撤回任务 */
async function handleWithdraw(row: BpmTaskApi.Task) {
  const hideLoading = message.loading({
    content: '正在撤回中...',
    duration: 0,
  });
  try {
    await withdrawTask(row.id);
    message.success('撤回成功');
    await gridApi.query();
  } finally {
    hideLoading();
  }
}
 
/** 是否采购订单审批任务(用于显示"反审批"、隐藏通用"撤回") */
function isPurchaseOrderApprove(row: BpmTaskApi.Task) {
  return (row.processInstance?.processDefinitionId || '').startsWith(
    'purchase_order_approve',
  );
}
 
/** 反审批采购订单(已审核 -> 未审核,在协同办公已办任务中操作) */
async function handleReverseApprove(row: BpmTaskApi.Task) {
  const hideLoading = message.loading({
    content: '反审批中...',
    duration: 0,
  });
  try {
    await reverseApprove(row.processInstance.id);
    message.success('反审批成功,订单已重新进入待办审批');
    await gridApi.query();
  } finally {
    hideLoading();
  }
}
 
const [Grid, gridApi] = useVbenVxeGrid({
  formOptions: {
    schema: useGridFormSchema(),
  },
  gridOptions: {
    columns: useGridColumns(),
    height: 'auto',
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page }, formValues) => {
          return await getTaskDonePage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            ...formValues,
          });
        },
      },
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      refresh: true,
      search: true,
    },
  } as VxeTableGridOptions<BpmTaskApi.Task>,
});
</script>
 
<template>
  <Page auto-content-height><Grid table-title="已办任务">
      <template #actions="{ row }">
        <TableAction
          :actions="[
            {
              label: '反审批',
              type: 'link',
              danger: true,
              icon: ACTION_ICON.AUDIT,
              ifShow: () => isPurchaseOrderApprove(row),
              popConfirm: {
                title: '确定要反审批该采购订单吗?订单将重新进入待办审批',
                confirm: handleReverseApprove.bind(null, row),
              },
            },
            {
              label: '撤回',
              type: 'link',
              danger: true,
              icon: ACTION_ICON.DELETE,
              ifShow: () => !isPurchaseOrderApprove(row),
              popConfirm: {
                title: '确定要撤回该任务吗?',
                confirm: handleWithdraw.bind(null, row),
              },
            },
            {
              label: '历史',
              type: 'link',
              icon: ACTION_ICON.VIEW,
              onClick: handleHistory.bind(null, row),
            },
          ]"
        />
      </template>
    </Grid>
  </Page>
</template>