<template>
  <el-select v-model="placeId" :multiple="multiple" placeholder="请选择" :disabled="disabled" clearable>
    <el-option v-for="item in placeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
  </el-select>
</template>

<script>
export default {
  name: 'placeSelect',
  props: {
    value: {},
    deptId: {},
    multiple: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      placeId: '',
      placeList: []
    };
  },
  watch: {
    value(val) {
      this.placeId = val;
    },
    deptId: {
      handler(newValue, oldValue) {
        if (oldValue != '') {
          this.placeId = '';
        }
        this.getList();
      },
      immediate: true
    },
    placeId(val) {
      this.$emit('input', val);
    }
  },
  mounted() {},
  methods: {
    getList() {
      //场所列表
      this.ajax({ url: '/work/place/list/all', data: { deptId: this.deptId } }).then((response) => {
        this.placeList = response.data;
      });
    }
  }
};
</script>
