1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <script setup>
- import {apiSystemUser} from '@/api/system'
- const model=defineModel()
- const props=defineProps({
- props:{},
- clearable:{
- type:Boolean,
- default:false
- },
- filterable:{
- type:Boolean,
- default:true
- },
- placeholder:{
- type:String,
- default:'营业部/销售'
- },
- onlySelectUser:{//是否只能选择销售用户
- type:Boolean,
- default:false
- }
- })
- const emits=defineEmits(['change'])
- const options=ref([])
- function formatData(arr){
- arr.forEach(item => {
- item.label=item.SysUserId?item.SysRealName:item.SysDepartmentName
- item.value=item.SysUserId?item.SysUserId:item.SysDepartmentId
- if(props.onlySelectUser){//如果只能选择销售用户则将最后一级为部门的禁用
- item.disabled=!item.SysUserId&&!item.ChildrenList?true:false
- }
-
- if(item.ChildrenList){
- formatData(item.ChildrenList)
- }
- });
- return arr
- }
- async function getData(){
- const res=await apiSystemUser.allUserForDepart({AllEnabled:false})//true显示所有销售(包含被禁用的)false表示仅显示启用的用户,默认false
- 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: 'value',
- label: 'label',
- children: 'ChildrenList',
- ...props.props
- }"
- v-model="model"
- :placeholder="props.placeholder"
- collapse-tags
- :clearable="clearable"
- :filterable="filterable"
- @change="handleChange"
- />
- </template>
|