<template>
  <uni-data-picker
    :modelValue="modelValue"
    :localdata="data"
    :map="{ text: 'text', value: useCode ? 'value' : 'text' }"
    @change="onChange"
  >
  </uni-data-picker>
</template>

<script setup lang="ts">
import NotConfigue from '@/api/NotConfigue';
import { onMounted, ref } from 'vue';

const data = ref();
const props = defineProps({	
  modelValue: { 
    type: Array,
    default: null 
  },
  useCode: {
    type: Boolean,
    default: false,
  },
})
const emit = defineEmits(['update:modelValue'])

onMounted(() => {
  NotConfigue.get('https://mn.wenlvti.net/app_static/xiangan/city-data.json', '', undefined).then((res) => {
    data.value = res.data; 
  })
});

function onChange(e: any) {
  emit('update:modelValue', e.detail.value.map((x: any) => props.useCode ? x.value : x.text));
}
</script>