<template>
  <div>
    <div class="titleBox">
      <PageTitle title="标签布控" >
        <el-button type="primary" size="small" @click="handleItem('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"></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" size="small"  @click="handleItem('edit',row)">编辑</el-link>
          <el-link type="primary" size="small"  @click="handleItem('detail',row)">详情</el-link>
          <el-link type="danger" size="small"  @click="handleItem('deleite',row)">删除</el-link>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight + 42"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 新增 -->
    <AddForm ref="addForm" @updateDate="getList"></AddForm>
  </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 AddForm from './components/addForm.vue'
import { qcckGet, qcckPost } from "@/api/qcckApi.js";
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
const { D_BZ_SF } = proxy.$dict("D_BZ_SF"); //获取字典数据
const searchBox = ref();
const addForm = ref()
const searchConfiger = ref([
  {
    label: "任务名称",
    prop: "rwmc",
    placeholder: "请输入任务名称",
    showType: "input",
  },
]);
const queryFrom = ref({});
const pageData = reactive({
  tableData: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: 120, //操作栏宽度

  tableColumn: [
    { label: "任务名称", prop: "rwmc" },
    { label: "布控人电话", prop: "bkysDh" },
    { label: "人员等级", prop: "bkysDj" },
    { label: "处置措施", prop: "czcs" },
    { label: "布控事由", prop: "bksy" },
  ]
});
onMounted(() => {
  tabHeightFn();
  getList()
});

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

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

// 获取列表
const getList = () => {
//   pageData.tableConfiger.loading = true;
//   let data = {
//     ...pageData.pageConfiger,
//     ...queryFrom.value,
//   };
//   qcckGet(data, "/mosty-gsxt/tbGsxtBk/selectPage").then((res) => {
//     pageData.tableData = res.records || [];
//     pageData.total = res.total;
//     pageData.tableConfiger.loading = false;
//   }).catch(() => {
//     pageData.tableConfiger.loading = false;
//   });
};

const handleItem = (type,row) => {
    if(type == 'delete'){

    }else{
        addForm.value.init(type,row);
    }
};

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

<style lang="scss" scoped>
.main-nav {
  padding: 16px;
  background-color: #fff;
}


.sub-nav {
  background-color: #fff;
  padding: 0 16px;
}

:deep(.el-tabs__header) {
  margin-bottom: 0;
}

:deep(.el-tabs__nav-wrap::after) {
  height: 1px;
  background: none;
}

:deep(.el-table--fit) {
  top: 52px !important;
}
.btns {
  height: 52px;
  padding: 10px;
  box-sizing: border-box;
}

</style>
