<template>
  <div class="mainView">
    <div class="jggk-page">
      <div class="module">
        <div class="titleName">
          <span class="title">领导简介</span>
          <div class="lookMore" @click="lookMore('ld')">查看更多</div>
        </div>
        <div class="contentBox">
          <ul class="leaderList">
            <li
              class="leader"
              v-for="item in structure.leaderData"
              :key="item.id"
            >
              <span class="name">{{ item.leaderName }}</span>
              <p>{{ filterPosition(item) }}</p>
            </li>
          </ul>
        </div>
      </div>
      <div class="module">
        <div class="titleName">
          <span class="title">机构职能</span>
          <div class="lookMore" @click="lookMore('zz')">查看更多</div>
        </div>
        <div class="contentBox">
          <div class="organization">
            <div class="title">内设机构</div>
            <ul class="organizationList">
              <li v-for="item in structure.institution.internal">
                {{ item.departmentName }}
              </li>
            </ul>
          </div>
          <div class="organization">
            <div class="title">直属单位</div>
            <ul class="organizationList">
              <li v-for="item in structure.institution.headquarters">
                {{ item.departmentName }}
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup name="">
import "@/style/jggk/index.less";
import { useRouter } from "vue-router";
import api from "@/api/jggk.js";
import { onMounted, reactive } from "vue";
import dictStore from "@/store/dictionary.js"; //引入仓库
const unitDict = dictStore().DICT_ZW;
const router = useRouter();
const structure = reactive({
  leaderData: [],
  institution: {
    internal: [],
    headquarters: [],
  },
});
onMounted(() => {
  getLeaderInfo();
  getInstitution();
});
// 领导简介
function getLeaderInfo() {
  api.leaderList({ size: 1000, current: 1, status: 2 }).then((res) => {
    if (res.code == 200) {
      structure.leaderData = res.data.records;
      structure.leaderData.map((item, index) => {
        // 把局长放第一位
        if (item.leaderPositionId == "1795638501398618113") {
          let data = structure.leaderData[0];
          structure.leaderData[0] = structure.leaderData[index];
          structure.leaderData[index] = data;
        }
      });
    }
  });
}
// 机构职能
function getInstitution() {
  api.institution({ size: 1000, current: 1 }).then((res) => {
    if (res.code == 200) {
      res.data.records.map((item) => {
        // 内设机构
        if (item.organizationCategory == 1) {
          structure.institution.internal.push(item);
          // 直属单位
        } else {
          structure.institution.headquarters.push(item);
        }
      });
    }
  });
}

// 过滤职位
function filterPosition(data) {
  let positionStr = "";
  let positionList = data.specificPositions.split(",");
  positionList.unshift(data.leaderPositionId);
  positionList.map((item) => {
    console.log(unitDict);
    unitDict.map((dic) => {
      if (item == dic.id) {
        positionStr = positionStr + "、" + dic.dictLabel;
      }
    });
  });
  return positionStr.slice(1);
}

// 查看更多
function lookMore(type) {
  router.push({ path: "/jggk/details", query: { type } });
}
</script>
<style scoped></style>
