<template>
  <div class="table-box">
    <ProTable ref="proTable" :columns="columns" :request-api="getTableList" :init-param="initParam" :data-callback="dataCallback">
      <!-- 表格操作 -->
      <template #operation="scope">
        <el-button type="primary" link @click="toDetail(scope.row)"> 查看详情 </el-button>
      </template>
    </ProTable>
    <el-dialog v-model="dialogVisible" title="详情" width="500px">
      <h3>火锅一人惨</h3>
      <el-row>
        <el-col :span="12"> 实际收益:+138.32 </el-col>
        <el-col :span="12"> 技术服务费(3%):-138.32 </el-col>
      </el-row>
      <el-row>
        <el-col :span="12"> 售价:+138.32 </el-col>
      </el-row>
      <h3>订单信息</h3>
      <div>
        <div>券码:</div>
        <div>下单时间:</div>
        <div>验券时间:</div>
        <div>入账时间:</div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup lang="tsx" name="voucherManagement">
import { onActivated, onMounted, reactive, ref } from "vue";
import ProTable from "@/components/ProTable/index.vue";
import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
import { getPaymentCycle } from "@/api/modules/homeEntry";
import { localGet } from "@/utils";
const dialogVisible = ref(true);
const toDetail = (row: any) => {
  dialogVisible.value = true;
};
// ProTable 实例（需要在使用它的地方之前定义）
const proTable = ref<ProTableInstance>();

// 表格配置项
const columns = reactive<ColumnProps<any>[]>([
  {
    prop: "name",
    label: "商品名称",
    search: {
      el: "input"
    }
  },
  {
    prop: "price",
    label: "券码",
    render: (scope: any) => {
      return scope.row.price ? `￥${scope.row.price}` : "--";
    }
  },
  {
    prop: "saleNum",
    label: "入账时间",
    render: scope => {
      return scope.row.saleNum === null || !scope.row.saleNum ? "--" : scope.row.saleNum;
    }
  },
  { prop: "operation", label: "操作", fixed: "right", width: 330 }
]);

// 如果表格需要初始化请求参数，直接定义传给 ProTable (之后每次请求都会自动带上该参数，此参数更改之后也会一直带上，改变此参数会自动刷新表格数据)
const initParam = reactive({
  storeId: localGet("createdId"),
  incomeType: 0,
  paymentType: 1,
  startTime: null,
  endTime: null
});
// 页面加载时触发查询
onMounted(async () => {
  proTable.value?.getTableList();
});

// 从其他页面返回时触发查询
onActivated(() => {
  proTable.value?.getTableList();
});

// dataCallback 是对于返回的表格数据做处理，如果你后台返回的数据不是 list && total 这些字段，可以在这里进行处理成这些字段
// 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
const dataCallback = (data: any) => {
  return {
    list: data.records,
    total: data.total
  };
};

// 如果你想在请求之前对当前请求参数做一些操作，可以自定义如下函数：params 为当前所有的请求参数（包括分页），最后返回请求列表接口
// 默认不做操作就直接在 ProTable 组件上绑定	:requestApi="getUserList"
const getTableList = (params: any) => {
  let newParams = JSON.parse(JSON.stringify(params));
  return getPaymentCycle(newParams);
};
</script>

<style lang="scss" scoped>
// 在组件样式中添加
.date-range {
  display: block; // 确保换行生效
  padding: 0 8px; // 可选：增加内边距
  word-wrap: break-word; // 长单词内换行
  white-space: normal; // 允许自然换行
}
.table-header-btn {
  .button {
    margin-bottom: 10px;
  }
  .tabs {
    :deep(.el-tabs__nav-wrap::after) {
      height: 0;
    }
  }
}
.reject-reason-content {
  padding: 20px 0;
  .reject-reason-item {
    display: flex;
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
    .reject-reason-label {
      flex-shrink: 0;
      min-width: 100px;
      font-size: 14px;
      font-weight: 500;
      color: #606266;
    }
    .reject-reason-value {
      flex: 1;
      font-size: 14px;
      color: #303133;
      word-break: break-word;
      &.reject-reason-text {
        min-height: 80px;
        padding: 12px;
        line-height: 1.6;
        white-space: pre-wrap;
        background-color: #f5f7fa;
        border-radius: 4px;
      }
    }
  }
}
</style>
