<template>
  <div>
    <div class="titleBox">
      <PageTitle title="布控审批">
        <div class="sub-nav">
          <el-tabs v-model="activeSubNav" @click="handleType">
            <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>
      </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 #jbxx="{ row }">
          <div>
            <img src="" alt="" />
            <ul>
              <li>群体名称：{{ row.qtMc }}</li>
              <!-- <li>所属辖区：</li> -->
              <li class="rowClass">
                风险等级：
                <DictTag
                  :tag="false"
                  :value="row.qtFxdj"
                  :options="D_GS_ZDQT_FXDJ"
                />
              </li>
              <li>创建时间：{{ row.xtCjsj }}</li>
            </ul>
          </div>
          <div class="flex">
            <el-button
              :key="index"
              type="primary"
              size="small"
              v-for="(item, index) in row.bqList"
            >
              {{ item.bqMc }}</el-button
            >
          </div>
        </template>
        <template #bgxx="{ row }">
          <div>背景资料：{{ row.qtBjzl }}</div>
          <div>创建单位：{{ row.xtCjbmmc }}</div>
        </template>
        <template #gkxx="{ row }">
          <div>管辖单位：{{ row.gxSsdwmc }}</div>
          <div>列控原因：{{ row.zdrLkyy }}</div>
          <div>开始时间：{{ row.startTime }}</div>
          <div>截至时间：{{ row.endTime }}</div>
        </template>
        <template #wkrs="{ row }">
          <span style="color: #0072ff">{{ row.wkrs }}</span>
        </template>
        <template #qtZt="{ row }">
          <DictTag :tag="false" :value="row.qtZt" :options="D_GS_ZDR_BK_ZT" />
        </template>

        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link
            size="small"
            type="primary"
            @click="autoEdit('auto', row)"
            v-if="row.qtZt === '02' && activeSubNav === 'myAudit'"
            >审核</el-link
          >
          <el-link
            size="small"
            type="success"
            @click="autoEdit('approval', row)"
            v-if="row.qtZt === '04' && activeSubNav === 'myApprove'"
            >审批</el-link
          >
          <el-link size="small" type="info" @click="autoEdit('detail', row)"
            >详情</el-link
          >
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 详情 -->
    <MpvGroupInfo ref="MpvGroupInfoRef" />
  </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 { qcckGet, qcckPost, qcckDelete } from "@/api/qcckApi.js";
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
import { setItem, getItem } from "@/utils/storage";
import { selectUserDeptPage } from "@/api/user-manage";
import MpvGroupInfo from "../mpvGroup/components/infoForm.vue";

const { proxy } = getCurrentInstance();
const { D_GS_ZDQT_FXDJ, D_GS_ZDR_RYJB, D_GS_ZDR_BK_ZT } = proxy.$dict("D_GS_ZDQT_FXDJ","D_GS_ZDR_RYJB","D_GS_ZDR_BK_ZT" ); //获取字典数据
const deptList = ref([]); //部门列表
const searchBox = ref(); //搜索框
const userId = getItem("USERID");
const MpvGroupInfoRef = ref(null);

// 子导航激活状态
const activeSubNav = ref("myAudit");
const searchConfiger = ref([
  {
    label: "群体名称",
    prop: "qtMc",
    placeholder: "请输入群体名称",
    showType: "input"
  },
  {
    label: "群体风险等级",
    prop: "qtFxdj",
    placeholder: "请选择群体风险等级",
    showType: "select",
    options: D_GS_ZDQT_FXDJ
  },
  {
    label: "重点人人员级别",
    prop: "zdrRyjb",
    placeholder: "请选择重点人人员级别",
    showType: "select",
    options: D_GS_ZDR_RYJB
  }
]);
const queryFrom = ref({});
const userInfo = ref({});
const pageData = reactive({
  tableData: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: "240", //操作栏宽度

  tableColumn: [
    { label: "群体基本信息", prop: "jbxx", showSolt: true },
    { label: "背景信息", prop: "bgxx", showSolt: true },
    { label: "管控信息", prop: "gkxx", showSolt: true },
    { label: "稳控人数", prop: "wkrs", showSolt: true, width: 80 },
    { label: "状态", prop: "qtZt", showSolt: true }
  ]
});
onMounted(() => {
  tabHeightFn();
  getUserInfo();
  getdepartmentList();
});

// 获取部门列表
const getdepartmentList = () => {
  selectUserDeptPage().then((res) => {
    deptList.value = res?.records.map((item) => ({
      label: item.deptName,
      value: item.deptId
    }));
  });
};
const getUserInfo = async () => {
  await qcckGet({}, `/mosty-base/sysUser/getUserInfo/${userId}`).then((res) => {
    userInfo.value = res;
    setItem("userInfo", res);
    getList();
  });
};

//选择类型
const handleType = () => {
  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,
    [activeSubNav.value === "myAudit" ? "bkshrSfzh" : "bksprSfzh"]:
      userInfo.value.idEntityCard
  };
  let url = "/mosty-gsxt/tbGsxtZdqt/selectPage";
  qcckGet(data, url)
    .then((res) => {
      pageData.tableData = res.records || [];
      pageData.total = res.total;
      pageData.tableConfiger.loading = false;
    })
    .catch(() => {
      pageData.tableConfiger.loading = false;
    });
};

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

// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight =
    window.innerHeight - searchBox.value.offsetHeight - 260;
  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;
}

.btns {
  height: 52px;
  padding: 10px;
  box-sizing: border-box;
}
::v-deep .el-tabs__nav-wrap::after {
  background: none;
}
</style>
