<!--
 * @Date: 2021-11-30 09:44:24
 * @LastEditors: JinxuChen
 * @LastEditTime: 2021-12-23 14:15:59
 * @FilePath: \GpsCardAdmin\src\views\off-limits-manage\alarm-query\index.vue
 * @description:
-->
<template>
    <div class="app-container">
        <div class="filter-container">
            <!-- 搜索 -->
            <el-input
                v-model="searchValue"
                :placeholder="placeholder"
                style="width: 200px; margin-left: 10px;"
                class="filter-item"
                @keyup.enter.native="onSearch"
                clearable
                @clear="onClear"
            />
            <el-button
                class="filter-item"
                style="margin-left: 10px;"
                type="primary"
                icon="el-icon-search"
                @click="onSearch"
            >搜索</el-button>
        </div>
        <!-- 表格 -->
        <!-- <el-table
            :key="tableKey"
            v-loading="listLoading"
            :data="list"
            border
            fit
            highlight-current-row
            style="width: 100%;"
            @sort-change="sortChange"
        ></el-table>-->
        <TTable :tableData="list" :columns="columns" @update="onUpdate" @delete="onDelete"></TTable>
        <!-- 分页 -->
        <pagination
            v-show="total>0"
            :total="total"
            ref="pages"
            :page.sync="page"
            :limit.sync="limit"
            @pagination="getList"
        />
    </div>
</template>

<script>
import TTable from "../../../components/TTable/TTable";
import Pagination from "@/components/Pagination";
import APIAlarmQuery from "@/api/alarm-query";
export default {
    name: "",
    components: { TTable, Pagination },
    data() {
        return {
            model: "",
            modelOptions: [
                {
                    value: "1",
                    label: "类别1"
                },
                {
                    value: "2",
                    label: "类别1"
                }
            ],
            searchValue: "",
            columns: [
                /* { prop: "alarmType", title: "告警类别", fixed: 'left' }, */
                { prop: "imei", title: "设备IMEI", fixed: 'left' },
                { prop: "alarmAddress", title: "告警地址" },
                { prop: "baiduLngLat", title: "百度经纬度" },
                { prop: "gaodelngLat", title: "高德经纬度" },
                { prop: "remarks", title: "告警内容" },
                { prop: "createTime", title: "创建时间", fixed: 'right' }
                /* {
                    action: true,
                    title: "操作",
                    actions: [
                        { fnName: "delete", title: "删除", type: "error" },
                    ]
                } */
            ],
            list: [
                {
                    alarmType: "出走风险",
                    imei: "141152552521",
                    alarmAddress: "广东省佛山市南海区",
                    createTime: "2021-11-30"
                }
            ],
            total: 0,
            page: 1,
            limit: 10,
            placeholder: '请输入内容'
        };
    },
    watch: {
        searchValue(value) {
            if (value === "") {
                this.$refs['pages'].currentPage = 1;
                this.getList();
            }
        }
    },
    methods: {
        // 搜索
        onSearch() {
            this.$refs['pages'].currentPage = 1;
            this.getList();
        },
        // 修改
        onUpdate(row) {
            console.log("修改", row);
        },
        // 删除
        onDelete(row) {
            console.log("删除", row);
        },
        // 获取分页数据
        getList() {
            let reqBody = {
                pageNumber: this.page,
                begNumber: this.limit,
                imei: this.checkIsNumber(this.searchValue) ? this.searchValue : "",
                keyword: this.checkIsNumber(this.searchValue) ? "": this.searchValue
            };
            APIAlarmQuery.getAlarmQuery(reqBody).then(res => {
                this.list = res.data.map(m => {
                    return {
                        imei: m.serialno,
                        content: m.address,
                        createTime: m.createTime || "无",
                        alarmAddress: m.address,
                        baiduLngLat: `${m.baiduLng}, ${m.baiduLat}`,
                        gaodelngLat: `${m.glng}, ${m.glat}`,
                        remarks: m.remarks,
                        keyId: m.keyId,

                    };
                });
                this.total = res.count;
            });
        },
        // 点击清除按钮时
        onClear() {
            this.$refs["pages"].currentPage = 1;
            this.getList();
        },
        // 判断是否是数字并且是15位
        checkIsNumber(value) {
            let reg = /^[0-9]+.?[0-9]*$/;
            if(value.length >= 15 && reg.test(value)) {
                return true
            }
        }
    },
    mounted() {
        this.getList();
    }
};
</script>

<style scoped>
</style>
