<template>
  <Mask :width="798" :height="540" :is-show="isFlowingWater" @close="close" title="流水记录"
        :show-footer="true">
    <template #default>
      <div class="content-flowing">
        <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>
       <div class="body_list">
         <el-table :data="tableData" style="height: 100%"
                   :header-cell-style="{ backgroundColor: '#F1F5FB'}">
           <el-table-column prop="createTime" label="创建时间" show-overflow-tooltip>
             <template #default="scope">
               {{ formatDate(scope.row.createTime) }}
             </template>
           </el-table-column>
           <el-table-column prop="beforeIntegral" label="变化前" show-overflow-tooltip/>
           <el-table-column prop="changeIntegral" label="变化量" show-overflow-tooltip/>
           <el-table-column prop="afterIntegral" label="变化后" show-overflow-tooltip/>
           <el-table-column prop="remark" label="备注" show-overflow-tooltip/>
         </el-table>
       </div>
      </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";
import {API} from "@/assets/config/API.ts";

const isFlowingWater = defineModel()
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 = () => {
  isFlowingWater.value = false
  id.value = ""
  emit('close')
}
const changePage = (page: any) => {
  const query = {
    pageNum: page,
    pageSize: 20,
    vipId: id.value
  }
  post(API.Patient.Integral.List, {query: query}).then((res: any) => {
    tableData.value.splice(0, tableData.length, ...res.list)
  })
}
const id = ref('')
const init = (id: any) => {
  if (!id) return
  const query = {
    pageNum: 1,
    pageSize: 10,
    vipId: id
  }
  post(API.Patient.Base.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')}`;
}
defineExpose({init})
</script>
<style scoped lang="scss">
.content-flowing {
  padding-top: 24px;
  height: 100%;
  display: flex;
  flex-direction: column;

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

    .right {
      flex: 1;
      min-width: 0;
      display: flex;
      flex-direction: column;
      justify-content: center;
      margin-left: 16px;
      .name {
        font-weight: bold;
        font-size: 24px;
        color: #333333;
        line-height: 33px;
        text-align: left;
        font-style: normal;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .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 {
    flex: 1;
    width: 100%;
    min-height: 0;
    background: #F9FAFC;
    padding: 24px 24px 0;
  }
}

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