<!-- 企业信息设置 -->
<template>
  <div>
    <!-- v-if="completeNum !== tabList?.length"  -->
    <div class="white-bgc mb-3">
      <ProgressBar
        label="企业信息填写完成度："
        :num="completeNum"
        :total="tabList?.length"
        :fontSize="14"
        :inlineDisplay="true"
        style="width: 350px;"
      ></ProgressBar>
    </div>
    <v-card class="card-box pa-5" style="min-height: 500px">
      <v-tabs v-model="tab" @update:model-value="handleTabClick" align-tabs="start" color="primary" bg-color="#f7f8fa">
        <v-tab v-for="val in tabList" :key="val.value" :value="val.value" >
          {{ val.label }}
          <template v-slot:append>
            <template v-if="val.status === false">
              <v-icon color="orange">mdi-information-outline</v-icon>
              <v-tooltip activator="parent" location="top">请完善{{ val.label }}</v-tooltip>
            </template>
          </template>
        </v-tab>
      </v-tabs>
      <div class="mt-3">
        <template v-for="item in tabList" :key="item.id">
          <div v-show="item.value === tab">
            <component
              ref="tabRef"
              class="mb-3"
              :is="item.path"
              @complete="complete"
              @change="val => tab = val"
            />
          </div>
        </template>
      </div>
      <!-- <v-window v-model="tab" class="mt-3">
        <v-window-item :value="val.value" v-for="val in tabList" :key="val.value">
          <component :is="val.path" ref="tabRef"></component>
        </v-window-item>
      </v-window> -->
    </v-card>
  </div>
</template>

<script setup>
defineOptions({ name: 'enterprise-system-management-information-settings'})
import basicInfo from './informationSettingsComponents/basicInfo.vue'
import enterpriseLogo from './informationSettingsComponents/enterpriseLogo.vue'
import enterpriseAlbum from './informationSettingsComponents/enterpriseAlbum.vue'
import welfareLabel from './informationSettingsComponents/welfareLabel.vue'
import enterpriseLabel from './informationSettingsComponents/enterpriseLabel.vue'
import businessInformation from './informationSettingsComponents/businessInformation.vue'
import authentication from './informationSettingsComponents/authentication.vue'
import ProgressBar from '@/components/ProgressBar'
import { ref, shallowRef, watch } from 'vue'
import { 
  useRoute, 
  // useRouter
} from 'vue-router'
import { useI18n } from '@/hooks/web/useI18n'

const route = useRoute()
// const router = useRouter()
const { t } = useI18n()
// tab
const tabRef = shallowRef()
const tab = ref(1)
const tabList = ref([
  { label: t('enterprise.infoSetting.basicInfo'), value: 1, path: basicInfo, id: 'basicInfo' },
  { label: t('enterprise.infoSetting.enterpriseLogo'), value: 2, path: enterpriseLogo, id: 'enterpriseLogo' },
  { label: t('enterprise.infoSetting.enterpriseAlbum'), value: 3, path: enterpriseAlbum, id: 'enterpriseAlbum' },
  { label: t('enterprise.infoSetting.welfareLabel'), value: 4, path: welfareLabel, id: 'welfareLabel' },
  { label: t('enterprise.infoSetting.enterpriseLabel'), value: 7, path: enterpriseLabel, id: 'enterpriseLabel' },
  { label: t('enterprise.infoSetting.businessInformation'), value: 5, path: businessInformation, id: 'businessInformation' },
  { label: t('setting.realNameAuthentication'), value: 6, path: authentication, id: 'authentication' },
])

watch(() => route?.query?.tabKey, (newVal) => { // newQuery, oldQuery
  if (newVal) tab.value = newVal - 0
}, { deep: true, immediate: true })

const handleTabClick = () => {
  // 基本信息-获取企业管理员实名认证信息
  // if (tab.value === 1) {
  //   tabRef.value[0].getAuthInfo()
  // }
  // router.push(`${route.path}?tabKey=${tab.value.toString()}`)
}

const completeNum = ref(0)
const complete = (val) => {
  if (!val?.id) return
  completeNum.value = 0
  tabList.value.forEach(e => {
    if (e.id === val.id) {
      e.status = val.status || false
    }
    if (e.status) {
      completeNum.value++
    }
  })
}
</script>

<style scoped lang="scss">
.topTip {
  background-color: #f7f8fa;
  color: #2f3640;
  padding: 12px 20px;
  margin: 10px 0 20px;
  font-size: 14px;
}
</style>
