<template>
  <el-dialog
    title="请选择目标文件夹（必选）"
    :visible.sync="visible"
    width="500px">
      <div class="folder-select" v-for="firstLevel of listData" :key="firstLevel.b_id">
        <!-- 第一层 -->
        <div :class="{canSelect: !(firstLevel.children && firstLevel.children.length > 0)}" class="folder-line select-first"  @click="upload(firstLevel)">
          <i class="el-icon-folder folder-icon"></i>
          <span class="folderName">{{ firstLevel.folder_name }}</span>
        </div>
        <div v-if="firstLevel.children && firstLevel.children.length > 0">
          <!-- 第二层 -->
          <div v-for="secondLevel of firstLevel.children" :key="secondLevel.b_id" class="select-padding">
            <div :class="{canSelect: !(secondLevel.children && secondLevel.children.length > 0)}" class="folder-line"  @click="upload(secondLevel)">
              <i class="el-icon-folder folder-icon"></i>
              <span class="folderName">{{ secondLevel.folder_name }}</span>
            </div>
            <div v-if="secondLevel.children && secondLevel.children.length > 0">
              <!-- 第三层 -->
              <div v-for="thirdLevel of secondLevel.children" :key="thirdLevel.b_id" class="select-padding"  @click="upload(thirdLevel)">
                <div class="folder-line canSelect">
                  <i class="el-icon-folder folder-icon"></i>
                  <span class="folderName">{{ thirdLevel.folder_name }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
  </el-dialog>
</template>

<script>
export default {
    name: 'UploadFile',
    props: {
        listData: {
            type: Array,
            default: () => {
                return []
            }
        },
        selectFolderVisible: {
            type: Boolean,
            default: false
        }
    },
    computed: {
        visible: {
            get () {
                return this.selectFolderVisible
            },
            set (value) {
                this.$emit('closeSelectFolderVisible')
            }
        }
    },
    data () {
        return {
        }
    },
    methods: {
        upload (file) {
            if (!(file.children && file.children.length > 0)) {
                this.$emit('selectUploadFile', file)
            }
            // this.$message({
            //     message: '上传成功',
            //     type: 'success'
            // })
        }
        // close () {
        //     this.$emit('closeSelectFolderVisible')
        // }
    }
}
</script>

<style lang="less" scoped>
.folder-select {
  font-size: 18px;

  .folder-line {
    line-height: 40px;

    .folder-icon {
      font-size: 30px;
      vertical-align: middle;
    }

    .folderName {
      vertical-align: middle;
      margin-left: 5px;
    }
  }

  .select-first {
    padding-left: 10px;
  }

  .select-padding {
    padding-left: 60px;
  }
}

.canSelect {
  cursor: pointer;
  color: black;
  &:hover{
    color: #409eff;
  }
}
</style>
