zhengyiming
2025-02-14 05357b9c587f64cd548e987643066b253cd9bfe0
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
<template>
  <ChooseInput :modelValue="inputValue" @click="handleOpen()"></ChooseInput>
</template>
 
<script setup lang="ts">
import { useAllAreaList } from '@12333/hooks';
import { Portal } from 'senin-mini/components';
import ChooseAreaActionSheet from '../ActionSheet/ChooseAreaActionSheet.vue';
import ChooseInput from './ChooseInput.vue';
import { computed, h } from 'vue';
 
defineOptions({
  name: 'ChooseInputWithAreaSheet',
});
 
const { findAreaNameFromCode } = useAllAreaList();
 
type Props = {
  modelValue: Array<number>;
  title?: string;
  max?: number;
};
 
const props = withDefaults(defineProps<Props>(), {
  title: '请选择地区',
});
const inputValue = computed(() =>
  props.modelValue.map((x) => findAreaNameFromCode(Number(x))).join(',')
);
 
const emit = defineEmits<{
  (e: 'update:modelValue', val: Array<string | number>): void;
}>();
 
function handleOpen() {
  Portal.add((key) => {
    return h(
      Portal.Container,
      { keyNumber: key, delayOpen: true },
      {
        default: ({ open, onClose }) =>
          h(ChooseAreaActionSheet, {
            modelValue: props.modelValue,
            max: props.max,
            visible: open.value,
            'onUpdate:visible': (value) => !value && onClose(),
            title: props.title,
            'onUpdate:modelValue': (value) => {
              emit('update:modelValue', value);
            },
          }),
      }
    );
  });
}
</script>