<template>
  <commonStyle v-if="show" :btnTitle="title" :close-on-content-click="true">
    <v-list>
      <v-list-item
        color="primary"
        :active="selectedItems.includes(item.value)"
        v-for="item in items" :key="item.id" :value="item.value"
        @click="handle(item.value)"
      >
        <template v-if="selectedItems.includes(item.value)" v-slot:append>
          <v-icon icon="mdi-check"></v-icon>
        </template>
        <v-list-item-title>{{ item.label }}</v-list-item-title>
      </v-list-item>
    </v-list>
  </commonStyle>
</template>
<script setup>
import commonStyle from './commonStyle.vue'
import { getDict } from '@/hooks/web/useDictionaries'
import { ref, inject } from 'vue';
defineOptions({name: 'conditionFilter-payScope'})
const emits = defineEmits(['inputChange'])
const query = inject('routeQuery')
const props = defineProps({
  positionIndexPage: { // 职位检索
    type: Boolean,
    default: false
  }
})

const title = ref('薪资待遇')
const show = ref(false)
let items = ref()
let selectedItems = ref([])

getDict('menduner_pay_scope').then(({ data }) => {
  data = data?.length && data || []
  items.value = data
  if (query && query.payType) {
    title.value = '薪资待遇(1)'
    selectedItems.value = [query.payType]
    if (!props.positionIndexPage) emits('inputChange', { values: selectedItems.value, isEmit: true })
  }
  show.value = true
})
const handle = (val) => {
  if (selectedItems.value.includes(val)) {
    selectedItems.value = selectedItems.value.filter(i => i !== val)
  } else {
    selectedItems.value = [val]
  }
  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>
