<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>
        <el-button type="danger" @click="addEdit('add', '')">
          <el-icon style="vertical-align: middle"><Dete /></el-icon>
          <span style="vertical-align: middle">批量删除</span>
        </el-button>
        <el-button>
          <span style="vertical-align: middle">导出</span>
        </el-button>
      </PageTitle>
    </div>
    <!-- 搜索 -->
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch" :key="pageData.keyCount"></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 #controls="{ row }">
          <el-link type="primary"  @click="addEdit('edit', row)">编辑</el-link>
          <el-link type="primary"  @click="addEdit('edit', row)">编辑</el-link>
          <el-link type="danger"  @click="delDictItem([row.id])">删除</el-link>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 编辑详情 -->
    <EditAddForm ref="detailDiloag" @updateDate="getList" />
  </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 EditAddForm from "./components/editAddForm.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: 'yymc', placeholder: "请输入语义名称", showType: "input" },
  { label: "要素类型", prop: 'yslx', placeholder: "请选择要素类型", showType: "select" },
  { label: "要素名称", prop: 'ysmc', placeholder: "请输入要素名称", showType: "input" }
]);
const queryFrom = ref({});
const pageData = reactive({
  tableData: [
    {
      id: 1,
      xh: 1,
      yymc: "XX公司",
      yslx: "实体识别",
      ysmc: "组织",
      ysms: "林芝某公司",
      bz: ""
    },
    {
      id: 2, 
      xh: 2,
      yymc: "林芝工布公园",
      yslx: "实体识别",
      ysmc: "地点",
      ysms: "工布公园",
      bz: ""
    }
  ], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "checkBox",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: 160, //操作栏宽度
  tableColumn: [
    { label: "语义名称", prop: "yymc" },
    { label: "要素类型", prop: "yslx" },
    { label: "要素名称", prop: "ysmc" },
    { label: "要素描述", prop: "ysms" },
    { label: "备注", prop: "bz" }
  ]
});
onMounted(() => {
  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;
  // qcckGet(queryFrom.value).then((res)=>{
  //   pageData.tableData = res.data.list;
  //   pageData.total = res.data.total;
  //   pageData.keyCount++;
  //   pageData.tableConfiger.loading = false;
  // })
}

// 删除
const delDictItem = (ids) =>{
  // proxy.$confirm("确定要删除", "警告", {type: "warning"}).then(() => {
  //   qcckPost(ids,url).then(()=>{
  //     proxy.$message({ type: "success",  message: "删除成功" });
  //     getList();
  //   })
  // }).catch(() => {});
}

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


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

<style>
.el-loading-mask {
  background: rgba(0, 0, 0, 0.5) !important;
}
</style>
