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

    <a-modal
      title="提示"
      :open="visible"
      @cancel="handleCancel"
      :closable="false"
    >
      <p>工作提示：问题延期申请，须在原整改时限到期前10天以上提出，否则本系统将无法进行延期操作！！！</p>
      <p>2026年1月起，取消问题超期记录申诉功能，请大家积极按期完成整改</p>
      <template #footer>
        <a-button @click="visible = false">确定</a-button>
      </template>
    </a-modal>
  </div>
</template>

<script>
import { h } from 'vue';
import { distinct, requestUserRole } from './Common/rectify_api';
import { tabsForXjdw } from './Common/tabsForRectify';
import xjdwDoubleCheck from './xjdw_DoubleCheck.vue';
import xjdwOverdueAppeal from './xjdw_OverdueAppeal.vue';
import xjdwPblmView from './xjdw_pblmView.vue';
import xjdwUnderRectify from './xjdw_UnderRectify.vue';
import xjdwOverDate from './xjdwOverDate.vue';
export default {
  components: {
    xjdwUnderRectify,
    xjdwPblmView,
    xjdwDoubleCheck,
    xjdwOverdueAppeal,
    xjdwOverDate,
  },
  props: [],
  data() {
    return {
      tabsForXjdw: [],
      activatedTab: 'none',
      pType: 1,
      userId: localStorage.getItem('persId'),
      visible: false,
      readOnlyRole: localStorage.getItem('readOnlyRole'),
    };
  },
  created() {
    this.showConfirm();
    setTimeout(() => {
      this.visible = true;
    }, 200);
    this.getAuthenticatedTabs(this.userId, tabsForXjdw);
  },
  methods: {
    showConfirm() {
      this.$confirm({
        title: '提示',
        content: () =>
          h(
            'div',
            { style: { color: 'red' } },
            '2026年1月起，取消问题超期记录申诉功能，请大家积极按期完成整改！',
          ),
        keyboard: false,
        cancelButtonProps: { style: { display: 'none' } },
        onOk() {
          console.log('OK');
        },
      });
    },
    handleTabClick(tab, event) {
      this.activatedTab = tab.name;
    },
    getAuthenticatedTabs(userId, tabs) {
      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 (flag) {
            authenticatedTabs = tabs;
          }
          // 去除重复的标签
          authenticatedTabs = distinct(authenticatedTabs);

          if (this.readOnlyRole == 'hide') {
            this.tabsForXjdw = [
              {
                value: 'xjdwPblmView',
                label: '问题查看',
                roles: [], // 督查处所有角色可见
              },
            ];
          } else {
            this.tabsForXjdw = authenticatedTabs;
          }

          if (authenticatedTabs.length > 0) {
            this.activatedTab = this.tabsForXjdw[0].value; // 默认显示第一个标签
          }
        }
      });
    },
    handleCancel() {
      this.visible = false;
    },
  },
};
</script>

<style lang='less' scoped>

</style>
