<template>
  <LabelBox
    :label="formItems.attrs?.label"
    :need-star="formItems.attrs?.needStar"
    :width="formItems.attrs?.width"
  >
    <el-select
      v-model="value"
      filterable
      remote
      reserve-keyword
      :placeholder="formItems.attrs?.placeholder || '请选择'"
      :clearable="formItems.clearable || true"
      :remote-method="selectApi"
      :loading="loading"
      @focus="selectfocusApi"
      @change="handleInput"
    >
      <el-option
        v-for="item in formItems.options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
  </LabelBox>
</template>

<script>
import LabelBox from '../labelBox/index.vue';

export default {
  components: {
    LabelBox,
  },
  props: {
    formItems: {
      type: Object,
      default: () => {},
    },
    value: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      loading: false,
    };
  },
  methods: {
    handleInput(value) {
      this.$emit('input', value);
    },
    selectApi(val) {
      // this.loading = true;
      this.$emit('outOperation', val);
    },
    // 聚焦时候拿全部数据
    selectfocusApi() {
      // this.loading = true;
      this.$emit('outOperation', undefined);
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep.el-select {
  width: 100%;
  height: 32px;
  line-height: 32px;
}

::v-deep.input-box {
  height: 32px;
}

::v-deep.el-select .el-input__icon {
  height: 32px;
  line-height: 33px;
}

::v-deep.el-select .el-input-group__prepend {
  box-sizing: border-box;
  padding: 0 10px;
  height: 32px;
  line-height: 32px;
  border: none;
}

::v-deep.el-select .el-input__inner {
  height: 32px;
  line-height: 32px;
}
</style>

