<template>
    <div class="main">
        <div class="container">
            <div class="left-menu">
                <div class="menu-header">上传人员列表({{ listData.length }}人)</div>
                <div class="search-header">
                    <el-input v-model="searchData" placeholder="请输入..."></el-input>
                    <el-button class="search-btn" type="primary" plain>搜索</el-button>
                </div>
                <div class="upload-list">
                    <el-menu
                        default-active="1"
                        class="el-menu-vertical-demo"
                        @open="listOpen">
                        <el-submenu
                            v-for="(item, index) of listData"
                            :key="index"
                            :index="String(index + 1)">
                            <template slot="title">
                                <div class="menus-title">
                                    <span>{{ item.user_name }}</span>
                                    <span class="upload-count" v-show="!taskMode">{{ item.total_count }}</span>
                                    <div class="progress-ctn" v-if="taskMode">
                                        <div style="flex: 1;margin-top: 7px;">
                                            <el-progress :show-text="false" :percentage="item.upload_count / item.total_count"></el-progress>
                                        </div>
                                        <div style="margin: -13px 7px 0 10px">{{ item.upload_count }} / {{ item.total_count }}</div>
                                    </div>
                                </div>
                            </template>
                            <el-menu-item-group>
                                <el-menu-item
                                    v-for="(innerItem, innerIndex) of item.fileChildren"
                                    :key="innerIndex"
                                    :index="(index+1)+'-'+(innerIndex+1)"
                                    @contextmenu.native.prevent.stop="showMenu($event,innerItem)"
                                    @dblclick.native="showFileOL(innerItem)">
                                    <span v-show="taskMode" class="point"></span>{{ innerItem.file_name }}
                                </el-menu-item>
                            </el-menu-item-group>
                        </el-submenu>
                    </el-menu>
                </div>
            </div>
            <div class="right-document">
                <iframe :src="documentUrl" width="100%" height= "100%" name="topFrame" noresize="noresize" frameborder="0" id="topFrame"></iframe>
            </div>

            <!-- 右键菜单栏 -->
            <div v-show="menuVisible" id="menu" :style="'left:'+coordinate.menuX+';top:'+coordinate.menuY">
                <ul class="menu">
                    <li class="menu_item padding_35">下载</li>
                    <li class="menu_item padding_35" @click="deleteVisible = true">删除</li>
                </ul>
            </div>

            <!-- 删除文件窗口 -->
            <el-dialog title="删除确认" :visible.sync="deleteVisible" width="500px">
                <h3>删除后不可恢复，确定删除吗？</h3>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="deleteVisible = false">取 消</el-button>
                    <el-button type="primary" @click="deleteVisible = false">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>

<script>
export default {
    name: 'Material',
    props: {
        taskMode: { // 是否为任务文件夹
            type: Boolean,
            default: false
        },
        listData: {
            type: Array,
            default: () => {
                return []
            }
        }
    },
    data () {
        return {
            searchData: '',
            menuVisible: false, // 右键菜单栏
            breadcrumb: ['首页'], // 面包屑
            options: [{
                value: 'allItem',
                label: '全部学期'
            }],
            documentUrl: '', // 文档在线预览地址
            deleteVisible: false, // 删除确认弹框
            coordinate: { // 菜单栏坐标
                menuX: '0px',
                menuY: '0px'
            }
        }
    },
    methods: {
        showMenu (MouseEvent, item) {
            /* 右键文件夹或文件时触发 */
            console.log(item)
            this.menuVisible = false
            this.menuVisible = true
            this.coordinate.menuX = MouseEvent.pageX + 5 + 'px'
            this.coordinate.menuY = MouseEvent.pageY + 'px'
            document.addEventListener('click', this.foo) // 给整个document添加监听鼠标事件，点击任何位置执行foo方法
        },
        showFileOL (file) {
            /* 双击预览文档 */
            let url = 'https://onlinepreview.vschool100.cn/onlinePreview?url=' + encodeURIComponent(file.file_path)
            this.documentUrl = url
        },
        listOpen (index) {
            let listIndex = parseInt(index) - 1
            this.$emit('getMaterialFile', listIndex)
        },
        foo () {
            /* 取消鼠标监听事件 菜单栏 */
            this.menuVisible = false
            this.uploadVisible = false
            document.removeEventListener('click', this.foo) // 关掉监听
        },
        format (item) {
            console.log(1111111111111, item)
            return '3/8'
        }
    },
    mounted () {
    }
}
</script>

<style lang="less" scoped>
.main {
    min-height: 100%;

    .headerNav {
        display: flex;
        justify-content: space-between;
        height: 45px;
        line-height: 45px;
        background: #e7e7e7;

        /deep/ .leftNav {
            padding: 0 20px;
            font-size: 18px;

            .el-breadcrumb {
                font-size: 18px;
                line-height: 45px;
                .el-breadcrumb__item {
                    &:not(:last-child) .el-breadcrumb__inner{
                        cursor: pointer;
                        &:hover {
                            color: #1890FF;
                        }
                    }

                    &:last-child .el-breadcrumb__inner{
                        color: black;
                    }
                }

            }
        }

        /deep/ .rightNav {
            padding: 0 30px;
            display: flex;
            .timer-select{
                padding-top: 1px;
                margin-right: 15px;
            }
        }
    }
    .container {
        padding: 15px 30px;
        display: flex;

        .left-menu {
            width: 260px;
            background: #F1F5F8;
            min-height: 500px;

            .menu-header {
                height: 50px;
                line-height: 50px;
                border-bottom: 1px solid #D7D7D7;
                padding-left: 20px;
            }

            .search-header {
                display: flex;
                padding: 12px 10px;;

                .search-btn {
                    margin-left: 7px;
                    font-size: 14px;
                }
            }

            /deep/ .upload-list {
                .el-menu {
                    background: none;
                    .el-submenu__title{
                        height: 45px;
                        line-height: 45px;
                        .menus-title {
                            display: flex;
                            .upload-count {
                                flex: 1;
                                text-align: right;
                                margin-right: 30px;
                            }
                            .progress-ctn {
                                width:250px;
                                padding:13px 10px 0 15px;
                                display: flex;
                            }
                        }

                    }
                    .el-menu-item-group__title {
                        height: 0;
                        padding: 0;
                    }
                    .el-menu-item {
                        overflow: hidden;
                        text-overflow: ellipsis;
                        padding: 0 5px 0 0;
                        height: 40px;
                        line-height: 40px;
                        &:focus, &:hover {
                            background: rgb(207, 233, 248);
                        }
                        .point {
                            display: inline-block;
                            width: 7px;
                            height: 7px;
                            background: #039D12;
                            border-radius: 14px;
                            margin-right: 10px;
                            margin-bottom: 2px
                        }
                    }
                }
            }
        }

        .right-document {
            min-height: 500px;
            flex: 1;
            margin-left:15px;
            background: #F2F2F2;
        }

        #menu {
            position: absolute;
            z-index: 999;
            border-radius: 3px;
            background-color: white;
            border: 1px solid rgb(235, 235, 235);
            width: 120px;

            .menu {

                .menu_item {
                    line-height: 35px;
                    border-bottom: 1px solid rgb(235, 235, 235);
                    font-size:13px;
                    cursor: pointer;
                    &:hover {
                        background-color: #1790ff;
                        color: white;
                    }

                    .upload_line {
                        padding: 0 6px 0 10px;
                        .upload-icon {
                            font-size: 22px;
                            vertical-align: middle;
                        }
                    }
                }

                .padding_35 {
                    padding-left: 40px;
                }
            }
        }

        /deep/ .dialog-footer {
            text-align: center;
            .el-button {
                width: 100px;
                height: 35px;
            }
        }
    }
}

</style>
