<template>
  <div>
    <div class="titleBox">
      <PageTitle title="布控审批" />
    </div>

    <!-- 搜索 -->
    <div ref="searchBox">
      <!-- 顶部主导航 -->
      <div class="main-nav">
        <el-button :class="['nav-btn', activeMainNav === 'todo' ? 'active' : '']" @click="activeMainNav = 'todo'">
          我的待办
        </el-button>
        <el-button :class="['nav-btn', activeMainNav === 'done' ? 'active' : '']" @click="activeMainNav = 'done'">
          我的已办
        </el-button>
      </div>
      <!-- 子导航 -->
      <div class="sub-nav">
        <el-tabs v-model="activeSubNav">
          <el-tab-pane label="我的发起" name="myInitiate"></el-tab-pane>
          <el-tab-pane label="我的审核" name="myAudit"></el-tab-pane>
          <el-tab-pane label="我的审批" name="myApprove"></el-tab-pane>
          <el-tab-pane label="我的签收" name="mySign"></el-tab-pane>
          <el-tab-pane label="我的处置" name="myHandle"></el-tab-pane>
        </el-tabs>
      </div>
      <Search :searchArr="searchConfiger" @submit="onSearch" :key="pageData.keyCount">
        <template #defaultSlot>
          <div>
            <el-input-number v-model="queryFrom.xqy"></el-input-number>
            <span class="ml10 mr10" style="color: #000">至</span>
            <el-input-number v-model="queryFrom.dqy"></el-input-number>
          </div>
        </template>
      </Search>
    </div>
    <!-- 表格 -->
    <div class="tabBox">
      <div ref="btns" class="btns flexcb">
        <div class="">
          <el-button>批量处理</el-button>
          <el-button>导出</el-button>
        </div>
        <el-input v-model="input2" style="max-width: 300px" placeholder="请输入关键字">
          <template #append><el-button type="primary" icon="Search"></el-button></template>
        </el-input>
      </div>

      <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-button size="small" @click="addEdit('detail', row)">详情</el-button>
          <el-button size="small">从业人员</el-button>
          <el-button size="small">转区域</el-button>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight + 42"
        :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 btns = ref();
  // 主导航激活状态
  const activeMainNav = ref("todo");
  // 子导航激活状态
  const activeSubNav = ref("myAudit");
  const searchConfiger = ref([
    {
      label: "布控类别",
      prop: "category",
      placeholder: "请输入布控类别",
      showType: "select",
      options: [{ label: "在业", value: "在业" }]
    },
    {
      label: "布控对象",
      prop: "target",
      placeholder: "请输入布控对象",
      showType: "select",
      options: [{ label: "在业", value: "在业" }]
    },
    {
      label: "布控状态",
      prop: "status",
      placeholder: "请输入布控状态",
      showType: "select",
      options: [{ label: "在业", value: "在业" }]
    },
    { label: "布控时间", prop: "dateRange", placeholder: "请输入布控时间", showType: "daterange" },
    {
      label: "预计布控类型",
      prop: "controlType",
      placeholder: "请输入布控类别",
      showType: "select",
      options: [{ label: "在业", value: "在业" }]
    },
    {
      label: "最近预警时间",
      prop: "lastAlertTime",
      placeholder: "请输入布控对象",
      showType: "select",
      options: [{ label: "在业", value: "在业" }]
    },
    {
      label: "布控发起单位",
      prop: "initiatingUnit",
      placeholder: "请输入布控状态",
      showType: "select",
      options: [{ label: "在业", value: "在业" }]
    },
    {
      label: "处置接收单位",
      prop: "receivingUnit",
      placeholder: "请输入布控状态",
      showType: "select",
      options: [{ label: "在业", value: "在业" }]
    }
  ]);
  const queryFrom = ref({});
  const pageData = reactive({
    tableData: [
      [
        {
          taskId: "任务编号",
          target: "人员",
          targetInfo: "石某某",
          measures: "布控公安机关",
          scope: "布控范围",
          alertInfo: "预警信息",
          startTime: "2024-04-05 12:00",
          endTime: "2024-04-10 12:00",
          lastAlertTime: "2024-04-10 12:00",
          creator: "张三"
        }
        // ... 更多数据
      ]
    ],
    keyCount: 0,
    tableConfiger: {
      rowHieght: 61,
      showSelectType: "null",
      loading: false
    },
    total: 0,
    pageConfiger: {
      pageSize: 20,
      pageCurrent: 1
    },
    controlsWidth: 250,
    tableColumn: [
      { label: "任务编号", prop: "taskId" },
      { label: "布控对象", prop: "target" },
      { label: "布控对象信息", prop: "targetInfo" },
      { label: "布控管控措施", prop: "measures" },
      { label: "布控范围", prop: "scope" },
      { label: "预警信息", prop: "alertInfo" },
      { label: "开始时间", prop: "startTime" },
      { label: "结束时间", prop: "endTime" },
      { label: "最近预警时间", prop: "lastAlertTime" },
      { label: "布控发起人", prop: "creator" }
    ]
  });
  onMounted(() => {
    // getList()
    tabHeightFn();
  });

  //选择类型
  const handleType = val => {
    pageData.keyCount++;
    pageData.pageConfiger.pageCurrent = 1;
    getList();
  };
  // 搜索
  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 = val => {
    // pageData.tableConfiger.loading = true;
    // let data = { ...pageData.pageConfiger, ...queryFrom.value };
    // let url = '/mosty-lzcj/tbDwKscs/queryList';
    // qcckPost(data,url).then(res=>{
    //   pageData.tableData = res.records || [];
    //   pageData.total = res.total;
    //   pageData.tableConfiger.loading = false;
    // }).catch(()=>{ pageData.tableConfiger.loading = false; })
  };

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

  // 表格高度计算
  const tabHeightFn = () => {
    console.log("btns.value.offsetHeight", btns.value.offsetHeight);

    pageData.tableHeight = window.innerHeight - searchBox.value.offsetHeight - btns.value.offsetHeight - 30 - 250;
    window.onresize = function () {
      tabHeightFn();
    };
  };
</script>

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

  .nav-btn {
    margin-right: 10px;
    border: none;
    background: none;
    &.active {
      background-color: #409eff;
      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;
  }

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