<!--
 * @Description: 
 * @Version: 
 * @Author: 黄先伟
 * @Date: 2024-02-06 16:09:19
-->
<template>
    <span>{{adcdName}}</span>
</template>

<script setup name="AreaView" lang="ts">
import { getAdcdByCode } from '@/api/adcd';
import { propTypes } from '@/utils/propTypes';
const adcdName = ref('');
const props = defineProps({
  value: String,
  multiple: propTypes.bool.def(false)
});
const getByCodeFn = async (code: string) => {
  const res = await getAdcdByCode(code);
  if (!res || res.code !== 200) return;
  adcdName.value = res.data?.fullName || '';
};
const getByCodeFnArr = async (vl: any) => {
  const address = []
  for (let i = 0; i < vl.length; i++) {
    const element = vl[i];
    const res = await getAdcdByCode(element);
    address.push(res.data.fullName)
  }
  adcdName.value = address.toString()
}
watch(
  () => props.value,
  (val) => {
    if (val) {
      if (!props.multiple) {
        getByCodeFn(val);
      } else {
        getByCodeFnArr(val)
      }
    }
  },
  { immediate: true }
);
</script>
<style lang="scss" scoped></style>
