<!-- 会员机构管理-机构管理-系统角色管理 -->
<template>
    <app-view>
        <app-table :data="dataList" :columns="tableColumns" :loading="loading">
            <!-- 创建时间 -->
            <template #modifytime="{ value }">
                {{ formatDate(value) }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-operation size="small"
                    :data-list="getActionButtons(['member_institution_role_details', 'member_institution_role_users',])"
                    @click="(code: string) => openComponent(code, row)" circle />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="onRefresh" />
            </template>
        </app-table>
        <component :is="componentMap.get(componentId)" v-bind="{ record }" @closed="closeComponent"
            v-if="componentId" />
    </app-view>
</template>

<script lang="ts" setup>
import { shallowRef } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDate } from '@/filters'
import { useEnum } from '@/hooks/enum'
import { useRequest } from '@/hooks/request'
import { useOperation } from '@/hooks/operation'
import { queryRole } from '@/services/api/admin'
import AppTable from '@pc/components/base/table/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import AppOperation from '@pc/components/base/operation/index.vue'

const userstatusEnum = useEnum('userstatus') // 状态
const roleTypeEnum = useEnum('roleType') // 角色

const { componentMap, componentId, record, openComponent, closeComponent, getActionButtons } = useOperation<Model.RoleRsp>({
    onClose: () => onRefresh()
})

const { dataList, total, pageSize, pageIndex, loading, run } = useRequest(queryRole, {
    params: {
        type: 1,
        pageNum: 1,
        pageSize: 20
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = shallowRef<Model.TableColumn[]>([
    { field: 'autoid', label: 'member.institution.role.rolename', formatValue: (val) => roleTypeEnum.getEnumTypeName(val) },
    { field: 'modifiername', label: 'member.institution.role.modifiername' },
    { field: 'modifytime', label: 'member.institution.role.modifytime' },
    { field: 'rolestatus', label: 'member.institution.role.rolestatus', formatValue: (val) => userstatusEnum.getEnumTypeName(val) },
    { field: 'operate', label: 'common.operate', fixed: 'right' }
])

const onRefresh = () => {
    run()
}
</script>