PickerAddressField.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <FlexRow width="100%" align="center">
  3. <input
  4. :value="modelValue"
  5. :placeholder="readonly ? '未填写' : '输入地址或者选择地图地址'"
  6. @input="handleInput"
  7. />
  8. <Button v-if="!disabled && !readonly" type="primary" size="mini" icon="map" @click="selectFromMap">地图选择</Button>
  9. <view v-else></view>
  10. </FlexRow>
  11. </template>
  12. <script setup lang="ts">
  13. import { type PropType } from 'vue';
  14. import Button from '@/components/basic/Button.vue';
  15. import FlexRow from '@/components/layout/FlexRow.vue';
  16. const props = defineProps({
  17. modelValue: {
  18. type: String,
  19. default: '',
  20. },
  21. /**
  22. * 是否禁用
  23. */
  24. disabled: {
  25. type: Boolean,
  26. default: false,
  27. },
  28. /**
  29. * 是否只读
  30. */
  31. readonly: {
  32. type: Boolean,
  33. default: false,
  34. },
  35. loadFormattedAddress: {
  36. type: Function as PropType<(latlon: [number,number]) => Promise<string>>,
  37. default: null,
  38. },
  39. });
  40. const emit = defineEmits(['update:modelValue']);
  41. function handleInput(e: any) {
  42. emit('update:modelValue', e.detail.value);
  43. }
  44. function selectFromMap() {
  45. uni.chooseLocation({
  46. success: (res) => {
  47. props.loadFormattedAddress([res.latitude, res.longitude]).then((info) => {
  48. console.log(info);
  49. emit('update:modelValue', info)
  50. })
  51. }
  52. })
  53. }
  54. defineOptions({
  55. options: {
  56. virtualHost: true,
  57. }
  58. })
  59. </script>