liuyu
昨天 93c133349a5ccd7a328371fa113dce69d5611f21
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
<script lang="ts" setup>
import type { FormInstance } from 'ant-design-vue';
 
import { nextTick, reactive, ref, toRefs } from 'vue';
 
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
 
import { omit } from 'lodash-es';
 
import { getCandidateUser } from '#/api/workFlow/task';
import { QueryUserSelect } from '#/components/CommonModal';
 
interface State {
  dataForm: any;
  defaultCandidateList: any[];
  branchList: any[];
  isCustomCopy: boolean;
  formData: any;
  eventType: string;
  loading: boolean;
  operatorId: string;
}
 
const emit = defineEmits(['register', 'confirm']);
 
const formElRef = ref<FormInstance>();
const state = reactive<State>({
  dataForm: {
    copyIds: [],
    branchList: [],
    candidateList: [],
  },
  defaultCandidateList: [],
  branchList: [],
  isCustomCopy: false,
  formData: {},
  eventType: '',
  loading: false,
  operatorId: '',
});
const { dataForm, isCustomCopy, loading, operatorId, branchList } = toRefs(state);
const [registerModal, { changeOkLoading }] = useModalInner(init);
 
function init(data) {
  changeOkLoading(false);
  state.loading = true;
  state.isCustomCopy = data.isCustomCopy;
  state.eventType = data.eventType;
  state.formData = data.formData;
  state.operatorId = data.operatorId;
  state.dataForm.copyIds = [];
  state.dataForm.candidateList = [];
  state.dataForm.branchList = [];
  state.branchList = data.branchList.map((o) => ({ ...omit(o, ['nodeCode', 'nodeName']), id: o.nodeCode, fullName: o.nodeName }));
  state.defaultCandidateList = data.candidateList.map((o) => ({
    ...o,
    label: '审批人',
    value: [],
    rules: o.selected ? [] : [{ required: true, message: '必填', trigger: 'change', type: 'array' }],
  }));
  state.dataForm.candidateList = state.defaultCandidateList;
  nextTick(() => {
    state.loading = false;
    formElRef.value?.clearValidate();
  });
}
async function handleSubmit() {
  try {
    const values = await formElRef.value?.validate();
    if (!values) return;
    const candidateList = {};
    for (let i = 0; i < state.dataForm.candidateList.length; i++) {
      candidateList[state.dataForm.candidateList[i].nodeCode] = state.dataForm.candidateList[i].value;
    }
    changeOkLoading(true);
    emit('confirm', {
      candidateList,
      copyIds: state.dataForm.copyIds.join(','),
      branchList: state.dataForm.branchList,
      eventType: state.eventType,
    });
  } catch {}
}
function onClose() {
  state.dataForm.copyIds = [];
  state.dataForm.candidateList = [];
}
function onBranchChange(val) {
  if (!val.length) return (state.dataForm.candidateList = state.defaultCandidateList);
  const list: any[] = [];
  for (const element of val) {
    inner: for (let j = 0; j < state.branchList.length; j++) {
      const o = state.branchList[j];
      if (element === o.id && o.isCandidates) {
        list.push({
          nodeCode: o.id,
          nodeName: o.fullName,
          isCandidates: o.isCandidates,
          label: '审批人',
          value: [],
          rules: o.selected ? [] : [{ required: true, message: `必填`, trigger: 'change', type: 'array' }],
        });
        break inner;
      }
    }
  }
  state.dataForm.candidateList = [...state.defaultCandidateList, ...list];
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="提交审核" @ok="handleSubmit" :min-height="52" destroy-on-close @cancel="onClose">
    <a-form
      :colon="false"
      :label-col="{ style: { width: dataForm.candidateList.length || branchList.length ? '130px' : '80px' } }"
      :model="dataForm"
      ref="formElRef"
      v-if="!loading">
      <a-form-item label="分支选择" name="branchList" :rules="[{ required: true, message: `必填`, trigger: 'change', type: 'array' }]" v-if="branchList.length">
        <jnpf-select v-model:value="dataForm.branchList" multiple placeholder="请选择" allow-clear @change="onBranchChange" :options="branchList" show-search />
      </a-form-item>
      <template v-for="(item, i) in dataForm.candidateList" :key="i">
        <a-form-item :label="item.nodeName + item.label" :name="['candidateList', i, 'value']" :rules="item.rules">
          <QueryUserSelect
            v-model:value="item.value"
            multiple
            :query="{ ...state.formData, nodeCode: item.nodeCode, operatorId }"
            :api="getCandidateUser"
            modal-title="候选人员" />
        </a-form-item>
        <a-form-item label="已选审批人" v-if="item.selected" class="candidate-selected">
          <jnpf-textarea v-model:value="item.selected" :auto-size="{ minRows: 1, maxRows: 4 }" disabled />
        </a-form-item>
      </template>
      <a-form-item label="抄送人员" name="copyIds" v-if="isCustomCopy">
        <jnpf-user-select v-model:value="dataForm.copyIds" multiple allow-clear />
      </a-form-item>
    </a-form>
  </BasicModal>
</template>