<!--
 * @Author: Fly
 * @Date: 2025-12-10 10:06:13
 * @LastEditTime: 2025-12-25 16:34:59
 * @Description: 
-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :size="ELsize" :inline="true" v-show="showSearch" label-width="auto">
      <el-form-item label="日期选择" prop="billDay">
        <el-date-picker v-model="queryParams.billDay" 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-button type="primary">导出</el-button> -->
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <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="getList"></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="日期" align="center" prop="cover">
        <template slot-scope="{ row }">
          {{ handleBillDay(row.billDay) | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="实际收款" align="center" prop="code">
        <template slot-scope="{ row }">
          {{ row.actualReceivePayment | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="实际到账" align="center" prop="skuSetName" show-overflow-tooltip>
        <template slot-scope="{ row }">
          {{ row.actualCredited | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="用户消耗积分" align="center" prop="salePrice">
        <template slot-scope="{ row }">
          {{ row.userUsePoint | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="店铺发放积分" align="center" prop="volume">
        <template slot-scope="{ row }">
          {{ row.businessGivePoint | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="在线订单数" align="center" prop="weight">
        <template slot-scope="{ row }">
          {{ row.onlineOrderNum | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="商城订单数" align="center" prop="weight">
        <template slot-scope="{ row }">
          {{ row.shopOrderNum | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="在线订单额" align="center" prop="weight">
        <template slot-scope="{ row }">
          {{ row.onlineOrderAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="商城订单额" align="center" prop="weight">
        <template slot-scope="{ row }">
          {{ row.shopOrderAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="商家让利" align="center" prop="weight">
        <template slot-scope="{ row }">
          {{ row.businessShouldSubsidy | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="预计今日结算" align="center" prop="weight">
        <template slot-scope="{ row }">
          {{ row.todaySettlement | 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";
import { getBusinessDayBillStatisticsShopApi, getBusinessDayBillPageShopApi } from "@/api/subsidyMode/businessDetails";
// import { productSkuSetStockPage } from "@/api/productInventory";
export default {
  mixins: [getListApi],
  data() {
    return {
      listURL: getBusinessDayBillPageShopApi,
      queryParams: {
        billDay: undefined
      },
      // 日期范围字段映射配置
      dateRangeMapping: {
        // 日期范围字段名: { start: 开始时间字段名, end: 结束时间字段名 }
        billDay: { start: 'startTime', end: 'endTime' }
      },
      StatisticsData: {},
      statisticsList: [
        {
          label: '实际收款额',
          field: 'actualReceivePayment'
        },
        {
          label: '在线订单额',
          field: 'onlineOrderAmount'
        },
        {
          label: '商城订单额',
          field: 'shopOrderAmount'
        },
        {
          label: '商家让利',
          field: 'businessShouldSubsidy'
        },
        {
          label: '累计结算',
          field: 'todaySettlement'
        }
      ]
    };
  },
  methods: {
    handleRefreshPage() {
      this.getStatistics();
      this.getList();
    },
    // 获取补贴队列业务统计
    async getStatistics() {
      try {
        // 处理日期范围参数
        const Params = this.processDateRangeParams({
          ...this.queryParams,
          ...this.search,
        });
        const { data } = await getBusinessDayBillStatisticsShopApi(Params);
        this.StatisticsData = data || {};
      } catch (error) {
        this.StatisticsData = {};
      }
    },
    handleBillDay(billDay) {
      if (!billDay) return '';
      return billDay.split(' ')[0];
    }
  },
};
</script>
<style scoped lang="scss"></style>
