<template>
    <div>
        <el-select ref="orgTree" v-model="selectValue" :multiple="opts.multiSelect" :placeholder="opts.placeholder">
            <el-option
                v-for="item in selectData"
                :key="item.fdId"
                :label="item.fdName"
                :value="item.fdId">
            </el-option>
        </el-select>
    </div>
</template>

<script>

import OrgBase from "./OrgBase";
import {handleDefaultParams} from "ap-util/util/ObjectUtil";

export default {
    name: "OrgTree",
    components: {},
    extends: OrgBase,
    props: {
        options: {
            type: Object,
            required: true
        },
        orgValue: {
            required: false
        },
    },
    data() {
        return {
            opts: {},
            selectValue: this.orgValue,
            selectData: []
        }
    },
    watch: {
        selectValue: {
            handler(value) {
                this.setOrgValue(value);
            },
            deep: true
        },
    },
    created() {

        // 默认参数设定
        this.opts = handleDefaultParams(this.options, {
            value: "",
            placeholder: "请选择",
            multiSelect: false,
            code: "",
            addOptions: [],
            params: {}
        });
        this.init();
    },
    methods: {
        init() {
            this.$request({
                url: '/apm/open/org/getOrgListByOrgGroup',
                method: 'post',
                data:  this.getParams(this.opts.params)
            }).then((response) => {
                let res = [];
                if (response.data != null) {
                    res = response.data;
                }
                this.selectData = this.getAddOptions().concat(res)
            });
        },
        getAddOptions(){
            let adds = this.opts.addOptions;
            let res = [];
            for (let i = 0; i < adds.length; i++) {
                res.push({
                    fdId:adds[i].value,
                    fdName:adds[i].label
                })
            }
            return res;
        },
    }
}
</script>

<style scoped>
</style>
