<template>
    <lj-list-tree-choose-common :allItem="allItem" :rawList="rawList" name-field="departmentname" button-field="departmentname" id-field="departmentid" @item-selected="handleItemSelected" ref="base"/>
</template>
<script>
    import LjListTreeChooseCommon from "components/lj-list-tree-choose-common";
    export default{
        name: "l1-department-choose",
        components: {LjListTreeChooseCommon},
        data() {
            return {
                eventName: "dept-chosen",
                allItem: { departmentid: -1, departmentname: "全部", handtype: "全部", sonflag: 0, parentid: 0 },
                rawList: []
            }
        },
        created() {
            this.getDataList();
        },
        methods: {
            open() {
                this.$refs.base.init();
                this.$refs.base.open();
            },
            handleItemSelected(item) {
                this.$emit(this.eventName, item);
            },
            getDataList() {
                let self = this;
                $lj.postLJRequest(
                    "GetL1Department", {
                        token: $lj.getStorage("token")
                    },
                    function(ret) {
                        if (ret) {
                            self.rawList = ret.DepartmentList;
                        }
                    }
                );
            }
        }
    }
</script>