<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 data from '../data/city-data.json'

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

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