<!--
 * @Title: 
 * @Description: 
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <div>
        <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>
    </div>
</template>

<script>

import { getImportPage } from "@/api/baseinfo/map/dangerarea.js";
export default {
    components: {

    },
    data() {
        return {
            detailDialog: false,
            loading: false,
            id: "",
            editForm: {},
            editDialog: false,
            form: {},
            selectionList: [],
            query: {},
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            option: {
                labelWidth: 120,
                viewLabelWidth: 100,
                searchlabelWidth: 100,
                height: "auto",
                calcHeight: 80,
                align: "center",
                headerAlign: "center",
                lazy: false,
                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                tree: true,
                border: true,
                index: true,
                selection: false,
                viewBtn: false,
                viewTitle: "危险区导入",
                editBtn: false,
                delBtn: false,
                addBtn: false,
                menu: false,
                menuWidth: 120,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: false,
                column: [
                    {
                        label: "导入结果",
                        prop: "importStatus",
                        span: 24,
                        width: 120,
                        html: true,
                        formatter: (val) => {
                            if (val.importStatus === 0) {
                                return '<b style="color:blue">导入中</b>'
                            } else if (val.importStatus === 1) {
                                return '<b style="color:green">导入成功</b>'
                            } else if (val.importStatus === 2) {
                                return '<b style="color:red">导入失败</b>'
                            } else {
                                return '';
                            }
                        },
                    },
                    {
                        label: "操作用户",
                        prop: "createUserName",
                        span: 24,
                        width: 120,
                        editDisplay: false,
                        addDisplay: false,
                        hide: true,
                    },
                    {
                        label: "导入时间",
                        prop: "importTime",
                        span: 24,
                        width: 160,
                    },
                    {
                        label: "导入说明",
                        prop: "remark",
                        span: 24,
                        overHidden: true,
                    },
                    {
                        label: "导入操作类型",
                        prop: "saveType",
                        span: 24,
                        width: 120,
                        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 '';
                            }
                        },
                    },
                    {
                        label: "文件名称",
                        prop: "fileName",
                        span: 24,
                        overHidden: true,
                    },
                ],
            },
            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 = {}) {
            this.loading = true;
            getImportPage(
                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>
