EnterpriseInfo.vue
6.16 KB
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
192
193
<template>
<div class="card">
<Card :bordered="false" class="card"> <BasicForm @register="registerForm" /></Card>
<Loading v-bind="compState" />
<a-button
@click="handleUpdateInfo"
size="large"
type="primary"
style="margin-top: 20px; background-color: #2950f7; border-radius: 5px"
>更新基本信息</a-button
>
</div>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
import { Card } from 'ant-design-vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { schemas } from '../config/enterPriseInfo.config';
import { getEnterPriseDetail, updateEnterPriseDetail } from '/@/api/oem/index';
import { Loading } from '/@/components/Loading';
import { useMessage } from '/@/hooks/web/useMessage';
import { getTownChild } from '/@/api/oem/index';
export default defineComponent({
components: {
Card,
BasicForm,
Loading,
},
setup() {
const compState = ref({
absolute: false,
loading: false,
tip: '拼命加载中...',
});
const [registerForm, { getFieldsValue, setFieldsValue, updateSchema }] = useForm({
labelWidth: 80,
schemas,
showResetButton: false,
showSubmitButton: false,
wrapperCol: {
span: 10,
},
});
const { createMessage } = useMessage();
const handleUpdateInfo = async () => {
try {
compState.value.loading = true;
const fieldsValue = getFieldsValue();
await updateEnterPriseDetail({
...fieldsValue,
codeProv: fieldsValue.nameProv,
codeCity: fieldsValue.nameCity,
codeCoun: fieldsValue.nameCoun,
codeTown: fieldsValue.nameTown,
});
compState.value.loading = false;
createMessage.success('更新信息成功');
} catch (e) {
createMessage.error('更新信息失败');
}
};
// 地区显示回显和数据联动
async function updateCityData(codeProv: string, codeCity: string, codeCoun: string) {
const nameCity = await getTownChild('codeProv', codeProv);
const nameCoun = await getTownChild('codeCity', codeCity);
const nameTown = await getTownChild('codeCoun', codeCoun);
nameCity.forEach((item) => {
item.label = item.nameCity;
item.value = item.codeCity;
});
nameCoun.forEach((item) => {
item.label = item.nameCoun;
item.value = item.codeCoun;
});
nameTown.forEach((item) => {
item.label = item.nameTown;
item.value = item.codeTown;
});
updateSchema({
field: 'nameTown',
componentProps: {
options: nameTown,
},
});
updateSchema({
field: 'nameCoun',
componentProps: {
options: nameCoun,
async onChange(value) {
if (value === undefined) {
setFieldsValue({
nameTown: undefined,
});
updateSchema({
field: 'nameTown',
componentProps: {
options: [],
},
});
}
let nameTown = await getTownChild('codeCoun', value);
nameTown.forEach((item) => {
item.label = item.nameTown;
item.value = item.codeTown;
});
setFieldsValue({
nameTown: undefined,
});
updateSchema({
field: 'nameTown',
componentProps: {
placeholder: '请选择街道/城镇',
options: nameTown,
},
});
},
},
});
updateSchema({
field: 'nameCity',
componentProps: ({ formModel }) => {
return {
options: nameCity,
onChange: async (value) => {
let nameCoun = await getTownChild('codeCity', value);
if (value === undefined) {
formModel.nameCoun = undefined; // reset city value
formModel.nameTown = undefined;
nameCoun = [];
updateSchema({
field: 'nameTown',
componentProps: {
options: [],
},
});
}
nameCoun.forEach((item) => {
item.label = item.nameCoun;
item.value = item.codeCoun;
});
formModel.nameCoun = undefined; // reset city value
formModel.nameTown = undefined;
updateSchema({
field: 'nameCoun',
componentProps: {
// 请选择区
options: nameCoun,
async onChange(value) {
let nameTown = await getTownChild('codeCoun', value);
if (value === undefined) {
formModel.nameTown = undefined;
nameTown = [];
}
nameTown.forEach((item) => {
item.label = item.nameTown;
item.value = item.codeTown;
});
formModel.nameTown = undefined;
updateSchema({
field: 'nameTown',
componentProps: {
placeholder: '请选择街道/城镇',
options: nameTown,
},
});
},
},
});
},
};
},
});
}
onMounted(async () => {
const res = await getEnterPriseDetail();
updateCityData(res.codeProv, res.codeCity, res.codeCoun);
setFieldsValue(res);
});
return {
registerForm,
compState,
handleUpdateInfo,
};
},
});
</script>
<style lang="less" scoped></style>