<template>
  <div id="cascaderMap">
    <span class="buildFloor">所属专业系统类型：</span>
    <el-cascader
      placeholder="请选择"
      :options="options"
      v-model="value"
      :props="props"
      filterable
      :style="isWidth ? '' : 'width:160px;'"
      size="small"
      @change="changeVal"
      change-on-select
    ></el-cascader>
  </div>
</template>
<script>
import { getEqCode } from "@/api/request";
export default {
  name: "getCode",
  props: {
    isWidth: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      value: [],
      options: [],
      props: {
        value: "code",
        label: "facility"
      },
      falg: true,
      content: []
    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  methods: {
    setValue(val) {
      this.value = val
    },
    //修改val
    changeVal(val) {
      let value = {}
      this.options.map(item => {
        if (item.code == val) {
          value = item
        }
      })
      this.$emit("change", value)
    },
    getData() {
      getEqCode().then(res => {
        console.log(res.data)
        this.options = this.changeArr(res.data.Content);
        if (!!this.value && this.value.length) {
          let value = {}
          this.options.map(item => {
            if (item.code == this.value[0]) {
              value = item
            }
          })
          this.$emit("change", value)
        }
        if (!this.falg) {
          this.changeList()
        }
      });
    },
    changeArr(arr) {
      let data = [];
      arr.map(item => {
        if (item.content && item.content.length) {
          return item.content.map(children => {
            data.push({ code: children.code, facility: children.system });
          });
        }
      });
      return data;
    },
    //上级页面传入content
    pushData(content) {
      this.content = content
      if (this.options.length) {
        this.falg = true
        this.changeList()
      } else {
        this.falg = false
      }
    },

    //修改list
    changeList() {
      this.options.map(item => {
        item.disabled = true
        this.content.map(child => {
          if (item.code == child) {
            item.disabled = false
          }
        })
      })
    }
  }
};
</script>
<style lang="less" scoped>
#cascaderMap {
  float: left;
  margin-left: 10px;
  .buildFloor {
    color: #999999;
    font-size: 14px;
  }
}
</style>
