| 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 | | <template> |  |   <ChooseInput :modelValue="inputValue" @click="handleOpen()"></ChooseInput> |  | </template> |  |   |  | <script setup lang="ts"> |  | import { useAllAreaList } from '@12333/hooks'; |  | import { Portal } from 'senin-mini/components'; |  | import ChooseInput from './ChooseInput.vue'; |  | import { Popup, Picker } from '@nutui/nutui-taro'; |  | import { computed, h } from 'vue'; |  |   |  | defineOptions({ |  |   name: 'ChooseInputWithAreaPicker', |  | }); |  |   |  | const { findAreaNameFromCode } = useAllAreaList(); |  |   |  | type Props = { |  |   fieldNames?: object; |  |   columns: API.AreaTreeNode[]; |  |   modelValue: Array<string>; |  |   title?: string; |  | }; |  |   |  | const props = withDefaults(defineProps<Props>(), { |  |   title: '选择地址', |  |   fieldNames: () => ({ |  |     text: 'areaName', |  |     value: 'areaCode', |  |     children: 'children', |  |   }), |  | }); |  | console.log('props: ', props); |  | const inputValue = computed(() => props.modelValue.map((x) => findAreaNameFromCode(x)).join(',')); |  |   |  | const emit = defineEmits<{ |  |   (e: 'update:modelValue', val: Array<string>): void; |  | }>(); |  |   |  | function handleOpen() { |  |   Portal.add((key) => { |  |     return h( |  |       Portal.Container, |  |       { keyNumber: key, delayOpen: true }, |  |       { |  |         default: ({ open, onClose }) => |  |           h( |  |             Popup, |  |             { |  |               visible: open.value, |  |               'onUpdate:visible': (value) => !value && onClose(), |  |               position: 'bottom', |  |             }, |  |             { |  |               default: () => |  |                 h(Picker, { |  |                   modelValue: props.modelValue, |  |                   columns: props.columns, |  |                   fieldNames: props.fieldNames, |  |                   title: props.title, |  |                   onCancel: onClose, |  |                   onConfirm: ({ selectedValue, selectedOptions }) => { |  |                     emit( |  |                       'update:modelValue', |  |                       selectedOptions.filter(Boolean).map((x) => x.areaCode) |  |                     ); |  |                     onClose(); |  |                   }, |  |                 }), |  |             } |  |           ), |  |       } |  |     ); |  |   }); |  | } |  | </script> | 
 |