<template>
  <!-- 修改前请注释以前的 -->
  <!-- 搜索 -->
  <div>
    <el-input style="width: 240px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入商户单号"
              v-model="outTradeNo" size="default"></el-input>
    <el-button class="ml-5" type="primary" @click="onSearch(outTradeNo)" size="default">搜索</el-button>

    <el-button type="warning" @click="reset" size="default">重置</el-button>
  </div>
  <div style="margin: 15px 0">

  </div>
  <!-- 数据展示 -->
  <el-table :data="tableData" border stripe header-cell-class-name="headerBg"
            :cell-style="{ 'text-align': 'center', 'font-size': '16px' }" @selection-change="handleSelectionChange"
            :header-cell-style="{ 'text-align': 'center' }">
    <el-table-column prop="id" label="退款编号" width="80">
      <template #default="{ $index }">
        {{ $index + 1 }}
      </template>
    </el-table-column>
    <el-table-column prop="outTradeNo" label="商户单号"></el-table-column>
    <el-table-column prop="outRefundNo" label="退款单号"></el-table-column>
    <el-table-column prop="refundAmount" label="退款金额" width="180">
      <template #default="scope">
        <div>
          {{ scope.row.refundAmount }} 元
        </div>
      </template>
    </el-table-column>
    <el-table-column prop="createTime" label="创建时间"></el-table-column>

  </el-table>
  <!-- 分页器 -->
  <div style="padding: 10px 0">
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                   :current-page="searchParams.current" :page-size="searchParams.pageSize" :page-sizes="[5, 10, 15, 20]"
                   :small="null" :disabled="null" :background="null" layout="total, sizes, prev, pager, next, jumper"
                   :total="total" />
  </div>
  <!-- 编辑/详情表单 -->

</template>

<script setup lang="ts">
import { ElMessage , type UploadProps , genFileId ,type UploadRawFile } from 'element-plus';
import { ref, onMounted, inject } from 'vue';
import myAxios from "@/api/myAxios";
import { handleChange, removePic, handleRemove,Exceed_ProductImg, ImgArr ,editForm} from '@/utils/entityProduct/picUpload';
const total = ref(0); //总页数
const outTradeNo = ref('');
const searchParams: any = ref({ //封装分页
  current: 1, //当前页码
  pageSize: 5, //每页显示条数
  sortField: "id",  //根据ID分类
  sortOrder: "descend", //降序
  outTradeNo: outTradeNo.value
})
//表单变量
const tableData : any= ref([]);  //实体类商品表格
const reload : any = inject("reload")  //页面重新刷新
onMounted(() => { //页面加载时获取商品列表和分类页表
  getProductList()
})
const getProductList = async () => {
  try {
    const res = await myAxios.post('/refund/list', { ...searchParams.value });
    console.log('res--->',res.data)
    if (res.data.code === 1) {
      tableData.value = res.data.data.records;
      total.value = parseInt(res.data.data.total)  //总数据量，用于分页
    } else {
      ElMessage({
        message: '获取数据失败',
      });
      return;
    }
  } catch (error) {
    ElMessage({
      message: '发生错误',
    });
  }
}


//详情或编辑

//处理行数大小变化
const handleSizeChange = (newSize: any) => {
  searchParams.value.pageSize = newSize //新的页面数
  getProductList()
}
//处理当前表格变化
const handleCurrentChange = (Current: any) => {
  searchParams.value.current = Current
  getProductList()
}
//重置按钮
const reset = () => {
  reload()
};

const onSearch = (data : String)=>{ //搜索按钮方法
  searchParams.value.outTradeNo = data
  searchParams.value.current = 1
  getProductList()
}

const handleSelectionChange =()=>{}
</script>

<style scoped>
.headerBg {
  background-color: #eee !important;
}
</style>