<template>
    <div>
        <!-- <el-row :gutter="10" style="margin-bottom: 0px;">
            <el-col :span="24">
                <basic-container>
                    <avue-form :option="searchOption" v-model="searchForm" @submit="handleImportSubmit">
                    </avue-form>
                </basic-container>
            </el-col>
        </el-row> -->
        <el-row :gutter="10" style="margin-bottom: 0px;">
            <el-col :span="24">
                <basic-container>
                    <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" ref="crud"
                        v-model="form" :permission="permissionList" @search-change="searchChange"
                        @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange"
                        @size-change="sizeChange" @refresh-change="refreshChange" @before-open="beforeOpen"
                        @sort-change="sortChange" @cell-click="cellClick" @on-load="onLoad">
                    </avue-crud>
                </basic-container>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import { getWaterUseConsumerYearCountPage } from "@/api/business/count/count";
import { mapGetters } from "vuex";

export default {
    data() {
        return {
            form: {},
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            searchForm: {
                tm: '',
            },
            searchOption: {
                submitText: '查询',
                column: [
                    {
                        label: "统计年月",
                        prop: "tm",
                        type: "date",
                        span: 6,
                        format: 'yyyy年MM月',
                        valueFormat: 'yyyy-MM-dd',
                    }
                ]
            },
            option: {
                height: 'auto',
                calcHeight: 30,
                tip: false,
                searchShow: true,
                searchMenuSpan: 6,
                border: true,
                index: true,
                selection: true,
                viewBtn: false,
                dialogClickModal: false,
                menu: false,
                column: [
                    {
                        label: "取用水户编码",
                        prop: "wiuCd",
                    }, {
                        label: "取用水户名称",
                        prop: "wiuNm",
                    }, {
                        label: "年份",
                        prop: "tm",
                        search: true,
                        type: "date",
                        format: 'yyyy年',
                        valueFormat: 'yyyy-MM-dd HH:mm:ss',
                    }, {
                        label: "累计用水量",
                        prop: "accw",
                    },
                ]
            },
            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(",");
        }
    },
    mounted() {
        this.searchForm.countTime = new Date();
    },
    props: {
        wiuCd: {
            type: [String],
            required: true
        },
    },
    methods: {
        init() {
            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.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;
            params['wiuCd'] = this.wiuCd;
            console.log("wiu " + JSON.stringify(params))
            getWaterUseConsumerYearCountPage(
                page.currentPage,
                page.pageSize,
                Object.assign(params, this.sort, 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>
