<template>
  <div>
    <div class="titleBox">
      <PageTitle title="情报语义分析"></PageTitle>
    </div>
    <div class="flex just-between">
      <!-- 左边 -->
      <div class="ww49">
        <div ref="searchBox">
          <Search :searchArr="searchConfiger" @submit="onSearch" />
        </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="danger" @click="delDictItem([row.id])">删除</el-link>
            </template>
          </MyTable>
          <div class="footBnt">
            <el-button type="primary">导入</el-button>
            <el-button type="primary">语义分析</el-button>
          </div>
        </div>
      </div>

      <!-- 右边表格 -->
      <div class="ww49">
        <div ref="searchBox">
          <Search :searchArr="searchConfiger" @submit="onSearch" />
        </div>
        <div class="tabBox">
          <MyTable
            :tableData="pageData.tableData"
            :tableColumn="pageData.tableColumn"
            :tableHeight="pageData.tableHeight"
            :key="pageData.keyCount"
            :tableConfiger="pageData.tableConfigerR"
            :controlsWidth="pageData.controlsWidth"
            @chooseData="chooseData"
          >
            <template #controls="{ row }">
              <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 }"
          />
        </div>
      </div>
    </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: "" }], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "checkBox",
    loading: false
  },
  tableConfigerR: {
    rowHieght: 61,
    showSelectType: null,
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: 160, //操作栏宽度
  tableColumn: [
    { label: "语义名称", prop: "yymc" },
    { label: "要素类型", prop: "yslx" },
    { label: "要素名称", prop: "ysmc" },
    { label: "要素描述", prop: "ysms" },
  ]
});
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 - 280;
  window.onresize = function () {
    tabHeightFn();
  };
};
</script>

<style lang="scss" scoped>
.footBnt{
  width: 100%;
  position: absolute;
  bottom: 10px;
  display: flex;
  justify-content: center;
}
</style>

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