<template>
    <div class="content">
        <div class="tabs">
            <ul>
                <li v-for="(tab,i) in tabs" @click="goTab(tab.url)" :class="{'active':tabIndex == i}">
                    {{tab.name}}
                </li>
            </ul>
        </div>
        <div class="panel">
            <div class="panel-body">
                <div class=" panel_control">
                    <el-row :gutter="20">
                        <el-col :span="4">
                            <em>探测器:</em>
                            <el-select v-model="panel.detidstr">
                                <el-option
                                        v-for="item in panel.detOptions"
                                        :key="item.Id"
                                        :label="item.Name"
                                        :value="item.Id">
                                </el-option>
                            </el-select>
                        </el-col>
                        <el-col :span="4">
                            <em>被检Mac:</em>
                            <el-input v-model="panel.detectedmac" placeholder="请输入被检测设备Mac"></el-input>
                        </el-col>
                        <el-col :span="6">
                            <em>检测时间:</em>
                            <el-date-picker
                                    v-model="panel.time1"
                                    type="daterange"
                                    range-separator="至"
                                    start-placeholder="开始日期"
                                    end-placeholder="结束日期">
                            </el-date-picker>
                        </el-col>
                        <el-col :span="4">
                            <el-button size="small" type="primary" @click="query">查询</el-button>
                        </el-col>
                    </el-row>
                </div>
            </div>
        </div>
        <el-table
                :data="tableData"
                is-horizontal-resize
                :default-sort="{prop: 'date', order: 'descending'}"
                v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.8)"
                class=""
                stripe
        >
            <el-table-column
                    prop="Id"
                    label="记录"
            >
            </el-table-column>
            <el-table-column
                    prop="DetectorId"
                    label="探测设备ID"
                    width="120"
            >
            </el-table-column>
            <el-table-column
                    prop="Macstr"
                    label="Mac地址"
            >
            </el-table-column>
            <el-table-column
                    prop="ProduceCom"
                    label="品牌"
            >
            </el-table-column>
            <el-table-column
                    prop="Path"
                    label="位置"
            >
            </el-table-column>
            <el-table-column
                    prop="SignalIntensity"
                    label="信号强度"
                    width="120"
            >
            </el-table-column>
            <el-table-column
                    prop="EditTime"
                    label="检测时间"
                    :formatter="filterFmtDate"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="DangerLevel"
                    label="危险等级"
                    width="120"
            >
                <template slot-scope="scope">
                    <span class="yellow" v-if="scope.row.DangerLevel == -1">危险</span>
                    <span v-if="scope.row.DangerLevel != -1">安全</span>
                </template>
            </el-table-column>

        </el-table>
        <br>
        <el-pagination
                background
                :total="pageination.total"
                :page-size="pageination.pageItem"
                @current-change="pageChange"
        ></el-pagination>
    </div>

</template>

<script>
    import Global from '../Global.js'
    import {LogWifiDetectedQueryByDetector, GetRegionAndDectorSelect} from '../api/getApiRes.js'

    let qs = require('qs');
    export default {
        data() {
            return {
                tabIndex: 1,
                tabs: [
                    {name: '手机信号记录', url: 'phoneSign'},
                    {name: 'WiFi信号记录', url: 'wifiSign'},
                    // {name: '0-6G扫描记录', url: 'GSign'},
                ],
                // panel 配置项目
                panel: {
                    usercode: '',
                    username: '',
                    compname: '',
                    keyword: '',
                    USERCODE: '',
                    detectedmac: '',
                    taskstatus: 99,
                    options: [
                        {value: 99, label: '全部'},
                        {value: 1, label: '进行中'},
                        {value: 2, label: '已完成'},
                    ],
                    detOptions: [],
                    detidstr: 0,
                    time1: globalBt2(),
                },
                pageination: {
                    pageItem: 10,
                    pageoptions: pageOptions(),
                    total: 300,
                    pageIndex: 1,
                },
                draw: 1,
                start: 0,
                recordsTotal: 0,
                tableData: [],
                allTableData: [],
                limit: '10',
                multipleSort: false,
                loading: true,
                fileList: [],
                multipleSelection: [],
                detectedmac: '',
            }
        },
        mounted() {
            this.getTableQuery();
        },
        methods: {
            getDetOption() {
                let param = {
                    'token': localStorage.token,
                };
                let postdata = qs.stringify(param);
                GetRegionAndDectorSelect(postdata).then(res => {
                    let json = res;
                    if (json.Code == 0) {
                        console.log(json);
                        this.panel.detOptions = json.DectectorRs;//所有设备
                        this.panel.detOptions.unshift({Id: 0, Name: '全部'});

                    } else {
                        that.$message.error(json.Memo);
                    }
                })
            },
            // 跳转tab页面
            goTab(url) {
                this.$router.push({path: url});
            },
            // 查询按钮
            query() {
                this.getTableQuery();
                this.$message.success('查询完毕');
            },
            // 页面数据查询
            getTableQuery() {
                // 获取探测器列表
                this.getDetOption();
                let that = this;
                that.loading = true;
                let param = {
                    token: localStorage.token,
                    detectorId: that.panel.detidstr,//探测器id列表
                    detectedmac: that.panel.detectedmac,//被检测设备Mac
                    bt: globaltime2String(that.panel.time1[0]) + ' 00:00:01',//开始时间
                    et: globaltime2String(that.panel.time1[1]) + ' 23:59:59',//结束时间
                    start: 1,//
                    tableMax: 300,//
                };
                let postdata = qs.stringify(param);
                LogWifiDetectedQueryByDetector(postdata).then(res => {
                    let json = res;
                    if (json.Code == 0) {
                        that.loading = false;
                        if (json.Rs) {
                            that.allTableData = json.Rs;
                            that.recordsTotal = json.Rs.length;
                        } else {
                            that.allTableData = [];
                            that.recordsTotal = 0;
                        }

                        // 设置分页数据
                        that.setPaginations();
                    } else {
                        that.$message.error(json.Memo);
                    }
                })
            },
            // 导出excel
            btnExpAll() {
                let that = this;
                let url = headapi + '?ctl=ajax&mod=czgl&act=czcx_excel';//获取
                let bt = globaltime2String(that.panel.time1[0]);
                let et = globaltime2String(that.panel.time1[1]);
                let usercode = that.panel.usercode;
                window.location = url + '&bt=' + bt + '&et=' + et + '&usercode=' + usercode;
            },
            // 设置分页数据
            setPaginations() {
                // 分页属性
                let that = this;
                that.pageination.total = that.recordsTotal;
                // 默认分页
                that.tableData = that.allTableData.filter((item, index) => {
                    return index < that.pageination.pageItem;
                });
            },
            // 每页显示数量
            handleSizeChange() {
                let that = this;
                that.tableData = that.allTableData.filter((item, index) => {
                    return index < that.pageination.pageItem;
                });
                that.draw = that.pageination.pageItem;
                that.getTableQuery();
            },
            // 翻页
            pageChange(pageIndex) {
                let that = this;
                // 获取当前页
                let index = that.pageination.pageItem * (pageIndex - 1);
                // 数据总数
                let nums = that.pageination.pageItem * pageIndex;
                // 容器
                let tables = [];
                for (var i = index; i < nums; i++) {
                    if (that.allTableData[i]) {
                        tables.push(that.allTableData[i])
                    }
                    this.tableData = tables;
                }
                that.start = index * that.draw;
                that.getTableQuery();
            },
            // 自动排序
            sortChange(params) {
                console.log(params)
            },
            // 过滤时间
            filterFmtDate(value, row, column) {
                let that = this;
                return globalfmtDate(column, 10);
            },
            // 过滤金额
            filterMoney(value, row, column) {
                let that = this;
                return parseFloat(column).toFixed(2);
            },
        },
    }
</script>

<style scoped>
    @import "../assets/css/panel.css";
    .tabs ul {
        width: 400px;
    }
    .content {
        width: 100%;
        overflow: hidden;
        display: block;
        margin: 0 auto;
        padding-left: 10px;
    }
</style>
