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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// import ...
import { OverlayIcon } from '@/components/overlay/OverlayIcon.tsx'
export const ItemList = defineComponent({
name: 'ItemList',
setup(/* _props, _ctx */) {
const selectedDateRef = ref('本月')
const currentDate = new DateTime()
const customDate = reactive<{ start: string; end: string }>({
start: currentDate.getOriginDate()?.format(),
end: currentDate.getOriginDate()?.format()
})
const dateList = [
{start: currentDate.firstDayOfMonth().format(), end: currentDate.lastDayOfMonth().format(),},
{
start: currentDate.subtract(1, 'month').firstDayOfMonth().format(),
end: currentDate.subtract(1, 'month').lastDayOfMonth().format(),
},
{start: currentDate.firstDayOfYear().format(), end: currentDate.lastDayOfYear().format(),},
] as const
const customDateRangeOverlayVisibleRef = ref(false)
const onSubmitCustomDateRange = (e: SubmitEvent) => {
e.preventDefault()
customDateRangeOverlayVisibleRef.value = false
}
const onCancelCustomDateRange = () => {
customDateRangeOverlayVisibleRef.value = false
}
const openCustomDateRange = () => {
customDateRangeOverlayVisibleRef.value = selectedDateRef.value === '自定义日期范围'
}
return () => (
<MainLayout>
{{
title: () => '山竹记账',
icon: () => <OverlayIcon/>,
default: () => (
<div class="h-full flex flex-col">
<SwitchTabs
selected={selectedDateRef.value}
v-model:selected={selectedDateRef.value}
onUpdate:selected={openCustomDateRange}
class="[&>nav>menu>li]:(text-start grow-0)">
<ItemTab tabName="本月" tabId="thisMonth">
<ItemSummary
startDate={dateList[0].start}
endDate={dateList[0].end} />
</ItemTab>
<ItemTab tabName="上月" tabId="lastMonth">
<ItemSummary
startDate={dateList[1].start}
endDate={dateList[1].end} />
</ItemTab>
<ItemTab tabName="今年" tabId="thisYear">
<ItemSummary
startDate={dateList[2].start}
endDate={dateList[2].end} />
</ItemTab>
<ItemTab tabName="自定义日期范围" tabId="customDateRange">
<ItemSummary
startDate={customDate.start}
endDate={customDate.end} />
</ItemTab>
</SwitchTabs>
{/* 自定义日期范围弹出层 */}
<Overlay
show={customDateRangeOverlayVisibleRef.value}
onClick={onCancelCustomDateRange}
class="flex items-center justify-center bg-[var(--overlay-mask-bg)]" >
<div
onClick={(e: MouseEvent) => e.stopPropagation()}
class="bg-[var(--overlay-bg)] w-80vw h-35vh">
<header class="bg-[var(--main)] text-[var(--dialog-header-text)] py-12px px-1em">
请选择时间
</header>
<main>
<FormContainer onSubmit={onSubmitCustomDateRange}>
<FormItem type="date" label="开始时间" v-model={customDate.start} />
<FormItem type="date" label="结束时间" v-model={customDate.end} />
<footer class="flex justify-between mt-1em children:(w-[calc(50%-.25em)])">
<FormItem type="button" onClick={onCancelCustomDateRange} buttonConfig={{level: 'default', text: '取 消' }}/>
<FormItem type="submit-button" buttonConfig={{level: 'primary', text: '确 认' }}/>
</footer>
</FormContainer>
</main>
</div>
</Overlay>
<FloatButton class="fixed bottom-1em right-1em" iconName="add" />
</div>
),
}}
</MainLayout>
)
},
})
|