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
| <script lang="ts" setup>
| import type { FormSchema } from '@jnpf/ui/form';
|
| import { computed, reactive } from 'vue';
|
| import { useMessage } from '@jnpf/hooks';
| import { BasicForm, useForm } from '@jnpf/ui/form';
| import { BasicModal, useModalInner } from '@jnpf/ui/modal';
|
| import { createTable, getInfo, updateTable } from '#/api/extend/table';
|
| interface State {
| dataForm: any;
| }
|
| const emit = defineEmits(['register', 'reload']);
| const state = reactive<State>({
| dataForm: {},
| });
| const schemas: FormSchema[] = [
| {
| field: 'projectName',
| label: '项目名称',
| component: 'Input',
| componentProps: { placeholder: '项目名称' },
| rules: [{ required: true, trigger: 'blur', message: '必填' }],
| },
| {
| field: 'projectCode',
| label: '项目编码',
| component: 'Input',
| componentProps: { placeholder: '项目编码' },
| rules: [{ required: true, trigger: 'blur', message: '必填' }],
| },
| {
| field: 'principal',
| label: '负责人',
| component: 'Input',
| componentProps: { placeholder: '负责人' },
| rules: [{ required: true, trigger: 'blur', message: '必填' }],
| },
| {
| field: 'jackStands',
| label: '立项人',
| component: 'Input',
| componentProps: { placeholder: '立项人' },
| },
| {
| field: 'projectType',
| label: '项目类型',
| component: 'Select',
| componentProps: { placeholder: '请选择项目类型' },
| rules: [{ required: true, trigger: 'change', message: '必填' }],
| },
| {
| field: 'projectPhase',
| label: '项目阶段',
| component: 'Input',
| componentProps: { placeholder: '项目阶段' },
| },
| {
| field: 'customerName',
| label: '客户名称',
| component: 'Input',
| componentProps: { placeholder: '客户名称' },
| },
| {
| field: 'interactionDate',
| label: '交互日期',
| component: 'DatePicker',
| componentProps: { placeholder: '选择交互日期' },
| },
| {
| field: 'costAmount',
| label: '费用金额',
| component: 'InputNumber',
| defaultValue: 0,
| componentProps: { placeholder: '费用金额' },
| },
| {
| field: 'tunesAmount',
| label: '已用金额',
| component: 'InputNumber',
| defaultValue: 0,
| componentProps: { placeholder: '已用金额' },
| },
| {
| field: 'projectedIncome',
| label: '预计收入',
| component: 'InputNumber',
| defaultValue: 0,
| componentProps: { placeholder: '预计收入' },
| },
| {
| field: 'description',
| label: '备注',
| component: 'Textarea',
| componentProps: { placeholder: '备注', rows: 3 },
| },
| ];
| const getTitle = computed(() => (state.dataForm.id ? '编辑' : '新建'));
| const { createMessage } = useMessage();
| const [registerForm, { setFieldsValue, validate, resetFields, updateSchema }] = useForm({ labelWidth: 80, schemas });
| const [registerModal, { closeModal, changeLoading, changeOkLoading }] = useModalInner(init);
|
| function init(data) {
| resetFields();
| state.dataForm.id = data.id;
| if (data.industryTypeList) updateSchema({ field: 'projectType', componentProps: { options: data.industryTypeList } });
| if (state.dataForm.id) {
| changeLoading(true);
| getInfo(state.dataForm.id).then((res) => {
| const data = res.data;
| state.dataForm = data;
| setFieldsValue(data);
| changeLoading(false);
| });
| }
| }
| async function handleSubmit() {
| const values = await validate();
| if (!values) return;
| changeOkLoading(true);
| const query = {
| ...values,
| id: state.dataForm.id,
| };
| const formMethod = state.dataForm.id ? updateTable : createTable;
| formMethod(query)
| .then((res) => {
| createMessage.success(res.msg);
| changeOkLoading(false);
| closeModal();
| emit('reload');
| })
| .catch(() => {
| changeOkLoading(false);
| });
| }
| </script>
| <template>
| <BasicModal v-bind="$attrs" :title="getTitle" show-ok-btn @ok="handleSubmit" @register="registerModal">
| <BasicForm @register="registerForm" />
| </BasicModal>
| </template>
|
|