<template>
    <div style="display: flex;">
        <el-select v-model="value" placeholder="请选择" filterable clearable allow-create default-first-option
            @input="$emit('balabala', value)" @change="getKeyId(value)" :disabled="disabled">
            <template v-if="zhKey">
                <el-option v-for="item in corpList" :key="item.id" :label="item.cname" :value="item.cname">
                </el-option>
            </template>
            <template v-else>
                <el-option v-for="item in corpList" :key="item.cname" :label="item.cname" :value="item.id">
                </el-option>
            </template>
        </el-select>
        <el-tooltip class="item" effect="dark" content="获取最新客户资料" placement="top-start">
            <el-button icon="el-icon-refresh" size="mini" v-if="label != 'shortName'"
                @click="refreshData"></el-button>
        </el-tooltip>
    </div>
</template>

<script>
import { allCropList } from "@/api/basicData/customerInformation";
import { kMaxLength } from "buffer";
export default {
    name: "main",
    data() {
        return {
            form: {},
            corpList: []
        };
    },
    props: {
        value: String,
        disabled: Boolean,
        zhKey: Boolean
    },
    model: {
        prop: "value",
        event: "balabala"
    },
    created() {
        this.getCorpList()
    },
    methods: {
        getCorpList() {
            let userObj = JSON.parse(localStorage.getItem("saber-userInfo")).content;
            allCropList({ corpType: 'KH', adminProfiles: userObj.role_name != "admin" ? userObj.user_id : null }).then(res => {
                this.corpList = res.data.data;
            });
        },
        refreshData() {
            this.getCorpList()
        },
        getKeyId(row) {
            if (this.zhKey) {
                if (row) {
                    let res = this.corpList.find(e => { return e.cname == row })
                    if (res) {
                        this.$emit('getCropId', res.id)
                    } else {
                        this.$emit('getCropId', null)
                    }
                } else {
                    this.$emit('getCropId', null)
                }
            }

        }
    },
    watch: {
    }
};
</script>

<style lang="scss" scoped>
</style>
