<template>
    <div id="modelFile">
        <span class="modelFile" style="margin-right: 12px;">模型文件</span>
        <el-cascader :options="options" :props="props" :show-all-levels="false" @change="handleChange" style="width:160px;"
        clearable placeholder="请选择模型文件" v-model="casVal"></el-cascader>
    </div>
</template>
<script>
import tools from "@/utils/scan/tools"
import { queryModelFile } from "@/api/data_admin/buildTaskApi"
import { mapGetters, mapActions } from "vuex"

export default {
  computed: {
    ...mapGetters("layout", [ "projectId", "secret", "userId" ])
  },
  data() {
    return {
      casVal: [],
      options: [],
      modelIdToFloorId: {},
      props: {
        value: "fileId",
        label: "fileName",
        children: "fileList"
      },
    };
  },
  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() {
      queryModelFile("", res => {
        this.options = res.content.map(item => {
          item.fileId = item.folderId
          item.fileName = item.folderName
          return item
        })
      });
    },
    //改变item
    handleChange(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>
