<template>
  <el-select
    :persistent="false"
    v-model="modelValue.types"
    popper-class="drop-type-actions"
  >
    <el-option
      v-for="item in getActionOptions"
      v-permission="item.permissions"
      :key="item.value"
      :label="item.label"
      :value="item.value"
      @click="handleClickChange(modelValue,disabledArr,item)"
      :disabled="disabledArr?.includes(item.value) && item.isDisabled"
    >
      <template v-if="item.value === BaseActiveFlag.FEESET_ACTIVE">
        <el-button
          :type="item.type"
          :color="item.color"
          :icon="item.icon"
          :disabled="disabledArr?.includes(item.value) && item.isDisabled"
          class="block"
        >
          <slot name="islabel" :item="item"></slot>
          <!-- {{ currentRow.activeFlag ? item.islabel : item.label }} -->
        </el-button>
      </template>
      <template v-else>
        <el-tooltip
          :disabled="!(item.disabledText) || !disabledArr?.includes(item.value)"
          :content="item.disabledText"
          placement="left"
        >
          <el-button
            :type="item.type"
            :color="item.color"
            :icon="item.icon"
            :disabled="disabledArr?.includes(item.value) && item.isDisabled"
            class="block"
          >
            {{ item.label }}
          </el-button>
        </el-tooltip>
      </template>
    </el-option>
  </el-select>
</template>
  
<script lang="ts" setup>
import type { ActionOptions } from './type';
import { BaseActiveFlag } from '@/type/BaseActiveFlag';
import { computed, unref } from 'vue';

const props = defineProps<{
  modelValue: Recordable,//当前行的响应数据
  actionOptions: ActionOptions[],//按钮组的数据
  disabledArr?: (number| string)[],//是否禁用按钮的状态
  isShowArr?: (number| string)[],//是否隐藏按钮的状态
}>()
const emit = defineEmits(['update:modelValue', 'clickChange'])
// const selectValue = computed({
//   get() {
//     return props.modelValue
//   },
//   set(value) {
//     emit('update:modelValue', value)
//   }
// })
// 是否隐藏按钮
const getIsShowArr = computed(() => {
  return props.isShowArr || []
})
// 处理是否隐藏对应按钮
const getActionOptions = computed(() => {
  const actionOptions = props.actionOptions
  const newActionOptions = actionOptions.filter((item) => !unref(getIsShowArr).includes(item.value))
  return newActionOptions
})
// 点击下拉框的值
const handleClickChange = (data: Recordable,disabledArr,item) => {
  if(disabledArr?.includes(item.value)) return
  emit('clickChange', data)
}
</script>
<style lang="scss">
.drop-type-actions {
  width: 110px;
  margin-right: 10px;
  .el-select-dropdown__wrap {
    .el-select-dropdown__item {
      padding: 0;
    }
  }

  .block {
    width: 100%;
    color: #fff;
  }
}
.drop-type-actions .el-select-dropdown__wrap {
  max-height: 560px;
}
</style>