<template>
  <u-button 
    type="primary"
    :plain="true"
    :text="dispayText"
    @click="onPick"
  >
  
  </u-button>
</template>

<script setup lang="ts">
import { computed } from 'vue';

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

const dispayText = computed(() => {
  return `经度：${props.modelValue[0] || '请填写'} 纬度：${props.modelValue[1] || '请填写'}`;
});
function onPick() {
  uni.chooseLocation({
    latitude: props.modelValue[1] as number,
    longitude: props.modelValue[0] as number,
    success: (res) => {
      emit('update:modelValue', [res.longitude, res.latitude]);
    },
    fail: (e) => {
      console.log(e)
    },
  });
}
</script>