<!--
 * @Author: Fly
 * @Date: 2025-12-10 10:06:13
 * @LastEditTime: 2025-12-22 15:57:39
 * @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="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable>
          <template v-for="item in OrderStatusOption">
            <el-option :label="item.label" :value="item.value" />
          </template>
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付方式" clearable>
          <template v-for="item in PayTypeOption">
            <el-option :label="item.label" :value="item.value" />
          </template>
        </el-select>
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNo">
        <el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="支付时间" prop="payTime">
        <el-date-picker v-model="queryParams.payTime" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="退款时间" prop="refundTime">
        <el-date-picker v-model="queryParams.refundTime" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <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="用户手机号" prop="userMobile">
        <el-input v-model="queryParams.userMobile" placeholder="请输入用户手机号" clearable @keyup.enter.native="handleQuery" />
      </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">
        <span :class="['table-top-type invariant-content', ELsize]">
          今日收款：<span class="table-top-num">{{ StatisticsData.todayAmount || 0 }}</span>
        </span>
        <span :class="['table-top-type ', ELsize]">
          补贴完成：<span class="table-top-num">{{ StatisticsData.subsidyComplete || 0 }}</span>
        </span>
        <span :class="['table-top-type', ELsize]">
          累计收款：<span class="table-top-num">{{ StatisticsData.totalAmount || 0 }}</span>
        </span>
        <span :class="['table-top-type', ELsize]">
          已退款：<span class="table-top-num">{{ StatisticsData.totalRefund || 0 }}</span>
        </span>
      </div>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="handleQuery"></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="businessName" show-overflow-tooltip>
        <template slot-scope="{ row }">
          {{ row.businessName | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="订单号" align="center" prop="orderNo" show-overflow-tooltip width="160">
        <template slot-scope="{ row }">
          {{ row.orderNo | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="payType" width="120" show-overflow-tooltip>
        <template slot-scope="{ row }">
          {{ row.payType | PayTypeFilter | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="用户手机号" align="center" show-overflow-tooltip prop="userMobile">
        <template slot-scope="{ row }">
          {{ row.userMobile | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="支付金额" align="center" show-overflow-tooltip prop="payAmount">
        <template slot-scope="{ row }">
          {{ row.payAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" show-overflow-tooltip prop="payTime">
        <template slot-scope="{ row }">
          {{ row.payTime | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="已补贴金额" align="center" show-overflow-tooltip prop="actualSubsidyAmount">
        <template slot-scope="{ row }">
          {{ row.actualSubsidyAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="退款时间" align="center" show-overflow-tooltip prop="refundTime">
        <template slot-scope="{ row }">
          {{ row.refundTime | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="已退金额" align="center" show-overflow-tooltip prop="refundAmount">
        <template slot-scope="{ row }">
          {{ row.refundAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" show-overflow-tooltip prop="orderStatus" width="100">
        <template slot-scope="{ row }">
          <!-- {{ row.orderStatus | OrderStatusFilter | TableItemEmpty }} -->
          <StatusTag :status-vo="row.orderStatus | OrderStatusFilter(true)" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="{row}">
          <el-button :size="ELTableSize" type="text" @click.stop="$refs.Particulars.open(row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <Particulars ref="Particulars" />

  </div>
</template>

<script>
import { getOnlineOrderStatisticsApi, getOnlineOrderPageApi, exportOnlineOrderApi } from '@/api/OnlineOrder.js';
import getListApi from '@/mixins/getListApi.js';
import Particulars from "./particulars.vue";
import { PayTypeOption, OrderStatusOption, } from "@/utils/statusEnum.js";
export default {
  mixins: [getListApi],
  components: { Particulars },
  data() {
    return {
      StatisticsData: {},
      listURL: getOnlineOrderPageApi,
      OrderStatusOption,
      PayTypeOption,
      queryForm: {
        orderStatus: undefined,
        payType: undefined,
        orderNo: undefined,
        payTime: undefined,
        businessName: undefined,
        userMobile: undefined
      },
      // 日期范围字段映射配置
      dateRangeMapping: {
        // 日期范围字段名: { start: 开始时间字段名, end: 结束时间字段名 }
        payTime: { start: 'payStartTime', end: 'payEndTime' },
        refundTime: { start: 'refundStartTime', end: 'refundEndTime' }
      },
      exportObj: {
        url: exportOnlineOrderApi,
        name: '平台在线订单列表'
      }
    }
  },

  methods: {
    // 刷新页面数据
    handleRefreshPage() {
      this.getOnlineOrderStatistics();
      this.getList();
    },

    async getOnlineOrderStatistics() {
      try {
        // 处理日期范围参数
        const Params = this.processDateRangeParams({
          ...this.queryParams,
          ...this.search,
        });
        const { data } = await getOnlineOrderStatisticsApi(Params);
        this.StatisticsData = data || {}
      } catch (error) {
        console.log('getOnlineOrderStatistics =  ', error);
        this.StatisticsData = {}
      }
    }
  }
}
</script>