<!--
 * @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" @row-del="rowDel"
                        @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
                        @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
                        @on-load="onLoad" @before-open="beforeOpen" @select-change="selectChange">
                        <template slot-scope="scope" slot="menuLeft">
                            <el-button v-if="permissionList.importBtn" type="primary" icon="el-icon-upload2" size="small"
                                @click="toImpoartHandler">导入转移路线</el-button>
                            <el-button v-if="permissionList.importBtn" type="primary" icon="el-icon-finished" size="small"
                                @click="toImportHistoryHandler">导入历史</el-button>
                        </template>
                        <template slot-scope="{ row, index }" slot="menu">
                            <el-button v-if="permission.order_change && row.orderClose == 0" style="color:orange"
                                type="text" size="small" @click="toMap(row)" icon="el-icon-position">
                                查看地图
                            </el-button>
                        </template>
                    </avue-crud>
                </basic-container>
            </el-col>
        </el-row>
        <el-drawer :visible.sync="leaveLineImportHistoryDialog" v-if="leaveLineImportHistoryDialog" title="导入记录"
            direction="rtl" size="60%" append-to-body="true">
            <leavelineimporthistoryVue ref="leavelineimporthistoryView"></leavelineimporthistoryVue>
        </el-drawer>
        <el-dialog title="导入向导" :visible.sync="leaveLineImportDialog" width="60%" height="60%" :close-on-click-modal="false"
            append-to-body :v-loading="importLoading" v-if="leaveLineImportDialog">
            <leavelineimportVue :importLoading="importLoading" :visible.sync="leaveLineImportDialog"
                ref="leavelineimportView">
            </leavelineimportVue>
        </el-dialog>
    </div>
</template>

<script>
import { getPage, remove, getDetail } from "@/api/baseinfo/map/leaveline.js";
import { mapGetters } from "vuex";
import leavelineimportVue from './leavelineimport.vue';
import leavelineimporthistoryVue from "./leavelineimporthistory.vue"
export default {
    components: {
        leavelineimportVue,
        leavelineimporthistoryVue,
    },
    data() {
        return {
            importLoading: false,
            leaveLineImportDialog: false,
            leaveLineImportHistoryDialog: false,
            id: "",
            post_code: '0',
            form: {},
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            option: {
                labelWidth: 140,
                viewLabelWidth: 140,
                searchLabelWidth: 140,
                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,
                editBtn: false,
                delBtn: true,
                addBtn: false,
                menuWidth: 220,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: false,
                column: [
                    {
                        label: "转移路线名称",
                        prop: "leaveLineName",
                        search: true,
                        span: 24,
                    },
                    {
                        label: "行政区编码",
                        prop: "adcd",
                        span: 24,
                    },
                    {
                        label: "行政区名称",
                        prop: "adnm",
                        span: 24,
                    },
                ],
            },
            data: [],
        };
    },
    computed: {
        ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {
                importBtn: this.vaildData(this.permission.danger_area_leave_line_import, false),
            };
        },
    },
    created() {

    },
    methods: {
        toImpoartHandler() {
            this.leaveLineImportDialog = true;
        },
        toImportHistoryHandler() {
            this.leaveLineImportHistoryDialog = true;
        },
        toMap(item) {
            console.log(JSON.stringify(item));
        },
        searchReset() {
            this.query = {};
            this.page.currentPage = 1;
            this.onLoad(this.page);
        },
        searchChange(params, done) {
            this.query = params;
            this.page.currentPage = 1;
            this.onLoad(this.page, params);
            done();
        },
        currentChange(currentPage) {
            console.log("currentPage " + currentPage);
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            var params = {};
            this.onLoad(this.page, params);
        },
        selectionChange(list) {
            this.selectionList = list;
        },
        selectChange(item) {
            console.log(JSON.stringify(item));
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },
        rowDel(row) {
            this.$confirm("确定将选择数据删除?", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    return remove(row.id);
                })
                .then(() => {
                    this.onLoad(this.page);
                    this.$message({
                        type: "success",
                        message: "操作成功!",
                    });
                });
        },
        beforeOpen(done, type) {
            if (["view"].includes(type)) {
                getDetail(this.form.id).then((res) => {
                    this.form = res.data.data;
                });
            }
            done();
        },
        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>
.box {
    height: 800px;
}

.el-scrollbar {
    height: 100%;
}

.box .el-scrollbar__wrap {
    overflow: scroll;
}
</style>
