<template>
  <div class="layout-padding">
    <div class="layout-padding-auto layout-padding-view">
      <!-- 表格 -->
      <el-table 
        :data="state.dataList" 
        v-loading="state.loading" 
        border 
        :cell-style="tableStyle.cellStyle" 
        :header-cell-style="tableStyle.headerCellStyle">
        <el-table-column type="index" label="序号" width="60" align="center" />
        <el-table-column prop="deptName" label="学院" show-overflow-tooltip align="center" />
        <el-table-column prop="classNo" label="班号" show-overflow-tooltip align="center" />
        <el-table-column prop="stuNo" label="学号" show-overflow-tooltip align="center" />
        <el-table-column prop="realName" label="姓名" show-overflow-tooltip align="center" />
        <el-table-column prop="roomNo" label="房间号" show-overflow-tooltip align="center" />
        <el-table-column prop="bedNo" label="床位号" show-overflow-tooltip align="center" />
        <el-table-column prop="teacherRealName" label="班主任" show-overflow-tooltip align="center" />
        <el-table-column prop="teacherPhone" label="班主任电话" show-overflow-tooltip align="center" />
        <el-table-column label="操作" width="150" align="center" fixed="right">
          <template #default="scope">
            <el-button 
              icon="View" 
              text 
              type="primary" 
              @click="handleView(scope.row)">
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup lang="ts" name="DormAbnormal">
import { reactive, onMounted } from 'vue'
import { BasicTableProps, useTable } from "/@/hooks/table";
import { queryStudentAbnormal } from "/@/api/stuwork/dormroomstudent";
import { useMessage } from "/@/hooks/message";

// 配置 useTable
const state: BasicTableProps = reactive<BasicTableProps>({
  queryForm: {},
  isPage: false, // 接口不支持分页
  pageList: async () => {
    try {
      const res = await queryStudentAbnormal()
      let dataList = []
      if (Array.isArray(res.data)) {
        dataList = res.data
      } else if (res.data && Array.isArray(res.data.records)) {
        dataList = res.data.records
      } else if (res.data && Array.isArray(res.data.list)) {
        dataList = res.data.list
      }
      return {
        ...res,
        data: dataList
      }
    } catch (err: any) {
      useMessage().error(err.msg || '获取数据失败')
      return {
        data: []
      }
    }
  },
  props: {
    item: 'records',
    totalCount: 'total'
  },
  createdIsNeed: true
})

// table hook
const {
  getDataList,
  tableStyle
} = useTable(state)

// 查看详情
const handleView = (row: any) => {
  // TODO: 实现查看详情功能
}

// 初始化
onMounted(() => {
  getDataList()
})
</script>

