<!--
 * @Author: Fly
 * @Date: 2025-12-10 10:06:13
 * @LastEditTime: 2025-12-22 11:21:28
 * @Description: 
-->
<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="userMobile">
        <el-input v-model="queryParams.userMobile" placeholder="请输入会员账号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="会员昵称" prop="userNickname">
        <el-input v-model="queryParams.userNickname" placeholder="请输入会员昵称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="代理区域" prop="areaTreaList">
        <el-cascader v-model="queryParams.areaTreaList" :options="areaTreaList"
          :props="{ expandTrigger: 'hover', checkStrictly: true }" placeholder="请选择省市区县"></el-cascader>
      </el-form-item>

      <el-form-item label="代理层级" prop="agentLevel">
        <el-select v-model="queryParams.agentLevel" placeholder="请选择代理层级" clearable>
          <el-option v-for="item in AgentLevelOption" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="代理上级" prop="parentAgentPhone">
        <el-input v-model="queryParams.parentAgentPhone" placeholder="请输入代理手机号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>

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

      <el-form-item label="身份证号" prop="idCard">
        <el-input v-model="queryParams.idCard" 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', ELsize]">
          累计收益：<span class="table-top-num">{{ statisticsObj.totalStatisticsAmount || 0 }}</span>
        </span>
        <span :class="['table-top-type', ELsize]">
          累计结算：<span class="table-top-num">{{ statisticsObj.totalStatisticsWithdrawalAmount || 0 }}</span>
        </span>
      </div>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table :border="TableBorder" :size="ELTableSize" v-loading="loading" :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="userMobile">
        <template slot-scope="{row}">
          {{ row.userMobile | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="会员昵称" align="center" prop="userNickname" show-overflow-tooltip>
        <template slot-scope="{row}">
          {{ row.userNickname | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="真实姓名" align="center" prop="realName" show-overflow-tooltip>
        <template slot-scope="{row}">
          {{ row.realName | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="身份证号码" align="center" prop="idCard">
        <template slot-scope="{row}">
          {{ row.idCard | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="代理层级" align="center" prop="agentLevel">
        <template slot-scope="{row}">
          {{ row.agentLevel | AgentLevelOptionFilter | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="代理上级" align="center" prop="proxyUpper">
        <template slot-scope="{row}">
          {{ row.parentAgentName | TableItemEmpty }}
        </template>
      </el-table-column>

      <el-table-column label="代理区域" align="center" prop="applyArea">
        <template slot-scope="{ row }">
          {{ row.provinceName + (row.cityName || "") + (row.areaName || "") | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="剩余账户码" align="center" prop="surplusAccountCode">
        <template slot-scope="{row}">
          {{ row.surplusAccountCode | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="店铺数量" align="center" prop="promotionBusinessNum">
        <template slot-scope="{row}">
          {{ row.promotionBusinessNum | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="累计收益" align="center" prop="totalStatisticsAmount">
        <template slot-scope="{row}">
          {{ row.totalStatisticsAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="累计结算" align="center" prop="totalStatisticsWithdrawalAmount">
        <template slot-scope="{row}">
          {{ row.totalStatisticsWithdrawalAmount | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="入驻时间" align="center" prop="createTime" width="170">
        <template slot-scope="{row}">
          {{ row.createTime | TableItemEmpty }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="120" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- handleView(scope.row) -->
          <el-button :size="ELTableSize" type="text" @click="$refs.AgentInfoRef.openHandle(scope.row)">用户信息</el-button>
          <el-dropdown style="margin-left: 5px;">
            <el-button type="text" :size="ELTableSize">更多<i class="el-icon-arrow-down" /></el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="$refs.ProxyStoreRef.openHandle(scope.row)">代理店铺</el-dropdown-item>
              <el-dropdown-item @click.native="$refs.StoreCodeViewRef.openHandle(scope.row)">账户码明细</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 代理店铺 -->
    <ProxyStore ref="ProxyStoreRef" />
    <!-- 账户码明细 -->
    <StoreCodeView ref="StoreCodeViewRef" />
    <!-- 用户信息 -->
    <AgentInfo ref="AgentInfoRef" />

  </div>
</template>
<script>
import getListApi from "@/mixins/getListApi";
import {
  agentAmountStatistics,
  agentPage,
  agentInfo,
} from "@/api/agentManage/agentList";
import ProxyStore from "@/views/agentManage/components/proxyStore.vue";
import StoreCodeView from "@/views/agentManage/components/storeCodeView.vue";
import AgentInfo from "@/views/agentManage/components/AgentInfo.vue";
import { AgentLevelOption } from "@/utils/statusEnum";
export default {
  mixins: [getListApi],
  components: { ProxyStore, StoreCodeView, AgentInfo },
  data() {
    return {
      AgentLevelOption,
      listURL: agentPage,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userMobile: undefined,
        userNickname: undefined,
        areaTreaList: undefined,
        agentLevel: undefined,
        parentAgentPhone: undefined,
        realName: undefined,
        idCard: undefined,
      },
      // 导出配置
      exportObj: {
        url: "/agent/agent/export", // 导出接口地址
        name: "代理商列表", // 导出文件名前缀
      },
      statisticsObj: {},
    };
  },
  created() {
    this.getAgentAmountStatistics();
    this.getCnAreaTree();
  },
  methods: {
    getAgentAmountStatistics() {
      agentAmountStatistics(this.queryParams).then((res) => {
        if (res.code == 200) {
          // console.log(res.data);
          this.statisticsObj = res.data || {};
        }
      });
    },

    handleRefreshPage() {
      this.getAgentAmountStatistics();
      this.getList();
    },

    // handleCommand(e, row) {
    //   // console.log(e, row);
    //   let path =
    //     e == 1 ? "/agentManage/proxyStore" : "/agentManage/storeCodeView";
    //   this.$router.push({
    //     path,
    //     query: { agentId: row.agentId },
    //   });
    // },
  },
};
</script>
