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

    </div>
</template>

<script>
    import { handleTree } from "@/assets/utils/index";
    import Treeselect from "@riophae/vue-treeselect";
    import "@riophae/vue-treeselect/dist/vue-treeselect.css";
    import table from "@/assets/mixins/table";
    import dialogShow from "./dialogshow";
    export default {
        name: "Dept",
        mixins: [table],
        components: { Treeselect, dialogShow },
        created() {
        },
        methods: {
            afterRender(data) {
              console.log("data",data)
                data.data = handleTree(data.data, "id","parentId");
                this.deptOptions = data.data;
                this.$refs.layoutTable.showType="treetable"
            },

            handleAdd(row) {
                this.$refs.dialogform.add(row, this.deptOptions);
            },

            /** 重写新增方法 */
            toAdd(row) {
              console.log("deptOptions", this.deptOptions)
              this.$refs.dialogform.add(row, this.deptOptions);
            },
            /** 重写编辑方法 */
            toEdit(row) {
                this.loading = true;
                this.$post(this.pageInfo.exclude+"?id="+row.id,{})
                    .then((res) => {
                        if (res && res.code && res.code == 1) {
                            this.deptOptions = handleTree(res.data.result);
                            this.$refs.dialogform.edit(row, this.deptOptions);
                            this.loading = false;
                        }
                    })
                    .catch((error) => {
                        this.$message.error(error.message);
                    });
            },
            /** 重写查看方法 */
            toView(row) {
                this.$refs.dialogform.view(row, this.deptOptions);
            },
          afterDel(data) {
              this.getData()
          },
        },
        data() {
            return {
                config: {
                    /** 树表是否默认展开 */
                    expand:true,
                    showType: "treetable",
                    search: [
                        {
                            name: "deptName",
                            type: "text",
                            label: "部门名称",
                            fuzzy: true
                        }
                    ],
                    columns: [
                        {label: "部门名称", prop: "deptName"},
                        {label: "部门状态", prop: "deptStatus",formatter:this.formatter},
                        {
                            label: "操作",
                            width: 280,
                            formatter: row => {
                                return (
                                    <div>
                                        <el-button
                                            size="mini"
                                            type="text"
                                            icon="el-icon-edit-outline"
                                            onClick={() => {
                                                this.handleAdd(row);
                                            }}
                                        >
                                            新增
                                        </el-button>
                                        <table-buttons
                                            noAdd
                                            noView
                                            row={row}
                                            onEdit={this.toEdit}
                                            onView={this.toView}
                                            onDel={this.toDel}
                                        />
                                    </div>
                                );
                            }
                        }
                    ]
                }
            };
        }
    };
</script>
