<!--
 * @Author: xiejiang
 * @Date: 2024-12-01 10:37:37
 * @LastEditors: xiejiang
 * @LastEditTime: 2024-12-08 15:11:47
 * @Description: 
 * Copyright（c）2024 by 好老师教育科技有限公司 All right Reserved.
-->
<template>
  <div class="bg-white p-[12px] h-full">
    <Back />
    <main class="m-auto max-w-[1012px]">
      <!-- 基本信息 -->
      <PageTitle title="基本信息" class="mb-[24px] mt-[12px]" />
      <div class="flex flex-wrap">
        <DetailTable label="角色名称" :value="state?.roleName" />
        <DetailTable label="状态">
          <span>
            {{ statusTxt(state?.status as number)?.title || '-' }}
          </span>
        </DetailTable>
        <DetailTable label="添加时间" :value="state?.inputTime" />
        <DetailTable label="添加人" :value="state?.inputUserName" />
        <DetailTable label="角色描述" width="100%" :value="state?.description" />
      </div>

      <!--    用户角色与权限     -->
      <PageTitle title="角色用户" class="my-[24px]" />
      <t-table
        :data="tableData"
        :columns="columns"
        :loading="loading"
        :pagination="pagination.total > 10 ? pagination : undefined"
      >
        <!-- 保留自定义列插槽 -->
        <template v-for="(_, name) in $slots" #[name]="scope">
          <slot :name="name" v-bind="scope" />
        </template>
        <template v-for="col in columns" #[col.colKey]="{ row }" :key="col.colKey">
          <template v-if="col.colKey != 'operation'">
            <div class="cell-content">{{ row[col.colKey] || '-' }}</div>
          </template>
        </template>
      </t-table>
    </main>
  </div>
</template>

<script setup lang="ts" name="role-detail">
import { useRoute } from 'vue-router'
import { PrimaryTableCol } from 'tdesign-vue-next'
import { useBasic } from '@/hooks/useBasic'
import { ResRoleList } from '@/api/interface/user-roles/index'
import { getRoleDetail } from '@/api/modules/user-roles/index'
import { statusTxt } from '@/utils/status'

const route = useRoute()

const state = ref<ResRoleList>()

const getData = () => {
  getRoleDetail({
    ...pagination.value,
    roleId: route.query.roleId as string
  }).then(res => {
    state.value = res.data
    tableData.value = res.data?.roleUsers?.list || []
    pagination.value.total = res?.recordsFiltered as number
  })
}

const { setBreadcrumb } = useBasic()

const loading = ref(false)

// 权限
const tableData = ref<any[]>()
const pagination = ref({
  page: 1,
  limit: 10,
  total: 0
})
// 表格columns配置
const columns: PrimaryTableCol[] = [
  {
    title: '序号',
    colKey: 'serial-number',
    width: 70
  },
  { title: '用户姓名', colKey: 'userName' },
  { title: '手机号码', colKey: 'mobile' },
  { title: '最近登录时间', colKey: 'role' },
  { title: '最近登录IP', colKey: 'role' },
  { title: '最近登录设备类型', colKey: 'role' }
]

onMounted(() => {
  setBreadcrumb([
    {
      title: '系统权限'
    },
    {
      title: '角色管理',
      name: 'users'
    },
    {
      title: '角色详情'
    }
  ])
  getData()
})
</script>
