<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>
|