<template>
  <Mask :width="798" :height="540" :is-show="isFlowingWater" @close="isFlowingWater = false" title="流水记录"
        :show-footer="true">
    <template #default>
      <div class="content">
        <div class="head">
          <img style="width: 60px;height: 60px"
               :src="'/static/images/member/' + (props.info.sex === 1 ? 'man' : 'women') + '.png'"
               alt="">
          <div class="right">
            <div class="name">
              {{ props.info.name }}
            </div>
            <div class="text">
              <div class="phone">
                {{ props.info.phone }}
              </div>
              <div class="grant-name">
                积分：
                <img style="width: 16px;height: 16px" src="/static/images/member/1.png" alt="">
                <span class="num">{{ props.info.integralBalance }}</span>
              </div>
            </div>
          </div>
        </div>
        <el-table class="body_list" :data="tableData"
                  style="border-radius: 8px;border: 1px solid #EAEAEC;border-bottom: none"
                  :header-cell-style="{ backgroundColor: '#F1F5FB'}">
          <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>
    </template>
    <template #footer>
      <div class="bottom">
        <el-pagination
            background
            layout="prev, pager, next"
            :page-size="20"
            :current-page="currentPage"
            :total="total"
            @current-change="changePage"
        />
      </div>
    </template>
  </Mask>
</template>
<script lang="ts" setup>
import {ref, defineEmits, defineProps, onMounted} from 'vue'
import {post} from "@/utils/request.ts";
import Mask from "@/components/common/Mask.vue";

const isFlowingWater = defineModel()
const props = defineProps({
  info: {
    type: Object,
    default: () => ({})
  },
  id: {
    type: String || Number,
    default: ""
  }
})
const currentPage = ref(1)
const tableData: any = ref<any>([])
const total = ref(0)
const emit = defineEmits(['close'])
const close = () => {
  emit('close')
}
onMounted(() => {
  if (!props.id) return
  init()
})
const changePage = (page: any) => {
  const query = {
    pageNum: page,
    pageSize: 20,
    vipId: props.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.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">
.content {
  padding-top: 24px;
  height: 100%;
  display: flex;
  flex-direction: column;

  .head {
    height: 60px;
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    padding: 0 24px;

    .name {
      font-weight: bold;
      font-size: 24px;
      color: #333333;
      line-height: 33px;
      text-align: left;
      font-style: normal;
    }

    .right {
      display: flex;
      flex-direction: column;
      justify-content: center;
      margin-left: 16px;

      .text {
        margin-top: 4px;
        display: flex;

        .phone {
          margin-right: 20px;
        }

        .grant-name {
          display: flex;

          .num {
            font-weight: bold;
            font-size: 24px;
            color: #4D6DE4;
            font-style: normal;
            line-height: 16px;
            margin-left: 6px;
          }
        }

      }
    }
  }

  .body_list {
    width: 100%;
    flex: 1;
    background: #F9FAFC;
    padding: 24px 24px 0;
  }
}

.bottom {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 24px;
}
</style>
