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
| <template>
| <ChooseInput :modelValue="modelValue" @click="handleOpen()"></ChooseInput>
| </template>
|
| <script setup lang="ts">
| import ChooseInput from './ChooseInput.vue';
| import { Popup, DatePicker } from '@nutui/nutui-taro';
| import { Portal } from 'senin-mini/components';
| import { h } from 'vue';
| import dayjs from 'dayjs';
|
| defineOptions({
| name: 'ChooseInputWithDatePicker',
| });
|
| type Props = {
| modelValue: string | number;
| };
|
| const props = withDefaults(defineProps<Props>(), {});
|
| const emit = defineEmits<{
| (e: 'update:modelValue', val: string | number): void;
| }>();
|
| function handleOpen() {
| const _modelValue = [props.modelValue];
| 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(DatePicker, {
| modelValue: _modelValue,
| onCancel: onClose,
| onConfirm: ({ selectedValue }) => {
| emit('update:modelValue', dayjs(selectedValue).format('YYYY-MM-DD'));
| onClose();
| },
| }),
| }
| ),
| }
| );
| });
| }
| </script>
|
|