<template>
  <el-select
    v-model="vModel"
    placeholder="请选择"
    filterable
    clearable
    v-bind="$attrs"
    @change="onChange"
  >
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value"
    >
    </el-option>
  </el-select>
</template>

<script>
import { getPage } from '@/api/scene';

export default {
  name: 'SceneSelect',

  props: {
    value: {
      type: String,
      default: ''
    }
  },

  data() {
    return {
      vModel: this.value,
      options: []
    };
  },

  watch: {
    value: {
      handler(val) {
        this.vModel = val;
      },
      immediate: true
    }
  },

  mounted() {
    this.loadData();
  },

  methods: {
    onChange(value) {
      console.log(value);
      this.$emit('input', value || null);
    },

    async loadData() {
      const { success, data, msg } = await getPage({
        isDel: false,
        auditStatus: 1,
        page: 1,
        size: 999999
      });
      if (success) {
        this.options = data.data.map(x => ({
          value: x.id,
          label: x.name
        }));
      }
    }
  }
};
</script>

<style lang="scss" scoped></style>
