<template>
    <div class="container">
        <div class="title_top">
            <div class="title_name" @click="handleHome">
                {{ this.$dictLabel('node_title2') }}
            </div>
        </div>

        <leftNav selNavId="2" />


        <div class="content_box">
            <div class="xmind_box">
                <graph-box ref="graph_box" v-if="isShow" @save="handlesave"></graph-box>
                <div v-if="!isShow" class="img_box" >
                    <img class="imgUrl" :src="imagesUrl" alt="" >

                </div>
            </div>
            <div class="but_box">
                <div class="but but_1" v-if="!isShow" @click="handelEdit"></div>
                <div class="but but_2" v-if="isShow" @click="saveDiagram"></div>
                <div class="but but_3" @click="handleChecklists"></div>
            </div>
        </div>
    </div>
</template>

<script>
import { taskDelite, taskUpdate, taskInfo } from "@/api/bigScreen/api.js";
import graphBox from "./graph/graph.vue";
export default {
    name: 'Xmind',
    props: {

    },
    components: {
        graphBox,
    },
    data(){
        return {
            isShow: false,
            taskId: '',
            Tip: null,
            imagesUrl: '',
        }
    },
    created() {
        this.taskId = this.$route.query.id
        this.getPageData()
    },
    mounted() {
        // this.openTip()
    },
    destroyed() {
        if (this.Tip) this.Tip.close()
    },
    methods: {
        openTip() {
            if (this.Tip) this.Tip.close()
            this.Tip = this.$notify({
                title: '快捷操作',
                dangerouslyUseHTMLString: true,
                duration: 0,
                message: ` <div class="tipsList">
                <div class="item"><p class="name">鼠标双击:</p><p class="value">编辑内容</p></div>
                <div class="item"><p class="name">ctrl+c:</p><p class="value">复制</p></div>
                <div class="item"><p class="name">ctrl+v:</p><p class="value">粘贴</p></div>
                <div class="item"><p class="name">ctrl+x:</p><p class="value">剪切</p></div>
                <div class="item"><p class="name">ctrl+a:</p><p class="value">全选</p></div>
                <div class="item"><p class="name">ctrl+z:</p><p class="value">撤销</p></div>
                <div class="item"><p class="name">ctrl+y:</p><p class="value">恢复</p></div>
                <div class="item"><p class="name">backspace:</p><p class="value">删除</p></div>
                </div>`
            });
        },
        getPageData() {
            let that = this
            let taskId = this.$dictLabel('lctid')
            if (taskId != '0') {
                this.taskId = taskId
            }
            if (this.taskId) {
                taskDelite(this.taskId).then(res => {
                    this.pageData = res
                    const { filedata = '' } = res
                    if (filedata) {
                        this.imagesUrl = filedata
                    } else {
                        this.isShow = true
                    }
                })
            } else {
                taskInfo().then(res => {
                    this.designId = res.id
                    this.pageData = res
                    const { filedata = '' } = res
                    if (filedata) {
                        this.imagesUrl = filedata
                    } else {
                        this.isShow = true
                    }
                })
            }
        },


        handelEdit(){
            this.isShow = true
        },
        //  保存 流程图
        saveDiagram(){
            if (this.$refs?.graph_box) {
                this.$refs.graph_box.save();
            }
        },
        handlesave(){
            console.log('---------');
            
            this.$nextTick(()=> {
                setTimeout(() => {
                    this.getPageData()
                    this.isShow = false
                }, 100);
    
            })
        },
        //  生成清单
        handleChecklists(){
            // this.$router.push('/matrix')
            this.$router.push({ path: '/matrix', query: { id: this.taskId } });
        },
        handleHome() {
            this.$router.push('/home')
        }
    }
}
</script>

<style lang="scss" scoped>
.container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 80px;
    padding-left: 200px;
    .content_box{
        // height: 100%;
        display: flex;
        align-items: flex-end;
        justify-content: flex-end;
        .xmind_box{
            // width: 1176px;
            width: 70vw;
            // height: 686px;
            height: calc(86vh - 80px);
            // background-color: #0857ac;
            border: 8px solid #cccccc;
            .img_box{
                // width: 100%;
                // height: 100%;
                background-color: #fff;
                display: flex;
                align-items: center;
                justify-content: center;
                width: 100%;
                height: 100%;
                    // padding: 0 10px;
                    // max-height: 100%;;
                    // overflow: auto;
                
                    &::-webkit-scrollbar {
                        width: 5px;
                        height: 12px;
                        border-radius: 8px;
                    }
                
                    //  滚动条轨道
                    &::-webkit-scrollbar-track {
                        /* -webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.5); */
                        border-radius: 8px;
                        background-color: #f1f1f1;
                    }
                
                    //  滚动条滑块
                    &::-webkit-scrollbar-thumb {
                        border-radius: 8px;
                        background: #ccc;
                        /* -webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.5); */
                    }
                .imgUrl{
                    // width: 100%;
                    width: auto;
                    height: 100%;
                    // // height: auto;
                    // max-width: 100%;
                    // // max-height: 100%;
                    // object-fit: contain;
                }
            }
        }
        .but_box{
            margin-left: 80px;
            margin-bottom: 80px;
            .but{
                width: 180px;
                height: 59px;
                background-repeat: no-repeat;
                background-position: -40px -40px;
                background-size: 260px 140px;
                cursor: pointer;
            }
            .but+ .but{
                margin-top: 20px;
            }
            .but_1 {
                background-image: url('~@/assets/bigScreen/task/but_edit.png');
            }
            .but_2 {
                background-image: url('~@/assets/bigScreen/task/but_sub_2.png');
            }
            .but_3 {
                background-image: url('~@/assets/bigScreen/task/but_list.png');
            }
        }
    }
}
</style>
<style lang="scss">
.tipsList {
    .item {
        display: flex;
        padding: 3px;

        .name {
            font-size: 16px;
            color: #666;
            margin: 0 10px 0 0;
        }

        .value {
            font-size: 16px;
            color: #333;
            margin: 0;
        }
    }

}
</style>