<template>
  <commonStyle :btnTitle="title" :close-on-content-click="true">
    <!-- 后端需要单选 -->
    <jobTypeCard :select="selectedItems" isSingle echo clearable @handleJobClick="handle"></jobTypeCard>
  </commonStyle>
</template>

<script setup>
import commonStyle from './commonStyle.vue'
import jobTypeCard from '@/components/jobTypeCard'
import { inject, ref } from 'vue'
defineOptions({name: 'conditionFilter-company-industry'})
const emits = defineEmits(['inputChange'])
const query = inject('routeQuery')
const props = defineProps({
  positionIndexPage: { // 职位检索
    type: Boolean,
    default: false
  }
})

const title = ref('职位类型')
const selectedItems = ref([])

if (query && query.positionId) {
  const str = query.positionId.split(',')[0]
  const arr = str.split('_')
  if (arr?.length) {
    selectedItems.value = arr
    title.value = selectedItems.value.length ? `职位类型(${selectedItems.value.length})` : '职位类型'
  }
}
const handle = (arr) => {
  selectedItems.value = arr
  title.value = selectedItems.value.length ? `职位类型(${selectedItems.value.length})` : '职位类型'
  if (props.positionIndexPage) emits('inputChange', selectedItems.value)
  else emits('inputChange', { values: arr.length ? arr[0] : '', isEmit: true })
}
</script>

<style lang="scss" scoped>
</style>
