<!--
 * @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" :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="{ row, index }" slot="menu">
                            <el-button type="text" size="small" @click="openReportDetail(row)" icon="el-icon-view">查看详情
                            </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,
} from "@/api/business/inspection/inspectionreport.js";

import { mapGetters } from "vuex";
import inspectionreportdetail from "./inspectionreportdetail.vue";
export default {
    components: {
        inspectionreportdetail,
    },
    props: {
        rainSeasonKind: {
            type: [Number],
            required: true
        },
    },
    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: 160,
                menu: false,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: 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: 12,
                        search: true,
                        hide: 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: "servicePersonName",
                        span: 24,
                    },
                    {
                        label: "填报时间",
                        prop: "createTime",
                        span: 24,
                        width: 150,
                    },
                    {
                        label: "行政区",
                        prop: "adCity",
                        span: 24,
                        html: true,
                        formatter: (val) => {
                            if (val.adCity) {
                                return '<b style="color: gray;">' + val.adCity + '</b>/' + '<b style="color: gray;">' + val.adDist + '</b>'
                            } else {
                                return '<b></b>'
                            }
                        }
                    },
                    {
                        label: "运维单位",
                        prop: "manageCompany",
                        span: 24,

                    },

                ],
            },
            data: [],
        };
    },
    computed: {
        ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {

            };
        },
    },
    created() {

    },
    watch: {
        // 'editForm.planId': {
        //     handler(val) {
        //         if (val != '' && val != undefined && val != null) {
        //             this.planId = val;
        //         }
        //     },
        //     immediate: true
        // }
    },
    methods: {
        init() {

        },
        openReportDetail(item) {
            this.reportDialog = true;
            this.dialogTitle = '设备巡检填报信息';
            this.id = item.id;
            this.$nextTick(() => {
                this.$refs["inspectionreportdetail"].init();
            });
        },
        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;
            params['rainSeasonKind'] = this.rainSeasonKind;
            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>
