<template>
    <div>
        <div class="bigBox">
            <div style="text-align: center;">
                <h2 style="font-size: 20px;">{{ needName }}</h2>
            </div>
            <div style="display: flex;justify-content: flex-start;align-items: center;height: 93%;">
                <div style="height: 100%;width: calc(100% - 0px);position: relative;">
                    <div class="setBox">
                        <div
                            style="width: 60%;display: flex;justify-content: flex-start;align-items: center;margin-left: 10px;">
                            <div style="width: calc(40%);">
                                <span style="font-size: 14px;color: #7484AB;">连接线:</span>
                                <span class="sv" :style="{ opacity: lineMenuColor == 'orange' ? 1 : 0.4 }"
                                    @click="svClick">SV</span>
                                <span class="goose" :style="{ opacity: lineMenuColor == 'orange' ? 0.4 : 1 }"
                                    @click="gooseClick">GOOSE</span>
                            </div>
                            <div style="display: flex;width: calc(30%);">
                                <span style="font-size: 14px;color: #7484AB;margin-left: 20px;">操作:</span>
                                <div class="cutPoint">
                                    <!-- <img style="width: 22px;height: 22px;display: block;"
                                        src="../../../assets/icon/iorn_pen.png" alt="">
                                    <span style="display: block;">控点</span> -->
                                </div>
                                <div class="deletePoint" @click="delClick">
                                    <img style="width: 22px;height: 22px;display: block;"
                                        src="../../../assets/icon/cut_knief.png" alt="">
                                    <span style="display: block;">删除</span>
                                </div>
                            </div>
                            <div style="display: flex;width: 30%;">
                                <div>
                                    <span style="margin-left: 5px;">X:</span>
                                    <el-input type="number" class="coord" v-model="fatX" @input="limitNumX"
                                        @change="xChange"></el-input>
                                </div>
                                <div>
                                    <span style="margin-left: 5px;">Y:</span>
                                    <el-input type="number" class="coord" v-model="fatY" @input="limitNumY"
                                        @change="yChange"></el-input>
                                </div>
                            </div>
                        </div>
                        <div style="width: calc(30%);">
                            <div style="width: calc(100%);">
                                <el-button type="primary" @click="cleanAll" plain>关闭</el-button>
                                <el-button type="primary" @click="saveMap">保存</el-button>
                            </div>
                        </div>
                        <div style="width: calc(15%);">
                            <span style="font-size: 14px;color: #7484AB;">双击节点或连接线可配置属性</span>
                        </div>
                    </div>
                    <div class="tableBox">
                        <!-- 建议使用这个 -->
                        <DrawDesigns ref="designsRef" :lineMenuColor="lineMenuColor" :needObj="needObj" :fatX="fatX"
                            :fatY="fatY" :nowLook="nowLook" :needId="needId" :needName="needName" :coolObj="coolObj"
                            :svOrGoose="svOrGoose" @backxy="backxy"></DrawDesigns>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { ref, onMounted, toRefs, watch } from 'vue';
import { ElMessage } from 'element-plus';
import cid from '@/api/cid/cid'
import FeelLoad from '@/pages/feelLoad/FeelLoad.vue'//bmnp
import FatherMap from '@/pages/mapLoad/FatherMap.vue';//jsplumb
import DrawDesigns from '@/pages/components/draw/DrawDesigns.vue';//logicflow
import { now } from 'moment';
export default {
    props: {
        tfType: {
            type: null || Number,
            required: true
        },
        insideNeed: {
            type: Object,
            required: true
        },
        lineId: {
            type: Number || String,
            required: true
        },
        setName: {
            type: String,
            required: true
        },
        setId: {
            type: Object,
            required: true
        }
    },
    setup(props, { emit }) {
        let moduleList = ref([])
        let lineMenuColor = ref('#255CE7')
        let designsRef = ref(null)
        let fatX = ref()
        let fatY = ref()
        let result = props.tfType
        let nowLook = ref(null)
        let needObj = ref({})
        let needId = ref('')
        let needName = ref('')
        let coolObj = ref({})
        let svOrGoose = ref(1)//0为sv，1为goose
        watch(() => props.tfType, (newVal) => {
            nowLook.value = newVal
        })
        watch(() => props.insideNeed, (newVal) => {
            needObj.value = newVal
        })
        watch(() => props.lineId, (newVal) => {
            needId.value = newVal
        })
        watch(() => props.setName, (newVal) => {
            needName.value = newVal
        })
        watch(() => props.setId, (newVal) => {
            coolObj.value = newVal
        })
        function searchModule() {
            needObj.value = props.insideNeed
            needId.value = props.lineId
            nowLook.value = result
            needName.value = props.setName
            coolObj.value = props.setId//模型整个数据
        }
        function svClick() {
            lineMenuColor.value = 'orange'
            svOrGoose.value = 0
            designsRef.value.orange()//切换为sv
        }
        function gooseClick() {
            lineMenuColor.value = '#255CE7'
            svOrGoose.value = 1
            designsRef.value.blue()//切换为goose
        }
        function delClick() {
            designsRef.value.delLine()//删除连接线
        }
        function saveMap() {
            designsRef.value.saveLine()//保存为图片
        }
        function cleanAll() {
            designsRef.value.cleanMap()//清除画布
            emit("closeDraw")
        }
        function limitNumX(e) {//强制转换为数字
            let types = e.replace(/\D/g, '');
            fatX.value = types - 0
        }
        function limitNumY(e) {//强制转换为数字
            let types = e.replace(/\D/g, '');
            fatY.value = types - 0
        }
        function xChange(e) {
            fatX.value = e - 0
            designsRef.value.momal()
        }
        function yChange(e) {
            fatY.value = e - 0
            designsRef.value.momal()
        }
        function backxy(x, y) {
            fatX.value = x
            fatY.value = y
        }
        onMounted(() => {
            searchModule()
        })
        return {
            moduleList,
            searchModule,
            lineMenuColor,
            svClick,
            gooseClick,
            designsRef,
            delClick,
            saveMap,
            cleanAll,
            fatX,
            fatY,
            backxy,
            xChange,
            yChange,
            limitNumX,//只能输入数字
            limitNumY,
            nowLook,
            result,
            needObj,
            needId,
            needName,
            coolObj,
            svOrGoose,//0为sv，1为goose
        }
    },
    components: {
        FeelLoad,
        FatherMap,
        DrawDesigns
    }
}
</script>

<style scoped>
.bigBox {
    width: 100%;
    height: calc(100vh - 150px);
    border: 1px solid #cbcbda;
    border-radius: 3px;
}

.tableBox {
    width: 100%;
    height: calc(100% - 10%);
}

.setBox {
    width: calc(100% - 14%);
    height: calc(100% - 90%);
    border: 1px solid #A3ADE0;
    position: absolute;
    top: 0px;
    left: calc(100% - 86.5%);
    z-index: 1;
    background-color: #F7F8FB;
    line-height: calc(600%);
    display: flex;
    justify-content: space-around;
    align-items: center;
    /* margin-top: 1px; */
}

.moduleBox {
    width: 10%;
    height: 100%;
    border: 1px solid green;
}

.sv {
    display: inline-block;
    width: 75px;
    height: 24px;
    text-align: center;
    line-height: 24px;
    border-top: 2px solid #FF7C03;
    font-size: 16px;
    margin-right: 20px;
    cursor: pointer;
    opacity: 0.4;
}

.sv:hover {
    opacity: 1;
}

.goose {
    display: inline-block;
    width: 75px;
    height: 24px;
    text-align: center;
    line-height: 24px;
    border-top: 2px solid #255CE7;
    font-size: 16px;
    cursor: pointer;
}

.goose:hover {
    opacity: 1;
}

.cutPoint {
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 14px;
    text-align: center;
    margin-right: 10px;
    cursor: pointer;
}

.deletePoint {
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 14px;
    text-align: center;
    cursor: pointer;
}

:deep(.lf-dndpanel) {
    height: 100%;
    width: 220px;
    overflow-y: auto;
    background-color: #F7F8FB;
    padding: 0;
    margin: 0;
}

:deep(.lf-dnd-item) {
    width: 38%;
    float: left;
    margin: 5%;
}

:deep(.lf-dnd-shape) {
    display: none;
}

:deep(.lf-dnd-text) {
    width: calc(100% - 8px);
    height: 42px;
    border: 1px solid #d3daef;
    margin-left: 2px;
    color: #255CE7;
    text-align: center;
    line-height: 22px;
    background: #e4dfdf;
    border-radius: 3px;
    padding: 3px;
}

.coord {
    width: 75px;
    height: 30px;
    background-color: transparent;
    border: none;
    margin-left: 5px;
}
</style>