<template>
  <div id="modelFile">
    <span class="modelFile" style="margin-right: 12px;">模型文件夹</span>
    <el-select v-model="casVal" filterable clearable placeholder="请选择模型文件夹" style="width:160px;" @change="handleChange">
      <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
    </el-select>
  </div>
</template>
<script>
import tools from "@/utils/scan/tools"
import request from "@/api/model/file.js";
import { mapGetters, mapActions } from "vuex"

export default {
  computed: {
    ...mapGetters("layout", ["projectId", "secret", "userId"])
  },
  data() {
    return {
      casVal: '',
      options: []
    };
  },
  created() {
    this.init()
  },
  watch: {
    projectId() {
      this.casVal = ''
      this.options = []
      this.init()
    }
  },
  methods: {
    //设置默认选项
    setValue(val) {
      if (val && val.length) {
        this.casVal = val
      }
    },
    //获取数据
    init() {
      this.getDirectory()
    },
    // 获取文件夹
    getDirectory() {
      request.queryModel("", res => {
        this.options = res.Content.map(t => {
          return {
            value: t.Id,
            label: t.Name
          }
        })
      });
    },
    //改变item
    handleChange(value) {
      this.options.map(item =>{
        if (item.value == value) {
          value = item
        }
      })
      value = value?value:{value:''}
      this.$emit("change", value)
    }
  }
};
</script>
<style lang="less">
.el-cascader .el-input .el-input__inner {
  vertical-align: bottom;
}
</style>
<style lang="less" scoped>
#modelFile {
  margin-left: 10px;
  float: left;
  .modelFile {
    color: #999999;
    font-size: 14px;
  }
}
</style>