<script setup>
import { apiCustomerUser } from '@/api/customer'

const model=defineModel()
const props=defineProps({
  props:{},
  clearable:{
    type:Boolean,
    default:false
  }
})
const emits=defineEmits(['change'])

const options=ref([])
function formatData(arr){
  arr.forEach(item => {
    let temarr=[]
    if(item.PublicChild){
      temarr=[...temarr,...item.PublicChild]
    }
    if(item.PrivateChild){
      temarr=[...temarr,...item.PrivateChild]
    }
    item.children=temarr
  });
  return arr
}

async function getData(){
  const res=await apiCustomerUser.userPermissionData()
  if(res.Ret!=200) return
  const arr=res.Data.List||[]
  options.value=formatData(arr)
}
getData()

function handleChange(){
  emits('change')
}

</script>
<template>
  <el-cascader
    :options="options"
    :props="{
      value: 'ChartPermissionId',
      label: 'PermissionName',
      children: 'children',
      ...props.props
    }"
    v-model="model"
    placeholder="品种"
    collapse-tags
    :clearable="clearable"
    @change="handleChange"
  />
</template>