<!--
 * @Title: 
 * @Description: 
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <el-row>
        <el-col :span="24">
            <basic-container>
                <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page"
                    :before-open="beforeOpen" 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"
                    @on-load="onLoad">
                </avue-crud>
            </basic-container>
        </el-col>

    </el-row>
</template>

<script>
import { getDetailPage } from "@/api/data/rtuImport.js";

export default {
    props: {
        id: {
            type: [Number],
            required: true
        },
    },
    components: {

    },
    data() {
        return {
            loading: false,
            form: {},
            selectionList: [],
            query: {},
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            option: {
                labelWidth: 120,
                viewLabelWidth: 100,
                searchlabelWidth: 100,
                height: "auto",
                calcHeight: 400,
                align: "center",
                headerAlign: "center",
                lazy: false,
                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                tree: true,
                border: true,
                index: true,
                selection: false,
                viewBtn: false,
                editBtn: false,
                delBtn: false,
                addBtn: false,
                menu: false,
                menuWidth: 220,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: false,
                column: [
                    {
                        label: "测站名称",
                        prop: "rtuName",
                        span: 24,
                    },
                    {
                        label: "测站编码",
                        prop: "rtuCode",
                        span: 24,
                    },
                    {
                        label: "操作类型",
                        prop: "saveType",
                        span: 24,
                        html: true,
                        formatter: (val) => {
                            if (val.saveType === 0) {
                                return '<b style="color:blue">只新增</b>'
                            } else if (val.saveType === 1) {
                                return '<b style="color:red">覆盖已有测站</b>'
                            } else if (val.saveType === 2) {
                                return '<b style="color:red">删除测站</b>'
                            } else {
                                return '';
                            }
                        },
                    },
                ],
            },
            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() {

    },
    methods: {
        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 = {}) {
            params['id'] = this.id;
            this.loading = true;
            getDetailPage(
                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>
