AreaView.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <!--
  2. * @Description:
  3. * @Version:
  4. * @Author: 黄先伟
  5. * @Date: 2024-02-06 16:09:19
  6. -->
  7. <template>
  8. <span>{{adcdName}}</span>
  9. </template>
  10. <script setup name="AreaView" lang="ts">
  11. import { getAdcdByCode } from '@/api/adcd';
  12. import { propTypes } from '@/utils/propTypes';
  13. const adcdName = ref('');
  14. const props = defineProps({
  15. value: String,
  16. multiple: propTypes.bool.def(false)
  17. });
  18. const getByCodeFn = async (code: string) => {
  19. const res = await getAdcdByCode(code);
  20. if (!res || res.code !== 200) return;
  21. adcdName.value = res.data?.fullName || '';
  22. };
  23. const getByCodeFnArr = async (vl: any) => {
  24. const address = []
  25. for (let i = 0; i < vl.length; i++) {
  26. const element = vl[i];
  27. const res = await getAdcdByCode(element);
  28. address.push(res.data.fullName)
  29. }
  30. adcdName.value = address.toString()
  31. }
  32. watch(
  33. () => props.value,
  34. (val) => {
  35. if (val) {
  36. if (!val) {
  37. adcdName.value = '';
  38. return;
  39. }
  40. if (!props.multiple) {
  41. getByCodeFn(val);
  42. } else {
  43. getByCodeFnArr(val)
  44. }
  45. }
  46. },
  47. { immediate: true }
  48. );
  49. </script>
  50. <style lang="scss" scoped></style>