<style>
.search-btn .not-type-btn:hover {
  background: #00a0e9;
  border-color: #00a0e9;
}
.config_home {
  background: #f0f2f5;
  padding: 10px;
  margin: -10px;
  overflow-y: hidden;
}
</style>
<template>
  <div class="layout-content-padding">
    <div class="layout-content-main">
<!--      <Row :gutter="10">-->
<!--        <Col span="12">-->
<!--          <messagePanel></messagePanel>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <myTask></myTask>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <taskCalendar></taskCalendar>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <UnfinishedContract></UnfinishedContract>-->
<!--        </Col>-->
<!--        <Col span="24">-->
<!--        <SampleProgress style="margin-bottom: 20px;"></SampleProgress>-->
<!--        </Col>-->
<!--        <Col span="24" style="margin-bottom: 10px;">-->
<!--          <SampleProgressDetail></SampleProgressDetail>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <UnfinishedItem></UnfinishedItem>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <YearContractNum></YearContractNum>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <DetectTypeNum></DetectTypeNum>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <ContractEndNum></ContractEndNum>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <YearTestItem></YearTestItem>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <YearOverItem></YearOverItem>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <GroupItem></GroupItem>-->
<!--        </Col>-->
<!--        <Col span="12">-->
<!--          <CustomerContract></CustomerContract>-->
<!--        </Col>-->
<!--      <Col span="24">-->
<!--        <ItemFlow></ItemFlow>-->
<!--      </Col>-->
      <div v-if="moduleList.length" class="config_home">
        <Row :gutter="10">
          <Col
            :sm="{span:item.alias === 'SampleProgress'||item.alias === 'SampleProgressDetail'||item.alias === 'ItemFlow' ?24:12}"
            v-for="(item,index) in finalList"
            :key="index"
            style="margin-bottom: 10px">
            <!-- eslint-disable-next-line vue/require-component-is -->
            <component :is="item.alias" @on-result-change="_result" keep-alive></component>
          </Col>
        </Row>
      </div>
    </div>
  </div>
</template>
<script>
import Global from '../../api/config'
import { sysOrg, sysUser } from '../../api'
import statisticalPanel from './statisticalPanel'
import messagePanel from './messagePanel'
import toDoTask from './ToDoTask'
import myTask from './MyTask'
import TaskFlow from './TaskFlow'
import taskCalendar from './task-calendar/TaskCalendar'
import UnfinishedContract from './UnfinishedContract'
import UnfinishedItem from './UnfinishedItem'
import YearContractNum from './YearContractNum'
import DetectTypeNum from './DetectTypeNum'
import ContractEndNum from './ContractEndNum'
import YearTestItem from './YearTestItem'
import YearOverItem from './YearOverItem'
import GroupItem from './GroupItem'
import CustomerContract from './CustomerContract'
import SampleProgress from './sample-progress/SampleProgress'
import SampleProgressDetail from './SampleProgressDetail'
import ItemFlow from './ItemFlowIndex'
export default {
  name: 'Workbench',
  components: {
    // eslint-disable-next-line vue/no-unused-components
    statisticalPanel,
    // eslint-disable-next-line vue/no-unused-components
    messagePanel,
    // eslint-disable-next-line vue/no-unused-components
    myTask,
    // eslint-disable-next-line vue/no-unused-components
    toDoTask,
    // eslint-disable-next-line vue/no-unused-components
    TaskFlow,
    // eslint-disable-next-line vue/no-unused-components
    taskCalendar,
    // eslint-disable-next-line vue/no-unused-components
    UnfinishedContract,
    // eslint-disable-next-line vue/no-unused-components
    UnfinishedItem,
    // eslint-disable-next-line vue/no-unused-components
    YearContractNum,
    // eslint-disable-next-line vue/no-unused-components
    DetectTypeNum,
    // eslint-disable-next-line vue/no-unused-components
    ContractEndNum,
    // eslint-disable-next-line vue/no-unused-components
    YearTestItem,
    // eslint-disable-next-line vue/no-unused-components
    YearOverItem,
    // eslint-disable-next-line vue/no-unused-components
    GroupItem,
    // eslint-disable-next-line vue/no-unused-components
    CustomerContract,
    // eslint-disable-next-line vue/no-unused-components
    SampleProgress,
    // eslint-disable-next-line vue/no-unused-components
    SampleProgressDetail,
    // eslint-disable-next-line vue/no-unused-components
    ItemFlow
  },
  data() {
    return {
      moduleList: [],
      userId: '',
      list: [],
      finalList: []
    }
  },
  mounted() {
    if (Global.getLn()) {
      this._getUserInfo()
    }
  },
  methods: {
    // 模块返回结果
    _result(module) {
      switch (module) {
        case 'FoodMyTask':
          this.$bus.emit('task-detail')
          break
      }
    },
    _open() {
      this._myModule()
    },
    _getUserInfo: async function() {
      const result = await sysUser.getUserInfo()
      if (result) {
        this.userId = result.id
        this._myModule()
      }
    },
    _myModule: async function() {
      const result = await sysOrg.getMenuByUserId(1304006677087891457)
      if (result) {
        console.log('菜单', result)
        const list = []
        for (let i = 0; i < result.length; i++) {
          if (result[i].status.display === '正常') {
            list.push(result[i].id)
          }
        }
        this.list = list
        console.log('启用的模块', list)
        this._getModule()
      }
    },
    _getModule: async function() {
      this.finalList = []
      console.log('this.userId', this.userId)
      const result = await sysOrg.getModulesList()
      if (result) {
        this.moduleList = result
        for (let i = 0; i < this.list.length; i++) {
          console.log(
            this.moduleList.findIndex(item => item.id === this.list[i])
          )
          this.finalList.push(
            this.moduleList[
              this.moduleList.findIndex(item => item.id === this.list[i])
            ]
          )
        }
        console.log(this.finalList)
        console.log('菜单', result)
      }
    }
  }
}
</script>

<style scoped>
</style>
