<!--
 * @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="6">
                <div class="box">
                    <el-scrollbar>
                        <basic-container>
                            <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick">
                                <span class="el-tree-node__label" slot-scope="{ node, data }">
                                    <span>
                                        <i class="el-icon-office-building"></i>
                                        {{ (node || {}).label }}
                                    </span>
                                </span>
                            </avue-tree>
                        </basic-container>
                    </el-scrollbar>
                </div>
            </el-col>
            <el-col :span="18">
                <basic-container>
                    <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page"
                        :before-open="beforeOpen" ref="crud" v-model="form" :permission="permissionList"
                        @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
                        @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
                        @on-load="onLoad" @before-open="beforeOpen" @select-change="selectChange">
                        <!-- <template slot="warnStatus" slot-scope="row">
                            <div v-if="row.row.warnStatus == 0" style="color: blue;">
                                正常
                            </div>
                            <div v-else-if="row.row.warnStatus == 1" style="color: blue;">
                                设备异常
                            </div>
                            <div v-else>

                            </div>
                        </template> -->

                        <template slot-scope="{ row, index }" slot="menu">
                            <el-button type="text" size="small" @click="toDangerAreaCheckList(row)">巡查信息
                            </el-button>
                            <el-button type="text" size="small" @click="toTransferResidentList(row)">转移清单
                            </el-button>
                        </template>
                    </avue-crud>
                </basic-container>
            </el-col>
        </el-row>
        <el-drawer :visible.sync="dangerAreaCheckDialog" v-if="dangerAreaCheckDialog" title="现场巡查" direction="rtl"
            size="60%" append-to-body="true">
            <yjdangerareachecklist ref="dangerareachecklistView" :warnId="warnId">
            </yjdangerareachecklist>
        </el-drawer>
        <el-drawer :visible.sync="transferResidentDialog" v-if="transferResidentDialog" title="转移清单" direction="rtl"
            size="60%" append-to-body="true">
            <yjtransferresidentlist ref="transferresidentlistView" :warnId="warnId">
            </yjtransferresidentlist>
        </el-drawer>
    </div>
</template>

<script>

import { getPage, getDetail } from "@/api/business/yj/yjwarn.js";
import { getLazyTree } from "@/api/baseinfo/wholeregion.js";
import { mapGetters } from "vuex";
import yjdangerareachecklist from "./yjdangerareachecklist.vue";
import yjtransferresidentlist from './yjtransferresidentlist.vue';
export default {
    components: {
        yjdangerareachecklist,
        yjtransferresidentlist
    },
    data() {
        return {
            id: '',
            warnId: '',
            editForm: {},
            editDialog: false,
            transferResidentDialog: false,
            dangerAreaCheckDialog: false,
            form: {},
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            treeCode: '',
            treeParentCode: '',
            treeData: [],
            treeOption: {
                nodeKey: "id",
                defaultExpandedKeys: [],
                lazy: true,
                treeLoad: function (node, resolve) {
                    const parentCode = (node.level === 0) ? "00" : node.data.value;
                    getLazyTree(parentCode).then(res => {
                        resolve(res.data.data.map(item => {
                            return {
                                ...item,
                                leaf: !item.hasChildren
                            }
                        }))

                        // this.treeOption.defaultExpandedKeys.push(this.treeData[0].id);
                        // this.treeCode = this.treeData[0].id;
                    });
                },
                addBtn: false,
                menu: true,
                size: "small",
                props: {
                    labelText: "标题",
                    label: "title",
                    value: "value",
                    children: "children",
                },
            },
            option: {
                labelWidth: 140,
                viewLabelWidth: 140,
                searchlabelWidth: 140,
                height: "auto",
                calcHeight: 80,
                align: "center",
                headerAlign: "center",
                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                border: true,
                index: true,
                selection: false,
                viewBtn: true,
                viewTitle: "预警响应信息",
                editBtn: true,
                delBtn: true,
                menuWidth: 200,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: false,
                column: [
                    {
                        label: "预警编码",
                        prop: "warnId",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "测站编码",
                        prop: "stcd",
                        search: true,
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "预警名称",
                        prop: "warnName",
                        span: 24,
                        overHidden: true,
                    },
                    {
                        label: "预警时间",
                        prop: "warnTime",
                        span: 24,
                    },
                    {
                        label: "预警等级",
                        prop: "warnLevelCode",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "预警信息",
                        prop: "warnInfo",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "预警状态",
                        prop: "warnStatus",
                        span: 24,
                        html: true,
                        type: 'radio',
                        dicData: [{
                            label: '审核未通过',
                            value: -1
                        }, {
                            label: '未审核',
                            value: 0
                        }, {
                            label: '待内部预警',
                            value: 1
                        }, {
                            label: '待外部预警',
                            value: 2
                        }, {
                            label: '待响应启动',
                            value: 3
                        }, {
                            label: '待响应反馈',
                            value: 4
                        }, {
                            label: '已启动响应',
                            value: 5
                        },]
                        // formatter: (val) => {
                        //     let htmltext = '';
                        //     if (val.warnStatus === 0) {
                        //         htmltext = '<b style="color:blue">未审核</b>';
                        //     } else if (val.warnStatus === 1) {
                        //         htmltext = '<b style="color:blue">待内部预警</b>';
                        //     } else if (val.warnStatus === 2) {
                        //         htmltext = '<b style="color:blue">待外部预警</b>';
                        //     } else if (val.warnStatus === 3) {
                        //         htmltext = '<b style="color:blue">待响应启动</b>';
                        //     } else if (val.warnStatus === 4) {
                        //         htmltext = '<b style="color:blue">待响应反馈</b>';
                        //     } else if (val.warnStatus === 5) {
                        //         htmltext = '<b style="color:blue">已启动响应</b>';
                        //     } else {
                        //         htmltext = '审核未通过';
                        //     }
                        //     return htmltext;
                        // }
                    },
                    {
                        label: "审核状态",
                        prop: "reviewStatus",
                        span: 24,
                        hide: true,
                        type: 'radio',
                        dicData: [{
                            label: '关闭',
                            value: 1
                        }, {
                            label: '通过',
                            value: 2
                        }]
                    },
                    {
                        label: "站类",
                        prop: "type",
                        span: 24,
                        hide: true,
                        type: 'radio',
                        dicData: [{
                            label: '雨量站',
                            value: 1
                        }, {
                            label: '河道水情站',
                            value: 2
                        }, {
                            label: '水库水情站',
                            value: 3
                        }, {
                            label: '政区',
                            value: 4
                        }, {
                            label: '人工',
                            value: 5
                        }]
                    },
                    {
                        label: "备注",
                        prop: "remark",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "雨量站预警频率",
                        prop: "rainWarnRate",
                        span: 24,
                        hide: true,
                        type: 'radio',
                        dicData: [{
                            label: '30分钟',
                            value: 1
                        }, {
                            label: '1小时',
                            value: 2
                        }, {
                            label: '3小时',
                            value: 3
                        }, {
                            label: '6小时',
                            value: 4
                        }, {
                            label: '12小时',
                            value: 5
                        }, {
                            label: '24小时',
                            value: 6
                        }]
                    },
                    {
                        label: "预警类别",
                        prop: "warnSort",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "预警定位（点,面）",
                        prop: "warnLocation",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "预警政区",
                        prop: "warnAdcd",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "预警点经度",
                        prop: "warnLgtd",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "预警点纬度",
                        prop: "warnLttd",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "降雨时段",
                        prop: "intv",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "降雨总量",
                        prop: "drp",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "河道水位",
                        prop: "z",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "河道流量",
                        prop: "q",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "河道水势",
                        prop: "wptn",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "水库水位",
                        prop: "rz",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "水库水势",
                        prop: "rwptn",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "水库流量",
                        prop: "inq",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "水库流量",
                        prop: "inq",
                        span: 24,
                        hide: true,
                    },
                ],
            },
            data: [],
        };
    },
    computed: {
        ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {
                addBtn: false,
                viewBtn: true,
                delBtn: false,
                editBtn: false,
            };
        },
        ids() {
            let ids = [];
            this.selectionList.forEach((ele) => {
                ids.push(ele.id);
            });
            return ids.join(",");
        },
    },
    mounted() { },
    created() {
    },
    methods: {
        // rowSave(row, done, loading) {
        //     add(row).then(
        //         () => {
        //             this.onLoad(this.page);
        //             this.$message({
        //                 type: "success",
        //                 message: "操作成功!",
        //             });
        //             done();
        //         },
        //         (error) => {
        //             window.console.log(error);
        //             loading();
        //         }
        //     );
        // },
        // rowUpdate(row, index, done, loading) {
        //     update(row).then(
        //         () => {
        //             this.onLoad(this.page);
        //             this.$message({
        //                 type: "success",
        //                 message: "操作成功!",
        //             });
        //             done();
        //         },
        //         (error) => {
        //             window.console.log(error);
        //             loading();
        //         }
        //     );
        // },
        // rowDel(row) {
        //     this.$confirm("确定将选择数据删除?", {
        //         confirmButtonText: "确定",
        //         cancelButtonText: "取消",
        //         type: "warning",
        //     })
        //         .then(() => {
        //             return remove(row.id);
        //         })
        //         .then(() => {
        //             this.onLoad(this.page);
        //             this.$message({
        //                 type: "success",
        //                 message: "操作成功!",
        //             });
        //         });
        // },
        toDangerAreaCheckList(row) {
            this.warnId = row.warnId;
            this.dangerAreaCheckDialog = true;
            this.$nextTick(() => {
                this.$refs["dangerareachecklistView"].initData();
            });
        },
        toTransferResidentList(row) {
            this.warnId = row.warnId;
            this.transferResidentDialog = true;
            this.$nextTick(() => {
                this.$refs["transferresidentlistView"].initData();
            });
        },
        nodeClick(data) {
            this.treeCode = data.id;
            this.treeParentCode = data.parentId;
            // this.query = {};
            // this.query['dangerAreaCode'] = this.treeCode;
            this.page.currentPage = 1;
            var params = {};
            // params['dangerAreaCode'] = this.treeCode;
            this.onLoad(this.page, params);
        },
        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;
        },
        selectChange(item) {
            console.log(item)
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },
        // handleDelete() {
        //     if (this.selectionList.length === 0) {
        //         this.$message.warning("请选择至少一条数据");
        //         return;
        //     }
        //     this.$confirm("确定将选择数据删除?", {
        //         confirmButtonText: "确定",
        //         cancelButtonText: "取消",
        //         type: "warning",
        //     })
        //         .then(() => {
        //             return remove(this.ids);
        //         })
        //         .then(() => {
        //             this.onLoad(this.page);
        //             this.$message({
        //                 type: "success",
        //                 message: "操作成功!",
        //             });
        //             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() {
            this.onLoad(this.page, this.query);
        },
        onLoad(page, params = {}) {
            this.loading = true;
            params['warnAdcd'] = this.treeCode;
            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>
<style>
.box {
    height: 800px;
}

.el-scrollbar {
    height: 100%;
}

.box .el-scrollbar__wrap {
    overflow: scroll;
}
</style>
