<template>
  <commonStyle :btnTitle="title" :close-on-content-click="false">
    <industryTypeCard :select="selectedItems" @handleClickIndustry="handle"></industryTypeCard>
  </commonStyle>
</template>

<script setup>
import commonStyle from './commonStyle.vue'
import industryTypeCard from '@/components/industryTypeCard'
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.industryIds) {
  const str = query.industryIds.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: selectedItems.value, isEmit: true })
}
</script>

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