<!--
 * @Author: Fly
 * @Date: 2025-12-12 17:32:24
 * @LastEditTime: 2025-12-25 10:28:44
 * @Description: 平台账目明细
-->
<template>
    <div class="app-container">
        <el-form :model="queryParams" :size="ELsize" ref="queryForm" :inline="true" v-show="showSearch"
            label-width="auto">
            <el-form-item label="店铺名称" prop="businessName">
                <el-input v-model="queryParams.businessName" placeholder="请输入店铺名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="店铺ID" prop="queryBusinessId">
                <el-input v-model="queryParams.queryBusinessId" placeholder="请输入店铺ID"
                    @input="e => queryParams.queryBusinessId = $numberFilter(e)" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="日期选择" prop="time">
                <el-date-picker v-model="queryParams.time" value-format="yyyy-MM-dd" type="daterange"
                    range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery('queryForm')">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" :size="ELsize"
                    @click="handleExport">导出</el-button>
            </el-col>
            <div class="table-top-statistics">
                <template v-for="item in statisticsList">
                    <span :class="['table-top-type', ELsize]">
                        {{ item.label }}：<span class="table-top-num">{{ StatisticsData[item.field] || 0 }}</span>
                    </span>
                </template>
            </div>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="handleRefreshPage"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :border="TableBorder" :size="ELTableSize" :data="dataList">
            <el-table-column type="index" width="55" label="序号" align="center">
                <template slot-scope="{$index}">
                    {{ $getTableIndex(queryParams, $index + 1) }}
                </template>
            </el-table-column>
            <el-table-column label="店铺ID" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.businessId | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="店铺名称" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.businessName | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="日期" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.dayValue | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="实际收款" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.actualReceivePayment | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="实际到账" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.actualCredited | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="在线订单额" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.onlineOrderAmount | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="商城订单额" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.shopOrderAmount | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="商家让利" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.businessShouldSubsidy | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="商家预估结算" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.todaySettlement | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="平台服务费用" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.platformServiceFee | TableItemEmpty }}
                </template>
            </el-table-column>
            <el-table-column label="平台所得(含让利)" align="center" show-overflow-tooltip>
                <template slot-scope="{ row }">
                    {{ row.platformIncome | TableItemEmpty }}
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script>
import getListApi from '@/mixins/getListApi.js';
import { getBusinessDayBillPageApi, getBusinessDayBillStatisticsApi, getBusinessDayBillExportApi } from '@/api/financeManage.js';
export default {
    name: 'DetailedAccounts',
    mixins: [getListApi],
    data() {
        return {
            listURL: getBusinessDayBillPageApi,
            queryParams: {
                businessName: undefined,
                queryBusinessId: undefined,
                time: undefined
            },
            // 日期范围字段映射配置
            dateRangeMapping: {
                // 日期范围字段名: { start: 开始时间字段名, end: 结束时间字段名 }
                time: { start: 'startTime', end: 'endTime' }
            },
            StatisticsData: {},
            statisticsList: [
                {
                    label: '实际收款额',
                    field: 'actualReceivePayment'
                },
                {
                    label: '在线订单额',
                    field: 'onlineOrderAmount'
                },
                {
                    label: '商城订单额',
                    field: 'shopOrderAmount'
                },
                {
                    label: '商家让利',
                    field: 'businessShouldSubsidy'
                },
                {
                    label: '平台服务费',
                    field: 'platformServiceFee'
                },
                {
                    label: '平台所得',
                    field: 'platformIncome'
                }
            ],
            exportObj: {
                url: getBusinessDayBillExportApi,
                name: '账目明细'
            }
        };
    },
    methods: {
        handleRefreshPage() {
            this.getStatistics();
            this.getList();
        },
        // 获取补贴队列业务统计
        async getStatistics() {
            try {
                // 处理日期范围参数
                const Params = this.processDateRangeParams({
                    ...this.queryParams,
                    ...this.search,
                });
                const { data } = await getBusinessDayBillStatisticsApi({ type: 'all', ...Params });
                this.StatisticsData = data || {};
            } catch (error) {
                this.StatisticsData = {};
            }
        },
    },
};
</script>