刘光辉
10 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
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
<script lang="ts" setup>
import { reactive, ref } from 'vue';
 
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
 
const emit = defineEmits(['register', 'confirm']);
const dataForm = reactive({
  biz_allow_myself: false,
  biz_review_optional: false,
  biz_sign_enabled: true,
  biz_sign_field: '',
  biz_user_id_field: '',
  controlKey: '',
  noShow: false,
});
const signFieldOptions = ref<{ fullName: string; id: string }[]>([]);
const userFieldOptions = ref<{ fullName: string; id: string }[]>([]);
const [registerModal, { closeModal }] = useModalInner(init);
 
function init(data: { config?: Partial<typeof dataForm>; drawingList?: any[] }) {
  const options = getFieldOptions(data?.drawingList || []);
  signFieldOptions.value = options.signFields;
  userFieldOptions.value = options.userFields;
  dataForm.biz_sign_enabled = true;
  dataForm.biz_sign_field = data?.config?.biz_sign_field || signFieldOptions.value.find((item) => item.id === 'biz_review_sign')?.id || '';
  dataForm.biz_user_id_field = data?.config?.biz_user_id_field ?? '';
  dataForm.biz_allow_myself = data?.config?.biz_allow_myself ?? false;
  dataForm.biz_review_optional = data?.config?.biz_review_optional ?? false;
  dataForm.controlKey = data?.config?.controlKey ?? '';
  dataForm.noShow = data?.config?.noShow ?? false;
}
 
function getFieldOptions(drawingList: any[]) {
  const signFields: { fullName: string; id: string }[] = [];
  const userFields: { fullName: string; id: string }[] = [];
  const loop = (nodes: any[], isInTable = false) => {
    if (!Array.isArray(nodes)) return;
    nodes.forEach((node) => {
      const config = node?.__config__;
      const isCurrentTable = isInTable || config?.jnpfKey === 'table';
      if (!isCurrentTable && node.__vModel__) {
        const option = { fullName: config?.label || node.__vModel__, id: node.__vModel__ };
        if (config?.jnpfKey === 'input') signFields.push(option);
      }
      if (config?.jnpfKey === 'userSelect' && node.__vModel__) {
        const id = config.isSubTable ? `${config.parentVModel}.${node.__vModel__}` : node.__vModel__;
        userFields.push({ fullName: config.label || node.__vModel__, id });
      }
      loop(config?.children, isCurrentTable);
    });
  };
  loop(drawingList);
  return { signFields, userFields };
}
 
function handleSubmit() {
  emit('confirm', { ...dataForm, biz_sign_enabled: true });
  closeModal();
}
</script>
 
<template>
  <BasicModal v-bind="$attrs" title="按钮配置" :width="500" :min-height="350" destroy-on-close @register="registerModal" @ok="handleSubmit">
    <a-form :colon="false" label-align="left" class="review-btn-config-form" :label-col="{ style: { width: '110px' } }">
      <a-form-item label="启用复核签名">
        <a-switch v-model:checked="dataForm.biz_sign_enabled" disabled />
      </a-form-item>
      <a-form-item label="复核签名字段" required>
        <jnpf-select v-model:value="dataForm.biz_sign_field" :options="signFieldOptions" placeholder="请选择" allow-clear show-search />
      </a-form-item>
      <a-form-item label="复核用户字段" required>
        <jnpf-select v-model:value="dataForm.biz_user_id_field" :options="userFieldOptions" placeholder="请选择" allow-clear show-search />
      </a-form-item>
      <a-form-item label="控件标识">
        <a-input v-model:value="dataForm.controlKey" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="复核是否可选">
        <a-switch v-model:checked="dataForm.biz_review_optional" />
      </a-form-item>
      <a-form-item label="允许自己复核">
        <a-switch v-model:checked="dataForm.biz_allow_myself" />
      </a-form-item>
      <a-form-item label="是否隐藏">
        <a-switch v-model:checked="dataForm.noShow" />
      </a-form-item>
    </a-form>
  </BasicModal>
</template>
 
<style scoped>
.review-btn-config-form :deep(.ant-form-item) {
  margin-bottom: 16px;
}
 
.review-btn-config-form :deep(.ant-form-item:last-child) {
  margin-bottom: 0;
}
</style>