<template>
  <el-form-item label="查询类型">
    <avue-select v-model="option.findType" :dic="controlOption.dicObj.deptFindType"></avue-select>
  </el-form-item>
  <el-form-item label="回显名称格式化">
    <avue-select
      v-model="option.textFormatter"
      :dic="dictTextFormatter"
      filterable
      allowCreate
      placeholder="请选择回显名称格式化"
    ></avue-select>
  </el-form-item>
  <el-form-item label="自定义处理部门数据">
    <el-input
      v-model="option.deptCustomStr"
      readonly
      placeholder="自定义处理部门数据"
      @click="openEditView('deptCustomStr', '自定义处理部门数据')"
    ></el-input>
  </el-form-item>
  <el-form-item label="操作配置">
    <el-checkbox :key="option.prop" v-model="option.multiple"> 多选 </el-checkbox>
    <el-checkbox :key="option.prop" v-model="option.checkStrictly"> 父子不互相关联 </el-checkbox>
    <el-checkbox :key="option.prop" v-model="option.leafOnly"> 勾选值只保留子节点 </el-checkbox>
    <el-checkbox :key="option.prop" v-model="option.stopParent"> 禁用父级勾选 </el-checkbox>
    <el-checkbox :key="option.prop" v-model="option.accordion">
      每次只展开一个同级树节点
    </el-checkbox>
  </el-form-item>
  <div class="flex items-center gap-x-20px">
    <el-form-item label="分隔符" class="flex-1">
      <avue-input v-model="option.separator"> </avue-input>
    </el-form-item>
  </div>
</template>

<script setup lang="ts">
import { lowFormDesignKey, lowFormDesignType } from '@/utils/symbols'
import controlOption from '@/components/LowDesign/src/utils/controlOption'
import { dictTextFormatter } from '@/components/LowFormDesign/utils/util'

defineOptions({ name: 'ConfigDeptSelect' })

const props = defineProps({
  modelValue: Object
})

const emit = defineEmits(['update:modelValue', 'open-med', 'copy-text'])
const { example } = inject<lowFormDesignType>(lowFormDesignKey) as lowFormDesignType

const option = ref<any>(props.modelValue)

const openEditView = (prop, label) => {
  let params = {
    headerBtn: [
      {
        name: `复制配置示例`,
        icon: 'solar:copy-outline',
        clickFun: () => emit('copy-text', example.deptDisabledExample),
        params: { size: 'small', type: 'primary' }
      }
    ]
  }
  emit('open-med', { prop, label, params })
}

watch(
  () => props.modelValue,
  (val: object) => {
    option.value = val
  }
)
watch(
  () => option.value,
  (val: object) => {
    emit('update:modelValue', val)
  }
)
</script>

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