@page "/report/shiftSalesReport"
@attribute [ReuseTabsPage(Title = "班次销售报表")]
<style>
    .daily-report-container {
        padding: 16px;
        background-color: #f5f7fa;
        min-height: 100vh;
        box-sizing: border-box;
        overflow: hidden;
    }

    .filter-section {
        margin-bottom: 16px;
        padding: 16px !important;
        background: white;
        border: 1px solid #ebeef5;
        border-radius: 4px;
    }

    .filter-content .filter-row {
        display: flex;
        align-items: center;
        gap: 16px;
        flex-wrap: wrap;
    }

        .filter-content .filter-row .filter-item {
            display: flex;
            align-items: center;
        }

            .filter-content .filter-row .filter-item .filter-label {
                margin-right: 8px;
                font-size: 14px;
                color: #606266;
                min-width: 32px;
            }

        .filter-content .filter-row .filter-actions {
            display: flex;
            gap: 8px;
            margin-left: auto;
        }

    .report-section {
        margin-bottom: 16px;
        padding: 16px;
        background: white;
        border: 1px solid #ebeef5;
        border-radius: 4px;
    }

    .section-header {
        margin-bottom: 16px;
        padding: 0 16px;
    }

        .section-header h3 {
            color: #303133;
            font-size: 16px;
            border-left: 4px solid #1890ff;
            padding-left: 10px;
            margin: 0;
        }

    .summary-section {
        padding: 16px;
    }

        .summary-section h3 {
            color: #303133;
            font-size: 16px;
            margin-bottom: 16px;
            border-left: 4px solid #1890ff;
            padding-left: 10px;
        }

    .summary-content {
        display: flex;
        justify-content: space-around;
    }

    .summary-item {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .summary-value {
        font-size: 24px;
        font-weight: 600;
        color: #1890ff;
        margin-bottom: 8px;
    }

    .summary-label {
        font-size: 14px;
        color: #909399;
    }

    .table-container {
        padding: 0 16px 16px;
    }

    /* Div表格样式 - 复杂表头 */
    .div-table {
        display: flex;
        flex-direction: column;
        border: 1px solid #ebeef5;
        border-radius: 4px;
        overflow: hidden;
        font-size: 14px;
    }

    /* 第一行表头（合并单元格） */
    .div-table-header-1 {
        display: flex;
        background-color: #e6f7ff;
        font-weight: 600;
        color: #606266;
        border-bottom: 2px solid #91d5ff;
    }

    /* 第二行表头（子标题） */
    .div-table-header-2 {
        display: flex;
        background-color: #fafafa;
        font-weight: 600;
        color: #606266;
        border-bottom: 1px solid #ebeef5;
    }

    .div-table-row {
        display: flex;
        border-bottom: 1px solid #ebeef5;
    }

        .div-table-row:last-child {
            border-bottom: none;
        }

        .div-table-row.total-row {
            font-weight: 600;
            background-color: #f0f9ff;
        }

        .div-table-row:nth-child(even) {
            background-color: #fafafa;
        }

    .div-table-cell {
        padding: 12px 8px;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .cell-left-align {
        text-align: left !important;
        justify-content: flex-start;
    }

    .cell-right-align {
        text-align: right !important;
        justify-content: flex-end;
    }

    .highlight-cell {
        color: #1890ff !important;
        font-weight: 500;
    }

    /* 列组标题样式 */
    .column-group-title {
        display: flex;
        align-items: center;
        justify-content: center;
        border-left: 1px solid #e8e8e8;
    }

        .column-group-title:first-child {
            border-left: none;
        }

    /* 子标题单元格 */
    .sub-header-cell {
        display: flex;
        align-items: center;
        justify-content: center;
        border-left: 1px solid #e8e8e8;
    }

        .sub-header-cell:first-child {
            border-left: none;
        }

    /* 数据单元格 */
    .data-cell {
        display: flex;
        align-items: center;
        justify-content: center;
        border-left: 1px solid #ebeef5;
    }

        .data-cell:first-child {
            border-left: none;
        }

    .data-cell-group {
        display: flex;
        flex: 1;
    }

    /* 响应式设计 */
    @@media (max-width: 768px) {
        .daily-report-container {
            padding: 12px;
        }

        .filter-section {
            padding: 12px !important;
        }

        .filter-content .filter-row {
            flex-direction: column;
            align-items: flex-start;
        }

            .filter-content .filter-row .filter-actions {
                margin-left: 0;
                width: 100%;
                display: flex;
                justify-content: center;
                margin-top: 8px;
            }

        .summary-content {
            flex-wrap: wrap;
        }

        .summary-item {
            width: 50%;
            margin-bottom: 16px;
        }

        .div-table {
            overflow-x: auto;
        }

        .div-table-header-1,
        .div-table-header-2,
        .div-table-row {
            min-width: 1200px;
        }

        .div-table-cell {
            padding: 8px 4px;
            font-size: 12px;
        }
    }
</style>

<div class="daily-report-container">
    <!-- 筛选条件 -->
    <div class="filter-section">
        <div class="filter-content">
            <div class="filter-row">
                <div class="filter-item">
                    <span class="filter-label">日期</span>
                    <DatePicker @bind-Value="Filter.StartDate"
                                Format="yyyy-MM-dd"
                                Style="width: 150px" />
                </div>
                <div class="filter-item">
                    <span class="filter-label">设备编号</span>
                    <Input @bind-Value="Filter.PlateNumber"
                           Placeholder="请输入设备编号"
                           Style="width: 150px" />
                </div>
                <!-- 班次 -->
                <div class="form-item">
                    <span class="form-label">班次</span>
                    <Select TItemValue="string" TItem="string"
                            DataSource="@ShiftName"
                            @bind-Value="@Filter.Shift"
                            Style="width: 120px"
                            Placeholder="请选择"
                            AllowClear />
                </div>
                <div class="filter-actions">
                    <Button Icon="search" OnClick="HandleQuery">查询</Button>
                    <Button Icon="reload" OnClick="HandleReset">重置</Button>
                </div>
            </div>
        </div>
    </div>

    <!-- 统计摘要 -->
    <div class="report-section">
        <div class="summary-section">
            <h3>统计摘要</h3>
            <div class="summary-content">
                <div class="summary-item">
                    <div class="summary-value">@Summary.TotalSalesQuantity</div>
                    <div class="summary-label">总销售数量</div>
                </div>
                <div class="summary-item">
                    <div class="summary-value">@FormatCurrency(Summary.TotalReceivable)</div>
                    <div class="summary-label">总应收金额</div>
                </div>
                <div class="summary-item">
                    <div class="summary-value">@FormatCurrency(Summary.TotalActual)</div>
                    <div class="summary-label">总实收金额</div>
                </div>
            </div>
        </div>
    </div>

    <!-- 营业收入 -->
    <div class="report-section">
        <div class="section-header">
            <h3>营业收入</h3>
        </div>
        <div class="table-container">
            <div class="div-table">
                <!-- 第一行表头（合并单元格） -->
                <div class="div-table-header-1">
                    <div class="div-table-cell column-group-title" style="width: 11.11%;">项目</div>
                    <div class="div-table-cell column-group-title" style="width: 33.33%;">
                        销售数量
                    </div>
                    <div class="div-table-cell column-group-title" style="width: 33.33%;">
                        应收金额
                    </div>
                    <div class="div-table-cell column-group-title" style="width: 22.23%;">
                        实收金额
                    </div>
                </div>

                <!-- 第二行表头（子标题） -->
                <div class="div-table-header-2">
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;"></div>

                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">早班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">晚班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">小计</div>

                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">早班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">晚班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">小计</div>

                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">早班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">晚班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">小计</div>
                </div>

                <!-- 表格数据行 -->
                @foreach (var item in OperatingIncome)
                {
                    <div class="div-table-row @(item.Name == "油品合计" ? "total-row" : "")">
                        <div class="div-table-cell cell-left-align" style="width: 11.11%;">@item.Name</div>

                        <!-- 销售数量 -->
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatNumber(item.MorningSalesQuantity)</div>
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatNumber(item.EveningSalesQuantity)</div>
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatNumber(item.TotalSalesQuantity)</div>

                        <!-- 应收金额 -->
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatCurrency(item.MorningReceivable)</div>
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatCurrency(item.EveningReceivable)</div>
                        <div class="div-table-cell cell-right-align highlight-cell" style="width: 11.11%;">@FormatCurrency(item.TotalReceivable)</div>

                        <!-- 实收金额 -->
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatCurrency(item.MorningActual)</div>
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatCurrency(item.EveningActual)</div>
                        <div class="div-table-cell cell-right-align highlight-cell" style="width: 11.11%;">@FormatCurrency(item.TotalActual)</div>
                    </div>
                }
            </div>
        </div>
    </div>

    <!-- 收入类别 -->
    <div class="report-section">
        <div class="section-header">
            <h3>收入类别</h3>
        </div>
        <div class="table-container">
            <div class="div-table">
                <!-- 第一行表头（合并单元格） -->
                <div class="div-table-header-1">
                    <div class="div-table-cell column-group-title" style="width: 11.11%;">项目</div>
                    <div class="div-table-cell column-group-title" style="width: 33.33%;">
                        收入笔数
                    </div>
                    <div class="div-table-cell column-group-title" style="width: 33.33%;">
                        应收金额
                    </div>
                    <div class="div-table-cell column-group-title" style="width: 22.23%;">
                        实收金额
                    </div>
                </div>

                <!-- 第二行表头（子标题） -->
                <div class="div-table-header-2">
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;"></div>

                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">早班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">晚班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">小计</div>

                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">早班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">晚班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">小计</div>

                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">早班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">晚班</div>
                    <div class="div-table-cell sub-header-cell" style="width: 11.11%;">小计</div>
                </div>

                <!-- 表格数据行 -->
                @foreach (var item in IncomeCategory)
                {
                    <div class="div-table-row @(item.Name == "合计" ? "total-row" : "")">
                        <div class="div-table-cell cell-left-align" style="width: 11.11%;">@item.Name</div>

                        <!-- 收入笔数 -->
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@item.MorningCount</div>
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@item.EveningCount</div>
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@item.TotalCount</div>

                        <!-- 应收金额 -->
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatCurrency(item.MorningReceivable)</div>
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatCurrency(item.EveningReceivable)</div>
                        <div class="div-table-cell cell-right-align highlight-cell" style="width: 11.11%;">@FormatCurrency(item.TotalReceivable)</div>

                        <!-- 实收金额 -->
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatCurrency(item.MorningActual)</div>
                        <div class="div-table-cell cell-right-align" style="width: 11.11%;">@FormatCurrency(item.EveningActual)</div>
                        <div class="div-table-cell cell-right-align highlight-cell" style="width: 11.11%;">@FormatCurrency(item.TotalActual)</div>
                    </div>
                }
            </div>
        </div>
    </div>
</div>