import React,{Component} from "react";
import {message, Select, Spin} from "antd";
import $ from "jquery/src/ajax";

class DepartmentList extends Component{
    constructor(props) {
        super(props);
        this.state={
            departmentArr:[],
        }
    }

    componentDidMount() {
        this.departmentList();
    }

    departmentList() {
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/organization/selectSuperId",
            data: {},
            success: function (data) {
                let thedata = data.data;
                let theArr = [];
                if (!thedata) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                } else {
                    thedata.map(function (item, index) {
                        theArr.push({
                            key: index,
                            name: item.name,
                            id: item.id
                        });
                    });
                }
                this.setState({
                    departmentArr: theArr
                });
            }.bind(this)
        }).always(
            function () {

            }.bind(this)
        );
    }

    render() {
        return(
            <Select
                placeholder="订单部门"
                style={{ width: 150, marginRight: 10 }}
                value={this.props.value}
                onChange={e => {
                    this.props.onChange(e);
                }}
            >
                {this.state.departmentArr.map(function (item) {
                    return <Select.Option key={item.id}>{item.name}</Select.Option>;
                })}
            </Select>
        )
    }
}

export default DepartmentList;
