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

<script>
import { h } from 'vue';
import request from '../../utils/gw_ajax_request';
import { distinct, requestUserRole } from './Common/rectify_api';
import { tabsForYwcc } from './Common/tabsForRectify';
import ywccDoubleCheck from './ywcc_DoubleCheck.vue';
import ywccDispatchPblm from './ywcc_disptachPblm.vue';
import ywccPblmView from './ywcc_pblmView.vue';
import ywccPendingApprove from './ywcc_pendingApprove.vue';
export default {
  data() {
    return {
      tabsForYwcc: [
        {
          value: 'ywccPendingApprove',
          label: '待审核问题',
          isShow: false,
        },
        {
          value: 'ywccDoubleCheck',
          label: '待复核问题',
          isShow: false,
        },
        {
          value: 'ywccPblmView',
          label: '问题查看',
          isShow: true,
        },
      ],
      ywTab: [
        {
          value: 'ywccPendingApprove',
          label: '待审核问题',
          isShow: false,
        },
        {
          value: 'ywccDoubleCheck',
          label: '待复核问题',
          isShow: false,
        },
        {
          value: 'ywccPblmView',
          label: '问题查看',
          isShow: true,
        },
      ],
      activatedTab: 'ywccPblmView',
      pType: 1,
      userId: localStorage.getItem('persId'),
      readOnlyRole: localStorage.getItem('readOnlyRole'),
    };
  },
  components: {
    ywccPblmView,
    ywccPendingApprove,
    ywccDispatchPblm,
    ywccDoubleCheck,
  },
  created() {
    this.showConfirm();
    this.getAuthenticatedTabs(this.userId, tabsForYwcc);
  },
  methods: {
    showConfirm() {
      this.$confirm({
        title: '提示',
        content: () =>
          h(
            'div',
            { style: { color: 'red' } },
            '问题超出5个工作日未审核，将推送公权力大数据平台预警，请知悉！',
          ),
        keyboard: false,
        cancelButtonProps: { style: { display: 'none' } },
        onOk() {
          console.log('OK');
        },
      });
    },
    handleTabClick(tab, event) {
      console.log(tab);
      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.tabsForYwcc = [
              {
                value: 'ywccPblmView',
                label: '问题查看',
                isShow: true,
              },
            ];
          } else {
            this.tabsForYwcc = authenticatedTabs;
          }
          if (authenticatedTabs.length > 0) {
            this.activatedTab = this.tabsForYwcc[0].value; // 默认显示第一个标签
          }
        }
      });
    },
    async getTabs() {
      await request.get(`dc/insp/pblm/pageSwitching`).then((res) => {
        this.ywTab[0].isShow = res.data.ywcsBlr;
        this.ywTab[1].isShow = res.data.ywcsShr;
        this.ywTab.forEach((item, index) => {
          if (!item.isShow) {
            this.ywTab.splice(index, 1);
          }
        });
        this.activatedTab = this.ywTab[0].value;
      });
    },
  },
};
</script>

<style lang='less' scoped>

</style>
