EnterpriseInfo.vue
6.23 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<template>
<div class="card">
<Card :bordered="false" class="card">
<BasicForm @register="registerForm">
<template #qrcode>
<ContentUploadText>
<template #uploadImg>
<CustomUploadComp :imgUrl="qrcodePic" @setImg="handleSetCodeImgUrl" />
</template>
<template #uploadText>
<div class="box-outline"> 支持.PNG、.JPG格式,建议尺寸为300*300px,大小不超过5M </div>
</template>
</ContentUploadText>
</template>
<template #customProv>
<BasicForm @register="registerCustomForm" />
</template>
</BasicForm>
</Card>
<Loading v-bind="compState" />
<Authority value="api:yt:enterprise:update:update">
<a-button
v-if="isWhereAdmin !== 'CUSTOMER_USER'"
@click="handleUpdateInfo"
type="primary"
class="mt-4"
>更新基本信息</a-button
>
</Authority>
</div>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref, computed } from 'vue';
import { Card } from 'ant-design-vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { schemas, provSchemas } from '../config/enterPriseInfo.config';
import { getEnterPriseDetail, updateEnterPriseDetail } from '/@/api/oem/index';
import { Loading } from '/@/components/Loading';
import { useMessage } from '/@/hooks/web/useMessage';
import { useUserStore } from '/@/store/modules/user';
import { createLocalStorage } from '/@/utils/cache';
import { Authority } from '/@/components/Authority';
import { USER_INFO_KEY } from '/@/enums/cacheEnum';
import { getAuthCache } from '/@/utils/auth';
import ContentUploadText from './ContentUploadText.vue';
import { CustomUploadComp } from './customUplaod/index';
export default defineComponent({
components: {
Card,
BasicForm,
Loading,
Authority,
ContentUploadText,
CustomUploadComp,
},
setup() {
const userInfo: any = getAuthCache(USER_INFO_KEY);
const isWhereAdmin: any = computed(() => {
if (userInfo.roles.includes('TENANT_ADMIN')) {
return 'TENANT_ADMIN';
} else if (userInfo.roles.includes('CUSTOMER_USER')) {
return 'CUSTOMER_USER';
} else {
return 'SYS_ADMIN';
}
});
const loading = ref(false);
const compState = ref({
absolute: false,
loading: false,
tip: '拼命加载中...',
});
const [registerForm, { getFieldsValue, setFieldsValue, validate, clearValidate }] = useForm({
labelWidth: 80,
schemas,
showResetButton: false,
showSubmitButton: false,
wrapperCol: {
span: 12,
},
});
const [registerCustomForm, { getFieldsValue: getNameTown, setFieldsValue: setNameTown }] =
useForm({
labelWidth: 80,
schemas: provSchemas,
showResetButton: false,
showSubmitButton: false,
compact: true,
actionColOptions: {
span: 0,
},
});
const { createMessage } = useMessage();
const qrcodePic = ref();
const handleSetCodeImgUrl = (d) => {
qrcodePic.value = d;
};
// 更新
const handleUpdateInfo = async () => {
try {
const fieldsValue = getFieldsValue();
const { nameTown } = getNameTown();
const newFieldValue: any = {
...fieldsValue,
codeTown: nameTown,
qrCode: qrcodePic.value,
};
delete newFieldValue.nameProv;
delete newFieldValue.nameCity;
delete newFieldValue.nameCoun;
delete newFieldValue.nameTown;
// 表单校验
let validateArray = [
'name',
'abbreviation',
'officialWebsite',
'email',
'synopsis',
'nameCountry',
'address',
'contacts',
'tel',
'id',
];
if (newFieldValue.qrCode == undefined || newFieldValue.qrCode == '') {
validateArray.push('qrcode');
} else {
const findExistIndex = validateArray.findIndex((o) => o == 'qrcode');
if (findExistIndex !== -1) {
validateArray.splice(findExistIndex, 1);
}
}
if (newFieldValue.codeTown == undefined) {
validateArray.push('prov');
} else {
const findExistIndex1 = validateArray.findIndex((o) => o == 'prov');
if (findExistIndex1 !== -1) {
validateArray.splice(findExistIndex1, 1);
}
clearValidate('prov');
}
const values = await validate(validateArray);
if (!values) return;
compState.value.loading = true;
await updateEnterPriseDetail(newFieldValue);
createMessage.success('更新信息成功');
setEnterPriseInfo(newFieldValue);
} finally {
compState.value.loading = false;
}
};
const userStore = useUserStore();
const storage = createLocalStorage();
// 设置企业信息
function setEnterPriseInfo(newFieldValue) {
// 保存store
userStore.setEnterPriseInfo(newFieldValue);
// 保存本地缓存
storage.set('enterpriseInfo', newFieldValue);
}
onMounted(async () => {
const res = await getEnterPriseDetail();
if (res.sysTown) {
const { codeCountry, codeProv, codeCity, codeCoun, codeTown } = res.sysTown;
setNameTown({
nameProv: codeProv,
nameCity: codeCity,
nameCoun: codeCoun,
nameTown: codeTown,
});
setFieldsValue({ nameCountry: codeCountry });
}
setFieldsValue(res);
qrcodePic.value = res.qrCode;
});
return {
registerForm,
compState,
qrcodePic,
handleUpdateInfo,
registerCustomForm,
loading,
isWhereAdmin,
handleSetCodeImgUrl,
};
},
});
</script>
<style lang="less" scoped>
.box-outline {
border: 1px dashed #d9d9d9;
}
.fill-img {
width: 100%;
height: 100%;
}
</style>