ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<script lang="ts" setup>
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
 
import { computed, nextTick, onMounted, reactive, toRefs, watch } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicForm, useForm } from '@jnpf/ui/form';
import { useModal } from '@jnpf/ui/modal';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { Grid as VxeGrid } from 'vxe-table';
 
import { del, getFlowDelegateInfo, getFlowDelegateList, notarize, stop } from '#/api/workFlow/flowDelegate';
import { $t } from '#/locales';
 
import Form from './Form.vue';
 
interface State {
  activeKey: number;
  keyword: string;
  userList: any[];
  activeUser: string;
}
 
defineOptions({ name: 'Entrust' });
 
const props = defineProps(['subActiveKey']);
 
const { createMessage } = useMessage();
const [registerForm, { openModal: openFormModal }] = useModal();
const state = reactive<State>({
  activeKey: 1,
  keyword: '',
  userList: [],
  activeUser: '',
});
const { activeKey } = toRefs(state);
const tabList = [
  { fullName: '我的委托', id: 1 },
  { fullName: '委托给我', id: 2 },
  { fullName: '我的代理', id: 3 },
  { fullName: '代理给我', id: 4 },
];
const [registerSearchForm, { resetFields }] = useForm({
  baseColProps: { span: 6 },
  showActionButtonGroup: true,
  showAdvancedButton: true,
  compact: true,
  schemas: [
    {
      field: 'keyword',
      label: $t('common.keyword'),
      component: 'Input',
      componentProps: {
        placeholder: $t('common.enterKeyword'),
        submitOnPressEnter: true,
      },
    },
  ],
});
const userColumns: any[] = [
  { title: '', width: 50 },
  { title: '序号', width: 50, align: 'center', type: 'seq' },
  { title: '受委托人', field: 'toUserName', width: 650 },
  { title: '流程状态', field: 'status', width: 120, align: 'center', slots: { default: 'status' } },
  { title: '' },
];
const [registerMyEntrustTable, { reload }] = useVxeTable({
  api: getFlowDelegateList,
  actionColumn: {
    width: 150,
    title: '操作',
    dataIndex: 'action',
  },
  immediate: false,
  rowKey: 'jnpfId',
  afterFetch: (data) => {
    const list = data.map((o) => ({
      ...o,
      jnpfId: o.id + Math.random(),
    }));
    return list;
  },
  expandConfig: {
    lazy: true,
    loadMethod({ row }) {
      return new Promise((resolve) => {
        getFlowDelegateInfo(row.id)
          .then((res) => {
            row.userList = res.data;
            resolve(row);
          })
          .catch(() => {});
      });
    },
  },
});
 
watch(
  () => state.activeKey,
  () => {
    resetFields();
  },
);
 
const getSearchInfo = computed(() => ({ keyword: state.keyword, type: state.activeKey }));
const getColumns = computed(() => {
  const myEntrustColumns: BasicColumn[] = [
    { title: '受委托人', dataIndex: 'toUserName', width: 200 },
    { title: '委托流程', dataIndex: 'flowName', width: 150 },
    { title: '开始时间', dataIndex: 'startTime', width: 150, format: 'date|YYYY-MM-DD HH:mm:ss' },
    { title: '结束时间', dataIndex: 'endTime', width: 150, format: 'date|YYYY-MM-DD HH:mm:ss' },
    { title: '状态', dataIndex: 'status', width: 120, align: 'center', slots: { default: 'status' } },
    { title: '委托说明', dataIndex: 'description', minWidth: 150 },
  ];
  const entrustColumns: BasicColumn[] = [
    { title: '委托人', dataIndex: 'userName', width: 200 },
    { title: '委托流程', dataIndex: 'flowName', width: 150 },
    { title: '开始时间', dataIndex: 'startTime', width: 150, format: 'date|YYYY-MM-DD HH:mm:ss' },
    { title: '结束时间', dataIndex: 'endTime', width: 150, format: 'date|YYYY-MM-DD HH:mm:ss' },
    { title: '生效状态', dataIndex: 'status', width: 120, align: 'center', slots: { default: 'status' } },
    { title: '委托说明', dataIndex: 'description', minWidth: 150 },
    { title: '确认状态', dataIndex: 'confirmStatus', width: 120, align: 'center', slots: { default: 'confirmStatus' } },
  ];
  if (state.activeKey === 1) return myEntrustColumns;
  if (state.activeKey === 2) return entrustColumns;
  if (state.activeKey === 3 || state.activeKey === 4) {
    const list = state.activeKey === 3 ? myEntrustColumns : entrustColumns;
    (list[0] as any).title = state.activeKey === 3 ? '代理人' : '被代理人';
    (list[1] as any).title = '代理流程';
    (list[5] as any).title = '代理说明';
    return list;
  }
  return [];
});
 
function getTableActions(record): ActionItem[] {
  return state.activeKey === 1 || state.activeKey === 3
    ? [
        {
          label: $t('common.editText'),
          disabled: record.status !== 0 || !record.isEdit,
          onClick: addOrUpdateHandle.bind(null, record.id),
        },
        {
          label: $t('common.delText'),
          color: 'error',
          disabled: record.status === 1,
          modelConfirm: {
            onOk: handleDelete.bind(null, record.id),
          },
        },
        {
          ifShow: record.status === 1,
          label: '终止',
          color: 'error',
          modelConfirm: {
            onOk: handleStop.bind(null, record.id),
            content: '终止后,流程不再进行委托!',
          },
        },
      ]
    : [
        {
          ifShow: record.status !== 2 && record.confirmStatus === 0,
          label: '接受',
          modelConfirm: {
            onOk: handleAcceptOrReject.bind(null, record.id, 1),
            content: '您确认要接受请求吗,是否继续?',
          },
        },
        {
          ifShow: record.status !== 2 && record.confirmStatus === 0,
          label: '拒绝',
          color: 'error',
          modelConfirm: {
            onOk: handleAcceptOrReject.bind(null, record.id, 2),
            content: '您确认要拒绝请求吗,是否继续?',
          },
        },
      ];
}
function handleStop(id) {
  stop(id).then((res) => {
    createMessage.success(res.msg);
    reload();
  });
}
function handleAcceptOrReject(id, type) {
  notarize(id, type).then((res) => {
    createMessage.success(res.msg);
    reload();
  });
}
function handleSubmit(values) {
  state.keyword = values?.keyword || '';
  handleSearch();
}
function handleReset() {
  state.keyword = '';
  handleSearch();
}
function handleSearch() {
  nextTick(() => reload({ page: 1 }));
}
// 新增委托/代理
function addOrUpdateHandle(id = '') {
  openFormModal(true, { id, type: state.activeKey === 1 ? 0 : 1 });
}
// 删除委托
function handleDelete(id) {
  del(id).then((res) => {
    createMessage.success(res.msg);
    reload();
  });
}
function getUserStatusContent(status) {
  return status === 0 ? '待确认' : status === 1 ? '已接受' : '已拒绝';
}
function getStatusContent(status) {
  return status === 0 ? '未生效' : status === 1 ? '生效中' : '已失效';
}
function getStatusColor(status) {
  return status === 0 ? '' : status === 1 ? 'processing' : 'error';
}
function getConfirmStatusContent(status) {
  return status === 0 ? '待确认' : status === 1 ? '已接受' : '已拒绝';
}
function getConfirmStatusColor(status) {
  return status === 0 ? '' : status === 1 ? 'success' : 'error';
}
 
onMounted(() => {
  state.activeKey = props.subActiveKey ? Number(props.subActiveKey) : 1;
  nextTick(() => reload({ page: 1 }));
});
</script>
<template>
  <div class="jnpf-content-wrapper pt-[10px]">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-search-box">
        <BasicForm class="search-form" @register="registerSearchForm" @submit="handleSubmit" @reset="handleReset" />
      </div>
      <div class="jnpf-content-wrapper-content bg-white">
        <a-tabs v-model:active-key="activeKey" class="jnpf-content-wrapper-tabs" destroy-inactive-tab-pane>
          <a-tab-pane :key="item.id" :tab="item.fullName" v-for="item in tabList" />
        </a-tabs>
        <BasicVxeTable
          @register="registerMyEntrustTable"
          :search-info="getSearchInfo"
          :columns="getColumns"
          :show-expand-column="activeKey == 1 || activeKey == 3">
          <template #headerTop v-if="activeKey == 1 || activeKey == 3">
            <a-alert
              :message="activeKey == 1 ? '委托是指允许受委托人代替委托人在系统中发起流程。' : '代理是指允许代理人代替被代理人在系统中处理流程审批。'"
              show-icon
              type="warning"
              class="mt-[10px]" />
          </template>
          <template #tableTitle v-if="activeKey == 1 || activeKey == 3">
            <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="addOrUpdateHandle()">新建</a-button>
          </template>
          <template #expandedRowRender="{ record }">
            <VxeGrid :data="record.userList" :columns="userColumns" :show-header="false" :min-height="0">
              <template #status="{ row: childRecord }">
                <a-tag :color="getConfirmStatusColor(childRecord.status)">{{ getUserStatusContent(childRecord.status) }}</a-tag>
              </template>
            </VxeGrid>
          </template>
          <template #status="{ record }">
            <a-tag :color="getStatusColor(record.status)">{{ getStatusContent(record.status) }}</a-tag>
          </template>
          <template #confirmStatus="{ record }">
            <a-tag :color="getConfirmStatusColor(record.confirmStatus)">{{ getConfirmStatusContent(record.confirmStatus) }}</a-tag>
          </template>
          <template #action="{ record }">
            <TableAction :actions="getTableActions(record)" />
          </template>
        </BasicVxeTable>
      </div>
    </div>
    <Form @register="registerForm" @reload="reload" />
  </div>
</template>