<script lang="jsx" >
import { defineComponent, inject, ref } from 'vue';
import { filterEnum, handleRowAccordToProp, formatValue, handleProp } from '@/utils/util'

export default defineComponent({
    props: {
        column: {
            tyep: Object,
            default: () => ({})
        }
    },
    setup(props, { emit, slots }) {
        const enumMap = inject("enumMap", ref(new Map()))
        
        // 渲染表格数据
        const renderCellData = (item, scope) => {
            return enumMap.value.get(item.prop) 
            ? filterEnum(handleRowAccordToProp(scope.row, item.prop), enumMap.value.get(item.prop), item.fieldNames) 
            : formatValue(handleRowAccordToProp(scope.row, item.prop))
        }

        const { column } = props
        return () => (
            <>
                <el-table-column {...column} showOverflowTooltip={column?.showOverflowTooltip ?? false } align={column.align ?? 'left'}>
                    {{
                        default: (scope) => {
                            if (column.render) return column.render(scope); //执行render函数
                            if(slots[handleProp(column.prop)]) return slots[handleProp(column.prop)](scope) //执行具名插槽
                            return renderCellData(column, scope)
                        }
                    }}
                </el-table-column>
            </>
        )
    }
})

</script>


<style scoped></style>