<!--
 * @Title: 
 * @Description: 
 * @Author: 893699165@qq.com
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <div>
        <basic-container>
            <avue-crud :option="option" :table-loading="loading" :page.sync="page" :data="data" ref="crud"
                v-model="form" :permission="permissionList" @row-del="rowDel" @row-update="rowUpdate"
                @row-save="rowSave" @search-change="searchChange" @search-reset="searchReset"
                @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
                @refresh-change="refreshChange" @on-load="onLoad" @before-open="beforeOpen">
                <template slot="warningStatus" slot-scope="row">
                    <div v-if="row.row.warningStatus==0" style="color: orangered;">
                        预警中
                    </div>
                    <div v-else style="color: blue;">
                        关闭
                    </div>
                </template>
                <template slot-scope="{ row, index }" slot="menu">

                    <el-button icon="el-icon-link" type="text" size="small" @click="toWarnInfoDetail(row)">预警详情
                    </el-button>

                </template>
            </avue-crud>
            <el-drawer :visible.sync="drawer" title="预警信息详情" direction="rtl" size="40%" append-to-body="true">
                <originalWarnInfoDetail :id="dataFromId" ref="originalWarnInfoDetail"></originalWarnInfoDetail>
            </el-drawer>
        </basic-container>

    </div>

</template>

<script>
import { getPage, getDetail } from "@/api/warning/warning";
// import { mapGetters } from "vuex";
import originalWarnInfoDetail from "./originalWarnInfoDetail";
export default {
    components: { originalWarnInfoDetail },
    data() {
        return {
            dataFromId: '',
            drawer: false,
            // rtuCode: "",
            editForm: {},
            editDialog: false,
            form: {},
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },

            option: {
                labelWidth: 120,
                viewLabelWidth: 100,
                searchlabelWidth: 100,
                //  height: "auto",
                calcHeight: 30,
                align: "center",
                headerAlign: "center",

                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                menu: true,
                border: true,
                index: true,
                height: 300,
                editBtn: false,
                delBtn: false,
                addBtn: false,
                viewBtn: false,
                viewBtnText: "预警详情",
                menuWidth: 220,
                dialogType: "drawer",

                dialogClickModal: false,
                column: [
                    {
                        label: "预警类型",
                        prop: "warningKind",
                        span: 12,
                    },
                    {
                        label: "预警信息",
                        prop: "warningDesc",
                        span: 12,
                    },
                    {
                        label: "预警时间",
                        prop: "warningHappenTime",
                        span: 12,
                        search: true,
                    },
                    {
                        label: "恢复时间",
                        prop: "warningRecoveryTime",
                        span: 12,
                        search: true,
                    },
                    {
                        label: "预警状态",
                        prop: "warningStatus",
                        span: 12,
                        solt: true,
                    },
                ],
            },
            data: [],
        };
    },
    props: {
        rtuCode: {
            type: [String],
            required: true
        },

    },
    created() {
        this.init();
    },
    methods: {
        init() {
            //this.$message.success(this.rtuCode)
            this.onLoad(this.page);
        },
        toWarnInfoDetail(row) {
            this.dataFromId = row.dataFromId;
            this.drawer = true;
        },
        searchReset() {
            this.query = {};
            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 (["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() {
            this.onLoad(this.page, this.query);
        },
        onLoad(page, params = {}) {
            this.loading = true;
            params['rtuCode'] = this.rtuCode;

            getPage(
                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>
