<!--
 * @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="4">
                <div class="box">
                    <el-scrollbar>
                        <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>
                    </el-scrollbar>
                </div>
            </el-col>
            <el-col :span="20">
                <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">
                        <template slot-scope="scope" slot="menuLeft">
                            <div class="line">
                                <div class="lineText">
                                    <span class="inspectionCount">本年度已巡检设备数量（至少一次）: {{ inspectionCountInfo.inspectionCount
                                    }}</span>
                                </div>
                                <div class="lineText">
                                    <span style="color: gray;">/</span>
                                </div>
                                <div class="lineText">
                                    <span class="beforeRainInspectionCount">汛前巡检设备数量: {{
                                        inspectionCountInfo.beforeRainInspectionCount
                                    }}</span>
                                </div>
                                <div class="lineText">
                                    <span style="color: gray;">/</span>
                                </div>
                                <div class="lineText">
                                    <span class="rainFirstInspectionCount">汛中第一次巡检设备数量: {{
                                        inspectionCountInfo.firstRainInspectionCount
                                    }}</span>
                                </div>
                                <div class="lineText">
                                    <span style="color: gray;">/</span>
                                </div>
                                <div class="lineText">
                                    <span class="rainSencodInspectionCount">汛中第二次巡检设备数量: {{
                                        inspectionCountInfo.sencodRainInspectionCount
                                    }}</span>
                                </div>
                            </div>
                        </template>
                        <template slot-scope="{ row, index }" slot="menu">
                            <el-button type="text" size="small" @click="openBeforeRainReportDetail(row)">汛前详情
                            </el-button>
                            <el-button type="text" size="small" @click="openRainFirstReportDetail(row)">汛中(一)详情
                            </el-button>
                            <el-button type="text" size="small" @click="openRainSencodReportDetail(row)">汛中(二)详情
                            </el-button>
                        </template>
                    </avue-crud>
                </basic-container>
            </el-col>
        </el-row>
        <el-drawer title="巡检填报记录" :visible.sync="reportDialog" v-if="reportDialog" :size="drawerSize" :direction="direction"
            :close-on-click-modal="false" append-to-body>
            <div slot="title" class="header-title">
                <span class="name">{{ dialogTitle }}</span>
            </div>
            <inspectionreportdetail :id="id" ref="inspectionreportdetail"></inspectionreportdetail>
        </el-drawer>
    </div>
</template>
<script>
import {
    getPage,
    getCountInfo,
} from "@/api/business/inspection/inspection.js";
import { getTree } from "@/api/baseinfo/region.js";
import { mapGetters } from "vuex";
import inspectionreportdetail from "./inspectionreportdetail.vue";
export default {
    components: {
        inspectionreportdetail,
    },
    data() {
        return {
            id: '',
            inspectionDate: '',
            beforeRainSeasonReportId: '',
            rainSeasonFirstReportId: '',
            rainSeasonSecondReportId: '',
            inspectionCountInfo: {
            },
            drawerSize: '50%',
            reportDialog: false,
            dialogTitle: '',
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            treeCode: '',
            treeParentCode: '',
            treeData: [],
            treeOption: {
                nodeKey: "id",
                defaultExpandedKeys: [],
                lazy: false,
                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: true,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                addBtn: false,
                border: true,
                index: true,
                editBtn: false,
                delBtn: false,
                viewBtn: false,
                menuWidth: 200,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: false,
                column: [
                    {
                        label: "测站名称",
                        prop: "rtuName",
                        span: 12,
                        search: true,
                        html: true,
                        formatter: (val) => {
                            if (val.rtuName) {
                                return '<b>' + val.rtuName + '</b>/' + '<b style="color:grey">' + val.rtuCode + '</b>'
                            } else {
                                return '<b>' + val.rtuName + '</b>'
                            }
                        }
                    },
                    {
                        label: "测站编码",
                        prop: "rtuCode",
                        span: 12,
                        search: true,
                        hide: true,
                    },
                    {
                        label: "汛前巡检ID",
                        prop: "beforeRainSeasonReportId",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "汛前巡检",
                        prop: "beforeRainSeasonStatus",
                        span: 24,
                        html: true,
                        formatter: (val) => {
                            if (val.beforeRainSeasonStatus == 1) {
                                return '<b style="color:darkcyan;">已填报</b>'
                            } else {
                                return '<b style="color:darkorange;">未填报</b>'
                            }
                        }
                    },
                    {
                        label: "汛前填报人",
                        prop: "beforeRainSeasonReportUserName",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "汛前填报时间",
                        prop: "beforeRainSeasonReportTime",
                        span: 24,

                    },
                    {
                        label: "汛中巡检(一)ID",
                        prop: "rainSeasonFirstReportId",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "汛中巡检(一)",
                        prop: "rainSeasonFirstStatus",
                        span: 24,
                        html: true,
                        formatter: (val) => {
                            if (val.rainSeasonFirstStatus == 1) {
                                return '<b style="color:darkcyan;">已填报</b>'
                            } else {
                                return '<b style="color:darkorange;">未填报</b>'
                            }
                        }
                    },
                    {
                        label: "汛中填报人(一)",
                        prop: "rainSeasonFirstReportUserName",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "汛中填报时间(一)",
                        prop: "rainSeasonFirstReportTime",
                        span: 24,

                    },
                    {
                        label: "汛中巡检(二)ID",
                        prop: "rainSeasonSecondReportId",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "汛中巡检(二)",
                        prop: "rainSeasonSecondStatus",
                        span: 24,
                        html: true,
                        formatter: (val) => {
                            if (val.rainSeasonSecondStatus == 1) {
                                return '<b style="color:darkcyan;">已填报</b>'
                            } else {
                                return '<b style="color:darkorange;">未填报</b>'
                            }
                        }
                    },
                    {
                        label: "汛中填报人(二)",
                        prop: "rainSeasonSecondReportUserName",
                        span: 24,
                        hide: true,
                    },
                    {
                        label: "汛中填报时间(二)",
                        prop: "rainSeasonSecondReportTime",
                        span: 24,
                    },
                ],
            },
            data: [],
        };
    },
    computed: {
        ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {

            };
        },
    },
    created() {
        this.initTree();
    },
    watch: {
        // 'editForm.planId': {
        //     handler(val) {
        //         if (val != '' && val != undefined && val != null) {
        //             this.planId = val;
        //         }
        //     },
        //     immediate: true
        // }
    },
    methods: {
        initTree() {
            this.treeData = [];
            getTree().then(res => {
                this.treeData = res.data.data.map(item => {
                    return {
                        ...item,
                        leaf: !item.hasChildren
                    }
                })
                this.treeOption.defaultExpandedKeys.push(this.treeData[0].id);
                this.treeCode = this.treeData[0].id;
                this.getCountInfo(this.treeCode);
            });
        },
        nodeClick(data) {
            this.treeCode = data.id;
            this.treeParentCode = data.parentId;
            this.query = {};
            this.query['adCode'] = this.treeCode;
            this.page.currentPage = 1;
            var params = {};
            this.onLoad(this.page, params);
            this.getCountInfo(this.treeCode);
        },
        getCountInfo(adCode) {
            getCountInfo(adCode).then((res) => {
                this.inspectionCountInfo = res.data.data;
            });
        },
        openBeforeRainReportDetail(item) {
            if (item.beforeRainSeasonStatus == 1) {
                this.reportDialog = true;
                this.dialogTitle = '汛前巡检填报信息';
                this.id = item.beforeRainSeasonReportId;
                this.$nextTick(() => {
                    this.$refs["inspectionreportdetail"].init();
                });
            } else {

                this.$confirm("汛前巡检暂未填报！", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    showCancelButton: false,
                    type: "warning",
                })
                    .then(() => {

                    })
                    .catch(() => { });
            }
        },
        openRainFirstReportDetail(item) {
            if (item.rainSeasonFirstStatus == 1) {
                this.reportDialog = true;
                this.dialogTitle = '汛中第一次巡检填报信息';
                this.id = item.rainSeasonFirstReportId;
                this.$nextTick(() => {
                    this.$refs["inspectionreportdetail"].init();
                });
            } else {
                this.$confirm("汛中第一次巡检暂未填报！", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    showCancelButton: false,
                    type: "warning",
                })
                    .then(() => {

                    })
                    .catch(() => { });
            }
        },
        openRainSencodReportDetail(item) {
            if (item.rainSeasonSecondStatus == 1) {
                this.reportDialog = true;
                this.dialogTitle = '汛中第二次巡检填报信息';
                this.id = item.rainSeasonSecondReportId;
                this.$nextTick(() => {
                    this.$refs["inspectionreportdetail"].init();
                });
            } else {
                this.$confirm("汛中第二次巡检暂未填报！", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    showCancelButton: false,
                    type: "warning",
                })
                    .then(() => {

                    })
                    .catch(() => { });
            }
        },
        searchReset() {
            this.query = {};
            this.query['adCode'] = this.treeCode;
            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;
            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  lang="scss" scoped>
.common-dialog {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;

    .el-dialog {
        margin: 0 auto !important;
        position: relative;
        overflow: hidden;

        .el-dialog__header {
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
            width: 100%;
            height: 60px;
            z-index: 1;
        }

        .el-dialog__body {
            position: relative;
            left: 0;
            top: 60px;
            bottom: 0;
            right: 0;
            padding: 0;
            width: 100%;
            overflow: hidden;
            overflow-y: auto;
            max-height: 90vh;
            padding-top: 80px;
            padding-bottom: 100px;
            z-index: 1;
        }

        .el-dialog__footer {
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
            width: 100%;
            height: 80px;
            z-index: 1;
        }
    }
}

.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 .inspectionCount {
    color: dodgerblue;
    font-size: 0.8rem;
}

.line .lineText .beforeRainInspectionCount {
    color: darkorange;
    font-size: 0.8rem;
}

.line .lineText .rainFirstInspectionCount {
    color: lightcoral;
    font-size: 0.8rem;
}

.line .lineText .rainSencodInspectionCount {
    color: darkcyan;
    font-size: 0.8rem;
}
</style>
