<!--
@ 作者: 秦东
@ 时间: 2025-06-10 14:20:12
@ 备注: 多行文本
-->
<script lang='ts' setup>
import { FormList } from '@/api/lowCode/form/type';
import { 
    constFormProps
} from '@/api/lowCode/utils';
import { nodePoweInfo,powerAryInfo } from '@/api/workFlow/type'
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 "";
    }
    
}

//获取阶段权限判断
const allNodePwoer = inject('flowNodePower')  as any
const currentNodePowerKey = inject('currentNodeKey') as any

//获取当前节点授权
const curNodePowerAry = () => {
  if(currentNodePowerKey && currentNodePowerKey.value && currentNodePowerKey.value != ""){
    if(allNodePwoer.value && Array.isArray(allNodePwoer.value) && allNodePwoer.value.length > 0){
      let powerAry: any[] = []
      allNodePwoer.value.forEach((item:nodePoweInfo) => {
        if(item.nodeKey == currentNodePowerKey.value){
          powerAry = item.powerAry
        }
      })
      return powerAry
    }else{
      return []
    }
  }else{
    return []
  }
}
/**
@ 作者: 秦东
@ 时间: 2025-11-06 14:03:21
@ 功能: 判断此组件是否可见
*/
const judgeIsShow = (key: string) => {
  let myPower = curNodePowerAry()     //获取权限数组
  if(Array.isArray(myPower) && myPower.length > 0){
    let isOk = true
    myPower.forEach((item:powerAryInfo) => {
      if(key == item.id){
        isOk = item.isLook
      }
    })
    return isOk
  }else{
    return true
  }
}
/**
@ 作者: 秦东
@ 时间: 2025-11-06 14:03:21
@ 功能: 判断此组件是否可编辑
*/
const judgeIsEdit = (key: string) => {
  let myPower = curNodePowerAry()     //获取权限数组
  if(Array.isArray(myPower) && myPower.length > 0){
    let isOk = false
    myPower.forEach((item:powerAryInfo) => {
      if(key == item.id){
        isOk = !item.isEdit
      }
    })
    return isOk
  }else{
    return false
  }
}
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 // 编辑模式
    }
    let myPower = curNodePowerAry()     //获取权限数组
    if(Array.isArray(myPower) && myPower.length > 0){
        let isOk = false
        myPower.forEach((item:powerAryInfo) => {
        if(key == item.id){
            isOk = !item.isEdit
        }
        })
        return isOk
    }else{
        return false
    }
}
</script>
<template>
    <el-input
        v-if="props.types!=3&&judgeIsShow(data.name)"
        v-bind="props.control"
        v-model="value"
        type="textarea"
        :autosize="{ minRows: 2, maxRows: 20 }"
        :placeholder="data.control.placeholder?data.control.placeholder:'请输入'+getLabel(data.item)" 
        :disabled="judgeIsDisabled(data.name)"    
    />
    <el-text v-else class="wordColor">{{value}}</el-text>
</template>
<style  lang='scss' scoped>
.wordColor{
	color:#000000;
}
</style>