<!--
 * @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>
            <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" :data="data" :page.sync="page"
                        :before-open="beforeOpen" 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"
                        @select-change="selectChange">

                    </avue-crud>
                </basic-container>
            </el-col>
        </el-row>

    </div>
</template>
  
<script>
import { getPage, } from "@/api/data/dataRiver.js";
import { getTree } from "@/api/business/manage/manage.js";

export default {
    components: {

    },
    data() {
        return {

            id: "",
            editForm: {},
            editDialog: false,
            form: {},
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            treeCache: {
                orgId: '',
                projectId: '',
            },
            projectTreeData: [

            ],
            treeOption: {
                nodeKey: "id",
                lazy: false,
                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",
                //height: 600,
                calcHeight: 30,
                align: "center",
                headerAlign: "center",
                lazy: false,
                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                tree: true,
                border: true,
                index: true,
                selection: true,
                viewBtn: false,
                viewTitle: "测站信息",
                editBtn: false,
                delBtn: false,
                addBtn: false,
                menu: false,
                dialogType: "drawer",
                dialogClickModal: false,
                column: [
                    {
                        label: "站点名称",
                        prop: "rtuName",
                        search: true,
                        span: 12,
                    },
                    {
                        label: "站点编码",
                        prop: "rtuCode",
                        span: 12,
                    },
                    {
                        label: "河道水位",
                        prop: "z",
                        span: 8,
                    },
                    {
                        label: "上报时间",
                        prop: "tm",
                        span: 8,
                    },
                ],
            },
            data: [],
        };
    },
    computed: {
        // ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {
                // addBtn: this.vaildData(this.permission.docCategory_add, false),
                // viewBtn: this.vaildData(this.permission.docCategory_view, false),
                // delBtn: this.vaildData(this.permission.docCategory_delete, false),
                // editBtn: this.vaildData(this.permission.docCategory_edit, false),
            };
        },
        ids() {
            let ids = [];
            this.selectionList.forEach((ele) => {
                ids.push(ele.id);
            });
            return ids.join(",");
        },
    },
    mounted() { },
    created() {
        this.initTree();
    },

    methods: {

        initTree() {
            getTree(
            ).then((res) => {
                const data = res.data.data;
                this.projectTreeData = data;
            });
        },
        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);
        },
        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.$message.success("ssssssssssssssssssssssssss")
            this.selectionList = list;
        },
        selectChange(item) {
            this.$message.success("sssssssssssssssss" + item)
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },

        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['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>
  