<template>
  <el-select
    :value="projectId"
    placeholder="请选择项目名称"
    filterable
    clearable
    :disabled="disabled"
    @change="handleInput"
  >
    <el-option
      v-for="item in options"
      :key="item.id"
      :label="item.projectName"
      :value="item.id"
    >
    </el-option>
  </el-select>
</template>
<script>
export default {
  props: {
    value: {
      type: String,
      default: '',
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      options: [],
    }
  },
  // mounted() {
  //   this.getProjectData(this.year)
  // },
  computed: {
    projectId() {
      return this.value
    },
  },
  methods: {
    getProjectData(year){
      let params = {
        pageBean: {
          page: 1,
          pageSize: -1,
          showTotal: true,
        }
      }
      if (year) {
        params.querys = [
          {
            operation: "BETWEEN",
            parentGroup: "",
            property: "commencement_time_",
            relation: "AND",
            value: [
                `${year}-01-01 00:00:00`,
               `${year}-12-31 23:59:59`
            ]
          },
        ]
      }
      this.$http
        .post('${cqxy}/biz/projectManagement/pm/v1/page', params)
        .then((resp) => {
          let response = resp.data.value
            this.options = response.rows
        })
    },
    handleInput(val) {
      let arr = this.options.filter((item) => {
        return item.id == val
      })
      this.$emit('input', val, ...arr)
      this.$emit('select', val, ...arr)
    },
  },
}
</script>
<style scoped></style>
