<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: "SiteBusiness",
        mixins: [table],
        components: { Treeselect, dialogShow },
        created() {
        },
        methods: {
            afterRender(data) {
                data.result = handleTree(data.result, "businessId","parentId");
                this.siteBusinessOptions = data.result;
                this.$refs.layoutTable.showType="treetable"
            },

            /** 重写新增方法 */
            toAdd(row) {
                this.$refs.dialogform.add(row, this.siteBusinessOptions);
            },
            /** 重写编辑方法 */
            toEdit(row) {
                this.loading = true;
                this.$post(this.pageInfo.exclude, {id : [row.id] })
                    .then((res) => {
                        if (res && res.code && res.code == 1) {
                            this.siteBusinessOptions = handleTree(res.data.result);
                            this.$refs.dialogform.edit(row, this.siteBusinessOptions);
                            this.loading = false;
                        }
                    })
                    .catch((error) => {
                        this.$message.error(error.message);
                    });
            },
            /** 重写查看方法 */
            toView(row) {
                this.$refs.dialogform.view(row, this.siteBusinessOptions);
            },
        },
        data() {
            return {
                config: {
                    /** 树表是否默认展开 */
                    expand:true,
                    showType: "treetable",
                    search: [
                    ],
                    columns: [
                        {label: "站点名称", prop: "siteName"},
                        {label: "业务名称", prop: "businessName"},

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