<!--
 * @Title: 
 * @Description: 预警测站列表,按测站统计
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <div>
        <el-row>
            <el-col :span="24">
                <basic-container>
                    <avue-crud :option="option" :table-loading="loading" :page.sync="page" :data="data" ref="crud"
                        v-model="form" @search-change="searchChange" @search-reset="searchReset"
                        @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
                        @refresh-change="refreshChange">
                    </avue-crud>
                </basic-container>
            </el-col>
        </el-row>
    </div>
</template>

<script>

import { getOthersWarnPage, getDetail } from "@/api/business/warning/warning.js";

// import { mapGetters } from "vuex";
export default {
    components: {

    },
    props: {
        deptId: {
            type: [Number],
            required: true
        },
    },
    name: 'otherwarninglist',
    data() {
        return {
            dialogTitle: "异常测站列表",
            id: "",
            form: {},
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            option: {
                labelWidth: 120,
                viewLabelWidth: 100,
                searchlabelWidth: 100,
                height: "auto",
                calcHeight: 80,
                align: "center",
                headerAlign: "center",
                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                addBtn: false,
                tree: true,
                border: true,
                index: true,
                editBtn: false,
                delBtn: false,
                menuWidth: 200,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: false,
                menu: false,
                column: [
                    {
                        label: "测站编码",
                        prop: "rtuCode",
                        span: 24,
                        search: true,
                        width: 160,
                        html: true,
                        formatter: (val) => {
                            if (val.rtuName) {
                                return '<b>' + val.rtuName + '</b>' + '<b>【' + val.rtuCode + '】</b>'
                            } else {
                                return '<b>' + val.rtuCode + '</b>'
                            }
                        }
                    },
                    {
                        label: "测站名称",
                        prop: "rtuName",
                        span: 24,
                        search: true,
                        hide: true,
                    },
                    // {
                    //     label: "行政区",
                    //     prop: "adCity",
                    //     span: 12,
                    //     html: true,
                    //     formatter: (val) => {
                    //         if (val.adDist) {
                    //             return '<b>' + val.adCity + '</b>/' + '<b>' + val.adDist + '</b>'
                    //         } else {
                    //             return '<b>' + val.adCity + '</b>'
                    //         }
                    //     }
                    // },
                    {
                        label: "运维单位",
                        prop: "manageCompany",
                        span: 12,
                        width: 180
                    },
                    {
                        label: "异常信息",
                        prop: "warningDesc",
                        span: 12,
                    },
                    {
                        label: "异常类别",
                        prop: "warningKind",
                        span: 12,
                        html: true,
                        formatter: (val) => {
                            if (val.warningKind) {
                                let htmltext = '';
                                if (val.warningKind == 1) {
                                    htmltext = '<b style="color:red">测站离线</b>';
                                } else if (val.warningKind == 2) {
                                    htmltext = '<b style="color:red">测站时钟异常</b>';
                                } else if (val.warningKind == 3) {
                                    htmltext = '<b style="color:red">测站雨量小时报漏报</b>';
                                } else if (val.warningKind == 4) {
                                    htmltext = '<b style="color:red">测站水位小时报漏报</b>';
                                } else if (val.warningKind == 5) {
                                    htmltext = '<b style="color:red">雨量5分钟上报延时</b>';
                                } else if (val.warningKind == 6) {
                                    htmltext = '<b style="color:red">雨量站小时上报延时</b>';
                                } else if (val.warningKind == 7) {
                                    htmltext = '<b style="color:red">水位站小时上报延时</b>';
                                } else if (val.warningKind == 8) {
                                    htmltext = '<b style="color:red">雨量疑似异常值</b>';
                                }

                                return htmltext;
                            }
                        }
                    },
                    {
                        label: "发生时间",
                        prop: "warningHappenTime",
                        span: 12,
                        width: 150
                    },
                ],
            },
            data: [],
        };
    },
    created() {

    },
    methods: {
        init() {
            this.onLoad(this.page);
        },
        searchReset() {
            this.query = {};
            this.page.currentPage = 1;
            this.onLoad(this.page);
        },
        searchChange(params, done) {
            this.query = params;
            this.page.currentPage = 1;
            this.onLoad(this.page, params);
            done();
        },
        selectionChange(list) {
            this.selectionList = list;
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },
        beforeOpen(done, type) {
            if (["edit", "view"].includes(type)) {
                getDetail(this.form.id).then((res) => {
                    this.form = res.data.data;
                });
            }
            done();
        },
        currentChange(currentPage) {
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            var params = {};
            this.onLoad(this.page, params);
        },
        onLoad(page, params = {}) {
            this.loading = true;
            params['deptId'] = this.deptId;
            console.log("load " + JSON.stringify(params))
            getOthersWarnPage(
                page.currentPage,
                page.pageSize,
                Object.assign(params, this.query)
            ).then((res) => {
                const data = res.data.data;
                this.page.total = data.total;
                this.data = data.records;
                this.loading = false;
                //this.selectionClear();
            });
        },
    },
};
</script>

<style  lang="scss" scoped>
.line {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
}

.line .lineText {
    margin-left: 10px;
    margin-right: 0px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.line .lineText .orderCount {

    color: green;
    font-size: 0.8rem;
}

.line .lineText .spliteLine {
    color: gray;
    font-size: 0.8rem;
}

.line .lineText .orderUnconfirm {

    color: lightcoral;
    font-size: 0.8rem;
}

.line .lineText .orderProcessing {

    color: dodgerblue;
    font-size: 0.8rem;
}
</style>
