<template>
    <basic-container>
        <avue-crud :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form" :page.sync="page"
            :permission="permissionList" @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="menu">
                <el-button type="text" icon="el-icon-view" size="small" @click.stop="handlePreview(scope.row)">查看年报
                </el-button>
            </template>

        </avue-crud>
    </basic-container>
</template>

<script>
import { getPage } from "@/api/baseinfo/wateruseconsumer.js";
import { mapGetters } from "vuex";

export default {
    data() {
        return {
            form: {},
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0
            },
            option: {
                labelWidth: 140,
                viewLabelWidth: 140,
                searchLabelWidth: 140,
                height: 'auto',
                calcHeight: 30,
                tip: false,
                searchShow: true,
                searchMenuSpan: 6,
                border: true,
                index: true,
                selection: true,
                viewBtn: true,
                dialogClickModal: false,
                column: [
                    {
                        label: "取用水户代码",
                        prop: "wiuCd",
                        search: true,
                        span: 24,
                    },
                    {
                        label: "取用水户名称",
                        prop: "wiuNm",
                        search: true,
                        span: 24,
                    },
                    {
                        label: "行政区",
                        prop: "orgName",
                        span: 24,
                    },
                    {
                        label: "法人代表",
                        prop: "lrNm",
                        span: 24,
                    },
                ]
            },
            data: []
        };
    },
    computed: {
        ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {
                addBtn: false,
                viewBtn: false,
                delBtn: false,
                editBtn: false
            };
        },
        ids() {
            let ids = [];
            this.selectionList.forEach(ele => {
                ids.push(ele.id);
            });
            return ids.join(",");
        }
    },
    methods: {
        handlePreview(row) {

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