<template>
    <div>
        <div class="container">
            <el-form-item label="频率" label-width="80px">
                <el-input v-model="form[0].inHarmList[0].inharm" :disabled="!form[0].inHarmFlag" />
            </el-form-item>

            <el-form-item label="含有率(%)" label-width="80px">
                <el-input v-model="form[0].inHarmList[0].fAmp" :disabled="!form[0].inHarmFlag" />
            </el-form-item>

            <el-form-item label="相角(°)" label-width="80px">
                <el-input v-model="form[0].inHarmList[0].fphase" :disabled="!form[0].inHarmFlag" />
            </el-form-item>
            <el-form-item label-width="80px">
                <el-button type="primary" @click="inHarmFlagAdd">添加</el-button>
            </el-form-item>
        </div>
        <div class="container" v-for="item in num" :key="item">
            <el-form-item label="频率" label-width="80px">
                <el-input v-model="form[0].inHarmList[item].inharm" :disabled="!form[0].inHarmFlag" />
            </el-form-item>

            <el-form-item label="含有率(%)" label-width="80px">
                <el-input v-model="form[0].inHarmList[item].fAmp" :disabled="!form[0].inHarmFlag" />
            </el-form-item>

            <el-form-item label="相角(°)" label-width="80px">
                <el-input v-model="form[0].inHarmList[item].fphase" :disabled="!form[0].inHarmFlag" />
            </el-form-item>
            <el-form-item label-width="80px">
                <el-button type="primary" @click="inHarmFlagDelete(item)">删除</el-button>
            </el-form-item>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const props = defineProps({
    childForm: {
        type: Array,
        required: true
    }
})

const form: any = computed({
    get() {
        return props.childForm
    },
    set(value) {}
})
const num = ref(0)

// 添加间谐波
const inHarmFlagAdd = () => {
    props.childForm[0].inHarmList.push({ inharm: '0', fAmp: '0', fphase: '0' })
    num.value += 1
}
// 删除
const inHarmFlagDelete = (number: number) => {
    props.childForm[0].inHarmList.splice(number, 1)
    num.value -= 1
}
</script>

<style lang="scss" scoped>
.container {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #ccc;
    width: 100%;
    margin-top: 10px;
    height: 40px;
}

.fixed-width-tabs:last-child {
    margin-right: 0; /* 最后一个 el-tabs 不需要右侧间距 */
}

.el-tab-pane {
    display: flex;
    flex-direction: column; /* 确保内容上下排列 */
}

.el-form-item {
    margin-bottom: 20px; /* 可选：添加表单项之间的间距 */
}
:deep(.el-form-item) {
    margin-bottom: 10px !important;
}
</style>
