<template>
    <div class="default-main">
        <div class="custom-table-header">
            <div class="title">角色推荐码</div>
            <el-button :icon="Refresh" type="primary" @click="refresh">刷新推荐码</el-button>
        </div>
        <Table ref="tableRef" />
    </div>
</template>
<script setup lang="ts">
import { Refresh } from '@element-plus/icons-vue'
import { ref, onMounted, provide } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { refreshReferralCode } from '@/api/user-boot/referralCode'

defineOptions({
    name: 'auth/menu'
})
const tableRef = ref()
const tableStore = new TableStore({
    showPage: false,
    method: 'POST',
    url: '/user-boot/referralCode/findReferralCode',
    column: [
    { title: '序号',  width: 80,formatter: (row: any) => {
        return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
      } },
        { title: '角色名称', field: 'roleName' },
        { title: '推荐码', field: 'roleReferralCode' }
    ]
})
provide('tableStore', tableStore)

onMounted(() => {
    tableStore.table.ref = tableRef.value
    tableStore.index()
    tableStore.table.loading = false
})
const refresh = () => {
    refreshReferralCode().then(res => {
        tableStore.table.data = res.data
    })
}
</script>
