<template>
    <div>
        <div class="fileBox">
            <div>
                <span style="border-right: 1px solid black;padding-right: 200px;">基准文件:{{ chicken }}</span>
            </div>
            <div>
                <span>对比文件:{{ kun }}</span>
            </div>
        </div>
        <!-- <div class="mapBox" v-if="lookType == 0"> -->
        <!-- <div class="scdBox">
                <div>
                    <img src="../../../assets/image/squer_scd.png" alt="">
                    <p>SCD版本</p>
                </div>
                <div>
                    <div id="oldScd">
                        <img src="../../../assets/icon/cilce_gray.png" alt="">
                        <span>V1.1.0</span>
                    </div>
                    <div id="newScd">
                        <img src="../../../assets/icon/clice_blue.png" alt="">
                        <span>V1.1.1</span>
                    </div>
                </div>
            </div>
            <div class="crcBox">
                <div>
                    <img src="../../../assets/image/squer_crc.png" alt="">
                    <p>CRC</p>
                </div>
                <div>
                    <div id="oldCrc">
                        <img src="../../../assets/icon/cilce_gray.png" alt="">
                        <span>1000000111100000</span>
                    </div>
                    <div id="newCrc">
                        <img src="../../../assets/icon/clice_blue.png" alt="">
                        <span>1000000111100022</span>
                    </div>
                </div>
            </div>
            <div class="iedBox">
                <div id="oldIed">
                    <img src="../../../assets/image/squer_ied.png" alt="">
                    <p>IED</p>
                </div>
                <div id="newIed">
                    <p id="addId" @click="lookAdd">
                        <el-icon style="color: #1D48E8;font-size: 18px;display: block;">
                            <CirclePlus />
                        </el-icon>
                        <span style="display: block;color: #1D48E8;">新增(5)</span>
                    </p>
                    <p id="editId" @click="lookEdit">
                        <el-icon style="color: #FECC2A;font-size: 18px;display: block;">
                            <EditPen />
                        </el-icon>
                        <span style="display: block;color: #FECC2A;">修改(10)</span>
                    </p>
                    <p id="delId" @click="lookDel">
                        <el-icon style="color: red;font-size: 18px;display: block;">
                            <Delete />
                        </el-icon>
                        <span style="display: block;color: red;">删除(2)</span>
                    </p>
                </div>
            </div> -->
        <!-- </div> -->
        <ScdNow v-if="lookType == 0" @nowBack="nowBack" :arrNew="arrNew"></ScdNow>
        <ScdAdd v-if="lookType == 1" :arrNew="arrNew"></ScdAdd>
        <ScdDel v-if="lookType == 3" :arrNew="arrNew"></ScdDel>
        <ScdEdit v-if="lookType == 2" :arrNew="arrNew"></ScdEdit>
    </div>
</template>

<script>
import { ref, onMounted, toRefs, watch, onBeforeUnmount } from 'vue';
import LeaderLine from '../../../../public/leader-line.min.js';
import scdCheck from '@/api/scdCheck/scdCheck'
import image from "../utils/image"
import ScdAdd from './ScdAdd.vue';
import ScdDel from './ScdDel.vue';
import ScdEdit from './ScdEdit.vue';
import ScdNow from './ScdNow.vue';
import { ElLoading } from 'element-plus';
export default {
    props: {
        antherBack: {
            type: Array,
            required: true
        },
        activeNav: {
            type: Number,
            required: true
        }
    },
    setup(props, { emit }) {
        let arrNew = ref([])
        let chicken = ref('')
        let kun = ref('')
        let lineList = []//线条显示
        let lookType = ref(0)//0为查看整体，1为新增，2为修改，3为删除
        watch(() => props.antherBack, (newVal) => {
            arrNew.value = newVal//监听传递数据变化
            if (!arrNew.value || !newVal) {
                return
            } else {
                if (arrNew.value.length == 1) {
                    chicken.value = arrNew.value[0].scd_name
                }
                if (arrNew.value.length == 2) {
                    chicken.value = arrNew.value[0].scd_name
                    kun.value = arrNew.value[1].scd_name
                }
            }

        })
        function lastList() {//初始化数据
            lookType.value = 0
            arrNew.value = props.antherBack
            if (!arrNew.value || !props.antherBack) {
                if (arrNew.value.length == 1) {
                    chicken.value = arrNew.value[0].scd_name
                }
                if (arrNew.value.length == 2) {
                    chicken.value = arrNew.value[0].scd_name
                    kun.value = arrNew.value[1].scd_name
                }
            }
        }
        function nowBack(data) {
            lookType.value = data
        }
        const openFullScreen2 = () => {
            const loading = ElLoading.service({
                lock: true,
                text: '正在加载',
                background: 'rgba(0, 0, 0, 0.7)',
            })
            setTimeout(() => {
                loading.close()
            }, 2000)
        }
        onMounted(() => {
            lastList()
            openFullScreen2()
        })
        onBeforeUnmount(() => {
            lookType.value = 0
            lineList.forEach(line => line.remove());//清除连线
        })
        return {
            chicken,//基准文件
            kun,//对比文件
            arrNew,//传递数组
            lastList,//初始化数据
            lineList,//线条显示
            lookType,//0为查看整体，1为新增，2为修改，3为删除
            nowBack,
            openFullScreen2,//加载
        }
    },
    components: {
        ScdAdd,
        ScdDel,
        ScdEdit,
        ScdNow
    }
}
</script>

<style>
p {
    margin: 0;
    padding: 0;
}

.fileBox {
    width: 90%;
    height: calc(100vh - 900px);
    background-color: white;
    margin: 10px auto;
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.mapBox {
    width: 90%;
    height: calc(100vh - 350px);
    margin: 0 auto;
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
}

.scdBox {
    width: 33%;
    height: auto;
    text-align: center;
    /* border: 1px solid red; */
}

.crcBox {
    width: 33%;
    height: auto;
    text-align: center;
    /* border: 1px solid red; */
}

.iedBox {
    width: 33%;
    height: auto;
    text-align: center;
    /* border: 1px solid red; */
    position: relative;
}

#newIed {
    position: absolute;
    top: 100px;
    right: 0px;
}

#oldScd {
    margin-bottom: 40px;
}

#oldCrc {
    margin-bottom: 40px;
}

#addId {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 112px;
    height: 40px;
    border: 1px dashed #1D48E8;
    background-color: rgb(239, 243, 255);
    border-radius: 5px;
    margin-bottom: 20px;
    cursor: pointer;
}

#editId {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 112px;
    height: 40px;
    border: 1px dashed #FECC2A;
    background-color: rgb(255, 251, 242);
    border-radius: 5px;
    margin-bottom: 20px;
    cursor: pointer;
}

#delId {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 112px;
    height: 40px;
    border: 1px dashed red;
    background-color: rgb(255, 236, 236);
    border-radius: 5px;
    margin-bottom: 20px;
    cursor: pointer;
}
</style>