<template>
  <span v-if="isLook">{{ select_look || '-' }}</span>
  <el-cascader
    v-else
    ref="tree"
    v-model="select"
    :options="options"
    :props="treeProps"
    :disabled="disabled"
    :show-all-levels="false"
    filterable
    clearable
  >
    <template #default="{ node, data }">
      <span>{{ data[field.label] }}</span>
      <!-- 需要拼装子级的处理 -->
      <span v-if="node.isLeaf && data.remark"> ({{ data.remark }}) </span>
    </template>
  </el-cascader>
</template>

<script setup lang="ts">
import { useOptions } from '../hooks/useOptions'

const props = defineProps({
  modelValue: {
    type: [String, Number, Array],
    default: () => ''
  },
  mode: {
    type: String,
    default: 'add'
  },
  formItem: {
    type: Object,
    default: () => {}
  },
  disabled: {
    type: Boolean,
    default: false
  }
})

const emits = defineEmits(['update:modelValue'])

const { options, field, isLook, select_look, select } = useOptions(props, emits)

const treeProps = {
  emitPath: false,
  multiple: props.formItem.isMultiple,
  value: field.value,
  label: field.label
}
</script>
