<template>
  <div class="index">
    <el-row>
      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
        <el-col :span="24" class="one">认证入驻 </el-col>
        <el-col :span="24" class="two">
          <el-select v-model="activeName" placeholder="请选择认证角色类型" size="large" style="width: 240px">
            <el-option v-for="item in roleList" :key="item.code" :label="item.title" :value="item.code" />
          </el-select>
        </el-col>
        <el-col :span="24" class="thr">
          <expert v-if="activeName == 'Expert'"></expert>
          <company v-if="activeName == 'Company'"></company>
          <incubator v-if="activeName == 'Incubator'"></incubator>
          <competition v-if="activeName == 'Competition'"></competition>
          <investment v-if="activeName == 'Investment'"></investment>
          <association v-if="activeName == 'Association'"></association>
          <school v-if="activeName == 'School'"></school>
          <state v-if="activeName == 'State'"></state>
          <unit v-if="activeName == 'Unit'"></unit>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { cloneDeep } from 'lodash-es'

const $checkRes = inject('$checkRes')
import { UserStore } from '@/store/user'
const userStore = UserStore()
const user = computed(() => userStore.user)
// 组件
import school from './parts/school.vue'
import association from './parts/association.vue'
import company from './parts/company.vue'
import competition from './parts/competition.vue'
import expert from './parts/expert.vue'
import incubator from './parts/incubator.vue'
import state from './parts/state.vue'
import unit from './parts/unit.vue'
import investment from './parts/investment.vue'

// 接口
import { RoleStore } from '@/store/api/system/role'
const roleStore = RoleStore()
import { UsersStore } from '@/store/api/user/user'
const store = UsersStore()
import { DictDataStore } from '@/store/api/system/dictData'
import { RegionStore } from '@/store/api/system/region'
import { SectorStore } from '@/store/api/platform/sector'
const sectorStore = SectorStore()
const dictDataStore = DictDataStore()
const regionStore = RegionStore()

const activeName = ref('')
// 加载中
const loading = ref(false)
// 字典
const roleList = ref([])
const typeList = ref([])
const genderList = ref([])
const fieldList = ref([])
const educationList = ref([])
const cityList = ref([])
const isUseList = ref([])
const patternList = ref([])
const scaleList = ref([])
const IndustryList = ref([])
const cardTypeList = ref([])
const contributionList = ref([])
const plateList = ref([])
const modeList = ref([])
const statusList = ref([])
const yearList = ref([])
// 请求
onMounted(async () => {
  loading.value = true
  await search()
  await searchOther()
  loading.value = false
})
const searchOther = async () => {
  let result
  // 角色
  result = await roleStore.prove({ user: user.value.id })
  if ($checkRes(result)) {
    roleList.value = result.data
    activeName.value = result.data[0].code
  }
  // 性别
  result = await dictDataStore.query({ code: 'gender', is_use: '0' })
  if ($checkRes(result)) genderList.value = result.data
  // 用户类型
  result = await dictDataStore.query({ code: 'userType', is_use: '0' })
  if ($checkRes(result)) typeList.value = result.data
  // 专家领域
  result = await dictDataStore.query({ code: 'field', is_use: '0' })
  if ($checkRes(result)) fieldList.value = result.data
  // 企业类型
  result = await dictDataStore.query({ code: 'companyType', is_use: '0' })
  if ($checkRes(result)) patternList.value = result.data
  // 企业规模
  result = await dictDataStore.query({ code: 'companyScale', is_use: '0' })
  if ($checkRes(result)) scaleList.value = result.data
  // 企业所属行业
  result = await dictDataStore.query({ code: 'companyIndustry', is_use: '0' })
  if ($checkRes(result)) IndustryList.value = result.data
  // 学历
  result = await dictDataStore.query({ code: 'education', is_use: '0' })
  if ($checkRes(result)) educationList.value = result.data
  // 证件类型
  result = await dictDataStore.query({ code: 'cardType', is_use: '0' })
  if ($checkRes(result)) cardTypeList.value = result.data
  // 出资方式
  result = await dictDataStore.query({ code: 'contribution', is_use: '0' })
  if ($checkRes(result)) contributionList.value = result.data
  // 是否使用
  result = await dictDataStore.query({ code: 'isUse', is_use: '0' })
  if ($checkRes(result)) isUseList.value = result.data
  // 城市
  result = await regionStore.area({ level: 'province', code: 22 })
  if ($checkRes(result)) cityList.value = result.data
  // 板块
  result = await sectorStore.query({ is_use: '0' })
  if ($checkRes(result)) plateList.value = result.data
  // 盈利模式
  result = await dictDataStore.query({ code: 'modeType', is_use: '0' })
  if ($checkRes(result)) modeList.value = result.data
  // 状态
  result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  if ($checkRes(result)) statusList.value = result.data
  // 年度
  result = await dictDataStore.query({ code: 'year', is_use: '0' })
  if ($checkRes(result)) yearList.value = result.data
}
const search = async () => {
  if (user.value.id) {
    let res = await store.detail(user.value.id)
    if (res.errcode == '0') userStore.setUser(res.data)
  }
}

// provide
provide('cloneDeep', cloneDeep)
// 字典
provide('genderList', genderList)
provide('fieldList', fieldList)
provide('educationList', educationList)
provide('cityList', cityList)
provide('isUseList', isUseList)
provide('patternList', patternList)
provide('scaleList', scaleList)
provide('IndustryList', IndustryList)
provide('cardTypeList', cardTypeList)
provide('contributionList', contributionList)
provide('plateList', plateList)
provide('modeList', modeList)
provide('yearList', yearList)
provide('statusList', statusList)
</script>
<style scoped lang="scss">
.main {
  .one {
    font-size: $global-font-size-20;
    font-weight: 700;
    margin: 0 0 20px 0;
  }
  .thr {
    padding: 20px;
  }
}
</style>
