<template>
  <div class="table_in_s">
    <el-select
      ref="inp"
      v-model="selectValue"
      :disabled="couldNotEdit || name == ''"
      size="small"
      @input="changeValue"
      class="table_in_select"
      placeholder="请选择"
    >
      <template v-if="selectArr && selectArr.length > 0">
        <el-option
          v-for="(items, index) in selectArr"
          :key="index+3500"
          :label="items.label"
          :value="items.value"
        ></el-option>
      </template>
    </el-select>
  </div>
</template>

<script>
import helper from "@/services/helper";
export default {
  props: {
    selectArr: {
      type: Array,
      default: () => {
        [];
      }
    },
    item: {
      default: ""
    },
    header: {
      type: String,
      default: ""
    },
    id: {
      type: [String, Number],
      default: ""
    },
    name: {
      type: String
    },
    rowId: {
      type: Number
    },
    couldNotEdit: {
      type: Boolean,
      default: false
    },
    hasDefault: {
      type: Boolean,
      default: false
    }
  },
  data: () => ({
    selectValue: "0"
  }),
  mounted() {
    this.selectValue = this.item;
    if (
      this.selectValue == null ||
      !this.selectValue ||
      this.selectValue == ""
    ) {
      if (this.selectArr && this.selectArr.length != 0) {
        if (this.hasDefault) {
          this.selectValue = this.selectArr[0].value;
        } else {
          this.selectValue = "";
        }
      } else {
        this.selectValue = "";
      }
    }
  },
  methods: {
    changeValue() {
      this.$emit("changeInputValue", {
        rowId: this.rowId,
        header: this.header,
        inputValue: this.selectValue,
        id: this.id
      });
    }
  }
};
</script>
<style scoped>
.table_in_s {
  height: 32px;
}

.table_in_select {
  text-align: center;
  font-size: 14px;
}
</style>
<style>
.table_in_s input {
  width: 100%;
  background-color: #f7f8f9;
  border-radius: 4px;
}
.table_in_s .el-input.is-disabled .el-input__inner {
  color: #70747c;
}
</style>