<template>
    <div class="page">
        <LayoutTable ref="layoutTable" :data="tableData" :config="tableConfig" />
        <dialog-show ref="dialogform" @ok="getData" />
            
    </div>
</template>

<script>
    import dialogShow from "./dialogshow";
    import { handleTree } from "@/assets/utils/table";
    import Treeselect from "@riophae/vue-treeselect";
    import "@riophae/vue-treeselect/dist/vue-treeselect.css";
    import table from "@/assets/mixins/table";
    export default {
        name: "Area",
        mixins: [table],
        components: { Treeselect, dialogShow },
        created() {
        },
        methods: {
            afterRender(data) {
                data.result = handleTree(data.result, "iid","pid");
                this.areaOptions = data.result;
                this.$refs.layoutTable.showType="treetable"
            },

            /** 重写新增方法 */
            toAdd(row) {
                this.$refs.dialogform.add(row, this.areaOptions);
            },
            /** 重写编辑方法 */
            toEdit(row) {
                this.loading = true;
                this.$post(this.pageInfo.exclude, {id : [row.id] })
                    .then((res) => {
                        if (res && res.code && res.code == 1) {
                            this.areaOptions = handleTree(res.data.result);
                            this.$refs.dialogform.edit(row, this.areaOptions);
                            this.loading = false;
                        }
                    })
                    .catch((error) => {
                        this.$message.error(error.message);
                    });
            },
            /** 重写查看方法 */
            toView(row) {
                this.$refs.dialogform.view(row, this.areaOptions);
            },
        },
        data() {
            return {
                config: {
                    /** 树表是否默认展开 */
                    expand:true,
                    showType: "treetable",
                    search: [
                        {
                            name: "name",
                            type: "text",
                            label: "区域名称",
                            fuzzy: true
                        },
                        {
                            name: "areaCode",
                            type: "text",
                            label: "区域编码",
                            fuzzy: true
                        },
                    ],
                    columns: [
                        {label: "区域编码", prop: "areaCode"},
                        {label: "区域等级", prop: "areaLevel"},

                        {
                            label: "操作",
                            width: 280,
                            formatter: row => {
                                return (
                                    <table-buttons  row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
                            );
                            }
                        }
                    ]
                }
            };
        }
    };
</script>