<template>
  <el-select
    filterable
    :value="value === 0 ? undefined : value"
    @change="change"
    v-bind="$attrs"
    clearable
  >
    <el-option
      v-for="supplier in getSuppliers"
      :key="supplier.id"
      :label="$l(supplier, 'company')"
      :value="supplier.id"
    ></el-option>
  </el-select>
</template>

<script>
/**
 * 供应商
 */
export default {
  name: "supplierSelect",
  props: {
    companyType: String,
    value: Number,
    allSupplier: Array,
    areaType: {
      type: Number,
      default: 0
    },
  },
  model: {
    prop: "value",
    event: "change",
  },
  data() {
    return {};
  },
  computed: {
    getSuppliers() {
      let allSupplier = this.allSupplier.filter(
        (item) => item.areaType == this.areaType
      );
      if(this.areaType == 1 || !this.companyType) return allSupplier;
      return allSupplier.filter((item) =>
        item.companyTypes.includes(this.companyType)
      );
    },
  },
  methods: {
    change(val) {
      this.$emit("change", val);
    },
  },
};
</script>
