<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" :size="ELsize" label-width="auto">
      <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="userMobile">
        <el-input v-model="queryParams.userMobile" placeholder="请输入用户手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="用户姓名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入用户姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="排队状态" prop="subsidyStatus">
        <el-select v-model="queryParams.subsidyStatus" placeholder="请选择排队状态" clearable>
          <template v-for="item in SubsidyStatusOption">
            <el-option :label="item.label" :value="item.value" />
          </template>
        </el-select>
      </el-form-item>

      <el-form-item label="消费时间" prop="consumeTime">
        <el-date-picker v-model="queryParams.consumeTime" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>

      <el-form-item label="排队时间" prop="queueTime">
        <el-date-picker v-model="queryParams.queueTime" 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">
        <span :class="['table-top-type invariant-content', ELsize]">
          今日补贴：<span class="table-top-num">{{ StatisticsData.todaySubsidy || 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.waitSubsidy || 0 }}</span>
        </span>
        <span :class="['table-top-type', ELsize]">
          已补贴积分：<span class="table-top-num">{{ StatisticsData.subsidyIntegral || 0 }}</span>
        </span>
      </div>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="handleRefreshPage" />
    </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">
        <template slot-scope="{ row }">
          {{ row.orderNo | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="当前队序" align="center" prop="code">
        <template slot-scope="{ row }">
          {{ (SubsidyStatusEnum.QUENING === row.subsidyStatus ? row.queueOrder : '') | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="订单金额" align="center" prop="skuSetName" show-overflow-tooltip>
        <template slot-scope="{ row }">
          {{ row.payAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="最多补贴金额" align="center" prop="salePrice">
        <template slot-scope="{ row }">
          {{ row.shouldSubsidyAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="已补贴金额" align="center" prop="volume">
        <template slot-scope="{ row }">
          {{ row.actualSubsidyAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="已补贴积分" align="center" prop="weight">
        <template slot-scope="{ row }">
          {{ row.subsidyPoints | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="用户手机号" align="center" prop="stock">
        <template slot-scope="{ row }">
          {{ row.userMobile | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="用户姓名" align="center" prop="weight">
        <template slot-scope="{ row }">
          {{ row.userName | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="消费时间" align="center" prop="stock">
        <template slot-scope="{ row }">
          {{ row.consumeTime | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="排队时间" align="center" prop="weight">
        <template slot-scope="{ row }">
          {{ row.queueTime | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="排队状态" align="center" prop="stock">
        <template slot-scope="{ row }">
           <StatusTag :status-vo="row.subsidyStatus | SubsidyStatusOptionFilter(true)" />
          <!-- {{ isCancelQueue(row) ? '不参与' : row.subsidyStatus | SubsidyStatusOptionFilter | TableItemEmpty }} -->
          <!-- <template v-if="isCancelQueue(row)">
            <StatusTag :status-vo="{ label: '不参与', type: 'info' }" />
          </template>
          <template v-else>
            <StatusTag :status-vo="row.subsidyStatus | SubsidyStatusOptionFilter(true)" />
          </template> -->
        </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 { getSubsidyQueueBusinessStatisticsApi, getSubsidyQueueBusinessPageApi, exportBusinessSubsidyQueuerApi } from "@/api/OnlineOrder";
import getListApi from "@/mixins/getListApi";
import { SubsidyStatusOption } from '@/utils/statusEnum.js';
import { isCancelQueue } from '@/utils/estimate.js';
import { SubsidyStatusEnum } from '@/utils/statusEnum.js';
export default {
  mixins: [getListApi],
  data() {
    return {
      SubsidyStatusEnum,
      isCancelQueue,
      SubsidyStatusOption,
      listURL: getSubsidyQueueBusinessPageApi,
      queryParams: {
        orderNo: undefined,
        userMobile: undefined,
        userName: undefined,
        subsidyStatus: undefined,
        consumeTime: undefined,
        queueTime: undefined
      },

      // 日期范围字段映射配置
      dateRangeMapping: {
        // 日期范围字段名: { start: 开始时间字段名, end: 结束时间字段名 }
        consumeTime: { start: 'consumeStartTime', end: 'consumeEndTime' },
        queueTime: { start: 'queueStartTime', end: 'queueEndTime' }
      },
      StatisticsData: {},

      exportObj: {
        url: exportBusinessSubsidyQueuerApi,
        name: '补贴队列业务列表'
      }
    };
  },
  methods: {
    handleRefreshPage() {
      this.getStatistics();
      this.getList();
    },
    // 获取补贴队列业务统计
    async getStatistics() {
      try {
        // 处理日期范围参数
        const Params = this.processDateRangeParams({
          ...this.queryParams,
          ...this.search,
        });
        const { data } = await getSubsidyQueueBusinessStatisticsApi(Params);
        this.StatisticsData = data || {};
      } catch (error) {
        this.StatisticsData = {};
      }
    },
  },
};
</script>
<style scoped lang="scss">
.tab-pane {
  display: flex;
  flex-wrap: wrap;

  .tab-flex-row {
    display: flex;
    align-items: center;
    margin-right: 30px;

    .value {
      color: #ffb017;
    }
  }
}
</style>
