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
| <template>
| <app-dialog-form
| v-bind="dialogFormProps"
| v-loading="appStore.getLoading('entityset')"
| >
| <app-form-fields v-bind="formFieldsProps">
| </app-form-fields>
| </app-dialog-form>
| </template>
|
| <script setup>
|
| import {useI18n} from 'vue-i18n';
|
| const {t} = useI18n();
|
| import {meta} from "@/hooks";
|
| const {useMetaData} = meta;
|
| import {useEntityStore, useAppStore} from '@/store/modules';
| import * as tools from "@/utils/tools.js";
|
| const entityStore = useEntityStore();
| const appStore = useAppStore();
|
| const dialogFormRef = ref();
| const formFieldsRef = ref();
|
| const props = defineProps({
| subReload: {
| type: Function,
| default: () => {
| }
| },
| });
|
| const formFieldsProps = {
| ref: formFieldsRef,
| fields: [{
| type: 'el-input',
| prop: 'name',
| label: '名称',
| col: {
| span: 12
| },
| item: {
| label: '名称',
| prop: 'name',
| },
| input: {
| placeholder: '请输入名称',
| }
| }]
| }
|
| const dialogFormProps = {
| title: '',
| ref: dialogFormRef,
| subSubmit: async () => {
| const data = await formFieldsRef.value.onValidate();
| const {id, code, parent_id, parent_codes, parent_sort, parent = {}} = formFieldsRef.value.getDefaultModel();
|
| await entityStore.saveEntity({
| dataName: 'hd_discount_policy',
| data: {
| hd_discount_policy: {
| ...(id ? {
| id,
| code,
| parent_codes,
| parent_sort,
| parent_id,
| } : {
| code: `${tools.convertPinyin(data.name)}_${tools.randomString(6)}`,
| parent_codes: `${parent.parent_codes ? parent.parent_codes + '->' : ''}${parent.code}`,
| parent_sort: `${parent.parent_sort ? parent.parent_sort + ',' : ''}${parent.name}`,
| parent_id: parent.id,
| }),
| type: 'policy',
| ...data,
| }
| }
| });
| props.subReload(Boolean(!id));
| },
| subReset: async () => {
| formFieldsRef.value.onReset();
| }
| };
| const onOpen = async (row) => {
| dialogFormProps.title = t(row.id ? 'common.dialog.title.edit' : 'common.dialog.title.add');
| dialogFormRef.value.$forceUpdate(dialogFormProps);
| dialogFormRef.value.onOpen();
|
| await nextTick();
| formFieldsRef.value.setDefaultModel(row);
| }
|
| defineExpose({
| onOpen,
| });
|
| </script>
|
|