<template>
  <div>
    <div class="titleBox">
      <PageTitle title="重点人员深度发掘">
        <el-button type="primary" @click="addEdit('add', '')">
          <el-icon style="vertical-align: middle"><CirclePlus /></el-icon>
          <span style="vertical-align: middle">新增</span>
        </el-button>
      </PageTitle>
    </div>
    <!-- 搜索 -->
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch" :key="pageData.keyCount">
        <template #defaultSlot>
          <div class="checkbox-group">
            <el-checkbox v-model="queryFrom.myNote">我的笔记</el-checkbox>
            <el-checkbox v-model="queryFrom.myCheck">我的审核</el-checkbox>
            <el-checkbox v-model="queryFrom.myApprove">我的审批</el-checkbox>
          </div>
        </template>
      </Search>
    </div>
    <!-- 表格 -->
    <div class="tabBox">
      <MyTable
        :tableData="pageData.tableData"
        :tableColumn="pageData.tableColumn"
        :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount"
        :tableConfiger="pageData.tableConfiger"
        :controlsWidth="pageData.controlsWidth"
        @chooseData="chooseData"
      >
        <!-- 基础信息 -->
        <template #basicInfo="{ row }">
          <div class="basic-info">
            <div class="avatar">
              <el-image :src="row.avatar" fit="cover"></el-image>
            </div>
            <div class="info-list">
              <div>姓名：{{ row.name }}</div>
              <div>性别：{{ row.gender }}</div>
              <div>年龄：{{ row.age }}</div>
              <div>身份证号：{{ row.idCard }}</div>
              <div>出生日期：{{ row.birthDate }}</div>
            </div>
          </div>
        </template>
        <!-- 操作 -->
        <template #controls="{ row }">
          <div class="control-buttons">
            <el-button type="primary" size="small" @click="handleDetail(row)">审核</el-button>
            <el-button type="info" size="small" @click="handleApprove(row)">审批</el-button>
            <el-button type="warning" size="small" @click="handleDelete(row)">去除</el-button>
            <el-button type="danger" size="small" @click="handleBlacklist(row)">拉黑</el-button>
          </div>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 详情 -->
    <DetailForm ref="detailDiloag" />
  </div>
</template>

<script setup>
import PageTitle from "@/components/aboutTable/PageTitle.vue";
import MyTable from "@/components/aboutTable/MyTable.vue";
import Pages from "@/components/aboutTable/Pages.vue";
import Search from "@/components/aboutTable/Search.vue";
import DetailForm from "./components/detailForm.vue";
import { qcckGet, qcckPost, qcckDelete } from "@/api/qcckApi.js";
import { reactive, ref, onMounted, getCurrentInstance } from "vue";

const { proxy } = getCurrentInstance();
const detailDiloag = ref();
const searchBox = ref(); //搜索框

const searchConfiger = ref([
  {
    label: "所属部门",
    prop: "department",
    placeholder: "请选择所属部门",
    showType: "department"
  },
  {
    label: "是否关注",
    prop: "isFollowed",
    placeholder: "请选择是否关注",
    showType: "select",
    options: [
      { label: "是", value: true },
      { label: "否", value: false }
    ]
  }
]);

const queryFrom = ref({
  myNote: false,
  myCheck: false,
  myApprove: false
});

const pageData = reactive({
  tableData: [],
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "checkbox",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  },
  controlsWidth: 300,
  tableColumn: [
    { label: "基础信息", prop: "basicInfo", minWidth: 300 },
    { label: "列控信息", prop: "controlInfo", minWidth: 200 },
    { label: "管控信息", prop: "manageInfo", minWidth: 200 },
    { label: "风险积分", prop: "riskScore", width: 100 },
    { label: "评分项", prop: "scoreItems", minWidth: 150 },
    { label: "最后关注", prop: "lastFollow", width: 120 },
  ]
});

onMounted(() => {
  getList();
  tabHeightFn();
});

// 搜索
const onSearch = (val) => {
  queryFrom.value = { ...val };
  pageData.pageConfiger.pageCurrent = 1;
  getList();
};

const changeNo = (val) => {
  pageData.pageConfiger.pageNum = val;
  getList();
};

const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
  getList();
};

// 获取列表
const getList = () => {
  // pageData.tableConfiger.loading = true;
  // let data = { ...pageData.pageConfiger, ...queryFrom.value };
  // API调用示例
  // qcckPost(data, '/api/deepExcavation/list').then(res => {
  //   pageData.tableData = res.records || [];
  //   pageData.total = res.total;
  //   pageData.tableConfiger.loading = false;
  // }).catch(() => { pageData.tableConfiger.loading = false; });
};

// 操作按钮处理函数
const handleDetail = (row) => {
  detailDiloag.value.init('detail', row);
};

// 详情
const addEdit = (type, row) => {
  detailDiloag.value.init(type, row);
};

const handleApprove = (row) => {
  detailDiloag.value.init('approve', row);
};

const handleDelete = (row) => {
  // 实现删除逻辑
};

const handleBlacklist = (row) => {
  // 实现拉黑逻辑
};

// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight = window.innerHeight - searchBox.value.offsetHeight - 250;
  window.onresize = function () {
    tabHeightFn();
  };
};
</script>

<style lang="scss" scoped>
.checkbox-group {
  display: flex;
  gap: 20px;
}

.basic-info {
  display: flex;
  gap: 15px;

  .avatar {
    width: 80px;
    height: 80px;
    overflow: hidden;
    border-radius: 4px;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  .info-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }
}

.control-buttons {
  display: flex;
  gap: 10px;
}
</style>
