<template>
  <div class="default-width mb-6 d-flex align-center justify-center">
    <span class="mr-2 color-primary" style="width: 80px; min-width: 80px;">{{ $t('position.popularPosition') }}：</span>
    <div style="overflow: hidden; height: 40px; ">
      <span v-for="(item, index) in jobs" :key="index" label size="small" class="mr-2 my-1 tag"  @click.stop="handleClick(item)">{{ item.nameCn }}</span>
    </div>
  </div>
</template>

<script setup>
import { getHotPositionList } from '@/api/common/index'
import { useRouter } from 'vue-router'
import Snackbar from '@/plugins/snackbar'
import { ref } from 'vue';
defineOptions({ name:'personal-hotJobs-list'})
const router = useRouter()


const handleClick = (item) => { 
  if (!item?.id) {
    console.log('岗位信息失效 岗位id不存在')
    return Snackbar.warning('岗位信息失效，请更换岗位查看详情')
  }
  window.open('/recruit/personal/position?positionId=' + item.id)
 }

// 获取行业树形
let jobs = ref(null)
const getTreeData = async () => {
  const res = await getHotPositionList()
  jobs.value = res.splice(0, 10) || []
}
getTreeData()
</script>

<style lang="scss" scoped>
.tag {
  background-color: #fff !important;
  color: var(--v-primary-base);
  padding: 5px 20px;
  display: inline-block;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
}
</style>