<template>
    <div class="alarm bg-white">
        <div class="ant-advanced-search-form">
            <a-form layout="inline" :label-col="labelCol" :wrapper-col="wrapperCol" :form="queryParam">
                <a-row :gutter="24">
                    <a-col :span="5" style="text-align: left">
                        <a-form-item  label="时间">
                            <a-range-picker @change="onTimeChange"
                                            v-model="time"
                                            format="YYYY-MM-DD HH:mm"
                                            :show-time="{
                                              defaultValue: [moment('00:00', 'HH:mm'), moment('23:59', 'HH:mm')],
                                            }"
                            >
                                <a-icon slot="suffixIcon" type="calendar"/>
                            </a-range-picker>
                        </a-form-item>
                    </a-col>
                    <a-col :span="19" style="text-align: right">
                        <a-button type="primary" @click="handleSearch">搜索</a-button>
                        <a-button style="margin-left: 15px" @click="reset">重置</a-button>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <a-table
            :columns="columns"
            :row-key="record => record.id"
            :data-source="data"
            :pagination="pagination"
            @change="handleGetalarmList"
        >
          <span slot="videoPath1" slot-scope="text">
              <a-button type="link"  @click="showModel(text)">
                  查看视频
              </a-button>
              
          </span> 
        </a-table>
        <Model
            :visible.sync="visible"
            :vid1.sync="vid1"
            :vid2.sync="vid2"
            @close="closeModel"
        />
    </div>
</template>

<script>
import Model from "./model.vue"
import {videoUrl} from "@/api/importExcel";
import moment from 'moment';
export default {
    name: "historyMonitoring",
    components: {
        // videoPlayer
        Model
    },
    data() {
        return {
            labelCol: { span: 6 },
            wrapperCol: { span: 18 },
            queryParam: {
                startTime: moment().subtract(1, "days").format('YYYY-MM-DD HH:mm:ss'), //当前时间的前一个天时间
                endTime: moment().format('YYYY-MM-DD HH:mm:ss')
            },
            time:[],
            pageNum:1,
            pageSize:10,
            data: [],
            pagination:{
                total:0,
                defaultPageSize:10, // 默认每页显示数量
                showTotal: total => `共 ${total} 条数据`, // 显示总数
                showSizeChanger:true, // 显示可改变每页数量
                pageSizeOptions: ['10', '20', '30'],
                onShowSizeChange:(current, pageSize)=>this.pageSize = pageSize // 改变每页数量时更新显示
            },
            loading: false,
            columns: [
                {
                    title: "时间",
                    dataIndex: "startTime",
                },
                {
                    title: "球机所属巷道 ",
                    dataIndex: "streetName",
                },
                {
                    title: "告警时长",
                    dataIndex: "timeLength",
                },
                {
                    title: "视频录像",
                    // dataIndex: "videoPath1",
                    scopedSlots: {customRender: 'videoPath1'}
                }
            ],
            visible: false,
            vid1: '',
            vid2:'',
        };
    },
    mounted() {
        this.handleGetalarmList()
    },
    methods: {
        moment,
        range(start, end) {
            const result = [];
            for (let i = start; i < end; i++) {
                result.push(i);
            }
            return result;
        },
        handleSearch(){
            console.log(this.queryParam)
            this.handleGetalarmList()
        },
        handleGetalarmList(pagination) {
            console.log(pagination)
            if(pagination){
                this.pagination.current = pagination.current;
                this.pagination.pageSize = pagination.pageSize;
                this.pageNum = pagination.current;
                this.pageSize = pagination.pageSize;
            }
            this.request();
        },
        request() {
            this.$api.httpApi.warnList({
                data: {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize,
                    ...this.queryParam
                }
            }).then(res => {
                const pagination = {...this.pagination};
                pagination.total = res.data.total;
                this.pagination = pagination;
                this.data = res.data.list
            }).catch(err => {

            });
        },
        onTimeChange(date, dateString) {
            this.handleReset()
            console.log(date)
            console.log(date[0].format('YYYY-MM-DD HH:mm:ss'))
            this.queryParam.startTime = date[0].format('YYYY-MM-DD HH:mm:ss')
            this.queryParam.endTime = date[1].format('YYYY-MM-DD HH:mm:ss')
        },
        handleReset() {
            this.queryParam.startTime = ""
            this.queryParam.endTime = ""
        },
        showModel(text) {
            this.visible = true
            this.vid1 = videoUrl + text.videoPath1
            this.vid2 = videoUrl + text.videoPath2
        },
        closeModel(visible, data) {
            this.visible = visible
            this.vid1 = data
        },
        reset() {
            this.queryParam.startTime = moment().subtract(1, "days").format('YYYY-MM-DD HH:mm:ss')
            this.queryParam.endTime = moment().format('YYYY-MM-DD HH:mm:ss')
            this.time = []
            this.handleGetalarmList()
        },
    },
};
</script>

<style lang="scss" scoped>
    .alarm {
        padding: 24px;
    }
    .ant-drawer-content-wrapper {
        height: auto !important;
    }
    .ant-drawer-body {
        text-align: center;
    }
    .ant-advanced-search-form .ant-form-item {
        display: flex;
        width: 100%;
    }
</style>
