<template>
    <div class="list-view">
        <div class="filters-container">
            <!-- <el-input placeholder="输入关键字" v-model="search" clearable class="filter-item"></el-input>
            <el-button @click="getData" type="primary" icon="el-icon-search" class="filter-item">搜索 </el-button> -->
            <!-- <el-button @click="addRow" type="primary" icon="el-icon-plus" class="filter-item">添加 </el-button> -->
            <!-- <el-button
                @click="download"
                type="primary"
                icon="el-icon-download"
                :loading="downloading"
                class="filter-item"
                >导出EXCEL
            </el-button> -->
        </div>
        <el-table
            :data="tableData"
            row-key="id"
            ref="table"
            header-row-class-name="table-header-row"
            header-cell-class-name="table-header-cell"
            row-class-name="table-row"
            cell-class-name="table-cell"
            :height="tableHeight"
        >
            <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
            <!-- <el-table-column prop="id" label="ID" width="100"> </el-table-column> -->
            <el-table-column prop="record.organizer" label="承办单位"> </el-table-column>
            <el-table-column prop="record.district" label="通讯地址"> </el-table-column>
            <el-table-column prop="supervisorUser.nickname" label="监管人员"> </el-table-column>
            <el-table-column prop="time" label="时间"> </el-table-column>
            <el-table-column prop="isRecord" label="考前备案" min-width="65">
                <template slot-scope="{ row }">
                    <!-- <el-tag :type="row.isRecord ? '' : 'info'">{{ row.isRecord }}</el-tag> -->
                    <i class="el-icon-check" v-if="row.isRecord"></i>
                    <i class="el-icon-close" v-else-if="!row.isRecord"></i>
                    <i class="el-icon-minus" v-else></i>
                </template>
            </el-table-column>
            <el-table-column prop="isPostExamGuide" label="考试简章" min-width="65">
                <template slot-scope="{ row }">
                    <!-- <el-tag :type="row.isPostExamGuide ? '' : 'info'">{{ row.isPostExamGuide }}</el-tag> -->
                    <i class="el-icon-check" v-if="row.isPostExamGuide"></i>
                    <i class="el-icon-close" v-else-if="!row.isPostExamGuide"></i>
                    <i class="el-icon-minus" v-else></i>
                </template>
            </el-table-column>
            <el-table-column prop="isPerfectDeviceServices" label="服务设备" min-width="65">
                <template slot-scope="{ row }">
                    <!-- <el-tag :type="row.isPerfectDeviceServices ? '' : 'info'">{{ row.isPerfectDeviceServices }}</el-tag> -->
                    <i class="el-icon-check" v-if="row.isPerfectDeviceServices"></i>
                    <i class="el-icon-close" v-else-if="!row.isPerfectDeviceServices"></i>
                    <i class="el-icon-minus" v-else></i>
                </template>
            </el-table-column>
            <!-- <el-table-column prop="isHaveTheSameTime" label="考试时间">
                <template slot-scope="{ row }">
                    <el-tag :type="row.isHaveTheSameTime ? '' : 'info'">{{ row.isHaveTheSameTime }}</el-tag>
                    <i class="el-icon-check" v-if="row.isRecord"></i>
                    <i class="el-icon-close" v-else-if="!row.isRecord"></i>
                </template>
            </el-table-column> -->
            <!-- <el-table-column prop="isSameAddress" label="考试地点">
                <template slot-scope="{ row }">
                    <i class="el-icon-check" v-if="row.isRecord"></i>
                    <i class="el-icon-close" v-else-if="!row.isRecord"></i>
                    <el-tag :type="row.isSameAddress ? '' : 'info'">{{ row.isSameAddress }}</el-tag>
                </template>
            </el-table-column> -->
            <el-table-column prop="isExaminer" label="考官证" min-width="65">
                <template slot-scope="{ row }">
                    <i class="el-icon-check" v-if="row.isExaminer"></i>
                    <i class="el-icon-close" v-else-if="!row.isExaminer"></i>
                    <i class="el-icon-minus" v-else></i>
                    <!-- <el-tag :type="row.isExaminer ? '' : 'info'">{{ row.isExaminer }}</el-tag> -->
                </template>
            </el-table-column>
            <!-- <el-table-column prop="isRate" label="做出评定">
                <template slot-scope="{ row }">
                    <el-tag :type="row.isRate ? '' : 'info'">{{ row.isRate }}</el-tag>
                </template>
            </el-table-column> -->
            <!-- <el-table-column prop="isSureContent" label="考级内容">
                <template slot-scope="{ row }">
                    <el-tag :type="row.isSureContent ? '' : 'info'">{{ row.isSureContent }}</el-tag>
                </template>
            </el-table-column> -->
            <el-table-column prop="isPostPoster" label="疫情防控指南" min-width="65">
                <template slot-scope="{ row }">
                    <!-- <el-tag :type="row.isPostPoster ? '' : 'info'">{{ row.isPostPoster }}</el-tag> -->
                    <i class="el-icon-check" v-if="row.isPostPoster"></i>
                    <i class="el-icon-close" v-else-if="!row.isPostPoster"></i>
                    <i class="el-icon-minus" v-else></i>
                </template>
            </el-table-column>
            <el-table-column prop="isHaveThermometer" label="体温设备">
                <template slot-scope="{ row }">
                    <!-- <el-tag :type="row.isHaveThermometer ? '' : 'info'">{{ row.isHaveThermometer }}</el-tag> -->
                    <i class="el-icon-check" v-if="row.isHaveThermometer"></i>
                    <i class="el-icon-close" v-else-if="!row.isHaveThermometer"></i>
                    <i class="el-icon-minus" v-else></i>
                </template>
            </el-table-column>
            <!-- <el-table-column prop="isSchedule" label="预约限流">
                <template slot-scope="{ row }">
                    <el-tag :type="row.isSchedule ? '' : 'info'">{{ row.isSchedule }}</el-tag>
                </template>
            </el-table-column> -->
            <el-table-column prop="other" label="其他"> </el-table-column>
            <el-table-column label="视频" min-width="100">
                <el-button type="primary" size="mini" plain @click="dialogVisible = true">查看视频</el-button>
            </el-table-column>
            <el-table-column label="直播" min-width="100">
                <el-button type="primary" size="mini" plain @click="showViedo = true">查看直播</el-button>
            </el-table-column>
            <el-table-column label="操作" align="center" fixed="right" min-width="85">
                <template slot-scope="{ row }">
                    <el-button @click="editRow(row)" type="primary" size="mini" plain>详情</el-button>
                    <!-- <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button> -->
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination-wrapper">
            <!-- <div class="multiple-mode-wrapper">
                <el-button v-if="!multipleMode" @click="toggleMultipleMode(true)">批量编辑</el-button>
                <el-button-group v-else>
                    <el-button @click="operation1">批量操作1</el-button>
                    <el-button @click="operation2">批量操作2</el-button>
                    <el-button @click="toggleMultipleMode(false)">取消</el-button>
                </el-button-group>
            </div> -->
            <el-pagination
                background
                @size-change="onSizeChange"
                @current-change="onCurrentChange"
                :current-page="page"
                :page-sizes="[10, 20, 30, 40, 50]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalElements"
            >
            </el-pagination>
        </div>
        <el-dialog title="视频列表" :visible.sync="dialogVisible" width="600px" center>
            <el-table :data="vurl">
                <el-table-column prop="name" label="名称"></el-table-column>
                <el-table-column prop="url" label="地址" min-width="200px"></el-table-column>
                <el-table-column label="操作"
                    ><template slot-scope="{ row }">
                        <el-button @click="playVideo(row)">播放</el-button>
                    </template></el-table-column
                >
            </el-table>
        </el-dialog>
        <el-dialog
            class="videoDialog"
            destroy-on-close
            center
            append-to-body
            :visible.sync="showViedo"
            @close="closeEvent"
            width="70%"
        >
            <video
                :src="videoUrl"
                controlsList="nodownload noremote footbar"
                controls="controls"
                style="height: 100%; max-width: 100%"
                oncontextmenu="return false;"
                onmouseleave="leaveVideo(this)"
                ref="video"
                v-if="showViedo"
                autoplay="autoplay"
                loop
            >
                您的浏览器不支持 video 标签。
            </video>
            <div style="text-align: center; margin: 5px auto 0 auto">
                <el-button size="medium" plain type="warning" icon="el-icon-caret-right">录制</el-button>
                <el-button size="medium" type="primary" plain>保存</el-button>
                <el-button size="medium">下放地方执法</el-button>
            </div>
            <div class="close" @click="showViedo = false">关闭</div>
        </el-dialog>
    </div>
</template>
<script>
import { mapState } from 'vuex';
import pageableTable from '@/mixins/pageableTable';

export default {
    name: 'RegulatoryList',
    mixins: [pageableTable],
    data() {
        return {
            multipleMode: false,
            search: '',
            url: '/regulatory/all',
            downloading: false,
            showViedo: false,
            dialogVisible: false,
            videoUrl: 'https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/video/2021-03-19-14-33-40dhjGRCso.mp4',
            vurl: [
                {
                    name: '舞蹈艺考',
                    url: 'https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/video/2021-03-19-14-33-40dhjGRCso.mp4'
                },
                {
                    name: '表演艺考',
                    url: 'https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/video/2021-03-19-14-47-24CxnKwMnv.mp4'
                },
                {
                    name: '舞蹈艺考',
                    url: 'https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/video/2021-03-19-14-47-40sDbsFufH.mp4'
                }
                // {
                //     name: '唱歌艺考',
                //     url: 'https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/video/2021-03-19-14-48-22BtOKfvcx.mp4'
                // }
            ]
        };
    },
    computed: {
        selection() {
            return this.$refs.table.selection.map(i => i.id);
        }
    },
    methods: {
        beforeGetData() {
            return { search: this.search };
        },
        toggleMultipleMode(multipleMode) {
            this.multipleMode = multipleMode;
            if (!multipleMode) {
                this.$refs.table.clearSelection();
            }
        },
        addRow() {
            this.$router.push({
                path: '/regulatoryEdit',
                query: {
                    ...this.$route.query
                }
            });
        },
        editRow(row) {
            this.$router.push({
                path: '/regulatoryEdit',
                query: {
                    id: row.id
                }
            });
        },
        download() {
            this.downloading = true;
            this.$axios
                .get('/regulatory/excel', {
                    responseType: 'blob',
                    params: { size: 10000 }
                })
                .then(res => {
                    console.log(res);
                    this.downloading = false;
                    const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
                    const link = document.createElement('a');
                    link.href = downloadUrl;
                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
                    document.body.appendChild(link);
                    link.click();
                    link.remove();
                })
                .catch(e => {
                    console.log(e);
                    this.downloading = false;
                    this.$message.error(e.error);
                });
        },
        operation1() {
            this.$notify({
                title: '提示',
                message: this.selection
            });
        },
        operation2() {
            this.$message('操作2');
        },
        deleteRow(row) {
            this.$alert('删除将无法恢复，确认要删除么？', '警告', { type: 'error' })
                .then(() => {
                    return this.$http.post(`/regulatory/del/${row.id}`);
                })
                .then(() => {
                    this.$message.success('删除成功');
                    this.getData();
                })
                .catch(e => {
                    if (e !== 'cancel') {
                        this.$message.error(e.error);
                    }
                });
        },
        distribute(content) {
            this.$alert(content, '提示', {
                confirmButtonText: '确定'
            });
        },
        closeEvent() {
            document.exitPictureInPicture();
            this.videoUrl =
                'https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/video/2021-03-19-14-33-40dhjGRCso.mp4';
        },
        playVideo(row) {
            this.dialogVisible = false;
            this.showViedo = true;
            this.videoUrl = row.url;
        }
    }
};
</script>
<style lang="less" scoped>
.videoDialog {
    display: flex;
    align-items: center;
    justify-content: center;
    .el-dialog {
        max-width: 900px;
        margin-top: 0px;

        .close {
            position: absolute;
            right: 0px;
            top: -42px;
            width: 71px;
            height: 32px;
            background: #00000015;

            font-size: 12px;
            color: #fdffff;
            line-height: 32px;
            text-align: center;
            cursor: pointer;

            &:hover {
                background: #00000055;
            }
        }
    }
    .el-dialog__header {
        display: none;
    }

    .el-dialog__body {
        padding: 0;

        video {
            display: block;
            height: auto;
            width: 100%;
            outline: none;
        }
    }
}
/deep/.el-button--medium {
    height: 44px;
    font-size: 16px;
    margin: 10px 40px 0;
}
</style>
