<template>
  <a-tabs v-model="activatedTab" type="card" style="height: 100%;">
    <a-tab-pane v-for="tab in tabsForSdcc" :key="tab.value" :tab="tab.label">
      <component :is="activatedTab" :pType="pType" :isJdcjbr="isJdcjbr" :isDataScreen="isDataScreen" style="height: 100%;" />
    </a-tab-pane>
  </a-tabs>
</template>

<script>
import { distinct, requestUserRole } from './Common/rectify_api';
import { tabsForSdcc } from './Common/tabsForRectify';
import sdccDoubleCheck from './sdcc_doubleCheck.vue';
import sdccPblmView from './sdcc_pblmView.vue';
import sdccPendingApprove from './sdcc_pendingApprove.vue';
import sdccPreApproval from './sdcc_preApproval.vue';
import sdccDirectorCheck from './sdccDirectorCheck.vue';
import sdccOperatorCheck from './sdccOperatorCheck.vue';

export default {
  data() {
    return {
      tabsForSdcc: [],
      activatedTab: 'sdccPreApproval',
      pType: 1,
      userId: localStorage.getItem('persId'),
      isJdcjbr: false, // 是否是监督处经办人
      isDataScreen: false, // 是否是监督处经办人或者监督处审核人  可以查看数据筛查按钮
      readOnlyRole: localStorage.getItem('readOnlyRole'),
    };
  },
  components: {
    sdccPblmView,
    sdccPendingApprove,
    sdccPreApproval,
    sdccDoubleCheck,
    sdccOperatorCheck,
    sdccDirectorCheck,
  },
  created() {
    this.getAuthenticatedTabs(this.userId, tabsForSdcc);
  },
  methods: {
    getAuthenticatedTabs(userId, tabs) {
      this.isJdcjbr = false;
      this.isDataScreen = false;
      const currentUser = { userId: userId };
      let userRoles = [];
      requestUserRole(currentUser).then((res) => {
        if (res.data != null) {
          userRoles = res.data; // 当前用户的所有角色列表
          let authenticatedTabs = [];
          let tempTabs = [];
          var flag = false;
          userRoles.forEach((userRole) => {
            // 用户所有角色可见的标签的集合
            tempTabs = tabs.filter(
              (tab) =>
                tab.roles.indexOf(userRole.roleId) > -1 ||
                tab.roles.length === 0,
            );
            tempTabs.forEach((tab) => {
              authenticatedTabs.push(tab);
            });
            if (userRole.roleId == '66a6e697fe3e4d02b79f9f90771a4b68') {
              flag = true;
            }
            if (userRole.roleId == '48fb7e333a1b44129bebfe6aff9ff34c') {
              // 判断是否是监督处经办人
              this.isJdcjbr = true;
            }
            if (
              userRole.roleId == '48fb7e333a1b44129bebfe6aff9ff34c' ||
              userRole.roleId == '9cd9be51352048328963a6ac6506724c'
            ) {
              // 判断是否是监督处经办人
              this.isDataScreen = true;
            }
          });
          if (flag) {
            authenticatedTabs = tabs;
          }
          // 去除重复的标签
          authenticatedTabs = distinct(authenticatedTabs);

          if (this.readOnlyRole == 'hide') {
            this.tabsForSdcc = [
              {
                value: 'sdccPblmView',
                label: '问题查看',
                roles: [], // 督查处所有角色可见
              },
            ];
          } else {
            this.tabsForSdcc = authenticatedTabs;
          }
          if (this.tabsForSdcc.length > 0) {
            this.activatedTab = this.tabsForSdcc[0].value; // 默认显示第一个标签
          }
        }
      });
    },
  },
};
</script>

<style lang='less' scoped>

</style>
