<template>
  <div>
    <div class="titleBox">
      <PageTitle title="情报语义分析"></PageTitle>
    </div>
    <div class="flex just-between">
      <!-- 左边 -->
      <div class="ww49" style="min-width: 647px;">
        <div ref="searchBox">
          <Search :searchArr="searchConfiger" @submit="onSearch">
            <el-button type="primary" @click="addForm('add',null)">新增</el-button>
          </Search>
        </div>
        <div class="tabBox">
          <MyTable
            :tableData="pageData.tableData"
            :tableColumn="pageData.tableColumn"
            :tableHeight="pageData.tableHeight1"
            :key="pageData.keyCount"
            :tableConfiger="pageData.tableConfiger"
            :controlsWidth="pageData.controlsWidth"
            @chooseData="chooseData"
          >
            <template #controls="{ row }">
              <el-link type="primary" @click="addForm('edit', row.id)">编辑</el-link>
              <el-link type="danger" @click="delDictItem(row.id)">删除</el-link>
            </template>
          </MyTable>
          <div class="txetBox"></div>
          <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="delDictItemRight(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: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  tableHeight1:300,
  tableConfigerR: {
    rowHieght: 61,
    showSelectType: null,
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: 160, //操作栏宽度
  tableColumn: [
    { label: "语义名称", prop: "yymc",showOverflowTooltip:true },
    { label: "要素类型", prop: "yslx",showOverflowTooltip:true },
    { label: "要素名称", prop: "ysmc",showOverflowTooltip:true },
    { label: "要素描述", prop: "ysms",showOverflowTooltip:true },
  ]
});
onMounted(() => {
  tabHeightFn();
  getList();
});



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



const getList = () => {
  pageData.tableConfiger.loading = true;
  qcckGet(queryFrom.value,'/mosty-gsxt/qbyy/selectList').then((res)=>{
    pageData.tableData = res || [];
    pageData.tableConfiger.loading = false;
  })
};

// 删除
const delDictItem = (id) => {
  proxy.$confirm("确定要删除", "警告", {type: "warning"}).then(() => {
    qcckPost({id},'/mosty-gsxt/qbyy/delete').then(()=>{
      proxy.$message({ type: "success",  message: "删除成功" });
      getList();
    })
  }).catch(() => {});
};

// 删除右边
const delDictItemRight = (id) => {
  // proxy.$confirm("确定要删除", "警告", {type: "warning"}).then(() => {
  //   qcckPost({id},'/mosty-gsxt/qbyy/delete').then(()=>{
  //     proxy.$message({ type: "success",  message: "删除成功" });
  //     getList();
  //   })
  // }).catch(() => {});
};


// 新增数据 -- 左边
const addForm = (type, id) =>{
  detailDiloag.value.init(type, id);
}


const changeNo = (val) => {
  // pageData.pageConfiger.pageNum = val;
  // getListR();
};
const changeSize = (val) => {
  // pageData.pageConfiger.pageSize = val;
  // getListR();
};



// 新增
const addEdit = (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;
}
.txetBox{
  position: absolute;
  bottom: 50px;
  height: 210px;
  width: 100%;
  padding: 0 10px;
  box-sizing: border-box;
  background: red;
}
</style>

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