mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 01:09:19 +08:00
style(店铺概览 商品概览): 优化工具栏样式
This commit is contained in:
+249
-165
@@ -1,7 +1,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
import { DatePicker, InputNumber, Select, Spin } from 'ant-design-vue';
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
|
import { DatePicker, InputNumber, Popover, Select, Spin } from 'ant-design-vue';
|
||||||
import type { Dayjs } from 'dayjs';
|
import type { Dayjs } from 'dayjs';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
@@ -10,7 +12,6 @@ import { normalizeOverviewRangePickerChange } from '#/utils/overview-date-range'
|
|||||||
import {
|
import {
|
||||||
overviewTimeRangeBtnClass,
|
overviewTimeRangeBtnClass,
|
||||||
overviewTimeRangeBtnState,
|
overviewTimeRangeBtnState,
|
||||||
overviewToolbarLabelClass,
|
|
||||||
overviewToolbarPanelClass,
|
overviewToolbarPanelClass,
|
||||||
overviewToolbarShellClass,
|
overviewToolbarShellClass,
|
||||||
} from '../../../styles/overview-toolbar-classes';
|
} from '../../../styles/overview-toolbar-classes';
|
||||||
@@ -63,6 +64,43 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
});
|
});
|
||||||
const emit = defineEmits<Emits>();
|
const emit = defineEmits<Emits>();
|
||||||
|
|
||||||
|
const openPopover = ref<string | null>(null);
|
||||||
|
|
||||||
|
function handlePopoverOpen(name: string, open: boolean) {
|
||||||
|
if (open) {
|
||||||
|
openPopover.value = name;
|
||||||
|
} else if (openPopover.value === name) {
|
||||||
|
openPopover.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ReceiptIcon = createIconifyIcon('lucide:receipt');
|
||||||
|
const FilterIcon = createIconifyIcon('lucide:sliders-horizontal');
|
||||||
|
const CalendarIcon = createIconifyIcon('lucide:calendar');
|
||||||
|
|
||||||
|
const collapsedFilterLabel = computed(() => {
|
||||||
|
const shopName = props.shopId != null && props.shopId > 0
|
||||||
|
? (props.shopOptions?.find((o) => o.value === String(props.shopId))?.label ?? `店铺 #${props.shopId}`)
|
||||||
|
: '全部';
|
||||||
|
const productName = props.productId != null && props.productId > 0
|
||||||
|
? (props.productOptions?.find((o) => o.value === String(props.productId))?.label ?? `商品 #${props.productId}`)
|
||||||
|
: '选择商品';
|
||||||
|
return `${shopName}/${productName}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const timeRangeLabel = computed(() => {
|
||||||
|
const t = props.modelValue.activeTimeRange;
|
||||||
|
if (t === 'today') return '今日';
|
||||||
|
if (t === 'yesterday') return '昨日';
|
||||||
|
if (t === '7days') return '近7日';
|
||||||
|
if (t === '30days') return '近30日';
|
||||||
|
if (t === 'thisMonth') return '本月';
|
||||||
|
if (props.modelValue.customDateRange) {
|
||||||
|
return `${props.modelValue.customDateRange[0].format('M/D')}-${props.modelValue.customDateRange[1].format('M/D')}`;
|
||||||
|
}
|
||||||
|
return '日期';
|
||||||
|
});
|
||||||
|
|
||||||
const shopSelectValue = computed(() => {
|
const shopSelectValue = computed(() => {
|
||||||
if (props.shopId != null && props.shopId > 0) {
|
if (props.shopId != null && props.shopId > 0) {
|
||||||
return String(props.shopId);
|
return String(props.shopId);
|
||||||
@@ -174,181 +212,227 @@ const handleTaxRateChange = (val: number | string | undefined) => {
|
|||||||
<div
|
<div
|
||||||
class="overview-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
|
class="overview-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
|
||||||
>
|
>
|
||||||
<div :class="overviewToolbarShellClass">
|
<!-- 税率 -->
|
||||||
<div :class="[overviewToolbarPanelClass, 'flex items-center gap-2 px-2 py-1']">
|
<Popover
|
||||||
<span class="shrink-0" :class="overviewToolbarLabelClass">税率</span>
|
trigger="click"
|
||||||
<InputNumber
|
:open="openPopover === 'taxRate'"
|
||||||
:value="props.modelValue.taxRate"
|
placement="bottom"
|
||||||
:min="0"
|
@update:open="(val: boolean) => handlePopoverOpen('taxRate', val)"
|
||||||
:max="1"
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
:step="0.01"
|
|
||||||
:precision="2"
|
|
||||||
size="small"
|
|
||||||
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-transparent !text-center !text-sm !font-bold !text-slate-800 !shadow-none dark:!text-slate-100"
|
|
||||||
:formatter="formatTaxRate"
|
|
||||||
:parser="parseTaxRate"
|
|
||||||
@change="handleTaxRateChange"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
:class="[
|
|
||||||
overviewToolbarShellClass,
|
|
||||||
'min-w-0 sm:max-w-[min(calc(100vw-2.5rem),56rem)]',
|
|
||||||
]"
|
|
||||||
>
|
>
|
||||||
<div
|
<template #content>
|
||||||
:class="[
|
<div class="flex items-center gap-2 whitespace-nowrap">
|
||||||
overviewToolbarPanelClass,
|
<span class="shrink-0 text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||||
'flex min-w-0 flex-col gap-2 p-1 sm:flex-row sm:items-center sm:gap-0 sm:divide-x sm:divide-slate-200 dark:sm:divide-[hsl(240deg_3.7%_28%)]',
|
税率
|
||||||
]"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="flex min-w-0 items-center gap-2 px-2 py-0.5 sm:w-[11.5rem] sm:flex-none sm:shrink-0 sm:py-0"
|
|
||||||
>
|
|
||||||
<span class="w-9 shrink-0 text-right" :class="overviewToolbarLabelClass">
|
|
||||||
店铺
|
|
||||||
</span>
|
</span>
|
||||||
<Select
|
<InputNumber
|
||||||
:value="shopSelectValue"
|
:value="props.modelValue.taxRate"
|
||||||
|
:min="0"
|
||||||
|
:max="1"
|
||||||
|
:step="0.01"
|
||||||
|
:precision="2"
|
||||||
size="small"
|
size="small"
|
||||||
show-search
|
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-transparent !text-center !text-sm !font-bold !text-slate-800 !shadow-none dark:!text-slate-100"
|
||||||
allow-clear
|
:formatter="formatTaxRate"
|
||||||
:filter-option="false"
|
:parser="parseTaxRate"
|
||||||
:loading="props.shopListLoading"
|
@change="handleTaxRateChange"
|
||||||
:options="props.shopOptions"
|
/>
|
||||||
placeholder="全部店铺"
|
|
||||||
:dropdown-match-select-width="false"
|
|
||||||
class="overview-header-select overview-shop-select min-w-0 flex-1"
|
|
||||||
@change="handleShopSelectChange"
|
|
||||||
@search="(kw: string) => emit('shop-search', kw)"
|
|
||||||
@popup-scroll="(e: Event) => emit('shop-popup-scroll', e)"
|
|
||||||
@dropdown-visible-change="
|
|
||||||
(open: boolean) => emit('shop-dropdown-visible-change', open)
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<template #notFoundContent>
|
|
||||||
<div v-if="props.shopListLoading" class="py-3 text-center">
|
|
||||||
<Spin size="small" />
|
|
||||||
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="py-3 text-center text-xs text-slate-600">暂无店铺</div>
|
|
||||||
</template>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
|
</template>
|
||||||
|
<div :class="[overviewToolbarShellClass, 'cursor-pointer']">
|
||||||
<div
|
<div
|
||||||
class="flex min-w-0 flex-1 items-center gap-2 border-t border-slate-200/80 px-2 pt-2 sm:min-w-[16rem] sm:border-t-0 sm:py-0 sm:pt-0 dark:border-[hsl(240deg_3.7%_22%)]"
|
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
<span class="w-9 shrink-0 text-right" :class="overviewToolbarLabelClass">
|
<ReceiptIcon class="h-4 w-4 shrink-0" />
|
||||||
商品
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">税率{{ formatTaxRate(props.modelValue.taxRate) }}</span>
|
||||||
</span>
|
|
||||||
<Select
|
|
||||||
:value="
|
|
||||||
props.productId != null && props.productId > 0
|
|
||||||
? String(props.productId)
|
|
||||||
: undefined
|
|
||||||
"
|
|
||||||
size="small"
|
|
||||||
show-search
|
|
||||||
:filter-option="false"
|
|
||||||
:loading="props.productListLoading"
|
|
||||||
:options="props.productOptions"
|
|
||||||
placeholder="选择商品"
|
|
||||||
:dropdown-match-select-width="false"
|
|
||||||
class="overview-header-select overview-product-select min-w-0 flex-1"
|
|
||||||
@change="handleProductSelectChange"
|
|
||||||
@search="(kw: string) => emit('product-search', kw)"
|
|
||||||
@popup-scroll="(e: Event) => emit('product-popup-scroll', e)"
|
|
||||||
@dropdown-visible-change="
|
|
||||||
(open: boolean) => emit('product-dropdown-visible-change', open)
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<template #notFoundContent>
|
|
||||||
<div v-if="props.productListLoading" class="py-3 text-center">
|
|
||||||
<Spin size="small" />
|
|
||||||
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="py-3 text-center text-xs text-slate-600">暂无商品</div>
|
|
||||||
</template>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Popover>
|
||||||
|
|
||||||
<div :class="overviewToolbarShellClass">
|
<!-- 店铺/商品 -->
|
||||||
<div
|
<Popover
|
||||||
:class="[overviewToolbarPanelClass, 'flex w-full items-center gap-1 overflow-x-auto p-1']"
|
trigger="click"
|
||||||
>
|
:open="openPopover === 'filter'"
|
||||||
<button
|
placement="bottom"
|
||||||
type="button"
|
@update:open="(val: boolean) => handlePopoverOpen('filter', val)"
|
||||||
:class="[
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
overviewTimeRangeBtnClass,
|
>
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'today'),
|
<template #content>
|
||||||
]"
|
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-0">
|
||||||
@click="switchTimeRange('today')"
|
<div
|
||||||
|
class="flex min-w-0 items-center gap-2 px-2 py-0.5 sm:w-[11.5rem] sm:flex-none sm:shrink-0 sm:py-0"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||||
|
>
|
||||||
|
店铺
|
||||||
|
</span>
|
||||||
|
<Select
|
||||||
|
:value="shopSelectValue"
|
||||||
|
size="small"
|
||||||
|
show-search
|
||||||
|
allow-clear
|
||||||
|
:filter-option="false"
|
||||||
|
:loading="props.shopListLoading"
|
||||||
|
:options="props.shopOptions"
|
||||||
|
placeholder="全部店铺"
|
||||||
|
:dropdown-match-select-width="false"
|
||||||
|
class="overview-header-select overview-shop-select min-w-0 flex-1"
|
||||||
|
@change="handleShopSelectChange"
|
||||||
|
@search="(kw: string) => emit('shop-search', kw)"
|
||||||
|
@popup-scroll="(e: Event) => emit('shop-popup-scroll', e)"
|
||||||
|
@dropdown-visible-change="
|
||||||
|
(open: boolean) => emit('shop-dropdown-visible-change', open)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<template #notFoundContent>
|
||||||
|
<div v-if="props.shopListLoading" class="py-3 text-center">
|
||||||
|
<Spin size="small" />
|
||||||
|
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="py-3 text-center text-xs text-slate-600">暂无店铺</div>
|
||||||
|
</template>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="flex min-w-0 flex-1 items-center gap-2 border-t border-slate-200/80 px-2 pt-2 sm:min-w-[16rem] sm:border-t-0 sm:py-0 sm:pt-0 dark:border-[hsl(240deg_3.7%_22%)]"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||||
|
>
|
||||||
|
商品
|
||||||
|
</span>
|
||||||
|
<Select
|
||||||
|
:value="
|
||||||
|
props.productId != null && props.productId > 0
|
||||||
|
? String(props.productId)
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
size="small"
|
||||||
|
show-search
|
||||||
|
:filter-option="false"
|
||||||
|
:loading="props.productListLoading"
|
||||||
|
:options="props.productOptions"
|
||||||
|
placeholder="选择商品"
|
||||||
|
:dropdown-match-select-width="false"
|
||||||
|
class="overview-header-select overview-product-select min-w-0 flex-1"
|
||||||
|
@change="handleProductSelectChange"
|
||||||
|
@search="(kw: string) => emit('product-search', kw)"
|
||||||
|
@popup-scroll="(e: Event) => emit('product-popup-scroll', e)"
|
||||||
|
@dropdown-visible-change="
|
||||||
|
(open: boolean) => emit('product-dropdown-visible-change', open)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<template #notFoundContent>
|
||||||
|
<div v-if="props.productListLoading" class="py-3 text-center">
|
||||||
|
<Spin size="small" />
|
||||||
|
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="py-3 text-center text-xs text-slate-600">暂无商品</div>
|
||||||
|
</template>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div :class="[overviewToolbarShellClass, 'cursor-pointer']">
|
||||||
|
<div
|
||||||
|
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
今日
|
<FilterIcon class="h-4 w-4 shrink-0" />
|
||||||
</button>
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">{{ collapsedFilterLabel }}</span>
|
||||||
<button
|
</div>
|
||||||
type="button"
|
|
||||||
:class="[
|
|
||||||
overviewTimeRangeBtnClass,
|
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'yesterday'),
|
|
||||||
]"
|
|
||||||
@click="switchTimeRange('yesterday')"
|
|
||||||
>
|
|
||||||
昨日
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
:class="[
|
|
||||||
overviewTimeRangeBtnClass,
|
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '7days'),
|
|
||||||
]"
|
|
||||||
@click="switchTimeRange('7days')"
|
|
||||||
>
|
|
||||||
近7日
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
:class="[
|
|
||||||
overviewTimeRangeBtnClass,
|
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '30days'),
|
|
||||||
]"
|
|
||||||
@click="switchTimeRange('30days')"
|
|
||||||
>
|
|
||||||
近30日
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
:class="[
|
|
||||||
overviewTimeRangeBtnClass,
|
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'thisMonth'),
|
|
||||||
]"
|
|
||||||
@click="switchTimeRange('thisMonth')"
|
|
||||||
>
|
|
||||||
本月
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-start">
|
</Popover>
|
||||||
<span
|
|
||||||
class="hidden whitespace-nowrap sm:inline"
|
<!-- 时间范围 -->
|
||||||
:class="overviewToolbarLabelClass"
|
<Popover
|
||||||
|
trigger="click"
|
||||||
|
:open="openPopover === 'timeRange'"
|
||||||
|
placement="bottom"
|
||||||
|
@update:open="(val: boolean) => handlePopoverOpen('timeRange', val)"
|
||||||
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
|
>
|
||||||
|
<template #content>
|
||||||
|
<div class="flex flex-col gap-2 px-1 py-0.5">
|
||||||
|
<div class="flex items-center gap-1 overflow-x-auto whitespace-nowrap">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'today'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('today')"
|
||||||
|
>
|
||||||
|
今日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'yesterday'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('yesterday')"
|
||||||
|
>
|
||||||
|
昨日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '7days'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('7days')"
|
||||||
|
>
|
||||||
|
近7日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '30days'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('30days')"
|
||||||
|
>
|
||||||
|
近30日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'thisMonth'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('thisMonth')"
|
||||||
|
>
|
||||||
|
本月
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||||
|
>
|
||||||
|
自定义日期
|
||||||
|
</span>
|
||||||
|
<DatePicker.RangePicker
|
||||||
|
:value="props.modelValue.customDateRange"
|
||||||
|
size="small"
|
||||||
|
format="YYYY-MM-DD"
|
||||||
|
:allow-clear="false"
|
||||||
|
:placeholder="['开始', '结束']"
|
||||||
|
class="overview-header-range-picker !h-8 !w-full !border-none !bg-transparent !text-sm !font-bold !text-slate-800 sm:!w-[220px] dark:!text-slate-200"
|
||||||
|
@change="handleCustomDateRangeChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div :class="[overviewToolbarShellClass, 'cursor-pointer']">
|
||||||
|
<div
|
||||||
|
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
自定义日期
|
<CalendarIcon class="h-4 w-4 shrink-0" />
|
||||||
</span>
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">{{ timeRangeLabel }}</span>
|
||||||
<DatePicker.RangePicker
|
</div>
|
||||||
:value="props.modelValue.customDateRange"
|
|
||||||
size="small"
|
|
||||||
format="YYYY-MM-DD"
|
|
||||||
:allow-clear="false"
|
|
||||||
:placeholder="['开始', '结束']"
|
|
||||||
class="overview-header-range-picker !h-8 !w-full !border-none !bg-transparent !text-sm !font-bold !text-slate-800 sm:!w-[220px] dark:!text-slate-200"
|
|
||||||
@change="handleCustomDateRangeChange"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
+209
-128
@@ -1,5 +1,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { DatePicker, InputNumber, Select, Spin } from 'ant-design-vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
|
import { DatePicker, InputNumber, Popover, Select, Spin } from 'ant-design-vue';
|
||||||
import type { Dayjs } from 'dayjs';
|
import type { Dayjs } from 'dayjs';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
@@ -8,7 +12,6 @@ import { normalizeOverviewRangePickerChange } from '#/utils/overview-date-range'
|
|||||||
import {
|
import {
|
||||||
overviewTimeRangeBtnClass,
|
overviewTimeRangeBtnClass,
|
||||||
overviewTimeRangeBtnState,
|
overviewTimeRangeBtnState,
|
||||||
overviewToolbarLabelClass,
|
|
||||||
overviewToolbarPanelClass,
|
overviewToolbarPanelClass,
|
||||||
overviewToolbarShellClass,
|
overviewToolbarShellClass,
|
||||||
} from '../../../styles/overview-toolbar-classes';
|
} from '../../../styles/overview-toolbar-classes';
|
||||||
@@ -51,6 +54,40 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
});
|
});
|
||||||
const emit = defineEmits<Emits>();
|
const emit = defineEmits<Emits>();
|
||||||
|
|
||||||
|
const openPopover = ref<string | null>(null);
|
||||||
|
|
||||||
|
function handlePopoverOpen(name: string, open: boolean) {
|
||||||
|
if (open) {
|
||||||
|
openPopover.value = name;
|
||||||
|
} else if (openPopover.value === name) {
|
||||||
|
openPopover.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ReceiptIcon = createIconifyIcon('lucide:receipt');
|
||||||
|
const ShopIcon = createIconifyIcon('lucide:store');
|
||||||
|
const CalendarIcon = createIconifyIcon('lucide:calendar');
|
||||||
|
|
||||||
|
const selectedShopName = computed(() => {
|
||||||
|
const id = props.shopId;
|
||||||
|
if (id == null || id <= 0) return '选择店铺';
|
||||||
|
const opt = props.shopOptions?.find((o) => o.value === String(id));
|
||||||
|
return opt?.label ?? `店铺 #${id}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const timeRangeLabel = computed(() => {
|
||||||
|
const t = props.modelValue.activeTimeRange;
|
||||||
|
if (t === 'today') return '今日';
|
||||||
|
if (t === 'yesterday') return '昨日';
|
||||||
|
if (t === '7days') return '近7日';
|
||||||
|
if (t === '30days') return '近30日';
|
||||||
|
if (t === 'thisMonth') return '本月';
|
||||||
|
if (props.modelValue.customDateRange) {
|
||||||
|
return `${props.modelValue.customDateRange[0].format('M/D')}-${props.modelValue.customDateRange[1].format('M/D')}`;
|
||||||
|
}
|
||||||
|
return '日期';
|
||||||
|
});
|
||||||
|
|
||||||
const handleShopSelectChange = (value: unknown) => {
|
const handleShopSelectChange = (value: unknown) => {
|
||||||
const id = Number(value);
|
const id = Number(value);
|
||||||
if (!Number.isFinite(id) || id <= 0) return;
|
if (!Number.isFinite(id) || id <= 0) return;
|
||||||
@@ -145,140 +182,184 @@ const handleTaxRateChange = (val: number | string | undefined) => {
|
|||||||
<div
|
<div
|
||||||
class="overview-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
|
class="overview-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
|
||||||
>
|
>
|
||||||
<div :class="overviewToolbarShellClass">
|
<!-- 税率 -->
|
||||||
<div :class="[overviewToolbarPanelClass, 'flex items-center gap-2 px-2 py-1']">
|
<Popover
|
||||||
<span class="shrink-0" :class="overviewToolbarLabelClass">税率</span>
|
trigger="click"
|
||||||
<InputNumber
|
:open="openPopover === 'taxRate'"
|
||||||
:value="props.modelValue.taxRate"
|
placement="bottom"
|
||||||
:min="0"
|
@update:open="(val: boolean) => handlePopoverOpen('taxRate', val)"
|
||||||
:max="1"
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
:step="0.01"
|
|
||||||
:precision="2"
|
|
||||||
size="small"
|
|
||||||
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-transparent !text-center !text-sm !font-bold !text-slate-800 !shadow-none dark:!text-slate-100"
|
|
||||||
:formatter="formatTaxRate"
|
|
||||||
:parser="parseTaxRate"
|
|
||||||
@change="handleTaxRateChange"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
:class="[
|
|
||||||
overviewToolbarShellClass,
|
|
||||||
'min-w-0 sm:max-w-[min(calc(100vw-2.5rem),28rem)]',
|
|
||||||
]"
|
|
||||||
>
|
>
|
||||||
<div
|
<template #content>
|
||||||
:class="[
|
<div class="flex items-center gap-2 whitespace-nowrap">
|
||||||
overviewToolbarPanelClass,
|
<span class="shrink-0 text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||||
'flex min-w-0 items-center gap-2 p-1 px-2 sm:min-w-[16rem]',
|
税率
|
||||||
]"
|
</span>
|
||||||
>
|
<InputNumber
|
||||||
<span class="w-9 shrink-0 text-right" :class="overviewToolbarLabelClass">
|
:value="props.modelValue.taxRate"
|
||||||
店铺
|
:min="0"
|
||||||
</span>
|
:max="1"
|
||||||
<Select
|
:step="0.01"
|
||||||
:value="props.shopId != null && props.shopId > 0 ? String(props.shopId) : undefined"
|
:precision="2"
|
||||||
size="small"
|
size="small"
|
||||||
show-search
|
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-transparent !text-center !text-sm !font-bold !text-slate-800 !shadow-none dark:!text-slate-100"
|
||||||
:filter-option="false"
|
:formatter="formatTaxRate"
|
||||||
:loading="props.shopListLoading"
|
:parser="parseTaxRate"
|
||||||
:options="props.shopOptions"
|
@change="handleTaxRateChange"
|
||||||
placeholder="选择店铺"
|
/>
|
||||||
:dropdown-match-select-width="false"
|
</div>
|
||||||
class="overview-header-select overview-shop-select min-w-0 flex-1"
|
</template>
|
||||||
@change="handleShopSelectChange"
|
<div :class="[overviewToolbarShellClass, 'cursor-pointer']">
|
||||||
@search="(kw: string) => emit('shop-search', kw)"
|
<div
|
||||||
@popup-scroll="(e: Event) => emit('shop-popup-scroll', e)"
|
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
@dropdown-visible-change="
|
|
||||||
(open: boolean) => emit('shop-dropdown-visible-change', open)
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<template #notFoundContent>
|
<ReceiptIcon class="h-4 w-4 shrink-0" />
|
||||||
<div v-if="props.shopListLoading" class="py-3 text-center">
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">税率{{ formatTaxRate(props.modelValue.taxRate) }}</span>
|
||||||
<Spin size="small" />
|
</div>
|
||||||
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="py-3 text-center text-xs text-slate-600">暂无店铺</div>
|
|
||||||
</template>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Popover>
|
||||||
|
|
||||||
<div :class="overviewToolbarShellClass">
|
<!-- 店铺 -->
|
||||||
<div
|
<Popover
|
||||||
:class="[overviewToolbarPanelClass, 'flex w-full items-center gap-1 overflow-x-auto p-1']"
|
trigger="click"
|
||||||
>
|
:open="openPopover === 'shop'"
|
||||||
<button
|
placement="bottom"
|
||||||
type="button"
|
@update:open="(val: boolean) => handlePopoverOpen('shop', val)"
|
||||||
:class="[
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
overviewTimeRangeBtnClass,
|
>
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'today'),
|
<template #content>
|
||||||
]"
|
<div class="flex items-center gap-2 px-2 py-0.5" style="min-width: 200px;">
|
||||||
@click="switchTimeRange('today')"
|
<span
|
||||||
|
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||||
|
>
|
||||||
|
店铺
|
||||||
|
</span>
|
||||||
|
<Select
|
||||||
|
:value="props.shopId != null && props.shopId > 0 ? String(props.shopId) : undefined"
|
||||||
|
size="small"
|
||||||
|
show-search
|
||||||
|
:filter-option="false"
|
||||||
|
:loading="props.shopListLoading"
|
||||||
|
:options="props.shopOptions"
|
||||||
|
placeholder="选择店铺"
|
||||||
|
:dropdown-match-select-width="false"
|
||||||
|
class="overview-header-select overview-shop-select min-w-0 flex-1"
|
||||||
|
@change="handleShopSelectChange"
|
||||||
|
@search="(kw: string) => emit('shop-search', kw)"
|
||||||
|
@popup-scroll="(e: Event) => emit('shop-popup-scroll', e)"
|
||||||
|
@dropdown-visible-change="
|
||||||
|
(open: boolean) => emit('shop-dropdown-visible-change', open)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<template #notFoundContent>
|
||||||
|
<div v-if="props.shopListLoading" class="py-3 text-center">
|
||||||
|
<Spin size="small" />
|
||||||
|
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="py-3 text-center text-xs text-slate-600">暂无店铺</div>
|
||||||
|
</template>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div :class="[overviewToolbarShellClass, 'cursor-pointer']">
|
||||||
|
<div
|
||||||
|
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
今日
|
<ShopIcon class="h-4 w-4 shrink-0" />
|
||||||
</button>
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">{{ selectedShopName }}</span>
|
||||||
<button
|
</div>
|
||||||
type="button"
|
|
||||||
:class="[
|
|
||||||
overviewTimeRangeBtnClass,
|
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'yesterday'),
|
|
||||||
]"
|
|
||||||
@click="switchTimeRange('yesterday')"
|
|
||||||
>
|
|
||||||
昨日
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
:class="[
|
|
||||||
overviewTimeRangeBtnClass,
|
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '7days'),
|
|
||||||
]"
|
|
||||||
@click="switchTimeRange('7days')"
|
|
||||||
>
|
|
||||||
近7日
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
:class="[
|
|
||||||
overviewTimeRangeBtnClass,
|
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '30days'),
|
|
||||||
]"
|
|
||||||
@click="switchTimeRange('30days')"
|
|
||||||
>
|
|
||||||
近30日
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
:class="[
|
|
||||||
overviewTimeRangeBtnClass,
|
|
||||||
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'thisMonth'),
|
|
||||||
]"
|
|
||||||
@click="switchTimeRange('thisMonth')"
|
|
||||||
>
|
|
||||||
本月
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-start">
|
</Popover>
|
||||||
<span
|
|
||||||
class="hidden whitespace-nowrap sm:inline"
|
<!-- 时间范围 -->
|
||||||
:class="overviewToolbarLabelClass"
|
<Popover
|
||||||
|
trigger="click"
|
||||||
|
:open="openPopover === 'timeRange'"
|
||||||
|
placement="bottom"
|
||||||
|
@update:open="(val: boolean) => handlePopoverOpen('timeRange', val)"
|
||||||
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
|
>
|
||||||
|
<template #content>
|
||||||
|
<div class="flex flex-col gap-2 px-1 py-0.5">
|
||||||
|
<div class="flex items-center gap-1 overflow-x-auto whitespace-nowrap">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'today'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('today')"
|
||||||
|
>
|
||||||
|
今日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'yesterday'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('yesterday')"
|
||||||
|
>
|
||||||
|
昨日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '7days'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('7days')"
|
||||||
|
>
|
||||||
|
近7日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '30days'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('30days')"
|
||||||
|
>
|
||||||
|
近30日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
overviewTimeRangeBtnClass,
|
||||||
|
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'thisMonth'),
|
||||||
|
]"
|
||||||
|
@click="switchTimeRange('thisMonth')"
|
||||||
|
>
|
||||||
|
本月
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||||
|
>
|
||||||
|
自定义日期
|
||||||
|
</span>
|
||||||
|
<DatePicker.RangePicker
|
||||||
|
:value="props.modelValue.customDateRange"
|
||||||
|
size="small"
|
||||||
|
format="YYYY-MM-DD"
|
||||||
|
:allow-clear="false"
|
||||||
|
:placeholder="['开始', '结束']"
|
||||||
|
class="overview-header-range-picker !h-8 !w-full !border-none !bg-transparent !text-sm !font-bold !text-slate-800 sm:!w-[220px] dark:!text-slate-200"
|
||||||
|
@change="handleCustomDateRangeChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div :class="[overviewToolbarShellClass, 'cursor-pointer']">
|
||||||
|
<div
|
||||||
|
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
自定义日期
|
<CalendarIcon class="h-4 w-4 shrink-0" />
|
||||||
</span>
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">{{ timeRangeLabel }}</span>
|
||||||
<DatePicker.RangePicker
|
</div>
|
||||||
:value="props.modelValue.customDateRange"
|
|
||||||
size="small"
|
|
||||||
format="YYYY-MM-DD"
|
|
||||||
:allow-clear="false"
|
|
||||||
:placeholder="['开始', '结束']"
|
|
||||||
class="overview-header-range-picker !h-8 !w-full !border-none !bg-transparent !text-sm !font-bold !text-slate-800 sm:!w-[220px] dark:!text-slate-200"
|
|
||||||
@change="handleCustomDateRangeChange"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user