<template>
  <div class="container">
    <div class="body">
      <div class="body_info">
        <span class="name">{{props.info.realName}}</span>
        <span>{{props.info.sex}}</span>
        <span class="phone">{{props.info.phone}}</span>
        <span>积分<span class="num">{{props.info.integralBalance}}</span></span>
      </div>
      <div class="body_list">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="createTime" label="创建时间" width="180">
            <template #default="scope">
              {{formatDate(scope.row.createTime)}}
            </template>
          </el-table-column>
          <el-table-column prop="beforeIntegral" label="变化前"/>
          <el-table-column prop="changeIntegral" label="变化量"/>
          <el-table-column prop="afterIntegral" label="变化后"/>
          <el-table-column prop="remark" label="备注"/>
        </el-table>
      </div>
    </div>
    <div class="bottom">
      <el-pagination
          background
          layout="prev, pager, next"
          :page-size="20"
          :current-page="currentPage"
          :total="total"
          @current-change="changePage"
      />
    </div>
  </div>
</template>

<script lang="ts" setup>
import {ref,defineEmits, defineProps, onMounted} from 'vue'
import CloseBtn from "@/components/CloseBtn.vue";
import {post} from "@/utils/request.ts";
const props = defineProps({
  info: {
    type: Object,
    default: () => ({})
  }
})
const currentPage = ref(1)
const tableData:any = ref<any>([])
const total = ref(0)
const emit = defineEmits(['close'])
const close = () => {
  emit('close')
}
onMounted(()=>{
  init()
})
const changePage = (page:any) => {
  const query = {
    pageNum: page,
    pageSize: 20,
    vipId: props.info.id
  }
  post('vip/integral/list',{query:query}).then((res:any)=>{
    tableData.value.splice(0,tableData.length,...res.list)
  })
}
const init = () => {
  const query = {
    pageNum: 1,
    pageSize: 10,
    vipId: props.info.id
  }
  post('vip/integral/list',{query:query}).then((res:any)=>{
    tableData.value.splice(0,tableData.length,...res.list)
    total.value = res.total_count
  })
}
//修改时间格式化
const formatDate = (isoStr:any) => {
  const date = new Date(isoStr);
  return `${date.getFullYear()}-${(date.getMonth()+1).toString().padStart(2,'0')}-${date.getDate().toString().padStart(2,'0')}`;
}
</script>
<style scoped lang="scss">
.container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 0;
  .title {
    height: 60px;
    font-size: 20px;

  }
  .body {
    flex: 1;
    .body_info{
      height: 50px;
      display: flex;
      font-size: 14px;
      padding-left: 10px;
      align-items: center;
      color: #bac2ca;
      .name{
        font-size: 16px;
        margin-right: 10px;
        color: #121111;
      }
      .phone{
        height: 15px;
        margin: 0 17px;
        line-height: 16px;
      }
      .num{
        color: #df9b86;
        margin-left: 10px;
      }
    }
  }
  .bottom {
    position: absolute;
    bottom: 0;
    height: 60px;
    display: flex;
    align-items: center;
  }
}

</style>
