zhengyiming
2025-03-24 21b418f4ffb8e76d72819e8d489b3179154cb0c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<template>
  <ChooseInput :modelValue="inputValue" @click="handleOpen()" v-bind="$attrs"></ChooseInput>
  <NutPopup v-model:visible="visible" position="bottom">
    <NutPicker
      :modelValue="modelValue"
      :columns="columns"
      :fieldNames="fieldNames"
      :title="title"
      @cancel="visible = false"
      @confirm="handleConfirm"
    >
    </NutPicker>
  </NutPopup>
</template>
 
<script setup lang="ts">
// import { useAllAreaList } from '../../hooks/area';
import ChooseInput from './ChooseInput.vue';
import { Popup as NutPopup, Picker as NutPicker } from '@nutui/nutui-taro';
import { computed, ref } from 'vue';
 
defineOptions({
  name: 'ChooseInputWithAreaPicker',
});
 
// const { findAreaNameFromCode } = useAllAreaList();
 
type Props = {
  fieldNames?: object;
  columns: API.AreaTreeNode[];
  modelValue: Array<string | number>;
  title?: string;
};
 
const props = withDefaults(defineProps<Props>(), {
  title: '选择地址',
  fieldNames: () => ({
    text: 'areaName',
    value: 'areaName',
    children: 'children',
  }),
});
const inputValue = computed(() => props.modelValue.join(','));
 
const emit = defineEmits<{
  (e: 'update:modelValue', val: Array<string | number>): void;
}>();
 
const visible = ref(false);
 
function handleOpen() {
  visible.value = true;
}
 
function handleConfirm({ selectedValue, selectedOptions }) {
  emit(
    'update:modelValue',
    selectedOptions.map((x) => x.areaName)
  );
  visible.value = false;
}
</script>