<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import request from '@/util/http.js'
import dayjs from 'dayjs'
import { useI18n } from 'vue-i18n'
import { Moneyfunds, refundOnline, exportFunds } from '@/api/cash/financialAccount.js'
import { useAdminStore } from '@/store/index.js'
import { storeToRefs } from 'pinia'
import _ from 'lodash';

const adminStore = useAdminStore()
const { adminData } = storeToRefs(adminStore)

const { t } = useI18n()
const route = useRoute()

const paytypeList = [
  t('cash.payMethods.stripe'),
  t('cash.payMethods.paymentAsia'),
  t('cash.payMethods.ipay88'),
  t('cash.payMethods.bankTransfer'),
  t('cash.payMethods.card'),
  t('cash.payMethods.cash'),
  t('cash.payMethods.check'),
  t('cash.payMethods.grabpay'),
  t('cash.payMethods.nets'),
  t('cash.payMethods.transfer'),
  t('cash.payMethods.paypal'),
]

const payPlatformOptions = ref([...paytypeList])

const statusOptions = [
  { label: t('common_list.received'), value: 4 },
  { label: t('common_list.refunded'), value: 6 }
]

// 地区树
const marketOptions = ref([])

// 查询参数
const queryParams = reactive({
  jwcode: '',
  markets: [], // 下拉多选
  timeRange: [], // [startTime, endTime]
  payType: '',
  orderCode: '',
  statuses: [],
  pageNum: 1,
  pageSize: 20
})

const total = ref(0)
const tableData = ref([])
const loading = ref(false)

// 转换树形结构（参考 coinConsumeDetail.vue）
const transformTree = (nodes) => {
  const allChildren = nodes.flatMap(node => node.children || []);
  return allChildren.map(child => {
    const grandchildren = child.children && child.children.length
      ? transformTree([child])
      : null;
    return {
      value: child.id,
      label: child.name,
      children: grandchildren
    };
  });
};

// 获取地区数据
const getMarket = async () => {
  try {
    const result = await request({ url: '/market/selectMarket' });
    if (result && result.data) {
      marketOptions.value = transformTree(result.data)
    }
  } catch (error) {
    console.error('获取地区失败', error)
  }
}

// 查询列表
const fetchData = async () => {
  loading.value = true
  try {
    // 构建请求参数
    const params = {
      pageNum: queryParams.pageNum,
      pageSize: queryParams.pageSize,
      fundsDTO: {
        jwcode: queryParams.jwcode,
        localMarket:queryParams.markets,
        startTime: queryParams.timeRange?.[0] ? dayjs(queryParams.timeRange[0]).format('YYYY-MM-DD HH:mm:ss') : '',
        endTime: queryParams.timeRange?.[1] ? dayjs(queryParams.timeRange[1]).format('YYYY-MM-DD HH:mm:ss') : '',
        payType: queryParams.payType,
        orderCode: queryParams.orderCode,
        statuses: queryParams.statuses,
      }
    }

    console.log('查询参数:', params)
    const res = await Moneyfunds(params)
    if (res.code == 200) {
      tableData.value = res.data.list || []
      total.value = res.data.total || 0
      loading.value = false
    } else {
      ElMessage.error(res.msg || t('elmessage.getDataFailed'))
      loading.value = false
    }
  } catch (error) {
    console.error(error)
    loading.value = false
    ElMessage.error(t('elmessage.getDataFailed'))
  }
}

const handleSearch = () => {
  queryParams.pageNum = 1
  fetchData()
}

const handleReset = () => {
  queryParams.jwcode = ''
  queryParams.markets = []
  queryParams.timeRange = null
  queryParams.payType = ''
  queryParams.orderCode = ''
  queryParams.statuses = []
  handleSearch()
}

const handlePageSizeChange = (val) => {
  queryParams.pageSize = val
  fetchData()
}

const handleCurrentChange = (val) => {
  queryParams.pageNum = val
  fetchData()
}

// 退款操作
const openRefundConfirm = (row) => {
  textContent.value = t('common.willRefundOrder') + '?'
  refundConfirmDialog.value = true
  refundFormData.value = {
    ...row,
    oldpermanentGold: row.permanentGold,//退款永久金币
    oldfreeGold: row.freeGold,//退款免费金币
    permanentGold: null,
    freeGold: null,
  }
  console.log(row);
}
const openRefundDialog = () => {
  refundDialog.value = true
  closeConfirmRefund()

}

const closeConfirmRefund = () => {
  refundConfirmDialog.value = false
  textContent.value = ''
}
const refundConfirmDialog = ref(false)
const textContent = ref('')
const refundDialog = ref(false)
const refundFormData = ref({})


const resetRefund = () => {
    refundFormData.value.refundModel = ''
    refundFormData.value.refundReason = ''
    refundFormData.value.permanentGold = null
    refundFormData.value.freeGold = null

}
const handleRefund = async () => {
  try {
    if (refundFormData.value.refundModel == 1) {
      refundFormData.value.permanentGold = refundFormData.value.oldpermanentGold
      refundFormData.value.freeGold = refundFormData.value.oldfreeGold
    }
    let params = {
      jwcode: refundFormData.value.jwcode,
      name: refundFormData.value.name,
      market: refundFormData.value.marketName,
      submitterMarket: adminData.value.markets,
      remark: refundFormData.value.remark,
      originalOrderId: refundFormData.value.id,
      refundReason: refundFormData.value.refundReason,
      refundModel: refundFormData.value.refundModel,
      orderCode: refundFormData.value.orderCode,
      submitterId: adminData.value.id,
      submitterMarket: adminData.value.markets,
      permanentGold: (refundFormData.value.permanentGold) * 100 || 0,
      handlingCharge: refundFormData.value.handlingCharge == null ? null : refundFormData.value.handlingCharge * 100,
      freeGold: (refundFormData.value.freeGold) * 100 || 0,
    }
    console.log('这是退款参数：', params);

    const res = await refundOnline(params)
    if (res.code == 200) {
      refundDialog.value = false
      fetchData()
    } else {
      ElMessage.error(res.msg || '退款失败')
    }
  } catch (error) {
    console.error(error)
  }
}

// ==================== 导出相关逻辑 ====================

const exportListVisible = ref(false)
const exportList = ref([])
const exportListLoading = ref(false)

// 导出Excel
const handleExport = async () => {
  try {
    const params = {
      pageNum: queryParams.pageNum,
      pageSize: queryParams.pageSize,
      fundsDTO: {
        jwcode: queryParams.jwcode,
        markets: queryParams.markets,
        startTime: queryParams.timeRange?.[0] ? dayjs(queryParams.timeRange[0]).format('YYYY-MM-DD HH:mm:ss') : '',
        endTime: queryParams.timeRange?.[1] ? dayjs(queryParams.timeRange[1]).format('YYYY-MM-DD HH:mm:ss') : '',
        payType: queryParams.payType,
        orderCode: queryParams.orderCode,
        statuses: queryParams.statuses,
      }
    }

    // TODO: 确认导出接口 URL
    const res = await exportFunds( params )
    if (res.code == 200) {

      console.log('导出参数', params)
      ElMessage.success(t('elmessage.exportSuccess'))
    }

  } catch (error) {
    console.error(error)
    ElMessage.error(t('elmessage.exportError'))
  }
}

// 打开导出列表弹窗
const openExportList = () => {
  getExportList()
  exportListVisible.value = true
}

// 获取导出列表
const getExportList = async () => {
  exportListLoading.value = true
  try {
    const result = await request({ url: '/export/export' })
    if (result.code === 200) {
      const filteredData = result.data.filter(item => item.type == 15);
      exportList.value = filteredData || []
    } else {
      ElMessage.error(result.msg || t('elmessage.getExportListError'))
    }
  } catch (error) {
    console.error('获取导出列表出错:', error)
    ElMessage.error(t('elmessage.getExportListError'))
  } finally {
    exportListLoading.value = false
  }
}

// 下载导出文件
const downloadExportFile = (item) => {
  if (item.state === 2) {
    const link = document.createElement('a')
    link.href = item.url
    link.download = item.fileName
    link.click()
  } else {
    ElMessage.warning(t('elmessage.exportingInProgress'))
  }
}

// 根据状态返回对应的标签类型
const getTagType = (state) => {
  switch (state) {
    case 0: return 'info';
    case 1: return 'primary';
    case 2: return 'success';
    case 3: return 'danger';
    default: return 'info';
  }
}

// 根据状态返回对应的标签文案
const getTagText = (state) => {
  switch (state) {
    case 0: return t('elmessage.pendingExecution');
    case 1: return t('elmessage.executing');
    case 2: return t('elmessage.executed');
    case 3: return t('elmessage.errorExecution');
    default: return t('elmessage.unknownStatus');
  }
}
const throttledsubmitRefund = _.throttle(handleRefund, 5000, {
  trailing: false
})
// 递归查找地区ID
// normalizeMarketLabel 标准化地区名称，用于对比匹配
const normalizeMarketLabel = (value) => {
  return String(value ?? '')
    .trim()
    .toLowerCase()
    .replace(/[\s_-]+/g, '')
}
// 传入的这两个参数对比，是否有匹配的地区ID
const findValueByLabel = (options, label) => {
  // option和label都调用normalizeMarketLabel函数
  const normalizedLabel = normalizeMarketLabel(label)
  for (const option of options) {
    if (normalizeMarketLabel(option.label) === normalizedLabel) {
      return option.value
    }
    if (option.children && option.children.length) {
      const found = findValueByLabel(option.children, label)
      if (found) return found
    }
  }
  return null
}

onMounted(async () => {
  await getMarket()
  
  // 处理从工作台跳转过来的地区参数
  // 如果出现URL中的?region=a&region=b 这种重复key，router会解析为['a','b'], 取第一个地区ID
  const regionName = Array.isArray(route.query.region) ? route.query.region[0] : route.query.region
  if (regionName && marketOptions.value.length) {
    const matchedId = findValueByLabel(marketOptions.value, regionName)
    if (matchedId) {
      // el-cascader 绑定的 markets 是数组
      queryParams.markets = [matchedId]
    }
  }
  
  fetchData()
})
</script>

<template>
  <div class="cash-flow-container">
    <!-- 搜索区域 -->
    <el-card class="search-card">
      <div class="search-bar">
        <!-- 第一行 -->
        <div class="search-row">
          <div class="search-item">
            <span class="label">{{ t('common.jwcode') }}：</span>
            <el-input v-model="queryParams.jwcode" :placeholder="t('common.jwcodePlaceholder')" clearable />
          </div>
          <div class="search-item">
            <span class="label">{{ t('common.market') }}：</span>
            <!-- 下拉多选，使用 el-cascader 匹配地区树结构 -->
            <el-cascader
              v-model="queryParams.markets"
              :options="marketOptions"
              :props="{ multiple: true, emitPath: false }"
              collapse-tags
              collapse-tags-tooltip
              :placeholder="t('common.marketPlaceholder')"
              clearable
              style="width: 220px;"
            />
          </div>
          <div class="search-item">
            <span class="label">{{ t('common.payPlatform1') }}：</span>
            <el-select v-model="queryParams.payType" :placeholder="t('common.payPlatformPlaceholder1')" clearable>
              <el-option v-for="item in payPlatformOptions" :key="item" :label="item" :value="item" />
            </el-select>
          </div>
          <div class="search-item">
            <span class="label">{{ t('common.status') }}：</span>
            <el-select v-model="queryParams.statuses[0]" :placeholder="t('common.statusPlaceholder')" clearable>
              <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </div>
             <div class="search-item">
              <span class="label">{{ t('common.orderNo') }}：</span>
              <el-input v-model="queryParams.orderCode" :placeholder="t('common.orderNoPlaceholder')" clearable />
            </div>  

             <div class="search-item" style="width: auto;">
            <span class="label">{{ t('common.payTime2') }}：</span>
            <el-date-picker
              v-model="queryParams.timeRange"
              type="datetimerange"
              :range-separator="t('common.to')"
              :start-placeholder="t('common.startTime')"
              :end-placeholder="t('common.endTime')"
              :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
              style="width: 350px;"
            />
          </div>
          <div class="search-btn-group">
            <el-button type="primary" @click="handleSearch">{{ t('common.search') }}</el-button>
            <el-button type="primary" @click="handleExport">{{ t('common.exportExcel') }}</el-button>
            <el-button type="primary" @click="openExportList">{{ t('common.viewExportList') }}</el-button>
            <el-button type="success" @click="handleReset">{{ t('common.reset') }}</el-button>
          </div>
        </div>
      </div>

    </el-card>

    <!-- 表格区域 -->
    <el-card class="table-card">
      <el-table :data="tableData" v-loading="loading" style="width: 100%; flex: 1;" :cell-style="{ textAlign: 'center' }"  :header-cell-style="{ background: '#F3FAFE', color: '#333',textAlign: 'center' }">
        <el-table-column type="index" :label="t('common_list.id')" width="60" align="center" fixed="left" />
        <el-table-column prop="jwcode" :label="t('common_list.jwcode')" width="120" fixed="left" />
        <el-table-column prop="name" :label="t('common_list.name')" width="150" show-overflow-tooltip />
        <el-table-column prop="marketName" :label="t('common_list.market')" width="120" show-overflow-tooltip />
        <el-table-column prop="orderCode" :label="t('common_list.orderCode')" width="280" show-overflow-tooltip />
        
        <el-table-column prop="paymentAmount" :label="t('common_list.payAmount')" width="150" align="right">
          <!-- <template #default="{ row }">
            {{ row.paymentAmount }} {{ row.paymentCurrency }}
          </template> -->
        </el-table-column>
        <el-table-column prop="paymentCurrencyName" :label="t('common_list.payCurrency')" width="120" show-overflow-tooltip />

        <el-table-column prop="receivedAmount" :label="t('common_list.receiveAmount')" width="150" align="right">
          <!-- <template #default="{ row }">
            {{ row.receivedAmount }} {{ row.receivedCurrency }}
          </template> -->
        </el-table-column>
        <el-table-column prop="receivedCurrencyName" :label="t('common_list.receiveCurrency')" width="120" show-overflow-tooltip />

        <el-table-column prop="handlingCharge" :label="t('common_list.fee')" width="100" align="right" />
        <el-table-column prop="payType" :label="t('common_list.payModel')" width="120" align="center" />
        <el-table-column prop="payTime" :label="t('common_list.payTime2')" width="180" align="center" />

        <el-table-column prop="status" :label="t('common_list.status')" width="120" align="center" fixed="right">
          <template #default="{ row }">
            <div style="display: flex;  align-items: center;">
            <el-tag :type="row.status === 4 ? 'success' : 'warning'" effect="plain">
              {{ row.status === 4 ? t('common_list.received') : t('common_list.refunded') }}
            </el-tag>
            <el-popover
              trigger="hover"
              placement="top"
              popper-class="refund-popover"
              width="auto"
              v-if="row.status === 6"
            >
              <div class="popover-content">
                <div class="popover-title">{{ t('common_list.refundDetail') }}</div>
                <div class="popover-item">
                  <span class="label">{{ t('common_list.refundAmount') }}：</span>
                  <span class="value">{{ row.refundAmount || '-' }}</span>
                </div>
                <div class="popover-item">
                  <span class="label">{{ t('common_list.refundCurrency') }}：</span>
                  <span class="value">{{ row.refundCurrency || '-' }}</span>
                </div>
              </div>
        <template #reference>
          <img 
            @click.stop      
            src="@/assets/SvgIcons/consume.svg" 
            style="width: 15px; height: 15px; margin-left: 5px; cursor: pointer; display: inline-block;"
          >
        </template>
      </el-popover>
      </div>
          </template>
        </el-table-column>

        <el-table-column :label="t('common_list.operation')" width="100" fixed="right" align="center">
          <template #default="{ row }">
            <el-button v-if="row.orderCode.slice(0, 4) == 'GOLD' && row.status === 4" type="danger" link size="small"
              @click="openRefundConfirm(row)">
              {{ t('common_list.refund') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination-container">
        <el-pagination background layout="total, sizes, prev, pager, next, jumper" :total="total"
          :current-page="queryParams.pageNum" :page-size="queryParams.pageSize" :page-sizes="[10, 20, 50, 100]"
          @size-change="handlePageSizeChange" @current-change="handleCurrentChange" />
      </div>
    </el-card>

    <!-- 导出列表弹窗 -->
    <el-dialog v-model="exportListVisible" :title="t('common_export.exportList')" width="80%">
      <el-table :data="exportList" style="width: 100% ;height: 60vh;" :loading="exportListLoading">
        <el-table-column prop="fileName" :label="t('common_export.fileName')" />
        <el-table-column prop="state" :label="t('common_export.status')">
          <template #default="scope">
            <el-tag :type="getTagType(scope.row.state)" :effect="scope.row.state === 3 ? 'light' : 'plain'">
              {{ getTagText(scope.row.state) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" :label="t('common_export.createTime')">
          <template #default="scope">
            {{ dayjs(scope.row.createTime).format('YYYY-MM-DD HH:mm:ss') }}
          </template>
        </el-table-column>
        <el-table-column :label="t('common_export.operation')">
          <template #default="scope">
            <el-button type="primary" size="small" @click="downloadExportFile(scope.row)"
              :disabled="scope.row.state !== 2">
              {{ t('common_export.download') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
        <div class="dialog-footer">
          <el-button text @click="exportListVisible = false">{{ t('common_export.close') }}</el-button>
        </div>
      </template>
    </el-dialog>

    <div class="recallDialog" v-show="refundConfirmDialog">
      <div class="close">
        <button @click="closeConfirmRefund" class="Btn">{{ t('common.close') }}</button>
      </div>
      <div class="text">
        <text class="txt">{{ textContent }}</text>
      </div>
      <div class="cancle">
        <button @click="closeConfirmRefund" class="Btn">{{ t('common.cancel') }}</button>
      </div>
      <div class="confirm">
        <button @click="openRefundDialog" class="Btn">{{ t('common.confirm') }}</button>
      </div>
    </div>

    <el-dialog v-model="refundDialog" :title="t('common_add.refund')" class="refundDialog" overflow draggable
      style="width: 40vw;" :before-close="closeRefundForm">
      <div style="display: flex;">
        <div class="left">
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.jwcode') }}</el-text>
            <el-input v-model="refundFormData.jwcode" style="width:10vw;" disabled />
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.customerName') }}</el-text>
            <el-input v-model="refundFormData.name" style="width:10vw;" disabled />
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.market') }}</el-text>
            <el-input v-model="refundFormData.marketName" style="width:10vw;" disabled />
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.activity') }}</el-text>
            <el-input v-model="refundFormData.activity" style="width:10vw;" disabled />
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.productName') }}</el-text>
            <el-input v-model="refundFormData.goodsName" style="width:10vw;" disabled />
          </div>
          <div style="display: flex; margin-bottom: 10px;">
            <div style=" display: flex; align-items: center;justify-content: center; ">
              <span style="color: #999999;  white-space: nowrap;">{{ t('common_add.permanentGold')
              }}：</span>
              <el-input style="padding-right: 10px;  height: 30px; width: 70px;"
                v-model="refundFormData.oldpermanentGold" disabled />
            </div>
            <div style=" display: flex; align-items: center;justify-content: center; ">
              <span style="color: #999999;  white-space: nowrap;">{{ t('common_add.freeGold') }}：</span>
              <el-input style="padding-right: 10px;  height: 30px; width: 70px;" v-model="refundFormData.oldfreeGold"
                disabled />
            </div>
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.payCurrency') }}</el-text>
            <el-input v-model="refundFormData.paymentCurrency" style="width:10vw;" disabled />
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.payAmount') }}</el-text>
            <el-input v-model="refundFormData.paymentAmount" style="width:10vw;" disabled />
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.payMethod') }}</el-text>
            <el-input v-model="refundFormData.payType" style="width:10vw;" disabled />
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.payTime') }}</el-text>
            <el-date-picker v-model="refundFormData.payTime" type="datetime" style="width:10vw;" disabled />
          </div>
          <div class="add-item">
            <el-text style="width:4vw;" size="small">{{ t('common_add.transferVoucher') }}</el-text>
            <el-form-item :rules="{ required: true, message: t('common_add.uploadPhoto'), trigger: 'change' }">
              <el-upload ref="uploadRef" :auto-upload="false" list-type="picture-card" :show-file-list="false">
                <template #default>
                  <img v-if="refundFormData.voucher" :src="refundFormData.voucher"
                    style="width: 100%; height: 100%; object-fit: cover;">
                  <el-icon v-else>
                    <Plus />
                  </el-icon>
                </template>
              </el-upload>
            </el-form-item>
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.remark') }}</el-text>
            <el-input v-model="refundFormData.remark" style="width:10vw;" :rows="2" type="textarea" maxLength="100"
              disabled show-word-limit />
          </div>
        </div>
        <div class="right">
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.refundModel') }}</el-text>
            <el-radio-group v-model="refundFormData.refundModel">
              <el-radio value="0">{{ t('common_add.refundModelAll') }}</el-radio>
              <el-radio value="1">{{ t('common_add.refundModelPart') }}</el-radio>
            </el-radio-group>
          </div>
          <div v-show="refundFormData.refundModel == '1'" style="display: flex; margin-bottom: 10px;">
            <div style=" display: flex; align-items: center;justify-content: center; ">
              <span style="color: #999999;  white-space: nowrap;">{{ t('common_add.permanentGold')
              }}：</span>
              <el-input style="padding-right: 10px;  height: 30px; width: 70px;"
                v-model="refundFormData.permanentGold" />
            </div>
            <div style=" display: flex; align-items: center;justify-content: center; ">
              <span style="color: #999999;  white-space: nowrap;">{{ t('common_add.freeGold') }}：</span>
              <el-input style="padding-right: 10px;  height: 30px; width: 70px;" v-model="refundFormData.freeGold" />
            </div>
          </div>
          <div class="add-item">
            <el-text style="width:4vw;">{{ t('common_add.refundReason') }}</el-text>
            <el-input v-model="refundFormData.refundReason" style="width:10vw;" :rows="5" maxlength="150"
              show-word-limit type="textarea" />
          </div>
          <div>{{ t('common_add.tip') }}</div>
          <div style="display:flex;justify-content: center;margin-top: 5vh;">
            <el-button type="default" @click="resetRefund">{{ t('common.reset') }}</el-button>
            <el-button type="primary" @click="throttledsubmitRefund">{{ t('common.submit') }}</el-button>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>



<style lang="scss">
.refund-popover {
  background-color: #EEF5FE !important;
  border: none !important;
  padding: 12px !important;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  width: 100px;
  min-width: none;
  .el-popper__arrow::before {
    background-color: #EEF5FE !important;
    border-color: #EEF5FE !important;
  }
}
</style>
<style scoped lang="scss">

  .popover-content {
  .popover-title {
    color: #409EFF;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 8px;
  }
  .popover-item {
    display: flex;
    font-size: 13px;
    color: #606266;
    margin-bottom: 4px;
    
    &:last-child {
      margin-bottom: 0;
    }
    .label {
      color: #606266;
    }
    .value {
      color: #606266;
      margin-left: 4px;
    }
  }
}
.cash-flow-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.search-card {
  margin-bottom: 10px;
  background: #F3FAFE; // 浅蓝背景
  border: none;

  :deep(.el-card__body) {
    padding: 15px;
  }
}

.search-bar {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
}

.search-item {
  display: flex;
  align-items: center;

  .label {
    font-size: 15px; // 参考 coinConsumeDetail 的 .text size="large"
    color: #000; // 或 #606266
    white-space: nowrap;
    margin-right: 8px;
    min-width: 60px;
    text-align: right;
  }

  .el-input,
  .el-select {
    width: 200px;
  }
}

.search-btn-group {
  margin-left: 20px; // 靠右对齐
  display: flex;
  gap: 10px;
}

.table-card {
  background: #E7F4FD;
  flex: 1;
  border: none;
  display: flex;
  flex-direction: column;

  :deep(.el-card__body) {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
}

.pagination-container {
  margin-top: 15px;
  display: flex;
  justify-content: flex-start;
}

// 表格样式覆盖 (参考 coinConsumeDetail)
:deep(.el-table__header-wrapper),
:deep(.el-table__body-wrapper),
:deep(.el-table__cell),
:deep(.el-table__body td) {
  background-color: #F3FAFE !important;
}

:deep(.el-table__row:hover > .el-table__cell) {
  background-color: #E5EBFE !important;
}

.refundDialog {
  .left {
    width: 50%;
    height: 70vh;
    min-height: 700px;
    padding: 0 2vw;

    .add-item {
      display: flex;
      align-items: center;
      margin-bottom: 1vh;
    }

    .image {
      width: 4vw !important;
      height: 4vw !important;
    }
  }

  .right {
    width: 50%;
    height: 50vh;

    .add-item {
      display: flex;
      align-items: center;
      margin-bottom: 1vh;
    }
  }
}

.recallDialog {
  //撤回弹窗提示
  height: 392px;
  width: 700px;
  background-image: url('/src/assets/receive-recall.png');
  position: fixed; // 固定定位，相对于浏览器窗口
  top: 50%; // 距离顶部50%
  left: 50%; // 距离左侧50%
  transform: translate(-50%, -50%); // 向左、向上平移自身宽高的50%，实现居中
  z-index: 1000; // 确保在其他元素上层显示

  .close {
    position: absolute;
    left: 625px;
    top: 20px;
    height: 38px;
    width: 38px;
    opacity: 0;

    .Btn {
      height: 100%;
      width: 100%;
      border-radius: 10px;
    }
  }

  .text {
    position: absolute;
    left: 185px;
    top: 190px;
    height: 67px;
    width: 500px;

    .txt {
      height: 100%;
      width: 100%;
      color: #001a42;
      font-family: "PingFang SC";
      font-size: 38px;
      font-style: normal;
      font-weight: 900;
      line-height: normal;
    }
  }

  .cancle {
    position: absolute;
    left: 185px;
    top: 304px;
    height: 55px;
    width: 150px;
    opacity: 0;

    .Btn {
      height: 100%;
      width: 100%;
      border-radius: 20px;
    }
  }

  .confirm {
    position: absolute;
    left: 375px;
    top: 304px;
    height: 55px;
    width: 150px;
    opacity: 0;

    .Btn {
      height: 100%;
      width: 100%;
      border-radius: 20px;
    }
  }
}
</style>
