<template>
  <el-select
    v-model="assetId"
    filterable
    placeholder="请选择 资产名称"
    :loading="loading"
    :disabled="disabled"
    :multiple="multiple"
    style="width: 100%;"
    @change="handleChange"
  >
    <el-option
      v-for="item in listData"
      :key="item.id"
      :label="item.zcmc"
      :value="item.id">
    </el-option>
  </el-select>
</template>

<script>
import { getList } from "@/api/basicResource/kyAssetList";

export default {
  name: 'ProjectSelect',
  props: {
    value: [String, Number],
    // 搜索条件
    params: Object,
    disabled: {
      type: Boolean,
      default: false
    },
    // 是否多选
    multiple: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      assetId: '',
      loading: false,
      listData: []
    }
  },
  mounted() {
    this.getAssetList();
  },
  methods: {
    getAssetList() {
      getList(1, 99999, this.params).then(({ data }) => {
        if (data.success) {
          this.listData = data.data.records;
          this.assetId = this.value;
        }
      })
    },
    handleChange(val) {
      let objData = this.listData.find(item => item.id === val);

      this.$emit('input', val);
      this.$emit('change', objData);
    },
  }
}
</script>