<script setup lang="ts">
import { ref } from 'vue'

const channelList = ref([
    { no: 1, type: '4~20mA', line: '开出一', down: 1, up: 8,delay:8,isInput:'0' },
    { no: 2, type: '1~5V', line: '开出一', down: 1, up: 8,delay:8,isInput:'0' },
    { no: 3, type: '4~20mA', line: '开出一', down: 1, up: 8,delay:8,isInput:'0' },
    { no: 4, type: '1~5V', line: '开出一', down: 1, up: 8,delay:8,isInput:'0' },
    { no: 5, type: '4~20mA', line: '开出一', down: 1, up: 8,delay:8,isInput:'0' },
    { no: 6, type: '1~5V', line: '开出一', down: 1, up: 8,delay:8,isInput:'1' },
    { no: 7, type: '4~20mA', line: '开出一', down: 1, up: 8,delay:8,isInput:'1' },
    { no: 8, type: '1~5V', line: '开出一', down: 1, up: 8,delay:8,isInput:'1' },
    { no: 9, type: '1~5V', line: '开出二', down: 1, up: 8,delay:8,isInput:'1' },
    { no: 10, type: '4~20mA', line: '开出二', down: 1, up: 8,delay:8,isInput:'1' },
    { no: 11, type: '4~20mA', line: '开出二', down: 1, up: 8,delay:8,isInput:'1' },
    { no: 12, type: '4~20mA', line: '开出二', down: 1, up: 8,delay:8,isInput:'1' },
])

const nodeOptions = ref(['开出一', '开出二'])

const handleSave = () => {
    console.log('保存AI通道设置', channelList.value)
}
</script>

<template>
    <div class="ai-alarm-container">
        <div class="panel">
            <div class="row header-row">
                <div class="cell cell-no">通道号</div>
                <div class="cell cell-type" style="color: #787878;">信号类型</div>
                <div class="cell cell-line">下限值</div>
                <div class="cell cell-category">上限值</div>
                <div class="cell cell-low">延时（s）</div>
                <div class="cell cell-high">输出节点</div>
                <div class="cell cell-high">是否投入</div>
            </div>
            <div class="row" v-for="(item, idx) in channelList" :key="idx">
                <div class="cell cell-no">{{ item.no }}</div>
                <div class="cell cell-type" style="background: #ffffff;">{{ item.type }}</div>
                <div class="cell cell-line" style="background: #ffffff;">
                    <el-input-number v-model="item.down" style="width: 100%;" :controls="false" />
                </div>
                <div class="cell cell-low" style="background: #ffffff;">
                    <el-input-number v-model="item.up" style="width: 100%;" :controls="false" />
                </div>
                <div class="cell cell-high" style="background: #ffffff;">
                    <el-input-number v-model="item.delay" style="width: 100%;" :controls="false" />
                </div>
                <div class="cell cell-line" style="background: #ffffff;">
                    <el-select v-model="item.line">
                        <el-option v-for="line in nodeOptions" :key="line" :value="line" :label="line"></el-option>
                    </el-select>
                </div>
                <div class="cell cell-category" style="background: #ffffff;">
                    <el-switch v-model="item.isInput" active-value="1" inactive-value="0" />
                </div>
            </div>
        </div>

        <div class="btn-wrap">
            <button class="save-btn" @click="handleSave">保存</button>
        </div>
    </div>
</template>

<style scoped lang="scss">
.ai-alarm-container {
    width: 100%;
    height: 100%;
    padding: 20px;

    .panel {
        background: #fff;
        border-radius: 6px;
        padding: 16px;
        box-shadow: 0px 0px 10px rgba(219, 225, 236, 1);
    }

    .title {
        margin: 0 0 16px 0;
        font-weight: 700;
        font-style: normal;
        font-size: 16px;
        color: #363636;
    }

    .row {
        display: flex;
        margin-bottom: 8px;

        &:last-child {
            margin-bottom: 0;
        }
    }

    .header-row .cell {
        background-color: #f9fafe;
        font-weight: 500;
    }

    .cell {
        border: 1px solid #e4e4e4;
        border-radius: 4px;
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 37px;
        box-sizing: border-box;
        background-color: #f9fafe;
        color: #787878;

        &+.cell {
            margin-left: 8px;
        }
    }

    .cell-no {
        width: 100px;
        background: #f9fafe;
    }

    .cell-type {
        flex: 1;
        background: transparent;
        color: #363636;
    }

    .cell-line {
        flex: 1;
    }

    .cell-category {
        flex: 1;
    }

    .cell-low {
        flex: 1;
    }

    .cell-high {
        flex: 1;
    }

    select,
    input {
        width: 85%;
        height: 32px;
        border: none;
        outline: none;
        text-align: center;
        background: transparent;
        font-size: 14px;
    }

    .btn-wrap {
        margin-top: 20px;
    }

    .save-btn {
        background-color: #0099ff;
        color: #fff;
        border: none;
        border-radius: 4px;
        width: 150px;
        height: 40px;
        font-size: 14px;
        cursor: pointer;
    }
}

// 去掉所有边框 + 阴影
:deep(.el-select__wrapper),
:deep(.el-input__wrapper) {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    text-align: center !important;
}

:deep(.el-select__wrapper.is-hover),
:deep(.el-input__wrapper.is-hover),
:deep(.el-select__wrapper.is-focused),
:deep(.el-input__wrapper.is-focused) {
    box-shadow: none !important;
    border: none !important;
}

:deep(.el-input__inner) {
    text-align: center !important;
}
</style>