zhuoyuan.wang
2024-06-19 15ebe96f28cadec6a726c5324593a40bbf56205f
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
<template>
  <app-page-form v-bind="pageFormProps">
    <app-g6-tree v-loading="loading" v-bind="g6TreeProps"/>
  </app-page-form>
</template>
 
<script setup>
 
const router = useRouter();
 
import {uuid} from '@/utils/tools.js';
import {useEntityStore} from '@/store/modules';
 
import {structure} from '@/hooks';
 
const {useStructureData} = structure;
 
const params = router.currentRoute.value.query;
 
const [actionStructure] = useStructureData([
  {
    target: {name: 'agm_agreement_template_detail', field: 'field_code'},
    entity: {name: 'v_data_field_rule_standrad', field: 'criterion_field_name'},
    type: 'list'
  },
])
 
 
const groupModeEnum = {
  form: '表单',
  list: '列表'
};
 
const typeEnum = {
  signatory: '签署方',
  detail: '协议明细'
}
 
const entityStore = useEntityStore();
 
import {closeTab} from '@/utils/iframe.js';
 
const pageFormProps = {
  subClose() {
    closeTab();
  },
  submitDom: false,
  resetDom: false,
}
 
const loading = ref(false);
 
const g6TreeRef = ref();
 
const g6TreeProps = {
  ref: g6TreeRef,
}
 
const initData = async () => {
  loading.value = true;
  const result = await entityStore.getEntity({
    dataName: 'pkg_agm_agreement_template',
    id: params.id,
  });
  const {agm_agreement_template, agm_agreement_template_detail} = result.data;
  await actionStructure(result.data)
 
  const groups = [];
  const fields = [];
 
  agm_agreement_template_detail.forEach(item => {
    if (item.$field_code.length) {
      const children = [];
      item.$field_code.forEach(item => {
        const {
          rule_name,
          rule_code,
          data_field_name,
          rule_type_code,
          rule_object_code,
          formula,
          rule_format_content
        } = item;
        if (rule_type_code === 'required') {
          children.push({id: uuid(), name: rule_name, desc: rule_code});
        }
        if (rule_type_code === 'data_standrad') {
          console.log(item);
          children.push({
            id: uuid(),
            name: rule_name,
            desc: rule_code,
            children: [{id: uuid(), name: rule_object_code, desc: data_field_name}]
          });
        }
        if (rule_type_code === 'calculate') {
          children.push({
            id: uuid(),
            name: rule_name,
            desc: rule_code,
            children: [{id: uuid(), name: '公式', desc: formula}]
          });
        }
        if(rule_type_code === 'format') {
          if (rule_code === 'format_date_cn') {
            children.push({
              id: uuid(),
              name: rule_name,
              desc: rule_code,
              children: [{id: uuid(), name: '日期格式', desc: rule_format_content}]
            });
          }
          if (rule_code === 'format_number') {
            children.push({
              id: uuid(),
              name: rule_name,
              desc: rule_code,
              children: [{id: uuid(), name: '公式', desc: rule_format_content}]
            });
          }
        }
      });
      item.children = children;
    }
 
 
    if (item.sort === 'group') {
      groups.push({
        id: item.id,
        group_id: item.group_id,
        name: item.group_name,
        desc: groupModeEnum[item.group_mode],
        type: item.type
      });
    }
 
    if (item.sort === 'field') {
      fields.push(item);
    }
  });
 
  fields.forEach(field => {
    groups.forEach(group => {
      if (group.group_id === field.group_id) {
        if (!group.children) {
          group.children = [];
        }
        group.children.push({
          id: uuid(),
          name: field.field_name,
          desc: field.field_code,
          ...(field.children ? {children: field.children} : {}),
        });
      }
    });
  });
 
  const children = Object.keys(typeEnum).map(key => ({id: uuid(), name: typeEnum[key], desc: key}));
 
  children.forEach(e => {
    groups.forEach(item => {
      if (e.desc === item.type) {
        if (!e.children) {
          e.children = [];
        }
        delete item.type;
        e.children.push(item)
      }
    })
  });
 
  const {id, name, agreement_type} = agm_agreement_template;
 
  loading.value = false;
  return {id, name, desc: agreement_type, children};
}
 
onMounted(async () => {
  const data = await initData();
  await nextTick();
  g6TreeRef.value.registerNode(data);
})
 
</script>
 
 
<style lang="scss" scoped>
.container {
  width: 100%;
}
</style>