<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="12">
                    <a-col :span="8">
                        <a-form-item class="ageInput" label="时间">
                            <a-range-picker @change="onTimeChange" v-model="queryParam.time"
                                            format="YYYY-MM-DD HH:mm">
                                <a-icon slot="suffixIcon" type="calendar"/>
                            </a-range-picker>
                        </a-form-item>
                    </a-col>
                    <a-col :span="16" style="text-align: right">
                        <a-button type="primary" @click="handleSearch">搜索</a-button>
                        <!--                        <a-button style="margin-left: 8px" @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="handleGetHistoryList"
        >
          <span slot="videoPath1" slot-scope="text">
              <a-button type="link" v-if="text.videoPath1" @click="showModel(text.videoPath1)">
                  查看视频
              </a-button>
              <span v-else>

              </span>
          </span>
            <span slot="videoPath2" slot-scope="text">
              <a-button type="link" v-if="text.videoPath2" @click="showModel(text.videoPath2)">
                  查看视频
              </a-button>
              <span v-else>

              </span>
          </span>
        </a-table>
        <Model
            :visible.sync="visible"
            :vid.sync="vid"
            @close="closeModel"
        />
    </div>
</template>

<script>
import Model from "./model.vue"
export default {
    name: "historyMonitoring",
    components: {
        // videoPlayer
        Model
    },
    data() {
        return {
            labelCol: { span: 6 },
            wrapperCol: { span: 18 },
            queryParam: {},
            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: "球机1",
                    // dataIndex: "videoPath1",
                    scopedSlots: {customRender: 'videoPath1'}
                },
                {
                    title: "球机2",
                    // dataIndex: "videoPath2",
                    scopedSlots: {customRender: 'videoPath2'}
                },
            ],
            visible: false,
            vid: ''
        };
    },
    mounted() {
        this.handleGetHistoryList()
    },
    methods: {
        handleSearch(){
            console.log(this.queryParam)
            this.handleGetHistoryList()
        },
        handleGetHistoryList(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 => {
                console.log(res)
                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 = ""
            this.time = ""
        },
        showModel(data) {
            this.visible = true
            this.vid = videoUrl + data
        },
        closeModel(visible, data) {
            this.visible = visible
            this.vid = data
        },
    },
};
</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>
