<!-- 
 * @Description: 学生画像
 * @Author: syy 
 * @Date: 2024-7-24
-->
<template>
  <div class="main-box">
    <TreeFilter
      ref="treeFilter"
      label="personSetName"
      id="personSetId"
      width="300px"
      title="班级管理"
      :show-all="true"
      :request-api="userManageClassManageApi.page"
      @change="changeTreeFilter"
    >
      <template v-slot:label="{ row }">
        <span class="custom-tree-node">
          <span>{{ row.node.label }} {{ row.node.userName ? `(${row.node.userName})` : "" }}</span>
        </span>
      </template>
    </TreeFilter>
    <div class="table-box">
      <ProTable ref="proTable" title="人员列表" :columns="columns" rowKey="id" :request-api="userManagePersonnelApi.page">
        <!-- 表格操作栏 -->
        <template #operation="scope">
          <el-space>
            <s-button link :opt="FormOptEnum.VIEW" @click="onView(scope.row)" />
          </el-space>
        </template>
      </ProTable>
    </div>
    <!-- 预览头像 -->
    <el-dialog v-model="visible" title="查看头像" width="830px" :before-close="handleClose">
      <div style="display: flex; align-items: center; justify-content: center">
        <img style="max-width: 100%; max-height: 600px" class="detailpic" :src="faceUrl" alt="" />
      </div>
    </el-dialog>
  </div>
</template>
<script setup lang="tsx" name="ViolationPortrait">
import { userManagePersonnelApi,userManageClassManageApi} from "@/api";
import { FormOptEnum } from "@/enums";
import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
import TreeFilter from "@/components/TreeFilter/index.vue";
import { useRouter } from "vue-router";
const visible = ref(false); //是否显示人员表单
const faceUrl = ref('');
const router = useRouter();
// 获取 ProTable 元素，调用其获取刷新数据方法（还能获取到当前查询参数，方便导出携带参数）
const proTable = ref<ProTableInstance>();
const treeFilter = ref<any>();
// 表格配置项
const columns: ColumnProps[] = [
{
    prop: "faceUrl",
    label: "人脸",
    render: scope => {
      return (
        <img src={scope.row.faces.length > 0 ? scope.row.faces[0].faceUrl : ''} onClick={() => viewHeadImage(scope)} style='width:50px;height:50px;' alt=''/>
      );
    }
  },
  {
    prop: "name",
    label: "姓名"
  },
  {
    prop: "personId",
    label: "人员ID"
  },
  {
    prop: "phone",
    label: "手机号"
  },
  {
    prop: "personSetName",
    label: "所属班级",
  },
  { prop: "operation", label: "操作", width: 250, fixed: "right" }
];
const viewHeadImage = (scope: any) => {
  faceUrl.value = scope.row.faces[0].faceUrl;
  visible.value = true
};
const handleClose = () => {
  visible.value = false;
};

const onView = (row: any) => {
  router.push({
    path:'/violation/portrait/detail',
    query: {
      personId: row.personId
    }
  });
};

/** 部门切换 */
const personSetId = ref<number | string>()
function changeTreeFilter(val: number | string) {
  personSetId.value = val
  proTable.value!.pageable.pageNum = 1;
  proTable.value!.searchParam.personSetId = val;
  proTable.value!.search();
}

</script>
<style scoped lang="scss">
.table-box {
  width: 100%;
  height: 100%;
}
.custom-tree-node {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  padding-right: 8px;
  font-size: 14px;
}
</style>
