<!--
@ 作者: 秦东
@ 时间: 2025-06-10 16:04:34
@ 备注: 下来组件
-->
<script lang='ts' setup>
import { AnalysisCss,AnalysisInputCss } from '@/api/common/cssInfo'
import { 
    formatNumber,
    constFormProps
} from '@/api/lowCode/utils';
const props = withDefaults(
    defineProps<{
		data: FormList
		tablekey: any
		numrun?: number
		modelValue?: any // 子表和弹性布局时时有传
		tProp?: string // 子表时的form-item的prop值，用于子表校验用
		types?:number
        control:any
    }>(),
    {}
)
const emits = defineEmits(['update:modelValue','pageIdAry'])
const formProps = inject(constFormProps, {}) as any
const config = computed(() => {
    return props.data.config || {}
})
const type = computed(() => {
    return formProps.value.type
})
const value = computed({
	get: () => {
		return props.modelValue
	},
	set: (newVal: any) => {
		emits('update:modelValue', newVal)
	},
});
/**
@ 作者: 秦东
@ 时间: 2025-06-10 14:25:01
@ 功能: 获取组件名称
*/
const getLabel = (val:any) => {
    if(val.label){
        return val.label;
    }else{
        return "";
    }
    
}
/**
@ 作者: 秦东
@ 时间: 2024-11-13 14:36:08
@ 功能: 解析css
*/
const getFormItemLableStyle = (ele: any) => {
    if(ele?.labelStyle){ 
    //   console.log("返回栅格宽度3",AnalysisCss(ele))
    	return AnalysisCss(ele?.labelStyle)
    }
}
const getFormItemInputStyle = (ele: any,sty:number) => {
    if(ele?.inputStyle){
    //   console.log("返回栅格宽度4",AnalysisInputCss(ele?.inputStyle,sty))
      return AnalysisInputCss(ele?.inputStyle,sty)
    }
}
/**
@ 作者: 秦东
@ 时间: 2024-07-27 15:11:42
@ 功能: 判断是否禁用
*/
const judgeIsDisabled = (key:string)  => {
    return false
	if (type.value === 3) {
      	return true // 查看模式，为不可编辑状态
    }
    if (type.value === 1 && config.value.addDisabled) {
      	return true
    }
    if (type.value === 2 && config.value.editDisabled) {
      	return true // 编辑模式
    }
	if(props.nodeKey != undefined && props.purview != undefined && props.purview != null && props.purview != null && props.purview != "" && props.purview != "") {
		if(props.purview.length < 1){
			return false;
		}else{
			let isShow = true;
			props.purview.forEach((item)=>{
				if(item.nodeKey == props.nodeKey){
					
					if(item.powerAry && item.powerAry.length > 0){
						item.powerAry.forEach((itm)=>{
							if(itm.id == key){
								console.log("判断此组件是否禁用",itm,itm.id == key,"--------->",itm.isLook)
								isShow =  !itm.isEdit
								
							}
						})
					}
				}
				
			})
			return isShow
		}
	}else{
		return false;
	}
}
/****input slot处理***/
const getInputSlot = (key?: string) => {
    const slot = key === 'p' ? config.value.prepend : config.value.append
    const has = slot.indexOf('key:') === 0
    if (!has) {
      	return false
    }
    const slotKey = slot.replace('key:', '')
    const control = getControlByName(slotKey)
    if (!control || Object.keys(control)?.length === 0) {
      	return false
    }
    return control
}
// 选择数据转换，默认尝试转数字
const transformOption = (val: string | number, type?: string) => {
    switch (config.value.transformData || type) {
		case 'none':
				return val
		case 'string':
			try {
				return val.toString()
			} catch (e) {
				return val
			}
    }
    return formatNumber(val)
}
/**
@ 作者: 秦东
@ 时间: 2025-06-10 11:13:06
@ 功能: 输出结果
*/
const valPrint = (val:any[],orgList:any[]) => {
	
    if(Array.isArray(val)){
        let title = new Array
        if(Array.isArray(orgList)){
            val.forEach((vitem: any) => {
                orgList.forEach((item: any) => {
                    if(vitem==item.value){
                        title.push(item.label)
                    }
                })
            })
        }
        if(title.length>0){
            return title.join("、")
        }else{
            return ""
        }
        
    }else{
        let title = ""
        if(Array.isArray(orgList)){
            orgList.forEach((item: any) => {
                if(item.value==val){
                    title =  item.label
                }
            })
	    }
        return title
    }
	
}
</script>
<template>
    <SelectDesign 
                    v-if="props.types!=3"
                    :data="data"
                    :disabled="judgeIsDisabled(data.name)"
                    v-model="value"
                    :options="props.data.options"
                    :remote-method="getAxiosOptions"
                    :transformOption="transformOption"
                    :placeholder="data.control.placeholder?data.control.placeholder:'请选择'+getLabel(data.item)"
    />
<el-text v-else class="wordColor">{{valPrint(value,props.data.options)}}</el-text>
</template>
<style  lang='scss' scoped>
.wordColor{
	color:#000000;
}
</style>