<template>
  <!-- 激活记录 -->
  <el-dialog v-model="show" title="激活记录" width="500px">
    <el-table :data="tableData.records" style="width: 100%">
      <el-table-column prop="periodMonth" label="激活时长（月）"></el-table-column>
      <el-table-column prop="amount" label="店铺签约金额">
        <template v-slot="scope">
          {{ formatMoney(scope.row.amount) }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="操作时间"></el-table-column>
    </el-table>
    <el-pagination v-model:current-page="tableData.page" v-model:page-size="tableData.size"
      :page-sizes="[10, 20, 50, 100]" :total="tableData.total" @current-change="getData" @size-change="getData"
      style="margin-top: 16px; text-align: right;" />
  </el-dialog>
</template>

<script setup>
import { ref, reactive } from "vue";
import ShopApi from "@/api/account/shop";
import { formatMoney } from "@/utils";

const shopInfo = ref({ id: '' })

const show = ref(false);
const tableData = reactive({
  loading: false,
  page: 1,
  size: 10,
  total: 0,
  records: [],
});

async function getData() {
  try {
    tableData.loading = true;
    const res = await ShopApi.registerRecord({
      page: tableData.page,
      size: tableData.size,
      shopId: shopInfo.value.id
    });
    tableData.records = res.records;
    tableData.total = res.totalRow;
  } catch (error) {
    console.log(error);
  } finally {
    tableData.loading = false;
  }
}

function open(data) {
  shopInfo.value = data;
  show.value = true;
  getData();
}

defineExpose({
  open,
});
</script>