<template>
  <div>
    <el-select
      v-model="value"
      filterable
      placeholder="请选择"
      @change="handleChange"
    >
      <el-option
        v-for="item in list"
        :key="item.agent_id"
        :value="item.agent_id"
        :label="item.agent_name"
      />
    </el-select>
  </div>
</template>

<script>
import { fetchCommonTable } from "@/api/common";
export default {
  name: "ZxAgentSelect",
  props: {
    pkg: {
      type: String,
      default: "",
    },
  },

  data() {
    return {
      value: "",
      list: [],
    };
  },

  watch: {
    value(val) {
      this.$emit("input", val);
    },
    pkg(val) {
      this._fetchCommonTable();
    },
  },
  created() {
    this._fetchCommonTable();
  },
  methods: {
    _fetchCommonTable() {
      let params = {
        sqlId: 1109,
        pkg: this.pkg,
      };
      fetchCommonTable(params).then((res) => {
        this.list = res.result.data;
        this.list.unshift({ agent_id: "", agent_name: "全部" });
      });
    },

    handleChange(val) {
      this.$emit("change", val);
    },
  },
};
</script>

<style>
</style>