<template>
  <div id="cascaderMap">
    <span class="buildFloor" style="margin-right: 12px;">竖井类型</span>
    <el-select v-model="id" @change="changeVal">
    <el-option
      v-for="item in options"
      :key="item.id"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import { getCenoteType } from "@/api/scan/request";
export default {
  name: "getCode",
  computed: {
    ...mapGetters("layout", ["projectId", "secret", "userId"])
  },
  data() {
    return {
      id: "",
      options: []
    };
  },
  created() {
    this.getData()
  },
  watch: {
    projectId() {
      this.getData()
      if (this.options.length) {
        this.changeVal(this.options[0].id)
      }
    }
  },
  methods: {
    //修改val
    changeVal(val) {
      let value = {};
      this.options.map(item => {
        if (item.id == val) {
          value = item;
        }
      });
      this.id = val;
      this.$emit("change", value);
    },
    async getData() {
      let param = {
        projectId: this.projectId
      }
      await getCenoteType (param, res => {
        let data = res.content;
        data.unshift({
          id: "",
          name: "全部"
        });
        this.options = data;
        this.id = "";
      })
    }
  }
};
</script>
<style lang="less" scoped>
#cascaderMap {
  float: left;
  margin-left: 10px;
  .buildFloor {
    color: #999999;
    font-size: 14px;
  }
}
</style>
