<template>

    <div :style="{ height: height }">
        <vxe-table height="auto" auto-resize :data="dataList" v-bind="defaultAttribute" :key="key">
            <vxe-column v-for="item in column" :field="item.field" :title="item.title"></vxe-column>
            < <!-- <vxe-column field="valueM" title=""></vxe-column> -->
        </vxe-table>
    </div>

</template>
<script setup lang='ts'>
import { mainHeight } from '@/utils/layout'
import { ref, reactive } from 'vue'
import { defaultAttribute } from '@/components/table/defaultAttribute'
const props = defineProps(['tableData'])
const height = mainHeight(325).height
const dataList = ref([])
const key: any = ref(0)
const column: any = ref([])
const setData = (data: any, targetType: any) => {

    dataList.value = JSON.parse(JSON.stringify(data))

    console.log("🚀 ~ setData ~ targetType:", targetType[0].code)
    if (targetType[0].code == 'base_data') {
        column.value = [
            { field: 'otherName', title: '名称', },
            { field: 'valueA', title: 'A相', },
            { field: 'valueB', title: 'B相', },
            { field: 'valueC', title: 'C相', },
        ]
    } else if (targetType[0].code == 'other_data') {
        let list: any = []
        data.forEach((item: any, i: any) => {
            if (i % 2 == 0) {
                list.push(item)
            } else {
                list[list.length - 1].otherName1 = item.otherName
                list[list.length - 1].valueM1 = item.valueM
            }

        })

        dataList.value = JSON.parse(JSON.stringify(list))

        column.value = [
            { field: 'otherName', title: '名称', },
            { field: 'valueM', title: '', },
            { field: 'otherName1', title: '名称', },
            { field: 'valueM1', title: '', },
        ]
    } else {
        column.value = [
            { field: 'otherName', title: '谐波次数', },
            { field: 'valueA', title: 'A相', },
            { field: 'valueB', title: 'B相', },
            { field: 'valueC', title: 'C相', },
        ]
    }
    key.value += 1
}


defineExpose({ setData })
</script>
<style lang="scss" scoped></style>
