<template>
  <div style="width: 100%;height: 100%;">
    <dashboard-person v-if="isReport && !isUnit" />
    <dashboard-expert v-if="isExpert && !isUnit" />
    <dashboard-unit v-if="isUnit" />
    <dashboard-gov v-if="isGov" />
    <dashboard-top v-if="isTop" />
    <dashboard-admin v-if="isAdmin" />
    <a-modal v-model="visibleUnitEdit" v-if="visibleUnitEdit" title="请先完善单位信息！" width="70%" :dialog-style="{ top: '12%' }" :footer="null" destroyOnClose :maskClosable="false" :closable="false">
      <unit-info-edit @sub="unitSave" />
    </a-modal>
  </div>
</template>
<script>
import { getUnitComplete, setUnitComplete } from '@/views/utils/auth'
import dashboardPerson from '@/views/home/components/dashboardPerson'
import dashboardExpert from '@/views/home/components/dashboardPerson'
import dashboardUnit from '@/views/home/components/dashboardUnit'
import dashboardGov from '@/views/home/components/dashboardGov'
import dashboardTop from '@/views/home/components/dashboardTop'
import dashboardAdmin from '@/views/home/components/dashboardAdmin'
import unitInfoEdit from '@/views/basicSetting/unit/edit'
export default {
  components: { dashboardPerson, dashboardExpert, dashboardUnit, dashboardGov, dashboardTop, dashboardAdmin, unitInfoEdit },
  data () {
    return {
      isTop: false,
      isGov: false,
      isUnit: false,
      isReport: false,
      isAdmin: false,
      isExpert: false,
      isUnitComplete: getUnitComplete(),
      visibleUnitEdit: false,
    };
  },
  created () {
    let user = JSON.parse(window.sessionStorage.getItem('user'))
    if (user && user.roles) {
      if (user.roles.indexOf("0") != -1) {
        this.isTop = true
      } else if (user.roles.indexOf("1") != -1) {
        this.isGov = true
      } else if (user.roles.indexOf("2") != -1) {
        this.isUnit = true
        if (!this.isUnitComplete) {
          this.visibleUnitEdit = true
        }
      } else if (user.roles.indexOf("3") != -1) {
        this.isReport = true
      } else if (user.roles.indexOf("4") != -1) {
        this.isAdmin = true
      } else if (user.roles.indexOf("5") != -1) {
        this.isExpert = true
      }
    }
  },
  methods: {
    unitSave () {
      setUnitComplete(true)
      this.isUnitComplete = true
      this.visibleUnitEdit = false
    }
  },
};
</script>
<style scoped lang="less">
</style>

