<!--
 * @Title: 
 * @Description: 
 * @Author: 893699165@qq.com
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <div>
        <el-row type="flex" justify="center">
            <el-col :span="19" style="padding-left:8px;">
                <avue-form :option="planOption" v-model="editForm" ref="editForm"></avue-form>
            </el-col>
            <el-col :span="5">
                <div style="display:flex; justify-content: center;align-items: center;height: 100%;">
                    <el-button type="primary" @click="openPlanManage()" plain>巡检计划管理
                    </el-button>
                </div>

            </el-col>
        </el-row>
        <el-row>
            <el-col :span="5">
                <div class="box">
                    <el-scrollbar>
                        <basic-container>
                            <avue-tree :option="treeOption" :data="projectTreeData" @node-click="nodeClick">
                                <span class="el-tree-node__label" slot-scope="{ node, data }">
                                    <span>
                                        <i class="el-icon-user-solid"></i>
                                        {{ (node || {}).label }}
                                    </span>
                                </span>
                                <template slot-scope="scope" slot="menu">
                                    <div class="avue-tree__item" @click.native="tip(scope.node,scope.data)">自定义按钮</div>
                                </template>
                            </avue-tree>
                        </basic-container>
                    </el-scrollbar>
                </div>
            </el-col>
            <el-col :span="19">
                <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)">填报详情
                            </el-button>
                            <!-- <el-button type="text" size="small" @click="orderOff(row)">人工关闭
      </el-button> -->
                        </template>
                    </avue-crud>
                </basic-container>
            </el-col>
        </el-row>
        <!-- <el-dialog
  title="预警配置"
  :visible.sync="configDialog"
  width="600px"
  :before-close="handleClose"
  :close-on-click-modal="false"
  append-to-body
>
  <el-form label-width="120px">
    <el-form-item label="预警总开关">
      <el-switch
        v-model="warningConfig.configSw"
        active-color="#13ce66"
        inactive-color="#ff4949"
        active-text="开"
        inactive-text="关"
      >
      </el-switch>
    </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="configDialog = false" size="small">取 消</el-button>
    <el-button type="primary" @click="confirmConfig" size="small"
      >确 定</el-button
    >
  </span>
</el-dialog> -->
        <!-- <el-dialog title="预警信息" :visible.sync="warnInfoDialog" width="80%" :close-on-click-modal="false" append-to-body>
  <rtuWarningList :rtuCode="rtuCode" ref="rtuWarningList"></rtuWarningList>
</el-dialog> -->

        <el-dialog title="巡检填报记录" :visible.sync="reportDialog" v-if="reportDialog" width="80%"
            :close-on-click-modal="false" append-to-body>
            <inspectionRportDetail :id="id" ref="inspectionRportDetail"></inspectionRportDetail>
        </el-dialog>


        <el-dialog title="巡检计划" :visible.sync="projectPlanDialog" v-if="projectPlanDialog" width="60%"
            :close-on-click-modal="false" append-to-body>
            <ProjectPlan :planSetting="planSetting" rel="planSetting"></ProjectPlan>
        </el-dialog>

    </div>

</template>
<script>
import { getList as getPlanList } from "@/api/project/projectPlan.js";
import { getTree } from "@/api/business/manage/manage.js";
import projectPlan from '@/views/project/projectPlan.vue'
import {
    getPage,
    getDetail,
} from "@/api/business/inspection/inspection";
// import { mapGetters } from "vuex";
import inspectionRportDetail from "./inspectionRportDetail";
import ProjectPlan from "../../project/projectPlan.vue";
//let baseUrl = 'http://localhost:40004/api/galaxy-test'
export default {
    components: {
        inspectionRportDetail,
        projectPlan,
        ProjectPlan
    },
    data() {
        return {
            id: '',
            projectPlanDialog: false,

            planSetting: {
                orgId: 0,
                projectId: 0,
                planTitle: ''
            },

            planOption: {
                submitBtn: false,
                emptyBtn: false,
                column: [{
                    label: '巡检计划',
                    prop: 'planId',
                    type: 'select',

                    dicUrl: `./api/galaxy-test/equipment/inspection/plan/all/list`,
                    props: {
                        label: "planTitle",
                        value: "id",
                    }
                }]
            },
            planId: '',

            reportDialog: false,

            editForm: {

            },
            editDialog: false,
            form: {},

            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            treeCache: {
                orgId: '',
                projectId: '',
            },
            projectTreeData: [

            ],
            treeOption: {
                nodeKey: "id",
                lazy: false,

                // treeLoad: function (node, resolve) {
                // const parentId = node.level === 0 ? 0 : node.data.id;
                // getDeptLazyTree(parentId).then((res) => {
                // resolve(
                // res.data.data.map((item) => {
                // return {
                // ...item,
                // leaf: !item.hasChildren,
                // };
                // })
                // );
                // });
                // },
                defaultExpandAll: true,
                addBtn: false,
                menu: false,
                size: "small",
                props: {
                    labelText: "标题",
                    label: "title",
                    value: "value",
                    children: "children",
                },
            },
            option: {
                labelWidth: 120,
                viewLabelWidth: 100,
                searchlabelWidth: 100,
                // height: "auto",
                calcHeight: 30,
                align: "center",
                headerAlign: "center",

                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                addBtn: false,

                border: true,
                index: true,
                height: 500,
                editBtn: false,
                delBtn: false,
                menuWidth: 160,
                dialogType: "drawer",

                dialogClickModal: false,
                column: [
                    //   {
                    //     label: "计划名称",
                    // prop: "planId",
                    // span: 12,
                    // type: "select",
                    // hide: true,
                    // search:true,
                    // dicUrl:`./api/galaxy-test/equipment/inspection/plan/all/list`,
                    // props:{
                    //   label:"planTitle",
                    //   value:"id",
                    // }
                    //   },
                    {

                        label: "测站名称",
                        prop: "rtuName",
                        span: 12,
                        search: true,
                    },
                    {
                        label: "测站编码",
                        prop: "rtuCode",
                        span: 12,
                        search: true,
                    },
                    {
                        label: "填报总结说明",
                        prop: "reportDesc",
                        span: 12,
                    },
                    {
                        label: "填报人",
                        prop: "createUser",
                        span: 12,
                    },
                    {
                        label: "填报时间",
                        prop: "createTime",
                        span: 12,
                    },


                ],
            },
            data: [],
        };
    },

    created() {
        this.init();
    },
    watch: {
        'editForm.planId': {
            handler(val) {
                if (val != '' && val != undefined && val != null) {
                    this.planId = val;
                    // this.$message.success(this.planId)
                }
            },
            immediate: true
        }
    },
    methods: {
        openPlanManage() {
            const planDate = new Date();
            //  this.planSetting.orgId = item.orgId;
            //  this.planSetting.projectId = item.id;
            const y = planDate.getFullYear();
            this.planSetting.planTitle = "" + y + "年度巡检计划";
            this.projectPlanDialog = true;
        },
        init() {
            this.initTree();
            this.initPlan();
        },
        initTree() {
            getTree(
            ).then((res) => {
                const data = res.data.data;
                this.projectTreeData = data;
            });
        },
        initPlan() {
            getPlanList(
            ).then((res) => {
                this.editForm.planId = res.data.data[0].id;
                this.planId = res.data.data[0].id;
                this.onLoad(this.page);
            });

        },
        nodeClick(data) {
            this.treeCache.orgId = data.orgId;
            this.treeCache.projectId = data.projectId;
            //this.$message.success(JSON.stringify(data))
            this.query = {};
            this.page.currentPage = 1;
            this.onLoad(this.page);
        },
        openReportDetail(item) {
            this.reportDialog = true;
            this.id = item.id;
            this.$nextTick(() => {
                this.$refs["inspectionRportDetail"].init();
            });
        },
        // orderOff(item) {
        // this.$prompt("请输入处理意见","是否确认关闭此工单？", {
        // confirmButtonText: "确定",
        // cancelButtonText: "取消",

        // })
        // .then(({ value }) => {
        //   confirm({ id: item.id, orderDesc: value }).then((res) => {
        // if (res.data.code == 200) {
        // this.$message({
        // type: "info",
        // message: "操作成功",
        // });
        // this.refreshChange();
        // }
        // });
        // })
        // .catch(() => { });
        // },


        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 (["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['planId'] = this.planId;
            params['orgId'] = this.treeCache.orgId;
            params['projectId'] = this.treeCache.projectId;

            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;
        }
    }
}
</style>
